NurbsCurve MatrixMath Maya api Python
Question: 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 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? Perhaps using one of the math modules or numpy?

Alternatively,

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

    
    
        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]) )
    


Answer: The easiest method is to use pymel's built-in versions of points and matrices
(pymel is built in to maya 2011+). The math types are in pymel.datatatypes;
here's an example of transforming a point by a matrix in pymel:

    
    
    import pymel.core as pm
    pt = pm.datatypes.Point(0,0,0)
    mt = pm.datatypes.Matrix(1,0,0,0, 0,1,0,0, 0,0,1,0, 5,5,5,1 )
    moved = pt * mt
    print moved
    # [5,5,5]
    

Pymel points and matrices will let you do your algorithm. The math is going to
be done in the API but the Python <> C++ conversions may still make it feel
pretty slow for big data.

It sounds like you're basically re-creating 'freeze transforms' followed by
'zero pivots'. Maybe you should try that as an alternative to doing this in
python math...

