Jump to content

ForEach VEX doubt!


Navneet Arora

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?

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

foreach_prim_curveu.hip

  • 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...