# Procedural grouping (grouping leafs of a tree)

## Recommended Posts

Hello,

I have this crude tree, and I want to group all ‘leaves’. The leafs are not connected to the tree, they just float around, and all of them are just these two prim squares. I can't find a way to make the grouping. I guess an expression or primitive wrangle could help, but I am a novice in these things.

##### Share on other sites

a primitive wrangle would be the solution with the pretty much the best performance yeah

I guess something like this could work (typing this from the top of my head, could have typo's/errors):

```////

int connectedVertCount, i, pts[];

connectedVertCount = 0;
pts = primpoints(0, @primnum);

for(i = 0; i < @numvtx; i++)
{
connectedVertCount += len( pointvertices(0, pts[i]));
}

@group_leaves = (connectedVertCount == 5); ```

##### Share on other sites

If the vertex count is the same/similar, you can do something like this inside a Primitive Wrangle node:

if ( primvertexcount ( 0, @primnum ) == 8 )

i@group_leaves = 1;

EDIT: Thought it was a single polygon, disregard this answer

Edited by pusat
##### Share on other sites

or you can use combination of Assemble SOP and Measure SOP. Assemble will make a name attribute for each polygon island which you can loop over. in the For each loop use Measure SOP and measure area of each polygon island. since all leaves will have the same area you can group them by area attribute. this is a slower method than wrangle but i'd say it will give better result in this particular case.

##### Share on other sites

I've done this exact thing for trees using the method above to measure the area, works great. Just cache out the new tree with correct groups afterwards and you won't need to worry about speed.

##### Share on other sites

Thank you all, both the wrangle code and the measure technique worked perfectly.

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×