Hi,
i managed to get as far as being able to wrap a curve of any length to any
polygon object. My code runs through each point on the curve and checks for the
closest point on the polygon mesh and then moves the curve point to the mesh
point.
HOWEVER.. my problem is that i want my script to find the exact spot on my mesh
that is closest, not just a cv point...
It seems like it should be easy, because whenever i make an object 'live' and
start to move another object around it slides smoothly along every fractional
point of the 'live' surface. What my script achieves is a zigzag effect with
the curve placing its points on the mesh vertex's rather than the literal
closest point on the mesh.
can anyone suggest any ways around this. Im sure theres a simple solution. Im
just being dumb.
here is my code. To make it work create a sphere and then draw a linear ep
curve next to it and run code...THANKYOU IN ADVANCE!!!:
//////////////////////////////////////////////////
import maya.cmds as cmds
import maya.api.OpenMaya as OpenMaya
import pymel.core as pm
i=0
geo = pm.PyNode("pSphere1")
try:
selectionList = OpenMaya.MSelectionList()
selectionList.add(geo.name())
nodeDagPath = selectionList.getDagPath(0)
except:
raise RuntimeError('maya.api.OpenMaya.MDagPath() failed on %s' %
geo.name())
curveSpanCount = cmds.getAttr('curve1' + ".spans")
curveCvCount = curveSpanCount+1
while i < curveCvCount:
curveCvPos = cmds.pointPosition('curve1' + ".cv" + str([i]))
mfnMesh = OpenMaya.MFnMesh(nodeDagPath)
point = OpenMaya.MPoint(curveCvPos[0], curveCvPos[1], curveCvPos[2])
space = OpenMaya.MSpace.kWorld
closestPoint, faceIdx = mfnMesh.getClosestPoint(point, space)
faceVerts = [geo.vtx[j] for j in geo.f[faceIdx].getVertices()]
closestVert = None
minLength = None
for v in faceVerts:
thisLength = (curveCvPos -
v.getPosition(space='world')).length()
if minLength is None or thisLength < minLength:
minLength = thisLength
closestVert = v
vertPos=closestVert.getPosition(space='world')
cmds.xform('curve1' + ".cv" + str([i]), t= (vertPos[0], vertPos[1],
vertPos[2]), a=True, ws=True)
i+=1
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/191b1d88-d94a-46c3-9a5c-afdf7ac7d279%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.