I'm trying to find the closest point on a mesh using the OpenMaya MMeshIntersector class but I want to limit the distance it searches. I'm using this so I can get the barycentricCoords to get a more accurate value.
Whenever I enter in a value to limit the distance, I get a RuntimeError: (kFailure): Unexpected Internal Failure. However if I enter in a value higher than 47.0, it works, but that's too high a value for my usage, I'm hoping to use values lower than 1. I'm not sure how to use the maxDistance flag, and there isn't much documentation on how to use it. Does anyone have any links or info on how to use it?
I've google searched and gone through the maya documents, haven't had much of luck getting any concrete info
import maya.OpenMaya as OpenMaya
def getBarycentricCoords(sourceMesh, targetMesh, distanceThreshold):
selectionList = OpenMaya.MSelectionList()
selectionList.add(sourceMesh)
sourceMeshDag = OpenMaya.MDagPath()
selectionList.getDagPath(0, sourceMeshDag)
selectionList = OpenMaya.MSelectionList()
selectionList.add(targetMesh)
targetMeshDag = OpenMaya.MDagPath()
selectionList.getDagPath(0, targetMeshDag)
mObj = OpenMaya.MObject()
currentFace = OpenMaya.MItMeshPolygon( sourceMeshDag, mObj )
targetMeshMPointArray = OpenMaya.MPointArray()
targetMeshMFnMesh = OpenMaya.MFnMesh(targetMeshDag)
targetMeshMFnMesh.getPoints(targetMeshMPointArray, OpenMaya.MSpace.kWorld)
matrix = sourceMeshDag.inclusiveMatrix()
node = sourceMeshDag.node()
intersector = OpenMaya.MMeshIntersector()
intersector.create( node, matrix )
pointInfo = OpenMaya.MPointOnMesh()
uUtil = OpenMaya.MScriptUtil(0.0)
uPtr = uUtil.asFloatPtr()
vUtil = OpenMaya.MScriptUtil(0.0)
vPtr = vUtil.asFloatPtr()
pointArray = OpenMaya.MPointArray()
vertIdList = OpenMaya.MIntArray()
for idx in range(targetMeshMPointArray.length()):
intersector.getClosestPoint( targetMeshMPointArray[idx], pointInfo, distanceThreshold )
pointInfo.getBarycentricCoords(uPtr,vPtr)
I expect any float value as the maxDistance should work, but I get RuntimeError: (kFailure): Unexpected Internal Failure
from maya that doesn't really help me debug the error itself.