Jump to content

Detect surface using VEX


localstarlight

Recommended Posts

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 by localstarlight
Link to comment
Share on other sites

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 :)

  • Like 1
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

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 :P (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.

  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...