Applying a 3d matrix to a bunch of 3d nurbs cvs

186 views
Skip to first unread message

Paxton

unread,
May 4, 2014, 1:50:12 PM5/4/14
to python_in...@googlegroups.com

Hey guys. long time lurker, first post...

I posted this over on stack overflow, but I think this might be a better place for it..


I am creating a toolset for creating nurbs curves/surfaces inside maya using python.

I have a set of dictionaries that include cvPositions, knots, form etc. each of which describe a preset 3d shape (cube, circle, pyramid etc). I also have a 3d matrix stored in the nodes metadata that is used as an offset for the shape. This allows you to scale/move/rotate the shape without moving the transform.

The problem is in the way I am applying this matrix is very slow:

First I will create a new (edit)transform at the position of the (orig)transform containing the curves. Next I will transfer cv positions in world space from (orig)transform to (edit)transform. Next i will move the (edit)transform into the matrix position. Finally I will world space transfer the cvPositions back to the (orig)transform

When creating hundreds of shapes, this is becoming prohibitively slow...

Can someone describe a mathematical way to apply a matrix to a set of 3d points? maybe using one of pythons math modules or perhaps numpy?

Alternatively,

Is there a way using OpenMaya api functions to do this? Perhaps with MPointArray? The following code block is about as far as I have gotten on that front:

cheers,

-Paxton

    crv = OpenMaya.MFnNurbsCurve( self.dagPath )
    cvs = OpenMaya.MPointArray()
    space = OpenMaya.MSpace.kWorld
    crv.getCVs(cvs, space)
    positions = []
    for i in range(cvs.length()):
        pt = cvs[i]
        positions.append( (pt[0], pt[1], pt[2]) )

Marcus Ottosson

unread,
May 4, 2014, 3:15:19 PM5/4/14
to python_in...@googlegroups.com
Hi Paxton,

This is possibly not what you are looking for, as you asked for a coded method, but Maya is quite capable of transforming points using a matrix via its own nodes.

Have a look at the fourByFourMatrix, multMatrix and decomposeMatrix nodes. You would connect the transform of your curve, or group of curves into multMatrix along with thr 4x4 matrix, which would multiply, or "transform" them using the 4x4. You could then use the decomposeMatrix to extract the new translate, rotate and scale.

If you'd rather apply the new transformation to the points themselves, you can use the output of multMatrix with a transformGeometry node which, given a set of geometry, transforms the geometry using the inputted matrix.

This could potentially be used real-time, and I'm sure it's quite fast as well.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/20487b33-cb96-4bd6-8b99-de2d6e02c73e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Marcus Ottosson
konstr...@gmail.com


Paxton

unread,
May 4, 2014, 11:41:32 PM5/4/14
to python_in...@googlegroups.com
Interesting idea!
I am setting this up to test the speed difference.
One question though. Since the transformGeometry nodes "transform" attr is a matrix attribute, how would I input a translate rotate or scale value?

is there a simple way to add translate/rotate/scale values to a matrix? 

Marcus Ottosson

unread,
May 5, 2014, 1:27:42 AM5/5/14
to python_in...@googlegroups.com
Sure, the opposite of a decomposeMatrix is called composeMatrix. Alternatively, you could use any transform node, as it will have regular t, r and s channels, and its outcoming matrix, either world or local.

Once you've got your t, r and s values baked into a matrix, there is a node called wtAddMatrix which "adds" a matrix onto another matrix, with the possibility to also blend, or "weight" either matrix.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
Marcus Ottosson
konstr...@gmail.com


Paxton

unread,
May 7, 2014, 12:42:48 PM5/7/14
to python_in...@googlegroups.com
Good stuff. 10X speed increase.
Thanks man

On Sunday, 4 May 2014 22:27:42 UTC-7, Marcus Ottosson wrote:
Sure, the opposite of a decomposeMatrix is called composeMatrix. Alternatively, you could use any transform node, as it will have regular t, r and s channels, and its outcoming matrix, either world or local.

Once you've got your t, r and s values baked into a matrix, there is a node called wtAddMatrix which "adds" a matrix onto another matrix, with the possibility to also blend, or "weight" either matrix.

On Monday, May 5, 2014, Paxton <paxton...@gmail.com> wrote:
Interesting idea!
I am setting this up to test the speed difference.
One question though. Since the transformGeometry nodes "transform" attr is a matrix attribute, how would I input a translate rotate or scale value?

is there a simple way to add translate/rotate/scale values to a matrix? 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.


--
Marcus Ottosson
konstr...@gmail.com


Marcus Ottosson

unread,
May 7, 2014, 1:21:34 PM5/7/14
to python_in...@googlegroups.com
Cool glad it helped. :)
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/55154320-c64a-4050-9ebd-5928faae0e59%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
Marcus Ottosson
konstr...@gmail.com


Reply all
Reply to author
Forward
0 new messages