Jump to content

U coordinate on closed prim

konstantin magnus

Recommended Posts

How can I read the U coordinate (from 0 to 1) of closed primitives in VEX?

I tried xyzdist and primuv ...

int prim;
vector uv;
xyzdist(0, @P, prim, uv);
v@uv_profile = set(uv.x, 0, 0);

... but I only got results that did not represent the relative distance between the vertices.


Edited by konstantin magnus
Added sketch
Link to comment
Share on other sites

No worries, I tried to have go at it in VEX, but I'm not entirely sure if the results are correct or accurate.

In the attached file, as it turns out, the initial SOPs method (in red) I suggested does seem to appear incorrect when laid out as a straight line. The VEX method (in green) seems to visually appear more correct.

Compare the points 4 to 8..


If I turn off the Closed toggle of the Curve SOP, the RED line will match the GREEN line.

Have a look at the setup, and see if it anywhere near the direction you wanted.
u_coord2.hiplc - H16.0.689 Indie

My head is kinda twirling at the moment, I may need to sleep this through for now :))


  • Like 2
Link to comment
Share on other sites

@galagast, thanks! I updated my own snippet with closure check to work like yours.


Here is what I got:

// Detail wrangle.
float length = primintrinsic(0, "measuredperimeter", 0);

// Set to false if value of 1.0 is unwanted for the last point
// of closed prims and instead need to be treated as if point with
// u=1 is coincident with the first point (like in unrolled prims).
int as_open = true;

// Compensate for closing auto-edge length.
if (as_open && primintrinsic(0, "closed", 0))
    vector auto_edge = point(0, "P", 0) - point(0, "P", @numpt-1);
    length -= length(auto_edge);

// Compute curve u.
float passed = 0;
for (int i = 1; i < @numpt; i++)
    vector d = point(0, "P", i) - point(0, "P", i-1);
    passed += length(d);
    setpointattrib(0, "u", i, passed/length);


Difference between behaviors "as open" and "as unrolled":



  • Like 2
  • Thanks 1
Link to comment
Share on other sites

I think primuvconvert function will be helpful for intrinsic uv attribute.


An example of code to get relative distance between the vertices.


// Run Over -> Points
int prim;
vector uv;
xyzdist(0, @P, prim, uv);

int mode = 4; // PRIMUV_UNIT_TO_UNITLEN
u@uv_profile = primuvconvert(@OpInput1, set(uv.x, 0.0), prim, mode);


Edited by satoru
  • Like 3
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.

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