Hi there,
What I want to do kinda works already, but I’d appreciate some insights I think I might be missing:
- Goal: Simulated (rigid) object on an elastic string, like a cat toy
- Simulation on proxy object shall be transferred to highres object
Problem:
- The bullet enginge does not give me the desired result (and it can drive me crazy)
- Ncloth is great, also for rigid objects, but it changes the shape and doesn’t give me the transform (required for transferring the animation from the proxy object)
My solution (see script):
- Attach locators to three vertices
- create 2 joint with IK handle and pole vector constraint, then attach objects to joint
My questions:
- I might be old school, is there a better way to simulate this type of rigid body (maybe a plugin I’m unaware of)? Is it me or is bullet really annoying?
- How would you make the elastic string? Hair solver?
- Is there a better non-expression way (without plugins! - including the bonus tools ones) to attach transforms to a vertex?
- Is there are more elegant way to transfer ncloth simulation to a transform?
Here’s the code:
import maya.cmds as mc
def nclothToTransform(ncloth = None, vtx1 = 9, vtx2 = 11, vtx3 = 10):
if not ncloth:
ncloth = mc.ls(sl = True)[0]
loc1 = '%s_loc1'%(ncloth)
loc2 = '%s_loc2'%(ncloth)
loc3 = '%s_loc3'%(ncloth)
for loc in [loc1,loc2,loc3]:
if mc.objExists(loc):
mc.delete(loc)
mc.spaceLocator(n = loc1)
mc.spaceLocator(n = loc2)
mc.spaceLocator(n = loc3)
mc.addAttr(loc1, ln = 'vtxNum', k = 1, at = 'double', dv = vtx1)
mc.addAttr(loc2, ln = 'vtxNum', k = 1, at = 'double', dv = vtx2)
mc.addAttr(loc3, ln = 'vtxNum', k = 1, at = 'double', dv = vtx3)
exp = ['float $pos[] = `pointPosition -w %s.vtx[%s.vtxNum]`;'%(ncloth, loc1), \
'%s.translateX = $pos[0]; %s.translateY = $pos[1]; %s.translateZ = $pos[2];'%(loc1, loc1, loc1), \
'float $pos[] = `pointPosition -w %s.vtx[%s.vtxNum]`;'%(ncloth, loc2), \
'%s.translateX = $pos[0]; %s.translateY = $pos[1]; %s.translateZ = $pos[2];'%(loc2, loc2, loc2), \
'float $pos[] = `pointPosition -w %s.vtx[%s.vtxNum]`;'%(ncloth, loc3), \
'%s.translateX = $pos[0]; %s.translateY = $pos[1]; %s.translateZ = $pos[2];'%(loc3, loc3, loc3)]
mc.expression(n = '%s_transExp'%ncloth, s = '\n'.join(exp))
mc.select( cl = True)
j1 = mc.joint(p = [0,0,0], n ='%s_jt%03d'%(ncloth, 1))
j2 = mc.joint(p = [0,0,0], n ='%s_jt%03d'%(ncloth, 2))
mc.pointConstraint(loc1, j1, mo = False)
c = mc.pointConstraint(loc2, j2, mo = False)
mc.delete(c)
handle, effector = mc.ikHandle( sj=j1, ee=j2, p=1, w=1, n='%s_IKHandle'%ncloth, sol='ikRPsolver' )
mc.pointConstraint(loc2, handle, mo = False)
mc.poleVectorConstraint(loc3, handle, weight = 1)
Thanks!