#log.info(_size) #mHandleFactory = self.asHandleFactory(_short) mc.select(cl=True) resize_masterShape(self) return True except Exception, err: cgmGEN.cgmExceptCB(Exception, err, localDat=vars()) _crv = CURVES.create_controlCurve(self.mNode, shape='squareOpen', direction='y+', sizeMode='fixed', size=1) TRANS.scale_to_boundingBox(_crv, [self.baseSize[0], None, self.baseSize[2]]) mHandleFactory.color(_crv, 'center', 'sub', transparent=False) mCrv = cgmMeta.validateObjArg(_crv, 'cgmObject') l_offsetCrvs = [] for shape in mCrv.getShapes(): offsetShape = mc.offsetCurve(shape, distance=-_offsetSize, ch=False)[0] mHandleFactory.color(offsetShape, 'center', 'main', transparent=False) l_offsetCrvs.append(offsetShape) for s in [_crv] + l_offsetCrvs: RIG.shapeParent_in_place(self.mNode, s, False) return True
def resize_masterShape(self, sizeBy=None, resize=False): try: _short = self.p_nameShort _str_func = '[{0}] resize_masterShape'.format(_short) log.debug("|{0}| >> ".format(_str_func) + '-' * 80) _sel = mc.ls(sl=True) _bb = False _bb = self.baseSize if resize: if _sel: _bb = TRANS.bbSize_get(_sel, False) #elif self.getBlockChildren(): # sizeBy = mc.ls(self.getBlockChildren(asMeta=False)) # _bb = TRANS.bbSize_get(sizeBy,False) self.baseSize = _bb log.debug("|{0}| >> _bb: {1}".format(_str_func, _bb)) mHandleFactory = self.asHandleFactory(_short) mc.delete(self.getShapes()) _average = MATH.average([_bb[0], _bb[2]]) _size = _average * 1.5 _offsetSize = _average * .01 _blockScale = self.blockScale mFormNull = self.atUtils('stateNull_verify', 'form') mNoTransformNull = self.atUtils('noTransformNull_verify', 'form') if resize or self.controlOffset == .9999: self.controlOffset = _offsetSize #Main curve =========================================================================== _crv = CURVES.create_fromName(name='circle', direction='y+', size=1) mCrv = cgmMeta.asMeta(_crv) SNAP.go(mCrv.mNode, self.mNode, rotation=False) TRANS.scale_to_boundingBox(mCrv.mNode, [_bb[0], None, _bb[2]]) #mDup = mCrv.doDuplicate(po=False) #mDup.p_position = MATH.list_add(mDup.p_position, [0,_offsetSize,0]) RIG.shapeParent_in_place(self.mNode, _crv, False) #RIG.shapeParent_in_place(self.mNode,mDup.mNode,False) mHandleFactory.color(self.mNode, 'center', 'main', transparent=False) #Bounding box ================================================================== if self.getMessage('bbHelper'): self.bbHelper.delete() _bb_shape = CURVES.create_controlCurve(self.mNode, 'cubeOpen', size=1, sizeMode='fixed') _bb_newSize = MATH.list_mult(self.baseSize, [_blockScale, _blockScale, _blockScale]) TRANS.scale_to_boundingBox(_bb_shape, _bb_newSize) mBBShape = cgmMeta.validateObjArg(_bb_shape, 'cgmObject', setClass=True) mBBShape.p_parent = mFormNull mBBShape.inheritsTransform = False mc.parentConstraint(self.mNode, mBBShape.mNode, maintainOffset=False) SNAPCALLS.snap(mBBShape.mNode, self.mNode, objPivot='axisBox', objMode='y-') CORERIG.copy_pivot(mBBShape.mNode, self.mNode) self.doConnectOut('baseSize', "{0}.scale".format(mBBShape.mNode)) #mHandleFactory.color(mBBShape.mNode,controlType='sub') mBBShape.setAttrFlags() mBBShape.doStore('cgmName', self) mBBShape.doStore('cgmType', 'bbVisualize') mBBShape.doName() mBBShape.template = True self.connectChildNode(mBBShape.mNode, 'bbHelper') #Offset visualize ================================================================== if self.getMessage('offsetHelper'): self.offsetHelper.delete() #Need to guess our offset size based on bounding box volume mShape = self.getShapes(asMeta=True)[0] l_return = mc.offsetCurve(mShape.mNode, distance=1, ch=True) #pprint.pprint(l_return) mHandleFactory.color(l_return[0], 'center', 'sub', transparent=False) mOffsetShape = cgmMeta.validateObjArg(l_return[0], 'cgmObject', setClass=True) mOffsetShape.p_parent = mNoTransformNull #mOffsetShape.doSnapTo(self) #mc.pointConstraint(self.mNode,mOffsetShape.mNode,maintainOffset=True) #mc.orientConstraint(self.mNode,mOffsetShape.mNode,maintainOffset=True) mOffsetShape.inheritsTransform = False mOffsetShape.dagLock() _arg = '{0}.distance = -{1}.controlOffset'.format( l_return[1], self.mNode) NODEFACTORY.argsToNodes(_arg).doBuild() #self.doConnectOut('controlOffset',"{0}.distance".format(l_return[1])) mOffsetShape.doStore('cgmName', self) mOffsetShape.doStore('cgmType', 'offsetVisualize') mOffsetShape.doName() self.connectChildNode(mOffsetShape.mNode, 'offsetHelper') return #Offset visualize ================================================================== if self.getMessage('offsetHelper'): self.offsetHelper.delete() mShape = self.getShapes(asMeta=True)[0] l_return = mc.offsetCurve(mShape.mNode, distance=1, ch=True) #pprint.pprint(l_return) mHandleFactory.color(l_return[0], 'center', 'sub', transparent=False) mOffsetShape = cgmMeta.validateObjArg(l_return[0], 'cgmObject', setClass=True) mOffsetShape.p_parent = mFormNull mOffsetShape.inheritsTransform = False mc.parentConstraint(self.mNode, mOffsetShape.mNode, maintainOffset=False) #mOffsetShape.setAttrFlags() _arg = '{0}.distance = -{1}.controlOffset * {1}.blockScale'.format( l_return[1], self.mNode) NODEFACTORY.argsToNodes(_arg).doBuild() #self.doConnectOut('controlOffset',"{0}.distance".format(l_return[1])) mOffsetShape.doStore('cgmName', self) mOffsetShape.doStore('cgmType', 'offsetVisualize') mOffsetShape.doName() self.connectChildNode(mOffsetShape.mNode, 'offsetHelper') return _crv = CURVES.create_fromName(name='squareOpen', direction='y+', size=1) TRANS.scale_to_boundingBox(_crv, [_bb[0], None, _bb[2]]) mHandleFactory.color(_crv, 'center', 'sub', transparent=False) mCrv = cgmMeta.validateObjArg(_crv, 'cgmObject') l_offsetCrvs = [] for shape in mCrv.getShapes(): offsetShape = mc.offsetCurve(shape, distance=-_offsetSize, ch=True)[0] mHandleFactory.color(offsetShape, 'center', 'main', transparent=False) l_offsetCrvs.append(offsetShape) RIG.combineShapes(l_offsetCrvs + [_crv], True) SNAP.go(_crv, self.mNode) RIG.shapeParent_in_place(self.mNode, _crv, True) self.baseSize = _bb #Bounding box ================================================================== if self.getMessage('offsetVisualize'): self.bbVisualize.delete() _bb_shape = CURVES.create_controlCurve(self.mNode, 'cubeOpen', size=1.0, sizeMode='fixed') mBBShape = cgmMeta.validateObjArg(_bb_shape, 'cgmObject', setClass=True) mBBShape.p_parent = mFormNull SNAPCALLS.snap(mBBShape.mNode, self.mNode, objPivot='axisBox', objMode='y-') CORERIG.copy_pivot(mBBShape.mNode, self.mNode) self.doConnectOut('baseSize', "{0}.scale".format(mBBShape.mNode)) mHandleFactory.color(mBBShape.mNode, controlType='sub') mBBShape.setAttrFlags() mBBShape.doStore('cgmName', self) mBBShape.doStore('cgmType', 'bbVisualize') mBBShape.doName() self.connectChildNode(mBBShape.mNode, 'bbHelper') return True except Exception, err: cgmGEN.cgmExceptCB(Exception, err, localDat=vars())
def create_proxyGeo(proxyShape='cube', size=[1, 1, 1], direction='z+', ch=True): try: #cube:sphere:cylinder:cone:torus _str_func = 'create_proxyGeo' _proxyShape = _d_proxyCreate.get(proxyShape, proxyShape) _call = getattr(mc, _proxyShape, None) if not _call: raise ValueError, "Failed to find maya.cmds call {0}".format( _proxyShape) #if proxyShape not in _d_create.keys(): #raise ValueError,"Unknown shape: {0}".format(proxyShape) _kws = {'ch': ch} if proxyShape in ['cube']: _kws['width'] = size[0] _kws['ch'] = False if proxyShape in ['cylinder', 'sphere', 'cone', 'cylinder', 'torus']: _kws['radius'] = max(size) / 2.0 _kws['axis'] = VALID.simpleAxis(direction).p_vector _res = _call(**_kws) if size is not None: if VALID.isListArg(size): TRANS.scale_to_boundingBox(_res[0], size) else: if absoluteSize: _f_current = DIST.get_bb_size(_res[0], True, True) multiplier = size / _f_current mc.scale(multiplier, multiplier, multiplier, _res[0], relative=True) else: mc.scale(size, size, size, _res[0], os=True) #mc.makeIdentity(_res[0], apply=True,s=1) """ if proxyShape == 'cube': _d_directionXRotates = {'x+':[0,0,0],'x-':[0,180,0],'y+':[0,0,90],'y-':[0,0,-90],'z+':[0,-90,0],'z-':[0,90,0]} _r_factor = _d_directionXRotates.get(direction) mc.rotate (_r_factor[0], _r_factor[1], _r_factor[2], _res[0], ws=True)""" #mc.makeIdentity(_res[0], apply=True,r =1, n= 1) if proxyShape == 'cube': _children = TRANS.children_get(_res[0]) for i, c in enumerate(_children): _children[i] = TRANS.parent_set(c, False) combineShapes(_children + [_res[0]], keepSource=False, replaceShapes=False) return _res except Exception, err: cgmGEN.cgmExceptCB(Exception, err, msg=vars())