iterating over other types of geometry inside the attribute wrangle

   4653   3   2
User Avatar
Member
143 posts
Joined: Sept. 2017
Offline
While my question probably boils down to my inability to define a range in VEX, I'll try to describe the whole thing in hopes of someone showing me an example, as I've been unable to find one.

I've been trying to make something like snow, scattered a point cloud onto a model, density dependent on the normal, so only the top parts would be covered, copied metaballs onto the points, which gives me relatively nice results, but there are some stray pieces of geometry, tiny mesh parts, that I want to get rid of, so my idea was to write a VEX function, that would count how many other points each point is connected to, write this to an attribute, and depending on that value, I could delete points, that fall below the treshold of mesh-island-size, that I would want to keep.

The closest I got was to get unique part IDs for every part into a primitive attribute, but I can't seem to be able to get a for/foreach loop to work inside the wrangle, to be able to count the number of primitives, that share the currently evaluated primitive's groupID.

I'll be thankful for examples, other/better ways to achieve this, but most of all for pointers to comprehensive guides on VEX syntax when dealing with loops and ranges, because I feel lost in the documentation when it comes to these topics.
User Avatar
Member
14 posts
Joined: May 2017
Offline
Since you want to compare each primitive to all other primitives, you would use a Primitive Wrangle. Then in a for-loop in that Wrangle you would do something like…

int totalPrims = nprims(geoself());
int num = 0; // Your counter for matching groupID

for (int i = 0; i < totalPrims; i++)
{
    if (i != @primnum) // Don't compare against the prim you're already testing
    {
        int otherPrimGroupId = primitive(geoself(), "groupID", i); // Get the attribute 'groupID' of primitive 'i' for this geometry
        if (i@groupID == otherPrimGroupId)
        {
            num++; // Matching id's, increment your counter
        }
    }
}

I think this is what you want to do, not sure if I entirely understood your question. Let me know!

Not sure if you saw this [www.sidefx.com] documentation. We use that for-loop syntax here, starting with i=0 (prim number 0) incrementing all the way until the total number of prims (nprims).
Edited by sashaouellet - Nov. 22, 2017 18:12:38
User Avatar
Member
8551 posts
Joined: July 2007
Online
assuming that your mesh doesn't already have varying prim attributes or groups
- append Connectivity SOP, and set it to Primitive
- append Polysoup SOP
- append Blast SOP with group like: @intrinsic:measuredarea<0.05

this will delete all pieces whose total area (of all primitives in the piece) is less than 0.05
instead of 0.05 put your own threshold
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
143 posts
Joined: Sept. 2017
Offline
Thanks guys!
  • Quick Links