Skip to content

Instantly share code, notes, and snippets.

#F. Hiba, C. Mendes, B. Lefebvre, P. Hubert
import maya.api.OpenMaya as om
import maya.cmds as cmds
from math import radians, degrees, sin, cos
from random import gauss, random, uniform, shuffle
from copy import copy
#4 utilities function related to transformations
#give the quaternion corresponding to the rottion from vector 1 to vector 2
@hdlx
hdlx / getClosestVertex.py
Last active September 21, 2023 08:19
Maya get closest vertex
import maya.api.OpenMaya as om
import maya.cmds as cmds
#returns the closest vertex given a mesh and a position [x,y,z] in world space.
#Uses om.MfnMesh.getClosestPoint() returned face ID and iterates through face's vertices.
def getClosestVertex(mayaMesh,pos=[0,0,0]):
mVector = om.MVector(pos)#using MVector type to represent position
selectionList = om.MSelectionList()
selectionList.add(mayaMesh)
dPath= selectionList.getDagPath(0)
@hdlx
hdlx / getCurveNormal.py
Last active March 5, 2021 12:38
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)