Hello there,
I want to copy the transformation from one object onto another while keeping its shape in the exact same position.
I couldn't figure out a better way than first applying the transform matrix and then transforming all the meshes vertexes back by the inverse matrix.
Heres my script:
import maya.cmds as mc
from cgkit.cgtypes import mat4
def copyTransform(source, toCopy):
#get the matrix
m = mc.xform(source, worldSpace = True, matrix=True, query=True)
mInv = mat4(m).inverse()
mc.select(toCopy)
#reset transform
mc.makeIdentity(apply=True, t=1, r=1, s=1, n=0)
mel.eval("performResetTransformations(0)")
#apply source transform
mc.xform(toCopy, worldSpace = True, matrix=m)
#transform all verts inversely
numVerts = mc.polyEvaluate(toCopy,vertex=True)
for i in range(0,numVerts):
n = toCopy+".vtx["+str(i)+"]"
mc.xform(n, matrix=mInv.toList(1))
mel.eval("DeleteHistory")
sel =
mc.ls(sl=True)
last = sel.pop()
for s in sel:
copyTransform(last, s)
It's seems a bit silly to me and im sure there must be a better way... Anyone?
Thanks so much,
seb
--
--
Sebastian Schoellhammer
3DArtist・Technical Director
www.subdivme.com/sebscorner