def boundingBoxCtrl(sel=[], prnt=True, *args):
"""
creates a control based on the bounding box
selList (list) - list of obj to use to create control
prnt (bool) - whether you want to parent the obj to the ctrl
"""
if not sel:
sel = cmds.ls(sl=True, type="transform")
if sel:
box = cmds.exactWorldBoundingBox(sel) #[xmin, ymin, zmin, xmax, ymax, zmax]
X = om.MVector(box[0], box[3])
Y = om.MVector(box[1], box[4])
Z = om.MVector(box[2], box[5])
#get bbox lengths along axes
lenX = (X.y - X.x)
lenY = (Y.y - Y.x)
lenZ = (Z.y - Z.x)
# print lenX, lenY, lenZ
ctrl = createControl(name="ctrl", type="cube", color="pink")
cvs ={"xyz":[5, 15],"-xyz":[0, 4],"xy-z":[10, 14],"x-yz":[6, 8],"-x-yz":[3, 7],"-x-y-z":[2, 12],"x-y-z":[9, 13],"-xy-z":[1, 11]}
for a in cvs["xyz"]:
cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.y, Y.y, Z.y))
for a in cvs["-xyz"]:
cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.x, Y.y, Z.y))
for a in cvs["x-yz"]:
cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.y, Y.x, Z.y))
for a in cvs["-x-yz"]:
cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.x, Y.x, Z.y))
for a in cvs["xy-z"]:
cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.y, Y.y, Z.x))
for a in cvs["-xy-z"]:
cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.x, Y.y, Z.x))
for a in cvs["-x-y-z"]:
cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.x, Y.x, Z.x))
for a in cvs["x-y-z"]:
cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.y, Y.x, Z.x))
# center pivot on ctrl
cmds.xform(ctrl, cp=True)
# get ctrl back to
wsPos = cmds.xform(ctrl, ws=True, q=True, rp=True)
cmds.xform(ctrl, ws=True, t=(-wsPos[0], -wsPos[1], -wsPos[2]))
cmds.makeIdentity(ctrl, apply=True)
cmds.xform(ctrl, ws=True, t=wsPos)
if prnt:
cmds.parent(sel, ctrl)
cmds.select(ctrl)
return(ctrl)
评论列表
文章目录