lol... 2 ND people responding at the exact same time :)
On Thu, Feb 12, 2009 at 12:06 PM, Judd Simantov <[email protected]> wrote: > this is a quick snippet I through together for you... it basically will > iterate the dag for meshes (you can set the filter type to whatever you > want)... then once you have the MDagPath or you can get an MObject to the > data you can do whatever you want to it. > > > ############################################### > > import maya.OpenMaya as om > > iter = om.MItDag(om.MItDag.kDepthFirst, om.MFn.kMesh) > > while not iter.isDone(): > > path = om.MDagPath() > iter.getPath(path) > print iter.partialPathName() > > iter.next() > > > ############################################### > > > On Thu, Feb 12, 2009 at 11:44 AM, ryant <[email protected]> wrote: > >> >> This is not exactly what your asking for but it is along those lines. >> This is an example of how to iterate over the selected meshes. This is >> outside the context of my plug which I could show also but from the >> looks there you have most of what you need and something like this >> might work. >> >> # Get the selection and create a selection list of all the nodes >> meshes >> selection = OpenMaya.MSelectionList() >> OpenMaya.MGlobal.getActiveSelectionList( selection ); >> >> # Create an itorator to iterate over the selection >> # Use the MFn class to as a filter to filter geometry types >> iter = OpenMaya.MItSelectionList ( selection, >> OpenMaya.MFn.kGeometric ); >> >> # Iterate over selected geometry nodes >> while not iter.isDone(): >> >> #Define local vars >> MObject iterMesh; >> MFnMesh selectMesh; >> MString name; >> MDagPath dagpath; >> >> #Get the mesh from iter >> iter.getDependNode( iterMesh ); >> >> #Debuging and displaying info >> selectMesh.setObject( iterMesh ); >> name = selectMesh.name(); >> MGlobal::displayInfo( "retreiving mesh named : " + name ); >> >> #Get the dag path of the geometry node >> iter.getDagPath( dagpath ); >> >> iter.next() >> >> On Feb 12, 8:44 am, "[email protected]" >> <[email protected]> wrote: >> > Hey, i ve been writing a bullet collsion tool and have completed the >> > first part of the technical part. basically the function is to fire a >> > ray and detect the first intersection with a mesh. a big thanks to all >> > the people who post here cuz without your help i would nt of been able >> > to begin to understand what the hell any of this means! the code is >> > good and with 2 locators as ray start and direction it detects >> > intersection the name of the face intersected and the normals of the >> > face. >> > >> > The next stage is to build in an itterator that will cycle through all >> > the meshs in a scene? any suggestions ? at the moment it just looks >> > for pcube1 >> > >> > import maya.cmds as mc >> > import maya.OpenMaya as om >> > >> > ## create 2 locators named start and finish to angle the ray points >> > >> > 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) >> > vectorToFinish = om.MFloatVector(vectBtwPnts[0],vectBtwPnts >> > [1],vectBtwPnts[2]) >> > >> > def nameToNode(name ): >> > selectionList = om.MSelectionList() >> > selectionList.add( name ) >> > node = om.MObject() >> > selectionList.getDependNode( 0, node ) >> > return node >> > >> > #retireves the right DAG node for selected objects >> > >> > def nameToDag( name ): >> > selectionList = om.MSelectionList() >> > selectionList.add( name ) >> > node = om.MDagPath() >> > selectionList.getDagPath( 0, node ) >> > return node >> > >> > ## this is where the itterator is needed ? ? >> > >> > dag = nameToDag(" pCube1 " ) >> > >> > meshFn = om.MFnMesh() >> > meshFn.setObject( dag ) >> > >> > raySource = om.MFloatPoint(startWP[0],startWP[1],startWP[2]) >> > rayDirection = vectorToFinish >> > 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(dag) >> > NormalFn.getPolygonNormal(faceNumber, vector, worldSpace) >> > hitFace = om.MScriptUtil ( hitFacePtr ).asInt() >> > 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 >> >> >> > --~--~---------~--~----~------------~-------~--~----~ Yours, Maya-Python Club Team. -~----------~----~----~----~------~----~------~--~---
