Jump to content

Find the longest edge of a triangle primitive and sort points on that.


Smicksus

Recommended Posts

Hi there,

I'm working on a setup where I need to find the longest side of a triangle and sort the points based on that.
Can someone help me out here with the vex?

I've attached an image what needs to happen:

- I have triangle with random point order from 0, 1, 2. (eventually in a for each primitive with lots of triangles)
- I need the point order to be 0 and 1 on the longest edge and 2 needs to be on the remaining point.

I've attached a simple hip scene for practice.

Thanks in advance for the help! This would help me a lot :)

 

screencap.png

Traingle_sort_debug.hip

Link to comment
Share on other sites

Hi,

You can write some VEX in a Primitive Wrangle SOP like this:

int pts [ ] = primpoints ( 0, @primnum );
vector pos [ ] = array ( );

foreach ( int pt; pts )
{
    vector p = point ( 0, "P", pt );
    append ( pos, p );
}

int closed = primintrinsic ( 0, "closed", @primnum );
if ( closed )
{
    append ( pts, pts [ 0 ] );
    append ( pos, pos [ 0 ] );
}

int count = len ( pts ) - 1;
for ( int i = 0; i < count; ++i )
{
    float s = distance2 ( pos [ i ], pos [ i + 1 ] );
    setpointattrib ( 0, "length", pts [ i ], s );
}

Then sort points using the length attribute with a Sort SOP, and make sure to turn on Reverse Point Sort.

image.thumb.png.5e0a234df7b45c64c525f85bf661f75f.png

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