def create_controlResizeObj(target=None): _str_func = "create_controlResizeObj" if target is None: _sel = mc.ls(sl=True) if _sel: _res = [] for t in _sel: _res.append(create_controlResizeObj(t)) return _res if not target: raise ValueError, "|{0}| >> Must have a target".format(_str_func) if ATTR.get_message(target, 'cgmControlResizer'): return ATTR.get_message(target, 'cgmControlResizer') handle = create_at(target, 'null') ATTR.set_message(target, 'cgmControlResizer', handle) ATTR.set_message(handle, 'cgmControlResizerSource', target) handle = mc.rename(handle, NAMES.base(target) + '_cgmResizer') shapeParent_in_place(handle, target) ATTR.set(target, 'template', 1) return handle
def push_controlResizeObj(target=None): _str_func = "push_controlResizeObj" if target is None: _sel = mc.ls(sl=True) if _sel: _res = [] for t in _sel: _res.append(push_controlResizeObj(t)) mc.select(_res) return _res if not target: raise ValueError, "|{0}| >> Must have a target".format(_str_func) if ATTR.has_attr(target, 'cgmControlResizerSource'): source = ATTR.get_message(target, 'cgmControlResizerSource') if not source: raise ValueError, "|{0}| >> no cgmControlResizerSource data on target: {1}".format( _str_func, target) source = source[0] shapeParent_in_place(source, target, keepSource=False, replaceShapes=True) if ATTR.has_attr(source, 'cgmControlResizer'): ATTR.delete(source, 'cgmControlResizer') ATTR.set(source, 'template', 0) mc.select(source) return source else: raise ValueError, "|{0}| >> no cgmControlResizerSource attr on target: {1}".format( _str_func, target)
def release_post_insert(self): #ATTR.set_messagse(_catch, 'tmpMsg', self.l_created[-1]) _loc = self.l_created[-1] _mLoc = r9Meta.MetaClass(_loc) _buffer = _mLoc.cgmLocDat _target = ATTR.get_message(_loc,'meshTarget')[0] _loc = mc.rename(_loc, "{0}_u{1}_v{2}_rayCast_loc".format(coreNames.get_base(_target), "{0:.4f}".format(_buffer['uv'][0]), "{0:.4f}".format(_buffer['uv'][1]), )) self.dropTool()
def matchTarget_snap(obj=None, move=True, rotate=True, boundingBox=False, pivot='rp'): """ Snap an object to it's match target :parameters: obj(str): Object to modify target(str): Target to match :returns success(bool) """ _str_func = 'matchTarget_snap' _obj = VALID.objString(obj, noneValid=False, calledFrom=__name__ + _str_func + ">> validate obj") _target = ATTR.get_message(_obj, 'cgmMatchTarget', 'cgmMatchDat', 0) if not _target: raise ValueError, "|{0}| >> {1} has no cgmMatchTarget.".format( _str_func, NAMES.get_short(_obj)) log.debug("|{0}| >> {1} snapping to: {2}.".format(_str_func, NAMES.get_short(_obj), _target[0])) go(obj, _target[0], move, rotate, pivot=pivot) return True _dict = POS.get_info(_target[0]) #cgmGEN.log_info_dict(_dict) pos = _dict['position'] if move: mc.move(pos[0], pos[1], pos[2], _obj, ws=True, rpr=True) if rotate: #if _dict.get('rotateOrder'):mc.xform(_obj, roo=_dict['rotateOrder'],p=True) if _dict.get('rotation'): mc.xform(_obj, ro=_dict['rotation'], ws=True) #if _dict.get('rotateAxis'):mc.xform(_obj, ra=_dict['rotateAxis'],p=True) return True
elif _targets: log.debug("|{0}| >> source mode...".format(_str_func)) if len(_targets) > 1: log.debug("|{0}| >> assuming midPoint...".format(_str_func)) return getAndMove(_loc, _targets, 'midPoint', forceBBCenter) else: log.debug("|{0}| >> singleTarget...".format(_str_func)) _d = POS.get_info(_targets, boundingBox=forceBBCenter) position(_loc, _d) return True else: log.debug("|{0}| >> tagged...".format(_str_func)) _mode = SEARCH.get_nodeTagInfo(_loc, 'cgmLocMode') if _mode == 'fromTarget': _targets = ATTR.get_message(_loc, 'cgmLocSource', 'cgmLocDat') return getAndMove(_loc, _targets, _mode, forceBBCenter) elif _mode == 'midPoint': _targets = ATTR.msgList_get(_loc, 'cgmLocSource', 'cgmLocDat') return getAndMove(_loc, _targets, _mode, forceBBCenter) elif _mode == 'closestPoint': _targets = ATTR.msgList_get(_loc, 'cgmLocSource', 'cgmLocDat') return getAndMove(_loc, _targets, _mode, forceBBCenter) elif _mode == 'closestTarget': _targets = ATTR.msgList_get(_loc, 'cgmLocSource', 'cgmLocDat') log.debug("|{0}| >> targets: {1}".format(_str_func, _targets)) return getAndMove(_loc, _targets, _mode, forceBBCenter) elif _mode == 'rayCast':
#>>>Scratch... m1.getMessage('rigNull',simple=False) import cgm.core.cgm_RigMeta as cgmRigMeta cgmRigMeta.cgmDynamicMatch(dynObject='l_knee_ik_anim',dynPrefix = "FKtoIK",dynMatchTargets='l_knee_blend_jnt') n1 = cgmRigMeta.cgmDynamicSwitch() n1.addSwitch() Rig.get_report(spine) m1.doRig() m1.rigDelete() reload(Rig) import cgm.core.lib.attribute_utils as ATTR reload(ATTR) m1 = cgmMeta.asMeta('l_leg_part') ATTR.get_message('M1_puppetNetwork','masterControl',simple = True) m1.modulePuppet.hasAttr('masterControl') m1.modulePuppet.masterControl m1.modulePuppet.getMessage('masterControl') cgmMeta.asMeta('l_leg_rigNull_dynSwitchSystem').getMessage('dynStoredAttr_0',simple=False) #ShapeCasting======================================================== from cgm.core.rigger import ModuleShapeCaster as mShapeCast reload(mShapeCast) from cgm.core.lib import shapeCaster as ShapeCast reload(ShapeCast) mShapeCast.go(m1,l_toBuild) m1 = cgmMeta.asMeta('l_arm_part') mShapeCast.go(m1,['segmentFK_Loli']) mShapeCast.go(m1,['settings'])
def get_objNameDict(obj, ignore=[False]): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns a generated dictionary of name info ARGUMENTS: obj(string) - object ignore(string) - default is 'none', only culls out cgmtags that are generated via returnCGMOrder() function RETURNS: namesDict(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ try: _str_funcName = "get_objNameDict" log.debug(">>> %s >>> " % (_str_funcName) + "=" * 75) if type(ignore) is not list: ignore = [ignore] namesDict = {} divider = returnCGMDivider() order = returnCGMOrder() nameBuilder = [] #>>> Get our cgmVar_iables #userAttrs = attributes.returnUserAttributes(obj) #cgmAttrs = lists.returnMatchList(userAttrs,order) #>>> Tag ignoring if ignore: for i in ignore: if i in order: order.remove(i) #>>> Geting our data for tag in order: tagInfo = SEARCH.get_tagInfo(obj, tag) if tagInfo is not False: namesDict[tag] = (tagInfo) if 'cgmIterator' in order: _iterator = ATTR.get(obj, 'cgmIterator') if _iterator is not False: log.debug("Iterator found") namesDict['cgmIterator'] = (_iterator) # remove tags up stream that we don't want if they don't exist on the actual object""" if not mc.objExists(obj + '.cgmTypeModifier'): if namesDict.get('cgmTypeModifier') != None: namesDict.pop('cgmTypeModifier') log.debug("%s >>> initial nameDict: %s " % (_str_funcName, namesDict)) #>>> checks if the names exist as objects or it's a shape node ChildNameObj = False nameObj = False cgmNameAttrType = ATTR.get_type(obj, 'cgmName') log.debug("cgmNameAttrType: {0}".format(cgmNameAttrType)) if cgmNameAttrType == 'message': #nameObj = SEARCH.get_nodeTagInfo(obj,'cgmName') nameObj = ATTR.get_message( obj, 'cgmName', simple=True) #SEARCH.get_nodeTagInfo(obj,'cgmName') if nameObj: nameObj = nameObj[0] nameObjDict = get_objNameDict(nameObj) #pprint.pprint(nameObjDict) for k in 'cgmDirection', 'cgmPosition': #if nameObjDict.get(k) and namesDict.get(k): try: namesDict.pop(k) except: pass log.debug("nameObj: {0}".format(nameObj)) namesDict['cgmName'] = names.getBaseName(nameObj) return namesDict typeTag = SEARCH.get_nodeTagInfo(obj, 'cgmType') isType = SEARCH.VALID.get_mayaType(obj) isShape = SEARCH.VALID.is_shape(obj) """first see if it's a group """ if isType == 'group' and typeTag == False: childrenObjects = TRANS.children_get(obj, False) log.debug("%s >>> group and no typeTag..." % (_str_funcName)) """ if it's a transform group """ groupNamesDict = {} if not nameObj: groupNamesDict['cgmName'] = childrenObjects[0] else: groupNamesDict['cgmName'] = nameObj groupNamesDict['cgmType'] = CORESHARE.d_cgmTypes.get('transform') if namesDict.get('cgmTypeModifier') != None: groupNamesDict['cgmTypeModifier'] = namesDict.get( 'cgmTypeModifier') return groupNamesDict """ see if there's a name tag""" elif isType in ['joint']: return namesDict elif isShape: #If we have a name object or shape log.debug("%s >>> nameObj not None or isType is 'shape'..." % (_str_funcName)) if isShape: #log.debug("%s >>> nameObj exists: '%s'..."%(_str_funcName,nameObj)) #Basic child object with cgmName tag childNamesDict = {} childNamesDict['cgmName'] = namesDict.get('cgmName') childNamesDict['cgmType'] = namesDict.get('cgmType') if namesDict.get('cgmTypeModifier') != None: childNamesDict['cgmTypeModifier'] = namesDict.get( 'cgmTypeModifier') if namesDict.get('cgmIterator') != None: childNamesDict['cgmIterator'] = namesDict.get( 'cgmIterator') return childNamesDict elif isShape or 'Constraint' in isType: """if so, it's a child name object""" log.debug("%s >>> child name object..." % (_str_funcName)) childNamesDict = {} childNamesDict['cgmName'] = TRANS.parent_get(obj, False) childNamesDict['cgmType'] = namesDict.get('cgmType') return childNamesDict else: log.debug("%s >>> No special case found. %s" % (_str_funcName, namesDict)) return namesDict else: return namesDict except Exception, err: raise cgmGEN.cgmExceptCB(Exception, err, msg=vars())
def _fnc_processInfluenceMode(self): ''' Sort out the joint data If joitn list is passed, try to use that, if not, Try skin cluster on target, cluster on source ''' _mode = self._influenceMode _l_configInfluenceList = self.get_ConfigJointList()#...get our config influence list self.l_configInfluenceList = _l_configInfluenceList#...store it _len_configList = len(_l_configInfluenceList) _targetMesh = self.mData.d_target['mesh'] #...See if we have a skin cluster... _targetSkin = skinning.querySkinCluster(_targetMesh) or False if _mode == 'config': _l_jointTargets = _l_configInfluenceList elif _mode == 'list': _l_joints = self.d_kws.get('jointList') if not _l_joints: return self._FailBreak_("jointList kw required. '{0}' influenceMode".format(_mode)) if not cgmValid.isListArg(_l_joints): return self._FailBreak_("jointList is not a list. '{0}' influenceMode".format(_mode)) if len(_l_joints) != len(_l_configInfluenceList): return self._FailBreak_("Non matching counts on target influences({0}) and config data({1}) | Cannot use '{2}' influenceMode".format(len(_l_joints),len(_l_configInfluenceList),_mode)) _l_jointTargets = _l_joints elif _mode == 'msgLink': _msgLink = self.d_kws.get('msgLink','rigJoint') _l_jointTargets = [] for o in _l_configInfluenceList: jnt = ATTR.get_message(o,_msgLink) log.info( "No msgLink on jnt | link: {0} | jnt: {1}".format(_msgLink,jnt) ) if not jnt: return self._FailBreak_("No msgLink on jnt | link: {0} | jnt: {1}".format(_msgLink,o)) _l_jointTargets.append(jnt[0]) elif _mode == 'target': if not _targetSkin: return self._FailBreak_("Target mesh not skinned, cannot use '{0}' influenceMode".format(_mode)) _l_targetInfluences = mc.listConnections(_targetSkin+'.matrix') or [] if len(_l_targetInfluences) != len(_l_configInfluenceList): #for i,jnt in enumerate(_l_configInfluenceList): #try:_bfr = _l_targetInfluences[i] #except: # _bfr = False #self.log_info("{0} | Config: {1} | target: {2}".format(i,jnt,_bfr)) if self._b_addMissingInfluences: self._b_case_addMissingInfluences = True#...set our case else: return self._FailBreak_("Non matching counts on target influences({0}) and config data({1}) | Cannot use '{2}' influenceMode".format(len(_l_targetInfluences),len(_l_configInfluenceList),_mode)) _l_jointTargets = _l_targetInfluences elif _mode == 'source': if not self.mData.d_source: return self._FailBreak_("No source data found, cannot use '{0}' influenceMode".format(_mode)) _sourceSkin = skinning.querySkinCluster(self.mData.d_source['mesh']) or False _l_sourceInfluences = mc.listConnections(_sourceSkin+'.matrix') or [] if len(_l_sourceInfluences) != len(_l_configInfluenceList): return self._FailBreak_("Non matching counts on source influences({0}) and config data({1}) | Cannot use '{2}' influenceMode".format(len(_l_sourceInfluences),len(_l_configInfluenceList),_mode)) _l_jointTargets = _l_sourceInfluences if self._b_case_addMissingInfluences:#Missing Influence Add... self.log_info("addMissingInfluencesAttempt... "+ cgmGeneral._str_subLine) if _len_configList < len(_l_jointTargets): self.log_warning("More targetJoints({0}) than config joints({1}). Not implemented".format(len(_l_jointTargets),_len_configList)) else: _d = {} for i,v in enumerate(_l_jointTargets):_d[i] = v#...push stuff to a list for i,jnt in enumerate(_l_configInfluenceList): try:_bfr = _l_jointTargets[i] except: _l_search = [jnt, self.mData.d_sourceSkin['matrix'][i]] self.log_info("{0} | Config: {1} | missing joint. Attempting to find: {2}".format(i,jnt,_l_search)) for o in _l_search: foundJnt = cgmValid.objString(o, mayaType = _validObjTypes, noneValid=True)#...mayaType = 'joint', if foundJnt: _d[i] = foundJnt self._l_missingInfluences.append(foundJnt) self.log_info("Found {0}".format(foundJnt)) break return self._FailBreak_("{0} | Not able to fo find joint ({1})".format(i,jnt)) #...push back to our list _l_jointTargets = [] for i in range(_len_configList):_l_jointTargets.append(False) for i,v in _d.iteritems(): _l_jointTargets[i] = v #self.log_info("{0} | Config: {1} | target: {2}".format(i,jnt,_bfr)) #self.log_info("Joints to use....") #for i,j in enumerate(_l_jointsToUse): #self.log_info("{0} : {1} | config idxed to: {2}".format(i,j,_l_configInfluenceList[i])) #...see if they exist with no conflicts #_l_jointTargets = l_dataJoints#...this will change try:_l_jointsToUse = cgmValid.objStringList(_l_jointTargets,mayaType = _validObjTypes)#...mayaType = 'joint' except Exception,Error:return self._FailBreak_("influenceMode '{0}' joint check fail | {1}".format(_mode,Error)) self.l_jointsToUse = _l_jointsToUse