localstarlight Posted August 7, 2017 Share Posted August 7, 2017 (edited) Suppose I have a position (e.g. [100,200,300]) and directional vector (e.g. [1,0,0]), is there a way in VEX to fire a line trace/ray from that point along that vector and get the position of the first surface primitive that's hit? Edited August 7, 2017 by localstarlight Quote Link to comment Share on other sites More sharing options...
symek Posted August 7, 2017 Share Posted August 7, 2017 9 minutes ago, localstarlight said: Suppose I have a position (e.g. [100,200,300]) and directional vector (e.g. [1,0,0]), is there a way in VEX to fire a line trace/ray from that point along that vector and get the position of the first surface primitive that's hit? in SOPs: intersect() in surface: rayhittest() or trace() Just a friendly remainder, that it is generally recommended to use docs page before asking basic questions on a forum 1 Quote Link to comment Share on other sites More sharing options...
localstarlight Posted August 7, 2017 Author Share Posted August 7, 2017 Great, thanks! I actually did various searches trying to find the answer, but clearly I was not phrasing my question right to turn it up. I only ever post on forums as a last resort, but thanks for the reminder nonetheless 1 Quote Link to comment Share on other sites More sharing options...
localstarlight Posted August 7, 2017 Author Share Posted August 7, 2017 I'm trying to use the first example you gave (SOPs: intersect) but can't get it to work for some reason. Here's the VEX I'm using: vector direction = @N * -100; vector new_position; float u,v; i@intersected_prim = intersect(0, v@P, direction, new_position, u, v); @P = new_position; I'm trying to shoot a trace in the opposite direction to the point normal. Essentially I have a tube mesh surrounding a more complicated shape, and I'm trying to project the points of the mesh inwards onto the more complicated geometry. The attribute @intersected_prim is returning a prim number (which I assume must be the id of a prim on the more complicated inner geo), but new_position doesn't seem to be getting the location of the intersection, and so @P remains unchanged. This is my first time using a VEX function that requires passing a variable by reference, so perhaps I'm doing something wrong with that? Quote Link to comment Share on other sites More sharing options...
symek Posted August 7, 2017 Share Posted August 7, 2017 Since you're tracing over second input's geometry (?), tiny correction is needed (note first argument); i@intersected_prim = intersect(1, v@P, direction, new_position, u, v); I would also recommend initializing new_position, u, v for extra safeness (it used to be mandatory, not sure now). hth, ps sorry also for previous criticism, I didn't notice that naming convention isn't actually very clear in that case. Quote Link to comment Share on other sites More sharing options...
Noobini Posted August 7, 2017 Share Posted August 7, 2017 take out the v in v@P when calling intersect() ? Quote Link to comment Share on other sites More sharing options...
localstarlight Posted August 8, 2017 Author Share Posted August 8, 2017 Hey symek, that did the trick. I had the input listed wrong. Thanks so much for your help! It works without initialising those variables, but good to know that's something to look out for. No apology necessary, I understand it's a bit frustrating when people treat forums as Google For some reason my searching only turned up trace(), which doesn't return the position of intersection, so I wasn't sure it was something VEX actually had. Thanks again for your help. 1 Quote Link to comment Share on other sites More sharing options...
acey195 Posted August 25, 2017 Share Posted August 25, 2017 slightly off-topic: On 8/8/2017 at 1:41 AM, Noobini said: take out the v in v@P when calling intersect() ? No keep it! casting all the variables for the win (and you are forced to cast it when using v@opinput1_P), so I just make it a habit to cast everything, it also avoids creating float attributes, when you really only need integers. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.