I'm trying to create a function that takes a list of xyz points and creates a nurbs curve in Autodesk Maya, using python.
To generate the points, I've been grabbing the points from an existing curve that was made manually, using this:
import maya.cmds as cmds
import maya.api.OpenMaya as OpenMaya2
mayaSel = cmds.ls(selection=True)[0]
msel = om2.MSelectionList()
msel.add(mayaSel)
curveMob = msel.getDependNode(0)
curvFn = om2.MFnNurbsCurve(curveMob)
points = om2.MPointArray()
points = curvFn.cvPositions()
pointArray = []
for point in points:
pointTuple = (point.x, point.y, point.z)
pointArray.append(pointTuple)
print (pointArray)
I then pass the given pointArray to this:
curv = cmds.curve(p=pointArray)
And it is working! The curve is being created - But the ends of the curve seem to to overshoot somehow, making the shape slightly different to the original curve:
Original Curve: IMG
Curve created from the control points of the original curve: IMG
I tried messing with the open/close curve options, and while it does close the curve, I can't find a way to maintain the original shape.
I suspect it maaay have something to do with the knots of the curve? But I'm not too sure, and my knowledge of curve knots is a bit limited. If anyone can point me in the right direction, I would really appreciate it! :)