# Flipping animation!

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

##### Share on other sites

Hm...I belive it must be much more simple, but that what I've got.

flip_test_vex.hip

Edited by Artem Smirnov
• 1

##### Share on other sites

That works great! And much faster than the method I ended up with! Any chance you could give a brief breakdown of your method (mainly the vex code)? I'm trying to dissect it but its quite advanced for me!

Thanks Artem!

##### 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?)))
• 1

##### Share on other sites

Very nice solution!!

##### Share on other sites

Thanks so much Artem!

## Create an account

Register a new account