Jump to content

find closest primitive with forloop


asnowcappedromance

Recommended Posts

hi,

I got a sphere which I scattered points upon. Now I want to take each single point that I scattered and find its closest primitive of the sphere.

Using xyzdist expression only gets me one primitive, I got to feed that into a foreach sop somehow to run multiple iterations.

How does that work?

happy thanksgiving,

Manu

find_closest_prim.hipnc

Link to comment
Share on other sites

Your scene didn't really make sense, you were running the expression on the spere and the points, and you were using $PT on a primitive group .... not sure what $PT returns when you are looping over primitives .... :/

Anyway, I have attached a scene. Just doing an attrib create on the points to record the nearest prim.

find_closest_prim.hipnc

Link to comment
Share on other sites

uhmm yeah, that makes sense :)

ok so now I copy stamped the primitives to the scattered points, but their positions get screwed up.

Computed their center of mass which I'm applying in a transform sop but the copy sop doesn't want to take that.

Can you check that out?

Thanks,

Manuel

find_closest_prim_v2.hipnc

Link to comment
Share on other sites

If you're just trying to copy the primitives back onto the points, you don't need to transform by the COM of the primitives: you need to transform by the negative position of the point you are trying to copy onto.

Since you are copying geometry off center, you can get the same result by essentially copying onto points at the origin. However, since your points might be moving around (also in attached file), we can just move the primitives in the opposite way the copy will move them instead. This results in the primitives having no net transform and happily in the correct place.

In this case (my file), since the points are driven by a particle simulation, we transform based on the scattered point location, not the moving one.

Finally, disabling Transform Using Template Point Attributes prevents the copy from transforming the primitives based on the particles normal and/or velocity.

Also, instead of the complicated xyzdist expression, I used 3 SOPs to do the job instead. If we generate unique points on the primitives we can still get the same scatter result and then attribute promote the primitive number to the points on each face so when points are scattered on them, they automatically pick up the primitive number.

find_closest_prim_v2.hipnc

Edited by graham
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...