Convert MMatrix to MFloatMatrix

287 views
Skip to first unread message

Narann

unread,
Sep 28, 2010, 10:23:29 AM9/28/10
to python_inside_maya
Hi all and thanks in advance for help! :)

I'm currently working on a python node wich combine mesh.

Everything work well but every mesh "go o origin". This is normal, I
have to muliply vertex position to the mesh matrix.

The prob is with MFloatMatrix and MMatrix:

inMeshMDagPath = currentInMeshMFnMesh.dagPath() # return MDagPath
object
inMeshInclusiveMMatrix = inMeshMDagPath.inclusiveMatrix() # return
MMatrix

[...later...]

inMeshMPointArray[i] *= inMeshInclusiveMMatrix # multiply the
points to the matrix

The prob is the * operator only work with MFloatMatrix and me, I give
a MMatrix.

I've found there a method from bateman (http://forums.cgsociety.org/
showthread.php?t=598626) but this is C++.

I just would like to know how to convert a MMatrix to a MFloatMatrix
easely in python...

Thanks in advance, have a good day! :)

Viktoras

unread,
Sep 29, 2010, 4:19:42 AM9/29/10
to python_in...@googlegroups.com
inMeshMPointArray is MFloatPointArray? that looks much easier for me
to convert to MPoints. if you're getting that via MFnMesh.getPoints(),
there's the MPointArray version too.

On 2010.09.28 17:23, Narann wrote:
> inMeshMPointArray[i] *= inMeshInclusiveMMatrix # multiply the
> points to the matrix
>
> The prob is the * operator only work with MFloatMatrix and me, I give
> a MMatrix.
>


--
Viktoras
www.neglostyti.com

Narann

unread,
Sep 29, 2010, 5:03:15 AM9/29/10
to python_inside_maya
Hi! And thanks for respond! :)

The way I find to avoid this prob is to never use MFloat(Point/Matrix/
etc...) with python. Just use M(Point/Matrix/etc...).

You was right! the prob was that I use MFloatPointArray instead
MPointArray. Anyway:

myMPointArray[i] should be a MPoint. But this crash:

inMeshMPointArray = OpenMaya.MPointArray()
inMeshMPointTmp = OpenMaya.MPoint()

for i in range( inMeshMPointArray.length() ) :
inMeshMPointTmp = inMeshMPointArray[i]
inMeshMPointTmp *= inMeshInclusiveMMatrix



And this don't crash:

inMeshMPointArray = OpenMaya.MPointArray()
inMeshMPointTmp = OpenMaya.MPoint()

for i in range( inMeshMPointArray.length() ) :
inMeshMPointTmp = OpenMaya.MPoint( inMeshMPointArray[i] )
inMeshMPointTmp *= inMeshInclusiveMMatrix

I "capsulate" the inMeshMPointArray[i] in a OpenMaya.MPoint() to use
it without have a maya segmentation fault (linux).

My prob is solve anyway (but Python Maya API is full of surprise :-( )

Thanks and have a good day!

Viktoras

unread,
Sep 29, 2010, 10:52:07 AM9/29/10
to python_in...@googlegroups.com
this shouldn't crash either and will look much cleaner:

for i in range( inMeshMPointArray.length() ) :

inMeshMPointTmp = inMeshMPointArray[i]*inMeshInclusiveMMatrix


On 2010.09.29 12:03, Narann wrote:
> for i in range( inMeshMPointArray.length() ) :
> inMeshMPointTmp = inMeshMPointArray[i]
> inMeshMPointTmp *= inMeshInclusiveMMatrix


--
Viktoras
www.neglostyti.com

Narann

unread,
Oct 1, 2010, 5:43:35 AM10/1/10
to python_inside_maya
Yes, your method work a is more clean. Thanks! :)

Anyway, this crash is very strange...
Reply all
Reply to author
Forward
0 new messages