IGNORE MY LAST POST !. sorted it now i was just being thick. Big
thanks to you all. Still learning all this stuff but i m picking it up
quite well, thanks for the iteration code, its good to look at some
examples. Here is the working collision script. just put in the 2
locators start and finish, aim it at any mesh and bingo it ll print
out co ordiantes normals and faces of hits.

next step is to save this all into a vector array and work out which
is the first collision.


again a BIG tanks to you all, you are the maya gods . . .

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