Jump to content
Sign in to follow this  
Navneet Arora

ForEach VEX doubt!

Recommended Posts

hey guys,

  I have various primitives and those have different amount of points on them, for example each one primitive might have 10 points and other might have 20 so it varies like this, Now i want to have an attributes which ranges from 0 to 1 for each primitive just like what we get from curveu attribute in resample node. I know how to do this in for each sop but i want to do this in vex, am somehow not able to get that loop working correctly. I store the array using primpoints to get the points on that primitive and iterate that through a for loop but i am not able to get normalised value ranging from 0 - 1. Can please someone help?

Share this post

Link to post
Share on other sites

Check the attached HIP. You can definitely do this in a single primitive wrangle.

The VEX looks like this:

int pts[] = primpoints(0, @primnum);
int npts = len(pts);
for(int i=0; i<npts; i++) {
    // need to explicitly cast i to float
    // in order to divide integers.
    float u = (float)i / npts;
    setpointattrib(0, "u", pts[i], u, "set");

The tricky bit you might have missed is that you have to explicitly cast your iterator to a float in order to get a float result for u when you're dividing i by npts.


  • Like 1

Share this post

Link to post
Share on other sites

thanks man! that works, i didn't miss that float thing i missed up with setting the attribute i believe. because i did turn that into float but certainly i was not setting up the attribute this way. anyways i really thank you for the help :)

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
Sign in to follow this