Welcome to od|forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

localstarlight

Detect surface using VEX

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

Share this post


Link to post
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 :)

1 person likes this

Share this post


Link to post
Share on other sites

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 person likes this

Share this post


Link to post
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?

Share this post


Link to post
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. 

Share this post


Link to post
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.

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now