Jump to content

Recommended Posts

Hi,

 

I have a grid of maybe 1000 triangles which are coloured black. I colour a few points white and use a point cloud and solver to spread the white colour throughout the grid. My intention is that once the triangle primitive turns white it flips 180 degrees. The rotation of the triangle should be such that triangle appears to be rotating away from the white colour. The tricky part is that I can't be sure on which way (and therefore which axis) the triangle will need to flip. My thinking so far is this:

 

Iterate over all black triangles (in vop sop or point wrangle) and find the nearest white point

Find the two points within that triangle that are furthest from my found white point

Set the vector of those two points as my rotation axis 

Flip triangle

 

It seems fairly simple but i'm struggling a little bit, and its an interesting topic finding the nearest point with an attribute above a certain value. I've attached a simple hip file to illustrate what I mean (and a vop sop with a half baked idea!)

 

Cheers,

Mike

 

 

 

 

flip_test_v1.hip

Link to comment
Share on other sites

don't like to write long posts...

The basic idea, as you said, is very simple.

 

Iterate over all black triangles (in vop sop or point wrangle) and find the nearest white point

Find the two points within that triangle that are furthest from my found white point

Set the vector of those two points as my rotation axis 

Flip triangle

But the problem is that while attributes are spreading, the axis may be redefined and triangles will go crazy. So I decided that 
we need to define axis and origin only once, when any point of the prim change its color for the first time. Thats what code inside sop solver is all about. We need to solve only once. So there is "solved" int attrib to chek if prim was already solved.
Then we iterate over prims and for each prim we get two arrays. One with prim point numbers and second with this points color. Then we do a simple bubble sort on the color array and get points in order of their color decreasing. Once we sorted the arrays we chek if there is any point with color and if we have one we build the axis vector from second and third points in the array. First point in the array is used to get axis aligned to top vector. Also the origin vector is defined and prim set to be solved.
Once we get our axis and origin there is no problem in rotating prim around. Rotate vex func is doing all math for us...
 
is my english horrible?)))
  • 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...