Skip to content

Instantly share code, notes, and snippets.

@hdlx
Last active March 5, 2021 12:38
Show Gist options
  • Select an option

  • Save hdlx/271eff183ab5400828a155a55b1692dc to your computer and use it in GitHub Desktop.

Select an option

Save hdlx/271eff183ab5400828a155a55b1692dc to your computer and use it in GitHub Desktop.

Revisions

  1. hdlx revised this gist Aug 23, 2019. No changes.
  2. hdlx revised this gist Aug 6, 2019. No changes.
  3. hdlx revised this gist Jan 18, 2018. No changes.
  4. hdlx created this gist Jan 18, 2018.
    17 changes: 17 additions & 0 deletions getCurveNormal.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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