Jump to content
konstantin magnus

U coordinate on closed prim

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.

u_Coord.jpg

Edited by konstantin magnus
Added sketch

Share this post


Link to post
Share on other sites
galagast    88

Hi, would a non-vex approach fit your needs?

1. Convert SOP: Convert to Nurbs; U Order 2.
2. UV Texture SOP: Type Arc Length; Attrib as Point.
3. Use the resulting uv.x point attribute.

u_coord.hiplc - H16.0.689 Indie

Share this post


Link to post
Share on other sites
galagast    88

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

image.png.0d0ef280ad2380b6a8fa74828de17e40.png

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

Cheers!
Jeff

  • Like 2

Share this post


Link to post
Share on other sites
f1480187    456

@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":

as_open.gif.d6bd7ecc5b0ef1aff1d5c85f407a1aa6.gif

as_unrolled.gif.b0af5625e3bef12a8ef7d83a38f5d0f1.gif

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Alright, thank you both! I mainly wanted to make sure I am not missing something obvious. Like there is no intrinsic U attribute or a dedicated function.

Edited by konstantin magnus

Share this post


Link to post
Share on other sites
satoru    4

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

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

×