wrend
10-26-2010, 02:39 PM
I feel kind of ashamed asking it, but can someone kindly help me out converting the python code below to mel? My transform matrix knowledge just aint quite there, which is crap, but perhaps this will help push it along.
import maya.OpenMaya as om
vec_1 = [1, 2, 3]
vec_2 = [4, 5, 6]
cross = [vec_1[1]*vec_2[2] - vec_1[2]*vec_2[1], vec_1[2]*vec_2[0] - vec_1[0]*vec_2[2], vec_1[0]*vec_2[1] - vec_1[1]*vec_2[0]]
tMatrix = vec_1 + [0] + vec_2 + [0] + cross + [0,0,0,0,1]
mMatrix = om.MMatrix()
om.MScriptUtil.createMatrixFromList(tMatrix, mMatrix)
tmMatrix = om.MTransformationMatrix(mMatrix)
rotate = tmMatrix.eulerRotation().reorder(om.MEulerRotation.kXYZ)
This is an aim constraint. Code slightly modified from an older post on google group 'python_inside_maya'.
My problems are in ensuring construction of the matrix correctly (as done by createMatrixFromList), and then extracting the euler rotation from it.
So its basic transform matrix manipulations that I'm missing. Needs to be done by hand in mel, for a mel proc. Why mel? Because the overhead of calling a mel proc compared to a python function (in their respective environments) starts to count when many thousands of calls are strung together. A python scripted command plug was even slower than a standard func (due to overheads in cmd construction?). A node is not an option (well, it is, but not at my current level).
Much appreciated.
import maya.OpenMaya as om
vec_1 = [1, 2, 3]
vec_2 = [4, 5, 6]
cross = [vec_1[1]*vec_2[2] - vec_1[2]*vec_2[1], vec_1[2]*vec_2[0] - vec_1[0]*vec_2[2], vec_1[0]*vec_2[1] - vec_1[1]*vec_2[0]]
tMatrix = vec_1 + [0] + vec_2 + [0] + cross + [0,0,0,0,1]
mMatrix = om.MMatrix()
om.MScriptUtil.createMatrixFromList(tMatrix, mMatrix)
tmMatrix = om.MTransformationMatrix(mMatrix)
rotate = tmMatrix.eulerRotation().reorder(om.MEulerRotation.kXYZ)
This is an aim constraint. Code slightly modified from an older post on google group 'python_inside_maya'.
My problems are in ensuring construction of the matrix correctly (as done by createMatrixFromList), and then extracting the euler rotation from it.
So its basic transform matrix manipulations that I'm missing. Needs to be done by hand in mel, for a mel proc. Why mel? Because the overhead of calling a mel proc compared to a python function (in their respective environments) starts to count when many thousands of calls are strung together. A python scripted command plug was even slower than a standard func (due to overheads in cmd construction?). A node is not an option (well, it is, but not at my current level).
Much appreciated.
