cwisbg

CompareMesh

May 27th, 2019
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. # get verts near edges of bounding box
  2. # get unique sets
  3. # add unique sets to setArray\
  4. """
  5. Bit 000000 = z+,x-,z-,x+,y+,y-
  6.  
  7. ValidType = 000000 type
  8. ValidOk = Compatible pairs
  9.  
  10. ValidType 4444 (Roof)
  11. ValidOk = 4,3 (Roof, walls)
  12.  
  13.  
  14. 0 = ground
  15. 1 = road
  16. 3 = wall
  17. 4 = roof
  18. 5 = roof wall
  19. 6 = wall to ground
  20. 8 = under
  21. 9 = above
  22. """
  23. from pymel.core import *
  24. def isIn(BoundingBox, Position):#(bb,obj):#xmin ymin zmin xmax ymax zmax.
  25. isInBounds = False
  26. if Position[0] <= BoundingBox[0] or Position[0] >= BoundingBox[3]:
  27. add = 0
  28. elif Position[1] <= BoundingBox[1] or Position[1] >= BoundingBox[4]:
  29. add = 0
  30. elif Position[2] <= BoundingBox[2] or Position[2] >= BoundingBox[5]:
  31. add = 0
  32. else:
  33. add=1
  34. if add:
  35. isInBounds = True
  36. return isInBounds
  37.  
  38. class Piece:
  39. def __init__(self):
  40. self.obj = []
  41. self.bb = []
  42. self.validType = []
  43. self.validOk = []
  44.  
  45. self.pointPosArray = []
  46. self.validObjs = []
  47.  
  48. def GetPoints(self, useBB):
  49. meshPoints = []
  50. for o in self.obj.listRelatives(c=1):
  51. for vtx in o.vtx:
  52. vtxPos = pointPosition(vtx,w=1)
  53. vtxPos = [vtxPos[0],vtxPos[1],vtxPos[2]]
  54. if useBB:
  55. bbOffset = [self.bb[0]-.1,self.bb[1]-.1,self.bb[2]-.1,self.bb[3]-.1,self.bb[4]-.1,self.bb[5]-.1]
  56. if not isIn(bbOffset, vtxPos):
  57. self.pointPosArray.append(vtxPos)
  58. def CompareMesh(self, Compare):
  59. meshCompatible = False
  60. meshLen = len(self.pointPosArray)
  61. meshCompareLen = len(Compare.pointPosArray)
  62. i = 0
  63. for p in self.pointPosArray:
  64. for pp in Compare.pointPosArray:
  65. if p == pp:
  66. print p, pp
  67. i+=1
  68. if i == meshLen:
  69. meshCompatible = True
  70. return meshCompatible
  71.  
  72.  
  73.  
  74.  
  75.  
  76. # Create Piece object array
  77. PiecesGrp = ls("Pieces")[0].listRelatives(c=1)
  78. PiecesGrpLen = len(PiecesGrp)
  79. PieceArray = []
  80. for piece in PiecesGrp:
  81. newPiece = Piece()
  82. newPiece.obj = piece
  83. newPiece.validType = piece.listRelatives(c=1)[-2]
  84. newPiece.validOk = piece.listRelatives(c=1)[-1]
  85.  
  86. #newPiece.bb = xform(piece,bb=1,q=1)
  87. #newPiece.GetPoints(1)
  88.  
  89.  
  90. """
  91. # Compare pieces
  92. PiecesGrpLen = len(PiecesGrp)
  93. for pieceObj in PieceArray:
  94. for pPieceObj in PieceArray:
  95. if pieceObj != pPieceObj:
  96. compareCheck = pieceObj.CompareMesh(pPieceObj)
  97. #print compareCheck
  98. if compareCheck:
  99. pieceObj.validObjs.append(pPieceObj)
  100. for validPiece in pieceObj.validObjs:
  101. print validPiece.obj
  102. """
Advertisement
Add Comment
Please, Sign In to add comment