Website powered by

Houdini: Remove Outside Pieces Using Python

Tutorial / 04 October 2019

Preparetion

To begin, I made a simple box object with a Voronoi fracture.


The geometry spreadsheet looks like below.
As you can see, there are 2 groups that are "group:inside" and "group:outside".
The primitive whose group:outside is 1 is the one that is on the object's surface.

For Each SOP

Then, I added a For Each SOP node after added a Connectivity SOP node.

Attribute Wrangle 1

In attribwrangle1, I set Run Over "Primitives" and wrote a expression below;

i@grp = @group_outside;

The expression copies Group attribute and paste them into a newly created attribute "grp".

Python

Because I couldn't figure out how to do in VEX, I decided to do in python instead.
The expression is below;

node = hou.pwd()
geo = node.geometry()

lis = list(geo.primIntAttribValues("grp"));

yes = any(lis)

if yes:
    geo.addAttrib(hou.attribType.Prim,"del",1)
else:
    geo.addAttrib(hou.attribType.Prim,"del",0)

 lis = list(geo.primIntAttribValues("grp"));

This returns all the values from "grp" attribute as a list like below;
[1,1,1,0,0,0,1,0,0]

yes = any(lis)

"any()" function returns True if there is a value 1 in the list.
If there is not the value 1 at all, then returns False.

if yes:
    geo.addAttrib(hou.attribType.Prim,"del",1)
else:
    geo.addAttrib(hou.attribType.Prim,"del",0)

If "yes" is True that means there is a value of 1 in the list, then add a value 1 in newly created attribute called "del".
If "yes" is False, then add 0.
So, geometry spreadsheet is below. As you can see, "del" is 1 because there is a value of 1 in "grp" at primitive number 9.

Attribute Wrangle 2

In this node, remove all the primitives whose "del" attribute is 1.
Expression is below;

Result

So, the result is below;

Successfully, all the pieces that have primitives on the surface of the box object.