am struggling a little with MfnMesh stuff. I have the coords of a point in space and i want to be able to fire off a vector from this point with direction in negative x. and then i want the script to print the coords of any collision points with a mesh.
here is some code i found which comes very close to solving it. but im just not smart enough to adapt slightly.
create a polySphere and run this:
#########################################
import maya.cmds as cmds
import maya.OpenMaya as om
def returnCollisionPoints(point=(10.0,2.0,3.0), dir=(-1.0, 0.0, 0.0)):
sel = om.MSelectionList()
dag = om.MDagPath()
#replace torus with arbitrary shape name
sel.add("pSphereShape1")
sel.getDagPath(0,dag)
mesh = om.MFnMesh(dag)
point = om.MFloatPoint(*point)
dir = om.MFloatVector(*dir)
hitPoints = om.MFloatPointArray()
mesh.allIntersections(
point, dir,
None, None,
False, om.MSpace.kWorld,
10000, False,
None,
None,
hitPoints,
None, None,
None, None,
None
)
return hitPoints
print returnCollisionPoints()
################################################
so it to be able to print out hitPoints as coordinates i guess. Does anyone know how to do this?
thanks alot,
Sam
sam;)