Hello all,
   I ve got quite far with my script now and with the 2 locators named
start and finish, you can detect first intersection with any meshs
within the scene, the face hit, and the normals of the face. My
problem is as follows.

 suppose you have 2 meshs in the firing line, it will report
interscetions with both, as mine is a ballistic plug in. i really only
need the first, now as far as i can figure this means i will need to
evaluate the distance between the impact point and the start point.
any ideas ? i had figured on using pythag to evaluate the distance
between intersection and start points, then using list functions to
call the lowest. but how to get the other correct data ?


import maya.cmds as mc
import maya.OpenMaya as om

iter = om.MItDag(om.MItDag.kDepthFirst, om.MFn.kMesh)

while not iter.isDone():

        iterDagPath = om.MDagPath()
        iter.getPath(iterDagPath)

        startWP = mc.xform('start',q=1,rp=1,ws=1)
        FinishWP = mc.xform('finish',q=1,rp=1,ws=1)

        vectBtwPnts=  ((startWP  [0] -FinishWP  [0])*-1), ((startWP
[1] -
FinishWP  [1])*-1), ((startWP  [2] -FinishWP  [2])*-1)
        VectorFloat = om.MFloatVector(vectBtwPnts[0],vectBtwPnts
[1],vectBtwPnts[2])

        meshFn = om.MFnMesh()
        meshFn.setObject( iterDagPath )

        raySource = om.MFloatPoint(startWP[0],startWP[1],startWP[2])
        rayDirection = VectorFloat
        rayDirection = rayDirection.normal()

        hitFacePtr = om.MScriptUtil().asIntPtr()
        hitPoint   = om.MFloatPoint()

        idsSorted          = False
        testBothDirections = False
        faceIds            = None
        triIds             = None
        accelParams        = None
        hitRayParam        = None
        hitTriangle        = None
        hitBary1           = None
        hitBary2           = None

        maxParamPtr                  = 99999999
        worldSpace = om.MSpace.kWorld

        hit =  meshFn.closestIntersection(raySource,
        rayDirection,
        faceIds,
        triIds,
        idsSorted,
        worldSpace,
        maxParamPtr,
        testBothDirections,
        accelParams,
        hitPoint,
        hitRayParam,
        hitFacePtr,
        hitTriangle,
        hitBary1,
        hitBary2)

        if hit:
                hitFace = om.MScriptUtil ( hitFacePtr ).asInt()

                faceNumber = hitFace
                vector = om.MVector()
                NormalFn = om.MFnMesh(iterDagPath)
                NormalFn.getPolygonNormal(faceNumber, vector,
worldSpace)
                hitFace = om.MScriptUtil ( hitFacePtr ).asInt()
                print iter.partialPathName()
                print "The hit point in X is %f " %hitPoint[0]
                print "The hit point in Y is %f " %hitPoint[1]
                print "The hit point in Z is %f " %hitPoint[2]
                print "The number of the face hit is %d" %hitFace

                print "The normal of the hit face is %f in x"
%vector.x
                print "The normal of the hit face is %f in y"
%vector.y
                print "The normal of the hit face is %f in z"
%vector.z

        iter.next()
--~--~---------~--~----~------------~-------~--~----~
Yours,
Maya-Python Club Team.
-~----------~----~----~----~------~----~------~--~---

Reply via email to