Here's a little script to get boundingBox of object. Click on thumbnail to se how it works.
Take care
Code: Select all
#--------------------------------------------------
# Function: onSimulationBegin
#--------------------------------------------------
def onSimulationBegin():
pass
#--------------------------------------------------
#--------------------------------------------------
#getBoundingBox - object and type of bounding box
def getBbx(bObj,bBxType):
#listOf"X"Positions
xList = []
#listOf"Y"Positions
yList = []
#listOf"Z"Positions
zList = []
#oVertList-objectVertexesList
oVertList = []
#if BoundingTypeTesting
if(bBxType == "bBxP"):
pxy = bObj.createProxy(PROXY_CUBE)
oVertList = pxy.getVertices(REF_GLOBAL)
scene.removeObject(pxy.getName())
else:
oVertList = bObj.getVertices(REF_GLOBAL)
#--------------------
#gettingPositionOfEachVertex
for v in range(len(oVertList)):
#appendingXPositionOfEachVertexes
xList.append(oVertList[v].getPosition().getX())
yList.append(oVertList[v].getPosition().getY())
zList.append(oVertList[v].getPosition().getZ())
#maxAndMinX
xMin = min(xList)
xMax = max(xList)
xBound = [xMin,xMax]
#maxAndMinY
yMin = min(yList)
yMax = max(yList)
yBound = [yMin,yMax]
#maxAndMinZ
zMin = min(zList)
zMax = max(zList)
zBound = [zMin,zMax]
return xBound, yBound, zBound
#--------------------------------------------------
def updateGeo(bObj,oBbx,bBxType):
#callingForGetBbXFunction-ObjectAndTypeOfBoundingBox
#x[0]-min x[1]-max
(x,y,z) = getBbx(bObj,bBxType)
#verticesPosition
v0 = Vector.new(x[0],y[0],z[0]); v1 = Vector.new(x[0],y[0],z[1])
v2 = Vector.new(x[1],y[0],z[1]); v3 = Vector.new(x[1],y[0],z[0])
v4 = Vector.new(x[0],y[1],z[0]); v5 = Vector.new(x[0],y[1],z[1])
v6 = Vector.new(x[1],y[1],z[1]); v7 = Vector.new(x[1],y[1],z[0])
#verticesPositionList
vertPosList = [v0,v1,v2,v3,v4,v5,v6,v7]
#----mainFunction(updatingVerticesPosition)
vertList = []
for p in vertPosList:
vtx = Vertex.new(p)
vertList.append(vtx)
oBbx.updateVertices(vertList,REF_GLOBAL)
#--------------------------------------------------
#--------------------------------------------------
# Function: onSimulationStep
#--------------------------------------------------
def onSimulationStep():
#objectThatBoundingBoxYouWantToGet
bObj = scene.getObject("object")
#objectBoundingBox_earlierCreatedCube
oBbx = scene.getObject("bbx")
#typeOfBoundingBox; bBxP - boundingBoxOfProxy bBx-boundingBox
bBxType = "bBx" #bBxP bBx
#updateGeometry
updateGeo(bObj,oBbx,bBxType)
#--------------------------------------------------
# Function: onSimulationFrame
#--------------------------------------------------
def onSimulationFrame():
pass
#--------------------------------------------------
# Function: onSimulationEnd
#--------------------------------------------------
def onSimulationEnd():
pass
#--------------------------------------------------
# Function: onChangeToFrame
#--------------------------------------------------
def onChangeToFrame():
pass
-
