Guest User

Untitled

a guest
Jun 18th, 2012
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. def nameToDag( name ):
  2.         selectionList = om.MSelectionList()
  3.         selectionList.add( name )
  4.         node = om.MDagPath()
  5.         selectionList.getDagPath( 0, node )
  6.         return node
  7.        
  8. def Intersect(source,floor_name):
  9.  
  10.     test_intersect=getIntersect(source,floor_name)
  11.     if test_intersect[1]==None:
  12.         return False
  13.    
  14.     # filter geometry
  15.     iter = om.MItDag( om.MItDag.kBreadthFirst,om.MFn.kMesh )
  16.     old_dist=999999
  17.     closest_mesh=None
  18.     object_list=cmds.ls(type='transform')
  19.     for object in object_list:
  20.         mesh_name=object
  21.         try:
  22.             cmds.select(mesh_name)
  23.         except:
  24.             continue
  25.  
  26.         try: intersection=getIntersect(source,mesh_name)
  27.         except:
  28.             continue
  29.         #print intersection
  30.         if intersection[0]!=False:
  31.             new_dist = distFunc(intersection[1],source)
  32.        
  33.             if new_dist<old_dist:
  34.                 closest_mesh=object
  35.                 old_dist=new_dist
  36.                 ret=intersection
  37.                
  38.     #print closest_mesh
  39.     if closest_mesh==floor_name:
  40.         return ret
  41.     return False
  42.    
  43. def getIntersect(source,mesh_name):
  44.     dag = nameToDag(mesh_name)
  45.     meshFn = om.MFnMesh()
  46.     meshFn.setObject( dag )
  47.     #This is the Ray being shot
  48.     raySource = om.MPoint(source[0],13,source[2],1)
  49.     rayDirection = om.MVector(0,-1,0)
  50.  
  51.     pointsValue = om.MPointArray()
  52.     polygonIdsValue = om.MIntArray()
  53.     spaceValue = 4
  54.     #toleranceValue = om.kMFnMeshPointTolerance
  55.     toleranceValue =  0.01
  56.     ret = om.MFnMesh.intersect(meshFn, raySource, rayDirection.normal(),
  57.     pointsValue, toleranceValue, spaceValue, polygonIdsValue )
  58.     pointLoc=[0,0,0]
  59.    
  60.     if ret==True:
  61.         pointLoc[0]=int(pointsValue[0].x)
  62.         pointLoc[1]=pointsValue[0].y
  63.         pointLoc[2]=int(pointsValue[0].z)
  64.         #print 'from: ',source, ' intersected ',mesh_name
  65.         return ret,pointLoc
  66.  
  67.     return ret,None
Advertisement
Add Comment
Please, Sign In to add comment