michaelb-01 Posted July 29, 2014 Share Posted July 29, 2014 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 Quote Link to comment Share on other sites More sharing options...
Artem Smirnov Posted August 2, 2014 Share Posted August 2, 2014 (edited) Hm...I belive it must be much more simple, but that what I've got. flip_test_vex.hip Edited August 2, 2014 by Artem Smirnov 1 Quote Link to comment Share on other sites More sharing options...
michaelb-01 Posted August 3, 2014 Author Share Posted August 3, 2014 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! Quote Link to comment Share on other sites More sharing options...
Artem Smirnov Posted August 3, 2014 Share Posted August 3, 2014 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 Quote Link to comment Share on other sites More sharing options...
Pazuzu Posted August 3, 2014 Share Posted August 3, 2014 Very nice solution!! Quote Link to comment Share on other sites More sharing options...
michaelb-01 Posted August 6, 2014 Author Share Posted August 6, 2014 Thanks so much Artem! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.