2D Nurbs Curves in maya python api (Curve on surface)

496 views
Skip to first unread message

Paxton

unread,
Apr 15, 2016, 2:14:58 AM4/15/16
to Python Programming for Autodesk Maya
Hey Guys, I am updating my rigging modules so that all (or most) of the "maya.cmds" are replaced with "maya.OpenMaya" functions.

So far so good...

Though I find myself stuck on 2d nurbsCurves

All of my bendyArms, Muscles and faces involve using the command "DuplicateSurfaceCurve" to create curves that live permanently within the 2d space of a nurbs surface
This has worked wonderfully up until now, but I would really like to learn how to build 2d "surface space" curves without resorting to the maya.cmds module..

Heres is my exploration of this topic un until now..


import maya.OpenMaya as om

#transform!
t = om.MFnDagNode().create('transform', 'i_am_a_thing')

#Plane!
point_array = om.MPointArray()
point_array.append(om.MPoint(*[-1.0,0.0,-1.0]))
point_array.append(om.MPoint(*[1.0,0.0,-1.0]))
point_array.append(om.MPoint(*[-1.0,0.0,1.0]))
point_array.append(om.MPoint(*[1.0,0.0,1.0]))

knot_aray_u = om.MDoubleArray()
knot_aray_u.append(0)
knot_aray_u.append(1)
knot_aray_v = om.MDoubleArray()
knot_aray_v.append(0)
knot_aray_v.append(1)
degree_u = 1
degree_v = 1
form_u = 1
form_v = 1
rational = False

s = om.MFnNurbsSurface().create(point_array, knot_aray_u, knot_aray_v, degree_u, degree_v, form_u, form_v, rational, t)


#Curve!

point_array = om.MPointArray()
point_array.append(om.MPoint(*[0.0, 1.0]))
point_array.append(om.MPoint(*[1.0, 1.0]))

knot_aray = om.MDoubleArray()
knot_aray.append(0)
knot_aray.append(1)

#Next line is where problems happen. 
#I assume I should pass the MObject of the shape node as the parent
#and set "create2D" to True.. 
#Yet, no luck.... Parent seems to be invalid :(

curve = om.MFnNurbsCurve().create(point_array, knot_aray, degree_u, form_u, True, False, s)

Any insight would be valuable as f*&%K
thanks,
-Paxton

Paxton

unread,
Apr 15, 2016, 2:18:42 PM4/15/16
to Python Programming for Autodesk Maya
Ok, I figured it out.. 
You need to create a 2d transform (with surface as parent)

heres how:


import maya.OpenMaya as om

#transform!
t = om.MFnDagNode().create('transform', 'i_am_a_3d_thing')

#Plane!
point_array = om.MPointArray()
point_array.append(om.MPoint(*[-1.0,0.0,-1.0]))
point_array.append(om.MPoint(*[1.0,0.0,-1.0]))
point_array.append(om.MPoint(*[-1.0,0.0,1.0]))
point_array.append(om.MPoint(*[1.0,0.0,1.0]))

knot_aray_u = om.MDoubleArray()
knot_aray_u.append(0)
knot_aray_u.append(1)
knot_aray_v = om.MDoubleArray()
knot_aray_v.append(0)
knot_aray_v.append(1)
degree_u = 1
degree_v = 1
form_u = 1
form_v = 1
rational = False

s = om.MFnNurbsSurface().create(point_array, knot_aray_u, knot_aray_v, degree_u, degree_v, form_u, form_v, rational, t)


#Curve!

point_array = om.MPointArray()
point_array.append(om.MPoint(*[0.0, 0.0]))
point_array.append(om.MPoint(*[1.0, 1.0]))

knot_aray = om.MDoubleArray()
knot_aray.append(0)
knot_aray.append(1)


#2d Transform!
t2 = om.MFnDagNode().create('transform', 'i_am_a_2d_thing', s)



curve = om.MFnNurbsCurve().create(point_array, knot_aray, degree_u, form_u, True, False, t2)

Marcus Ottosson

unread,
Apr 16, 2016, 4:42:26 AM4/16/16
to python_in...@googlegroups.com
Thanks for sharing!

--
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/f5444ad1-dd73-4349-a583-9feee66cdd5e%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