Skip to content

Instantly share code, notes, and snippets.

@crydalch
Created June 15, 2012 23:16
Show Gist options
  • Save crydalch/2939191 to your computer and use it in GitHub Desktop.
Save crydalch/2939191 to your computer and use it in GitHub Desktop.
Python SOP - Get RBD Fracture Points
# Before this node, use a Partition SOP with $NAME as the rule, and I put a Cache SOP afterwards to cache the result. Thanks to Dan Bodenstein and Jeff Lait for the help in solving this problem.
# This code is called when instances of this SOP cook.
node = hou.pwd()
geo = node.geometry()
# Add code to modify the contents of geo.
allGrps = geo.primGroups()
targetGrps = [x for x in allGrps if node.parm("grpmask").eval() in x.name()]
sim = hou.node(node.parm("dopnetpath").eval()).simulation()
# For each of the groups (each group is a fracture piece), get its position, translate and orient values, and save a tuple of each in this list values[]
values = []
for grp in targetGrps:
dopobj = sim.findObject(grp.name())
sbdata = dopobj.findSubData("Position").options()
tval = sbdata.field("t")
pval = sbdata.field("p")
oval = sbdata.field("orient")
values.append((tval,pval,oval))
# Blast away the old geometry
geo.clear()
# Create the orient attribute
orient_attr = geo.addAttrib(hou.attribType.Point, "orient", (0.0,1.0,0.0,0.0))
# Create a point for each of the old pieces, withe position being properly offset and w/ orientation
for i in values:
point = geo.createPoint()
point.setPosition(i[0] + i[1])
point.setAttribValue(orient_attr,i[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment