Hi all,
I have a group of prims and I'd like to loop over them and PolyBridge to the nearest other prim in the group. Can anyone point me in the right direction as to how this might be achieved?
I appreciate this is probably straightforward (if not completely trivial) in VEX - but this more an exercise in the Nodes available to me in Houdini as opposed to reinventing the wheel every time in VEX.
Thanks
Dave
PolyBridge to Nearest Prim
5328 7 2- Calx
- Member
- 8 posts
- Joined: 3月 2017
- Offline
- A-OC
- Member
- 253 posts
- Joined: 7月 2006
- Offline
- Calx
- Member
- 8 posts
- Joined: 3月 2017
- Offline
Sure, example scene attached.
And a bit of psuedocode to explain what I want to do in the loop.
Genuinely appreciate the help
Thanks
Dave
And a bit of psuedocode to explain what I want to do in the loop.
Genuinely appreciate the help
Thanks
Dave
for (prim this_prim in Group_ENDS) { prim closest_prim; float smallest_dist = BIG_NUMBER; for (prim that_prim in Group_ENDS) { if(this_prim != that_prim) { float this_dist = distance(this_prim, that_prim); if(this_dist < smallest_dist) { smallest_dist = this_dist; closest_prim = that_prim; } } } polybridge(this_prim, closest_prim); remove_from_group(this_prim); remove_from_group(closest_prim); }
Edited by Calx - 2019年8月4日 07:59:56
- A-OC
- Member
- 253 posts
- Joined: 7月 2006
- Offline
- Calx
- Member
- 8 posts
- Joined: 3月 2017
- Offline
A-OC
Hey, this turned out a bit more complicated than I thought.
The first thing to note is that I stole the node “create_explicit_lines” from the Connect Adjacent Pieces sop. Then, it's a matter of creating the two groups and the attribute as the piece to loop over in the for-each.
Thanks for spending time on this, really appreciated. Huge step forward for me.
In the example scene everything works perfectly, but when i dropped it into my actual work file, SOME of the faces bridge with the incorrect winding, so i suppose my next rabbithole is working out how to unify everything before running the approach you've outline as I have no way of specifying winding order per pair.
As you can see on the attached, the pairs in the blue box bridged perfectly, but the pairs in the yellow box need winding order reversing in order to get the correct result.
- A-OC
- Member
- 253 posts
- Joined: 7月 2006
- Offline
- A-OC
- Member
- 253 posts
- Joined: 7月 2006
- Offline
Now that I'm testing this further, it will work better if you compare the face normal to the vector defined by the face center pointing to the other face. To clarify, let's define:
n1 = face normal 1
n2 = face normal 2
fc1 = face center 1
fc2 = face center 2
vec1 = normalize( fc2 - fc1 );
vec2 = normalize( fc1 - fc2 );
dot_p1 = dot( n1, vec1 );
dot_p2 = dot( n2, vec2 );
if ( dot_p1 < 0 ) flip face 1
if ( dot_p2 < 0 ) flip face 2
n1 = face normal 1
n2 = face normal 2
fc1 = face center 1
fc2 = face center 2
vec1 = normalize( fc2 - fc1 );
vec2 = normalize( fc1 - fc2 );
dot_p1 = dot( n1, vec1 );
dot_p2 = dot( n2, vec2 );
if ( dot_p1 < 0 ) flip face 1
if ( dot_p2 < 0 ) flip face 2
- Calx
- Member
- 8 posts
- Joined: 3月 2017
- Offline
-
- Quick Links