def copy_constraint(sourceConstraint=None, targetObj=None, constraintType=None, maintainOffset=True): """ Copy the constraint settings from a constraint to another object :parameters: node(str): node to query :returns list of constraints(list) """ _str_func = 'copy_constraint' log.debug("|{0}| >> constraint: {1} ".format(_str_func, sourceConstraint)) d_source = get_datDict(sourceConstraint) _type = d_source['type'] if constraintType is None: if targetObj is None: raise ValueError, "|{0}| >> Must have targetObject or constraintType ".format( _str_func) else: log.info( "|{0}| >> No constraintType passed. Using source's: '{1}' ". format(_str_func, _type)) constraintType = _type _call = _d_type_to_call.get(constraintType, False) if not _call: raise ValueError, "|{0}| >> {1} not a known type of constraint. node: {2}".format( _str_func, _type, sourceConstraint) if targetObj is None: targetObj = d_source['driven'] log.info( "|{0}| >> No target object passed. Using source's: '{1}' ".format( _str_func, targetObj)) cgmGEN.func_snapShot(vars()) result = _call(d_source['targets'], targetObj, maintainOffset=maintainOffset) d_result = get_datDict(result[0]) for i, a in enumerate(d_result['attrs']): if d_source['attrDrivers'][i]: ATTR.connect("{0}".format(d_source['attrDrivers'][i]), "{0}.{1}".format(result[0], d_result['attrs'][i])) else: ATTR.set(result[0], d_result['attrs'][i], d_source['attrWeights'][d_source['attrs'][i]]) return result
def snap(obj=None, targets=None, position=True, rotation=True, rotateAxis=False, rotateOrder=False, rotatePivot=False, scalePivot=False, objPivot='rp', objMode=None, objLoc=False, targetPivot='rp', targetMode=None, targetLoc=False, queryMode=False, space='w', mark=False, **kws): """ Core snap functionality. :parameters: obj(str): Object to modify target(str): Objects to snap to objPivot targetPivot objMode = targetMode position rotation rotateAxis rotateOrder scalePivot space mark :returns success(bool) """ try: _str_func = 'snap' try: obj = obj.mNode except: pass _obj = VALID.mNodeString(obj) if targets is None: log.debug("|{0}| >> self target... ".format(_str_func)) _targets = [_obj] else: _targets = VALID.mNodeStringList(targets) reload(VALID) _pivotObj = VALID.kw_fromDict(objPivot, SHARED._d_pivotArgs, noneValid=True) _pivotTar = VALID.kw_fromDict(targetPivot, SHARED._d_pivotArgs, noneValid=True) _space = VALID.kw_fromDict(space, SHARED._d_spaceArgs, noneValid=False, calledFrom=__name__ + _str_func + ">> validate space") log.debug( "|{0}| >> obj: {1}({2}-{3}) | target:({4}-{5})({6}) | space: {7}". format(_str_func, _obj, _pivotObj, objMode, _pivotTar, targetMode, _targets, _space)) log.debug( "|{0}| >> position: {1} | rotation:{2} | rotateAxis: {3} | rotateOrder: {4}" .format(_str_func, position, rotation, rotateAxis, rotateOrder)) kws_xform = {'ws': False, 'os': False} if _space == 'world': kws_xform['ws'] = True else: kws_xform['os'] = True #Mode type defaults... if objMode is None: if _pivotObj is 'boundingBox': objMode = 'center' elif _pivotObj in ['castCenter', 'castFar', 'castNear', 'axisBox']: objMode = 'z+' if targetMode is None: if _pivotTar is 'boundingBox': targetMode = 'center' elif _pivotTar in ['castCenter', 'castFar', 'castNear', 'axisBox']: targetMode = 'z+' if _pivotTar in ['castFar', 'castAllFar', 'castNear', 'castAllNear']: if targetMode == 'center': log.debug( "|{0}| >> Center target mode invalid with {1}. Changing to 'z+' " .format(_str_func, _pivotTar)) targetMode = 'z+' #cgmGEN.func_snapShot(vars()) if position or objLoc or targetLoc or rotatePivot or scalePivot: kws_xform_move = copy.copy(kws_xform) if _pivotTar == 'sp': kws_xform_move['spr'] = True else: kws_xform_move['rpr'] = True #>>>Target pos ------------------------------------------------------------------------------ log.debug( "|{0}| >> Position True. Getting target pivot pos {1} ".format( _str_func, _pivotTar)) l_nameBuild = [ '_'.join([NAMES.get_base(o) for o in _targets]), _pivotTar ] if targetMode and _pivotTar not in [ 'sp', 'rp', 'closestPoint', 'groundPos' ]: l_nameBuild.append(targetMode) l_pos = [] if _pivotTar in ['sp', 'rp']: log.debug("|{0}| >> xform query... ".format(_str_func)) for t in _targets: l_pos.append(POS.get(t, _pivotTar, _space)) pos_target = DIST.get_average_position(l_pos) elif _pivotTar == 'closestPoint': log.debug("|{0}|...closestPoint...".format(_str_func)) pos_target = DIST.get_by_dist(_obj, _targets, resMode='pointOnSurface') else: log.debug("|{0}| >> special query... ".format(_str_func)) _targetsSpecial = copy.copy(_targets) if _pivotTar not in [ 'axisBox', 'groundPos', 'castCenter', 'boundingBox' ]: _targetsSpecial.insert(0, _obj) pos_target = get_special_pos(_targetsSpecial, _pivotTar, targetMode) if not pos_target: return log.error("No position detected") if targetLoc: _loc = mc.spaceLocator()[0] mc.move(pos_target[0], pos_target[1], pos_target[2], _loc, ws=True) mc.rename(_loc, '{0}_loc'.format('_'.join(l_nameBuild))) log.debug("|{0}| >> Target pivot: {1}".format( _str_func, pos_target)) #>>>Obj piv ------------------------------------------------------------------------------ log.debug("|{0}| >> Getting obj pivot pos {1} ".format( _str_func, _pivotObj)) l_nameBuild = [NAMES.get_base(_obj), _pivotObj] if objMode and _pivotObj not in [ 'sp', 'rp', 'closestPoint', 'groundPos' ]: l_nameBuild.append(objMode) l_pos = [] if _pivotObj in ['sp', 'rp']: log.debug("|{0}| >> xform query... ".format(_str_func)) pos_obj = POS.get(_obj, _pivotObj, _space) elif _pivotObj == 'closestPoint': log.debug("|{0}|...closestPoint...".format(_str_func)) pos_obj = DIST.get_by_dist(_targets[0], _obj, resMode='pointOnSurface') else: log.debug("|{0}| >> special query... ".format(_str_func)) pos_obj = get_special_pos(_obj, _pivotObj, objMode) if objLoc: _loc = mc.spaceLocator()[0] mc.move(pos_obj[0], pos_obj[1], pos_obj[2], _loc, ws=True) mc.rename(_loc, '{0}_loc'.format('_'.join(l_nameBuild))) log.debug("|{0}| >> Obj pivot: {1}".format(_str_func, pos_obj)) if queryMode: pprint.pprint(vars()) log.warning("|{0}| >> Query mode. No snap".format(_str_func)) mc.select([_obj] + _targets) return True #>>>Obj piv ------------------------------------------------------------------------------ if position: log.debug("|{0}| >> Positioning... ".format(_str_func)) if _pivotObj == 'rp': TRANS.position_set(obj, pos_target) #POS.set(_obj, pos_target) else: p_start = TRANS.position_get(_obj) _vector_to_objPivot = COREMATH.get_vector_of_two_points( p_start, pos_obj) _dist_base = DIST.get_distance_between_points( p_start, pos_obj) #...get our base distance p_result = DIST.get_pos_by_vec_dist( pos_target, _vector_to_objPivot, -_dist_base) cgmGEN.func_snapShot(vars()) POS.set(_obj, p_result) if rotateAxis: log.debug("|{0}|...rotateAxis...".format(_str_func)) mc.xform(obj, ra=mc.xform(_targets[0], q=True, ra=True, **kws_xform), p=True, **kws_xform) if rotateOrder: log.debug("|{0}|...rotateOrder...".format(_str_func)) mc.xform(obj, roo=mc.xform(_targets[0], q=True, roo=True), p=True) if rotation: log.debug("|{0}|...rotation...".format(_str_func)) _t_ro = ATTR.get_enumValueString(_targets[0], 'rotateOrder') _obj_ro = ATTR.get_enumValueString(obj, 'rotateOrder') if _t_ro != _obj_ro: #Creating a loc to get our target space rotateOrder into new space log.debug( "|{0}|...rotateOrders don't match...".format(_str_func)) _loc = mc.spaceLocator(n='tmp_roTranslation')[0] ATTR.set(_loc, 'rotateOrder', _t_ro) rot = mc.xform(_targets[0], q=True, ro=True, **kws_xform) mc.xform(_loc, ro=rot, **kws_xform) mc.xform(_loc, roo=_obj_ro, p=True) rot = mc.xform(_loc, q=True, ro=True, **kws_xform) mc.delete(_loc) else: rot = mc.xform(_targets[0], q=True, ro=True, **kws_xform) mc.xform(_obj, ro=rot, **kws_xform) if rotatePivot: log.debug("|{0}|...rotatePivot...".format(_str_func)) mc.xform(obj, rp=pos_target, p=True, **kws_xform) if scalePivot: log.debug("|{0}|...scalePivot...".format(_str_func)) mc.xform(obj, sp=pos_target, p=True, **kws_xform) except Exception, err: cgmGEN.cgmExceptCB(Exception, err)
def build_aimSequence(l_driven = None, l_targets = None, l_parents = None, l_upTargets = None, msgLink_masterGroup = 'masterGroup', aim = [0,0,1], up = [0,1,0], mode = 'sequence',#sequence,singleBlend upMode = 'objRotation',#objRotation,decomposeMatrix upParent = [0,1,0], rootTargetEnd = None, rootTargetStart=None,#specify root targets by index and mObj mRoot = None,#need for sequence interpType = None, maintainOffset = False): """ This kind of setup is for setting up a blended constraint so that obj2 in an obj1/obj2/obj3 sequence can aim forward or back as can obj3. :parameters: l_jointChain1 - First set of objects :returns: :raises: Exception | if reached """ _str_func = 'build_aimSequence' ml_driven = cgmMeta.validateObjListArg(l_driven,'cgmObject') ml_targets = cgmMeta.validateObjListArg(l_targets,'cgmObject',noneValid=True) ml_parents = cgmMeta.validateObjListArg(l_parents,'cgmObject',noneValid=True) ml_upTargets = cgmMeta.validateObjListArg(l_upTargets,'cgmObject',noneValid=True) if not ml_upTargets: ml_upTargets = ml_parents axis_aim = VALID.simpleAxis(aim) axis_aimNeg = axis_aim.inverse axis_up = VALID.simpleAxis(up) v_aim = axis_aim.p_vector#aimVector v_aimNeg = axis_aimNeg.p_vector#aimVectorNegative v_up = axis_up.p_vector #upVector #cgmGEN.func_snapShot(vars()) if mode == 'singleBlend': if len(ml_targets) != 2: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have 2 targets.".format(_str_func)) if len(ml_driven) != 1: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have 1 driven obj.".format(_str_func)) if not ml_parents: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have handleParents.".format(_str_func)) if len(ml_parents) != 1: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have 1 handleParent.".format(_str_func)) mDriven = ml_driven[0] if not mDriven.getMessage(msgLink_masterGroup): log.debug("|{0}| >> No master group, creating...".format(_str_func)) raise ValueError, log.error("|{0}| >> Add the create masterGroup setup, Josh".format(_str_func)) mMasterGroup = mDriven.getMessage(msgLink_masterGroup,asMeta=True)[0] s_rootTarget = False s_targetForward = ml_targets[-1].mNode s_targetBack = ml_targets[0].mNode i = 0 mMasterGroup.p_parent = ml_parents[i] mUpDecomp = None if upMode == 'decomposeMatrix': #Decompose matrix for parent... mUpDecomp = cgmMeta.cgmNode(nodeType = 'decomposeMatrix') mUpDecomp.rename("{0}_aimMatrix".format(ml_parents[i].p_nameBase)) #mUpDecomp.doStore('cgmName',ml_parents[i]) #mUpDecomp.addAttr('cgmType','aimMatrix',attrType='string',lock=True) #mUpDecomp.doName() ATTR.connect("{0}.worldMatrix".format(ml_parents[i].mNode),"{0}.{1}".format(mUpDecomp.mNode,'inputMatrix')) d_worldUp = {'worldUpObject' : ml_parents[i].mNode, 'worldUpType' : 'vector', 'worldUpVector': [0,0,0]} elif upMode == 'objectRotation': d_worldUp = {'worldUpObject' : ml_parents[i].mNode, 'worldUpType' : 'objectRotation', 'worldUpVector': upParent} else: raise ValueError, log.error("|{0}| >> Unknown upMode: {1}".format(_str_func,upMode)) if s_targetForward: mAimForward = mDriven.doCreateAt() mAimForward.parent = mMasterGroup mAimForward.doStore('cgmTypeModifier','forward') mAimForward.doStore('cgmType','aimer') mAimForward.doName() _const=mc.aimConstraint(s_targetForward, mAimForward.mNode, maintainOffset = True, #skip = 'z', aimVector = v_aim, upVector = v_up, **d_worldUp) s_targetForward = mAimForward.mNode if mUpDecomp: ATTR.connect("%s.%s"%(mUpDecomp.mNode,"outputRotate"),"%s.%s"%(_const[0],"upVector")) else: s_targetForward = ml_parents[i].mNode if s_targetBack: mAimBack = mDriven.doCreateAt() mAimBack.parent = mMasterGroup mAimBack.doStore('cgmTypeModifier','back') mAimBack.doStore('cgmType','aimer') mAimBack.doName() _const = mc.aimConstraint(s_targetBack, mAimBack.mNode, maintainOffset = True, #skip = 'z', aimVector = v_aimNeg, upVector = v_up, **d_worldUp) s_targetBack = mAimBack.mNode if mUpDecomp: ATTR.connect("%s.%s"%(mUpDecomp.mNode,"outputRotate"),"%s.%s"%(_const[0],"upVector")) else: s_targetBack = s_rootTarget #ml_parents[i].mNode pprint.pprint([s_targetForward,s_targetBack]) mAimGroup = mDriven.doGroup(True,asMeta=True,typeModifier = 'aim') mDriven.parent = False const = mc.orientConstraint([s_targetForward, s_targetBack], mAimGroup.mNode, maintainOffset = True)[0] d_blendReturn = NODEFACTORY.createSingleBlendNetwork([mDriven.mNode,'followRoot'], [mDriven.mNode,'resultRootFollow'], [mDriven.mNode,'resultAimFollow'], keyable=True) targetWeights = mc.orientConstraint(const,q=True, weightAliasList=True,maintainOffset=True) #Connect d_blendReturn['d_result1']['mi_plug'].doConnectOut('%s.%s' % (const,targetWeights[0])) d_blendReturn['d_result2']['mi_plug'].doConnectOut('%s.%s' % (const,targetWeights[1])) d_blendReturn['d_result1']['mi_plug'].p_hidden = True d_blendReturn['d_result2']['mi_plug'].p_hidden = True mDriven.parent = mAimGroup#...parent back mDriven.followRoot = .5 return True elif mode == 'sequence': """ if len(ml_targets) != 2: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have 2 targets.".format(_str_func)) if len(ml_driven) != 1: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have 1 driven obj.".format(_str_func)) if not ml_parents: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have handleParents.".format(_str_func)) if len(ml_parents) != 1: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have 1 handleParent.".format(_str_func)) """ for i,mDriven in enumerate(ml_driven): log.debug("|{0}| >> on: {1} | {2}".format(_str_func,i,mDriven)) mUpDecomp = False if not mDriven.getMessage(msgLink_masterGroup): log.debug("|{0}| >> No master group, creating...".format(_str_func)) raise ValueError, log.error("|{0}| >> Add the create masterGroup setup, Josh".format(_str_func)) mDriven.masterGroup.parent = ml_parents[i] if upMode == 'decomposeMatrix': #Decompose matrix for parent... mUpDecomp = cgmMeta.cgmNode(nodeType = 'decomposeMatrix') mUpDecomp.rename("{0}_aimMatrix".format(ml_parents[i].p_nameBase)) #mUpDecomp.doStore('cgmName',ml_parents[i]) #mUpDecomp.addAttr('cgmType','aimMatrix',attrType='string',lock=True) #mUpDecomp.doName() ATTR.connect("{0}.worldMatrix".format(ml_upTargets[i].mNode),"{0}.{1}".format(mUpDecomp.mNode,'inputMatrix')) d_worldUp = {'worldUpObject' : ml_upTargets[i].mNode, 'worldUpType' : 'vector', 'worldUpVector': [0,0,0]} elif upMode == 'objectRotation': d_worldUp = {'worldUpObject' : ml_upTargets[i].mNode, 'worldUpType' : 'objectRotation', 'worldUpVector': upParent} else: raise ValueError, log.error("|{0}| >> Unknown upMode: {1}".format(_str_func,upMode)) s_rootTarget = False s_targetForward = False s_targetBack = False mMasterGroup = mDriven.masterGroup b_first = False if mDriven == ml_driven[0]: log.debug("|{0}| >> First handle: {1}".format(_str_func,mDriven)) if len(ml_driven) <=2: s_targetForward = ml_parents[-1].mNode else: s_targetForward = ml_driven[i+1].getMessage('masterGroup')[0] if rootTargetStart: s_rootTarget = rootTargetStart.mNode else: s_rootTarget = mRoot.mNode b_first = True elif mDriven == ml_driven[-1]: log.debug("|{0}| >> Last handle: {1}".format(_str_func,mDriven)) if rootTargetEnd: s_rootTarget = rootTargetEnd.mNode else: s_rootTarget = ml_parents[i].mNode s_targetBack = ml_driven[i-1].getMessage('masterGroup')[0] else: log.debug("|{0}| >> Reg handle: {1}".format(_str_func,mDriven)) s_targetForward = ml_driven[i+1].getMessage('masterGroup')[0] s_targetBack = ml_driven[i-1].getMessage('masterGroup')[0] #Decompose matrix for parent... """ mUpDecomp = cgmMeta.cgmNode(nodeType = 'decomposeMatrix') mUpDecomp.doStore('cgmName',ml_parents[i]) mUpDecomp.addAttr('cgmType','aimMatrix',attrType='string',lock=True) mUpDecomp.doName() ATTR.connect("%s.worldMatrix"%(ml_parents[i].mNode),"%s.%s"%(mUpDecomp.mNode,'inputMatrix')) """ if s_targetForward: mAimForward = mDriven.doCreateAt() mAimForward.parent = mMasterGroup mAimForward.doStore('cgmTypeModifier','forward') mAimForward.doStore('cgmType','aimer') mAimForward.doName() _const=mc.aimConstraint(s_targetForward, mAimForward.mNode, maintainOffset = True, #skip = 'z', aimVector = v_aim, upVector = v_up,**d_worldUp) s_targetForward = mAimForward.mNode if mUpDecomp: ATTR.connect("%s.%s"%(mUpDecomp.mNode,"outputRotate"),"%s.%s"%(_const[0],"upVector")) elif s_rootTarget: s_targetForward = s_rootTarget else: s_targetForward = ml_parents[i].mNode if s_targetBack: mAimBack = mDriven.doCreateAt() mAimBack.parent = mMasterGroup mAimBack.doStore('cgmTypeModifier','back') mAimBack.doStore('cgmType','aimer') mAimBack.doName() _const = mc.aimConstraint(s_targetBack, mAimBack.mNode, maintainOffset = True, #skip = 'z', aimVector = v_aimNeg, upVector = v_up, **d_worldUp) s_targetBack = mAimBack.mNode if mUpDecomp: ATTR.connect("%s.%s"%(mUpDecomp.mNode,"outputRotate"),"%s.%s"%(_const[0],"upVector")) else: s_targetBack = s_rootTarget #ml_parents[i].mNode #pprint.pprint([s_targetForward,s_targetBack]) mAimGroup = mDriven.doGroup(True,asMeta=True,typeModifier = 'aim') mDriven.parent = False log.debug("|{0}| >> obj: {1} | {2}".format(_str_func,i,mDriven)) log.debug("|{0}| >> forward: {1}".format(_str_func,s_targetForward)) log.debug("|{0}| >> back: {1}".format(_str_func,s_targetBack)) log.debug(cgmGEN._str_subLine) if b_first: const = mc.orientConstraint([s_targetBack, s_targetForward], mAimGroup.mNode, maintainOffset = True)[0] else: const = mc.orientConstraint([s_targetForward, s_targetBack], mAimGroup.mNode, maintainOffset = True)[0] d_blendReturn = NODEFACTORY.createSingleBlendNetwork([mDriven.mNode,'followRoot'], [mDriven.mNode,'resultRootFollow'], [mDriven.mNode,'resultAimFollow'], keyable=True) targetWeights = mc.orientConstraint(const,q=True, weightAliasList=True,maintainOffset=True) #Connect d_blendReturn['d_result1']['mi_plug'].doConnectOut('%s.%s' % (const,targetWeights[0])) d_blendReturn['d_result2']['mi_plug'].doConnectOut('%s.%s' % (const,targetWeights[1])) d_blendReturn['d_result1']['mi_plug'].p_hidden = True d_blendReturn['d_result2']['mi_plug'].p_hidden = True mDriven.parent = mAimGroup#...parent back if interpType: ATTR.set(const,'interpType',interpType) #if mDriven in [ml_driven[0],ml_driven[-1]]: # mDriven.followRoot = 1 #else: mDriven.followRoot = .5 return True raise ValueError,"Not done..." return for i,mObj in enumerate(ml_driven): return mObj.masterGroup.parent = ml_parents[i] s_rootTarget = False s_targetForward = False s_targetBack = False mMasterGroup = mObj.masterGroup b_first = False if mObj == ml_driven[0]: log.debug("|{0}| >> First handle: {1}".format(_str_func,mObj)) if len(ml_driven) <=2: s_targetForward = ml_parents[-1].mNode else: s_targetForward = ml_driven[i+1].getMessage('masterGroup')[0] s_rootTarget = mRoot.mNode b_first = True elif mObj == ml_driven[-1]: log.debug("|{0}| >> Last handle: {1}".format(_str_func,mObj)) s_rootTarget = ml_parents[i].mNode s_targetBack = ml_driven[i-1].getMessage('masterGroup')[0] else: log.debug("|{0}| >> Reg handle: {1}".format(_str_func,mObj)) s_targetForward = ml_driven[i+1].getMessage('masterGroup')[0] s_targetBack = ml_driven[i-1].getMessage('masterGroup')[0] #Decompose matrix for parent... mUpDecomp = cgmMeta.cgmNode(nodeType = 'decomposeMatrix') mUpDecomp.doStore('cgmName',ml_parents[i]) mUpDecomp.addAttr('cgmType','aimMatrix',attrType='string',lock=True) mUpDecomp.doName() ATTR.connect("%s.worldMatrix"%(ml_parents[i].mNode),"%s.%s"%(mUpDecomp.mNode,'inputMatrix')) if s_targetForward: mAimForward = mObj.doCreateAt() mAimForward.parent = mMasterGroup mAimForward.doStore('cgmTypeModifier','forward') mAimForward.doStore('cgmType','aimer') mAimForward.doName() _const=mc.aimConstraint(s_targetForward, mAimForward.mNode, maintainOffset = True, #skip = 'z', aimVector = [0,0,1], upVector = [1,0,0], worldUpObject = ml_parents[i].mNode, worldUpType = 'vector', worldUpVector = [0,0,0]) s_targetForward = mAimForward.mNode ATTR.connect("%s.%s"%(mUpDecomp.mNode,"outputRotate"),"%s.%s"%(_const[0],"upVector")) else: s_targetForward = ml_parents[i].mNode if s_targetBack: mAimBack = mObj.doCreateAt() mAimBack.parent = mMasterGroup mAimBack.doStore('cgmTypeModifier','back') mAimBack.doStore('cgmType','aimer') mAimBack.doName() _const = mc.aimConstraint(s_targetBack, mAimBack.mNode, maintainOffset = True, #skip = 'z', aimVector = [0,0,-1], upVector = [1,0,0], worldUpObject = ml_parents[i].mNode, worldUpType = 'vector', worldUpVector = [0,0,0]) s_targetBack = mAimBack.mNode ATTR.connect("%s.%s"%(mUpDecomp.mNode,"outputRotate"),"%s.%s"%(_const[0],"upVector")) else: s_targetBack = s_rootTarget #ml_parents[i].mNode pprint.pprint([s_targetForward,s_targetBack]) mAimGroup = mObj.doGroup(True,asMeta=True,typeModifier = 'aim') mObj.parent = False if b_first: const = mc.orientConstraint([s_targetBack, s_targetForward], mAimGroup.mNode, maintainOffset = True)[0] else: const = mc.orientConstraint([s_targetForward, s_targetBack], mAimGroup.mNode, maintainOffset = True)[0] d_blendReturn = NODEFACTORY.createSingleBlendNetwork([mObj.mNode,'followRoot'], [mObj.mNode,'resultRootFollow'], [mObj.mNode,'resultAimFollow'], keyable=True) targetWeights = mc.orientConstraint(const,q=True, weightAliasList=True,maintainOffset=True) #Connect d_blendReturn['d_result1']['mi_plug'].doConnectOut('%s.%s' % (const,targetWeights[0])) d_blendReturn['d_result2']['mi_plug'].doConnectOut('%s.%s' % (const,targetWeights[1])) d_blendReturn['d_result1']['mi_plug'].p_hidden = True d_blendReturn['d_result2']['mi_plug'].p_hidden = True mObj.parent = mAimGroup#...parent back if mObj in [ml_driven[0],ml_driven[-1]]: mObj.followRoot = 1 else: mObj.followRoot = .5
def create_localAxisProxyBAK(obj=None): """ Make a local axis box around a given object so that you can then """ try: _str_func = 'create_localAxisProxy' _dag = VALID.getTransform(obj) if not _dag: raise ValueError, "Must have a dag node" l_shapes = TRANS.shapes_get(_dag) _dup = mc.duplicate(l_shapes, po=False, rc=True)[0] #_dup = TRANS.parent_set(_dup,False) #Get some values... t = ATTR.get(_dup, 'translate') r = ATTR.get(_dup, 'rotate') s = ATTR.get(_dup, 'scale') o = TRANS.orient_get(_dup) shear = ATTR.get(_dup, 'shear') _scaleLossy = TRANS.scaleLossy_get(_dag) #Reset our stuff before we make our bb... TRANS.orient_set(_dup, (0, 0, 0)) ATTR.set(_dup, 'scale', [1, 1, 1]) _size = POS.get_bb_size(_dup, True) import cgm.core.lib.math_utils as COREMATH reload(COREMATH) #_proxy = create_proxyGeo('cube',COREMATH.list_div(_scaleLossy,_size)) _proxy = create_proxyGeo('cube', _size) mc.makeIdentity(_proxy, apply=True, scale=True) return #mc.xform(_proxy, scale = _size, worldSpace = True, absolute = True) #Parent it to the dup... _proxy = TRANS.parent_set(_proxy, _dup) ATTR.reset(_proxy, ['t', 'r', 'shear']) #_dup = TRANS.parent_set(_dup, TRANS.parents_get(_dag)) SNAP.go(_dup, _dag) ATTR.set(_dup, 'shear', shear) #TRANS.scaleLocal_set(_dup, s) #mc.delete(_dup) #_scaleLossy = TRANS.scaleLossy_get(_dag) #import cgm.core.lib.math_utils as COREMATH #TRANS.scaleLocal_set(_dup, COREMATH.list_mult([-1.0,-1.0,-1.0],_scaleLossy,)) #proxy = TRANS.parent_set(_proxy, False) cgmGEN.func_snapShot(vars()) #ATTR.set(_dup,'translate',t) #ATTR.set(_dup,'rotate',r) #SNAP.go(_proxy[0],_dag) #ATTR.set(_proxy[0],'scale',_scaleLossy) #TRANS.scaleLocal_set(_dup,[1,1,1]) #ATTR.set(_dup,'shear',[0,0,0]) #_proxy = TRANS.parent_set(_proxy, False) #TRANS.scaleLocal_set(_proxy,_scaleLossy) #ATTR.set(_dup,'scale',s) return mc.rename(_proxy, "{0}_localAxisProxy".format(NAMES.get_base(_dag))) except Exception, err: cgmGEN.cgmExceptCB(Exception, err, msg=vars())