Skip to content

Instantly share code, notes, and snippets.

@hdlx
Last active March 5, 2021 12:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hdlx/271eff183ab5400828a155a55b1692dc to your computer and use it in GitHub Desktop.
Save hdlx/271eff183ab5400828a155a55b1692dc to your computer and use it in GitHub Desktop.
Maya get curve normal
import maya.api.OpenMaya as om
import maya.cmds as cmds
#Returns normal, tangent, at a given point on a curve, given the curve and a position in space.
#result as a list of openmaya MVector()
def getCurveNormal(mayaCurve, pos=[0,0,0]):
selectionList = om.MSelectionList()
selectionList.add(mayaCurve)
dPath= selectionList.getDagPath(0)
mCurve=om.MFnNurbsCurve (dPath)
res=mCurve.closestPoint(om.MPoint(om.MVector(pos)),space=om.MSpace.kWorld)
point=om.MVector(res[0])
param=res[1]
n=mCurve.normal(param,space=om.MSpace.kWorld)
t=mCurve.tangent(param,space=om.MSpace.kWorld)
li=[n,t,point]
return li
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment