Advertisement
cwisbg

Checkisin

May 24th, 2019
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.72 KB | None | 0 0
  1. from pymel.core import *
  2.  
  3. def isIn(BoundingBox, Position):#(bb,obj):#xmin ymin zmin xmax ymax zmax.
  4.     isInBounds = False
  5.     if Position[0] <= BoundingBox[0] or Position[0] >= BoundingBox[3]:
  6.         add = 0
  7.     elif Position[1] <= BoundingBox[1] or Position[1] >= BoundingBox[4]:
  8.         add = 0    
  9.     elif Position[2] <= BoundingBox[2] or Position[2] >= BoundingBox[5]:
  10.         add = 0        
  11.     else:
  12.         add=1
  13.     if add:
  14.         isInBounds = True
  15.     return isInBounds
  16.    
  17. def GetSceneBounds(boundsList, doRound):#xmin ymin zmin xmax ymax zmax.
  18.     sceneBB = [1000,1000,1000,-1000,-1000,-1000]
  19.     for BB in boundsList:
  20.         if BB[0] < sceneBB[0]:
  21.             sceneBB[0] = BB[0]
  22.         if BB[1] < sceneBB[1]:
  23.             sceneBB[1] = BB[1]
  24.         if BB[2] < sceneBB[2]:
  25.             sceneBB[2] = BB[2]  
  26.         if BB[3] > sceneBB[3]:
  27.             sceneBB[3] = BB[3]
  28.         if BB[4] > sceneBB[4]:
  29.             sceneBB[4] = BB[4]
  30.         if BB[5] > sceneBB[5]:
  31.             sceneBB[5] = BB[5]
  32.     if doRound:  
  33.         sceneBBRounded = [0,0,0,0,0,0]
  34.         i=0
  35.         for BB in sceneBB:
  36.             print round(BB)
  37.             sceneBBRounded[i] = round(BB)
  38.             i+=1          
  39.         return sceneBBRounded
  40.     else:
  41.         return sceneBB
  42.  
  43. def showBB(BB):
  44.     newBB = BB
  45.     c = polyCube(w=0,h=0,d=0, n = "showCube_")
  46.     move(newBB[0]+.5,0,0, str(c[0])+".f[5]", r=1,wd=1,ws=1)
  47.     move(0,newBB[1]+.5,0, str(c[0])+".f[3]", r=1,wd=1,ws=1)
  48.     move(0,0,newBB[2]+.5, str(c[0])+".f[2]", r=1,wd=1,ws=1)
  49.     move(newBB[3]-.5,0,0, str(c[0])+".f[4]",  r=1,wd=1,ws=1)
  50.     move(0,newBB[4]-.5,0, str(c[0])+".f[1]",  r=1,wd=1,ws=1)
  51.     move(0,0,newBB[5]-.5, str(c[0])+".f[0]",  r=1,wd=1,ws=1)
  52. def VoxelizeFromBB(BB):
  53.     toGrp = []
  54.     print BB[0]+BB[3]
  55.     for i in range(BB[0],BB[3]):
  56.         refresh(cw=1)
  57.         c = polyCube()[0]
  58.         move(c, x, y, z)
  59.         scale(c, .2,.2,.2)
  60.         toGrp.append(c)
  61.     parent(toGrp, tmpGrp)      
  62.  
  63. class GridNode:
  64.     def __init__(self):
  65.         self.pos = []
  66.         self.obj = []
  67.         self.isActive = False
  68.  
  69. ThingsGrp = ls("ThingsGrp")[0].listRelatives(c=1)
  70.  
  71. #Bounding box objects
  72. BoundsGrp = ls("BoundsObjs")[0].listRelatives(c=1)
  73. BBList = []
  74. for bounds in BoundsGrp:
  75.     BB = xform(bounds,bb=1,q=1)
  76.     BBList.append(BB)
  77.    
  78. sceneBB = GetSceneBounds(BBList, 0) # bb list, doRound
  79. #sceneBBCenter = (sceneBB[0]+sceneBB[3])/2, (sceneBB[1]+sceneBB[4])/2, (sceneBB[2]+sceneBB[5])/2
  80. showBB(sceneBB)
  81. #VoxelizeFromBB(sceneBB)
  82.  
  83.  
  84. """  
  85. for s in ThingsGrp:
  86.    for BB in BBList:
  87.        boundCheck = isIn(BB,s.getTranslation())
  88.        if not boundCheck:
  89.            scale(s,.1,.1,.1)
  90.        else:
  91.            scale(s,1,1,1)
  92. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement