I’m fairly new to scripting, so please bear with me. I’ve never used PyMel or API before, just Maya cmds.
I’m trying to make a simple animation mirroring script for Maya 2012 (I know I can just use the bonus tools in Maya, but I’d really like to make my own). I want it to be able to mirror bone animation as well as rig animation in the end. I realize that by trying to mirror bone animation, I’m making more work for myself (the joint orients will probably get messed up), but I’d like to try.
From my research, it seems that the majority of people use matrices for this sort of thing(though I don’t fully understand why).
As a way to test mirroring one object’s transform to another object, I wrote this script:
import maya.cmds as cmds
import pymel.core as pm
import pymel.core.datatypes as dt
currentSelection1= pm.ls(selection=True)[0]
currentSelection2= pm.ls(selection=True)[1]
currentMatrix = currentSelection1.getMatrix(worldSpace=True)
print currentMatrix.formated()
reflectionMatrix_YZ = dt.Matrix(-1.0,0.0,0.0,0.0, 0.0,1.0,0.0,0.0, 0.0,0.0,1.0,0.0, 0.0,0.0,0.0,1.0)
newMatrix = currentMatrix * reflectionMatrix_YZ
currentSelection2.setMatrix(newMatrix , worldSpace=True)
newReflectedMatrix = currentSelection2.getMatrix(worldSpace=True)
print newReflectedMatrix .formated()
On first look, it SEEMS like it works. However, the “currentSelection2” object ends up with -1 scale in Z.
My question(s) is: How can I mirror something, using matrices, without getting negative scale? Is there a better way to do this? Do I even need to use matrices?
Thank you in advance.