import maya.cmds as cmds
# In the "RenderManProceduralShape->Scripts->Pre Shape Python Script" copy the following text:
# import rfm2.api.strings as apistr; import pp_place_blobby; pp_place_blobby.setDataStr(apistr.expand_string("<shape>"))
def setDataStr(shapeName):
tnode = cmds.getAttr(shapeName + '.target')
# If the name of the transform node of the target shape has
# not been specified we assume the RenderManProgram has been
# parented to the polymesh that will "receive" the Blobby.
if len(tnode) == 0:
tnode = cmds.listRelatives(shapeName, parent=True)[0]
tnode = cmds.listRelatives(tnode, parent=True)[0]
scale = str(cmds.getAttr(shapeName + '.scale'))
use_local_space = cmds.getAttr(shapeName + '.use_local_space')
coords = get_coordinates(tnode, use_local_space)
rounded = []
# Reduce precision to 3 decimal places - less text to pass.
for coord in coords:
rounded.append(round(coord,3))
coords_str = " ".join(map(str, rounded))
text = scale + ' ' + str(len(coords)) + ' ' + coords_str
cmds.setAttr(shapeName + '.data', text, type='string')
# Returns a flat list of coords ie. [x0,y0,z0,x1,y1,z1....]
def get_coordinates(tnode, useLocalSpace=True):
verts = []
shape = cmds.listRelatives(tnode, shapes=True)[0]
num_verts = cmds.polyEvaluate(tnode, vertex=True)
for n in range(num_verts):
vert_str = shape + '.vtx[%d]' % n;
vert_pos = cmds.pointPosition(vert_str, local=useLocalSpace)
verts.extend(vert_pos)
return verts