Hey guys,
So I’ve always thought Houdini’s exploded-view node was pretty awesome, and I wanted to try and recreate it inside of Maya (not as a node but a quick python script).
I’ve come very close to getting it to do what I want (see attached images), but there’s a strange offset that’s happening (see third image).
It’s likely a very simple fix which is frustrating :banghead:
Below is the code:
import pymel.core as pmc
sel = pmc.ls(sl=True)
for piece in sel:
cpom = pmc.createNode('closestPointOnMesh')
localPos = pmc.xform(piece, q=1, ws=1, rp=1)
# add localTranslation attributes to connect the cpom to
try:
pmc.addAttr(piece, ln='localPos', at='double3')
attrs = ['localPosX', 'localPosY', 'localPosZ']
for attr in attrs:
pmc.addAttr(piece, ln=attr, at='double', p='localPos')
except: pass
pmc.connectAttr('%s.outMesh'%piece.getShape(), '%s.inMesh'%cpom)
pmc.setAttr('%s.localPosX' % piece, localPos[0])
pmc.setAttr('%s.localPosY' % piece, localPos[1])
pmc.setAttr('%s.localPosZ' % piece, localPos[2])
pmc.connectAttr('%s.localPosX'%piece, '%s.inPositionX'%cpom)
pmc.connectAttr('%s.localPosY'%piece, '%s.inPositionY'%cpom)
pmc.connectAttr('%s.localPosZ'%piece, '%s.inPositionZ'%cpom)
unitVector = pmc.getAttr('%s.inPosition'%cpom)
newPos = []
for i in range(len(unitVector)):
newPos.append(unitVector[i])
piece.translate.set(newPos)
# cleanup all closest point on mesh nodes
for node in pmc.ls('closest*'):
pmc.delete(node)
I should mention: the reason why I added the localPos attributes was to take into consideration that the individual pieces might have their transformations frozen, and we want the world-space positions, but the closestPointOnMesh node wants the local translation values.
Let me know if you figure this out.
__
cw