本文整理汇总了Python中maya.cmds.exactWorldBoundingBox函数的典型用法代码示例。如果您正苦于以下问题:Python exactWorldBoundingBox函数的具体用法?Python exactWorldBoundingBox怎么用?Python exactWorldBoundingBox使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exactWorldBoundingBox函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search
def search(self):
for a in self.follicleGrp:
cm.group(n='group_'+str(a), em=True, w=True)
x1, y1, z1, x2, y2, z2 = cm.exactWorldBoundingBox(a)
x1 = (x1+x2)/2
y1 = (y1+y2)/2
z1 = (z1+z2)/2
x1 = abs(x1)
y1 = abs(y1)
z1 = abs(z1)
for b in self.curveGrp:
x1c, y1c, z1c, x2c, y2c, z2c = cm.exactWorldBoundingBox(b)
x1c = abs(x1c)
y1c = abs(y1c)
z1c = abs(z1c)
diffx1=x1c-x1
diffy1=y1c-y1
diffz1=z1c-z1
if diffx1<self.Dist and diffx1>-self.Dist and diffy1<self.Dist and diffy1>-self.Dist and diffz1<self.Dist and diffz1>-self.Dist:
if cm.listRelatives(b, p=False):
print b, 'Has no parent'
cm.parent(b, 'group_'+str(a))
more = 0
for c in self.curveGrp:
if cm.listRelatives(c, p=False):
more = 1
if more==1:
self.Dist += (self.Dist*.8)
print '***Refining search.'
new.refineSearch()
示例2: refineSearch
def refineSearch(self):
for a in self.curveGrp:
if cm.listRelatives(a, p=True):
self.curveGrp.remove(a)
for a in self.follicleGrp:
cm.group(n='group_2_'+str(a), em=True, w=True)
x1, y1, z1, x2, y2, z2 = cm.exactWorldBoundingBox(a)
x1 = (x1+x2)/2
y1 = (y1+y2)/2
z1 = (z1+z2)/2
x1 = abs(x1)
y1 = abs(y1)
z1 = abs(z1)
for b in self.curveGrp:
x1c, y1c, z1c, x2c, y2c, z2c = cm.exactWorldBoundingBox(b)
x1c = abs(x1c)
y1c = abs(y1c)
z1c = abs(z1c)
diffx1=x1c-x1
diffy1=y1c-y1
diffz1=z1c-z1
if diffx1<self.Dist and diffx1>-self.Dist and diffy1<self.Dist and diffy1>-self.Dist and diffz1<self.Dist and diffz1>-self.Dist:
if cm.listRelatives(b, p=False):
print b, 'has no parent'
cm.parent(b, 'group_2_'+str(a))
else:
pass
示例3: BBintersection
def BBintersection(obj1, obj2):
#derive the bounding box that is the intersection of two bounding boxes
#coords returned as MVector
BB1 = mc.exactWorldBoundingBox(obj1)
BB2 = mc.exactWorldBoundingBox(obj2)
BB1min = om.MVector(BB1[0],BB1[1],BB1[2])
BB1max = om.MVector(BB1[3],BB1[4],BB1[5])
BB2min = om.MVector(BB2[0],BB2[1],BB2[2])
BB2max = om.MVector(BB2[3],BB2[4],BB2[5])
if BB1min.x >= BB2min.x: outMinX = BB1min.x
if BB1min.x <= BB2min.x: outMinX = BB2min.x
if BB1min.y >= BB2min.y: outMinY = BB1min.y
if BB1min.y <= BB2min.y: outMinY = BB2min.y
if BB1min.z >= BB2min.z: outMinZ = BB1min.z
if BB1min.z <= BB2min.z: outMinZ = BB2min.z
outMin = om.MVector(outMinX,outMinY,outMinZ)
if BB1max.x <= BB2max.x: outMaxX = BB1max.x
if BB1max.x >= BB2max.x: outMaxX = BB2max.x
if BB1max.y <= BB2max.y: outMaxY = BB1max.y
if BB1max.y >= BB2max.y: outMaxY = BB2max.y
if BB1max.z <= BB2max.z: outMaxZ = BB1max.z
if BB1max.z >= BB2max.z: outMaxZ = BB2max.z
outMax = om.MVector(outMaxX,outMaxY,outMaxZ)
return outMin,outMax
示例4: placeTreesInSquare
def placeTreesInSquare(squareBbox, shaders):
'''
Places trees randomly in a given square.
squareBbox: A list of two tuples containing the x- and z-coordinates for the
bounding box of a square.
shaders: A list of shaders for the tree crowns.
On exit: A cube of the same size as the square been created and assigned a green
shader in order to make it look like grass. Trees have created using
makeTree(...), and placed randomly using a dart throwing algorithm which
gives up after six failed attempts. Everything is united into one object
which is returned as a tuple with the object name and the node name.
'''
treeList = []
width = squareBbox[1][0] - squareBbox[0][0]
depth = squareBbox[1][1] - squareBbox[0][1]
grass = cmds.polyCube(name = "grass", h = 0.3, w = width, d = depth)
cmds.xform(grass, translation = (squareBbox[0][0] + 0.5 * width,0.15,squareBbox[0][1] + 0.5 * depth))
cmds.sets(grass[0], edit=True, forceElement="grassMaterialGroup")
while True:
failCount = 0
tree = makeTree(shaders)
treeList.append(tree)
bbox1 = cmds.exactWorldBoundingBox(tree[0])
radius = (bbox1[3] - bbox1[0]) / 2.0
coorx = random.uniform(squareBbox[0][0] + radius, squareBbox[1][0] - radius)
coorz = random.uniform(squareBbox[0][1] + radius, squareBbox[1][1] - radius)
cmds.xform(tree[0], translation = (coorx, 0, coorz))
while True:
failed = False
for j in treeList:
bbox1 = cmds.exactWorldBoundingBox(tree[0])
bbox2 = cmds.exactWorldBoundingBox(j[0])
# Check if the tree intersects with element j in treeList.
xinters = (bbox1[0] < bbox2[3] and bbox1[0] > bbox2[0])\
or (bbox2[0] < bbox1[3] and bbox2[0] > bbox1[0])
zinters = (bbox1[2] < bbox2[5] and bbox1[2] > bbox2[2])\
or (bbox2[2] < bbox1[5] and bbox2[2] > bbox1[2])
if xinters and zinters:
coorx = random.uniform(squareBbox[0][0] + radius, squareBbox[1][0] - radius)
coorz = random.uniform(squareBbox[0][1] + radius, squareBbox[1][1] - radius)
cmds.xform(tree[0], translation = (coorx, 0, coorz))
failCount = failCount + 1
failed = True
break
if (failed == False) or (failCount > 5):
break
if (failCount > 5) or (len(treeList) == 10):
break
cmds.delete(tree[0]) # Delete the last tree that was not successfully placed.
treeList.pop()
for i in treeList:
grass = cmds.polyUnite(grass[0], i[0])
return grass
示例5: BBoxToCurve
def BBoxToCurve( obj, autoParent = False ):
bbinfo = mc.exactWorldBoundingBox( obj ) # xmin, ymin, zmin, xmax, ymax, zmax
point1 = [bbinfo[0],bbinfo[1],bbinfo[2]]
point2 = [bbinfo[3],bbinfo[4],bbinfo[5]]
coords = ([point1[0], point2[1], point2[2] ],
point2,
[ point2[0], point2[1], point1[2] ],
[ point1[0], point2[1], point1[2] ],
[ point1[0], point2[1], point2[2] ],
[ point1[0], point1[1], point2[2] ],
point1,
[ point2[0], point1[1], point1[2] ],
[ point2[0], point1[1], point2[2] ],
[ point1[0], point1[1], point2[2] ],
[ point2[0], point1[1], point2[2] ],
point2,
[ point2[0], point2[1], point1[2] ],
[ point2[0], point1[1], point1[2] ],
point1,
[ point1[0], point2[1], point1[2] ])
bbox = mc.curve( d = 1, p = coords, k = [ a for a in range(len(coords))], n = "cube#" )
if autoParent:
shape = mc.listRelatives( bbox, f = True, s = True )
mc.select( shape, obj )
mc.parent( add = True, shape = True )
mc.delete( bbox )
return bbox
示例6: bulge_button
def bulge_button( self, *args ):
if( cmds.objExists( "ZBend" ) ):
cmds.confirmDialog( title="Error", message="First delete the bulge history on the previously\ndeformed object before bulging another.", button="Okie Dokie" )
return 0
latestSelection = cmds.ls( selection=True )
if( len( latestSelection ) == 0 ):
return 0
if( len( latestSelection ) == 1 ):
self.relatives = cmds.listRelatives( children=True )
if( len(self.relatives) == 1 ):
self.bbox = cmds.exactWorldBoundingBox( latestSelection )
cmds.nonLinear( type='bend', curvature=cmds.intSliderGrp( "x_bulge_slider", value=True, query=True ) )
cmds.rename( "XBend" )
cmds.move((self.bbox[0] + self.bbox[3])/2, self.bbox[1], (self.bbox[2] + self.bbox[5])/2, "XBend", rpr=True )
cmds.setAttr( "XBend.rotateZ", -90 )
cmds.select( latestSelection )
cmds.nonLinear( type='bend', curvature=cmds.intSliderGrp( "z_bulge_slider", value=True, query=True ) )
cmds.rename( "ZBend" )
cmds.move((self.bbox[0] + self.bbox[3])/2, self.bbox[1], (self.bbox[2] + self.bbox[5])/2, "ZBend", rpr=True )
cmds.setAttr( "ZBend.rotateZ", -90 )
cmds.setAttr( "ZBend.rotateX", 90 )
cmds.connectControl( "x_bulge_slider", "bend1.curvature" )
cmds.connectControl( "z_bulge_slider", "bend2.curvature" )
cmds.select( latestSelection )
示例7: duplicate_button
def duplicate_button( self, *args ):
self.original_selected_objects = cmds.ls( selection=True )
if( len(self.original_selected_objects) == 0 ):
print "Nothing selected"
return 0
elif( len(self.original_selected_objects) == 1 ):
self.relatives = cmds.listRelatives( children=True )
if( len(self.relatives) == 1 ):
print "Skip combine"
cmds.duplicate( self.original_selected_objects, name=self.original_selected_objects[0] + "_Copy" )
cmds.delete( constructionHistory=True )
the_parent = cmds.listRelatives( parent=True )
if( the_parent != None ):
cmds.parent( self.original_selected_objects[0] + "_Copy", world=True )
else:
self.combine()
else:
self.combine()
self.newOriginCopy = cmds.ls( selection=True )[0]
self.bbox = cmds.exactWorldBoundingBox( self.newOriginCopy )
cmds.move((self.bbox[0] + self.bbox[3])/2, self.bbox[1], (self.bbox[2] + self.bbox[5])/2, self.newOriginCopy + ".scalePivot", self.newOriginCopy + ".rotatePivot", absolute=True)
cmds.move( 0, 0, 0, self.newOriginCopy, rpr=True )
cmds.makeIdentity( apply=True, t=1, r=1, s=1 )
cmds.delete( constructionHistory=True )
示例8: setLocs
def setLocs(mesh):
global voxelSize, cubeSize, xmin, xmax, ymin, ymax, zmin, zmax, xLocs, yLocs, zLocs
bb = cmds.exactWorldBoundingBox(mesh)
xmin = bb[0]
ymin = bb[1]
zmin = bb[2]
xmax = bb[3]
ymax = bb[4]
zmax = bb[5]
# make 3 arrays of ray start points, one for each axis
xLocs = []
yLocs = []
zLocs = []
fac = 1/voxelSize
for y in range(int(ymin*fac), int(ymax*fac+1)):
for z in range(int(zmin*fac), int(zmax*fac+1)):
loc = (xmax, y*voxelSize, z*voxelSize)
xLocs.append(loc)
for z in range(int(zmin*fac), int(zmax*fac+1)):
for x in range(int(xmin*fac), int(xmax*fac+1)):
loc = (x*voxelSize, ymax, z*voxelSize)
yLocs.append(loc)
for x in range(int(xmin*fac), int(xmax*fac+1)):
for y in range(int(ymin*fac), int(ymax*fac+1)):
loc = (x*voxelSize, y*voxelSize, zmax)
zLocs.append(loc)
示例9: exactLocalBoundingBox
def exactLocalBoundingBox(*args,**keywords):
if len(args)==0:
args=mc.ls(sl=True)
obj=args[0]
r=False #relative to the rotate pivot
for k in keywords:
if k=='r' or k=='relative':
r=keywords[k]
if k in locals():
exec(k+'=keywords[k]')
t,r,s=mc.getAttr(obj+'.t')[0],mc.getAttr(obj+'.r')[0],mc.getAttr(obj+'.s')[0]
mc.setAttr(obj+'.t',0,0,0)
mc.setAttr(obj+'.r',0,0,0)
mc.setAttr(obj+'.s',1,1,1)
if r:
rp=mc.xform(obj,q=True,ws=True,rp=True)
mc.xform(obj,ws=True,t=(-rp[0],-rp[1],-rp[2]))
returnVal=mc.exactWorldBoundingBox(obj)
mc.setAttr(obj+'.t',*t)
mc.setAttr(obj+'.r',*r)
mc.setAttr(obj+'.s',*s)
return returnVal
示例10: _get_recommended_pivot_bank
def _get_recommended_pivot_bank(self, geometries, tm_ref, tm_ref_dir, pos_toes, direction=1):
"""
Determine recommended position using ray-cast from the toes.
TODO: If the ray-case fail, use a specified default value.
return: The recommended position as a world pymel.datatypes.Vector
"""
# Sanity check, ensure that at least one point is in the bounds of geometries.
# This can prevent rays from being fired from outside a geometry.
# TODO: Make it more robust.
filtered_geometries = []
for geometry in geometries:
xmin, ymin, zmin, xmax, ymax, zmax = cmds.exactWorldBoundingBox(geometry.__melobject__())
bound = pymel.datatypes.BoundingBox((xmin, ymin, zmin), (xmax, ymax, zmax))
if bound.contains(pos_toes):
filtered_geometries.append(geometry)
dir = pymel.datatypes.Point(direction, 0, 0) * tm_ref_dir
pos = libRigging.ray_cast_nearest(pos_toes, dir, filtered_geometries)
if not pos:
cmds.warning("Can't automatically solve FootRoll bank inn pivot.")
pos = pos_toes
pos.y = 0
return pos
示例11: make_origin_target
def make_origin_target():
o = cmds.polySphere() # create a sphere
cmds.select(o) # select the sphere
bbox = cmds.exactWorldBoundingBox() # create bounding box around it
bottom = [(bbox[0] + bbox[3])/2, bbox[1], (bbox[2] + bbox[5])/2] # define the bottom of the bounding box
cmds.xform(piv=bottom, ws=True) # move the sphere to the bottom of the bounding box
cmds.move(rpr=True)
cmds.makeIdentity(apply=True, t=1, r=1, s=1, n=0) # freeze transforms
示例12: isBoundingBoxCross
def isBoundingBoxCross( firstObj, secondObj ):
bboxFirst = cmds.exactWorldBoundingBox( firstObj )
bboxSecond = cmds.exactWorldBoundingBox( secondObj )
firstMin = bboxFirst[:3]
firstMax = bboxFirst[3:]
secondMin = bboxSecond[:3]
secondMax = bboxSecond[3:]
isCross = True
for dimantion in [ [0,1], [1,2], [2,0] ]:
for i in dimantion:
if firstMax[i] < secondMin[i] or firstMin[i] > secondMax[i]:
isCross = False
break
return isCross
示例13: failUnlessCubeWidthEqual
def failUnlessCubeWidthEqual(self, timeValueList):
for time, value in timeValueList:
MayaCmds.currentTime(time, update = True)
bbox = MayaCmds.exactWorldBoundingBox('cube')
width = bbox[3] - bbox[0]
self.failUnlessAlmostEqual(
value, width, 3,
'Time: %f, Width: %f (expected) != %f' % (time, value, width))
示例14: create_guide
def create_guide():
if cmds.objExists('loc_guide_deformer'):
cmds.delete('loc_guide_deformer')
bound_centre = [0,0,0]
if len(cmds.ls(sl=True)) is not 0:
bound = cmds.exactWorldBoundingBox(cmds.ls (sl = True))
bound_centre = [(bound[0] + bound[3])/2, (bound[1] + bound[4])/2, (bound[2] + bound[5])/2]
cmds.spaceLocator (n="loc_guide_deformer", a = True, p = (bound_centre[0], bound_centre[1], bound_centre[2]))
cmds.CenterPivot()
示例15: run
def run():
"""Measure the scene bounding box for geometric objects in centimeters.
---
units, bounding box, center and dimensions for scene
sceneboundingbox() -> (string,
float, float, float,
float, float, float,
float, float, float,
float, float, float)
"""
t0 = float(time.time())
verbose = cmds.optionVar(query='checkmateVerbosity')
units = cmds.currentUnit(query=True, linear=True)
if units != 'cm' :
cmds.currentUnit(linear='cm')
#raise InvalidLinearUnits, "current linear unit is not centimeters"
transforms = cmds.ls(transforms=True)
geometry = cmds.ls(geometry=True)
try:
bbox = cmds.exactWorldBoundingBox(geometry)
except TypeError:
return (units,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0)
(bbMinX, bbMinY, bbMinZ,
bbMaxX, bbMaxY, bbMaxZ) = cmds.exactWorldBoundingBox(geometry)
width = bbMaxX - bbMinX
height = bbMaxY - bbMinY
depth = bbMaxZ - bbMinZ
centerX = ( bbMaxX + bbMinX ) / 2.0
centerY = ( bbMaxY + bbMinY ) / 2.0
centerZ = ( bbMaxZ + bbMinZ ) / 2.0
print '%-24s : %.6f seconds' % ('stats.bbox.run()',
float(time.time())-t0
)
return (units,
bbMinX, bbMinY, bbMinZ,
bbMaxX, bbMaxY, bbMaxZ,
centerX, centerY, centerZ,
width, height, depth)