def matchInternalPoseObjects(self, nodes=None, fromFilter=True): ''' This is a throw-away and only used in the UI to select for debugging! from a given poseFile return or select the internal stored objects ''' InternalNodes = [] if not fromFilter: #no filter, we just pass in the longName thats stored for key in self.poseDict.keys(): if cmds.objExists(self.poseDict[key]['longName']): InternalNodes.append(self.poseDict[key]['longName']) elif cmds.objExists(key): InternalNodes.append(key) elif cmds.objExists(r9Core.nodeNameStrip(key)): InternalNodes.append(r9Core.nodeNameStrip(key)) else: #use the internal Poses filter and then Match against scene nodes if self.settings.filterIsActive(): filterData = r9Core.FilterNode(nodes, self.settings).ProcessFilter() matchedPairs = self._matchNodesToPoseData(filterData) if matchedPairs: InternalNodes = [node for _, node in matchedPairs] if not InternalNodes: raise StandardError('No Matching Nodes found!!') return InternalNodes
def matchInternalPoseObjects(self, nodes=None, fromFilter=True): ''' This is a throw-away and only used in the UI to select for debugging! from a given poseFile return or select the internal stored objects ''' InternalNodes=[] if not fromFilter: #no filter, we just pass in the longName thats stored for key in self.poseDict.keys(): if cmds.objExists(self.poseDict[key]['longName']): InternalNodes.append(self.poseDict[key]['longName']) elif cmds.objExists(key): InternalNodes.append(key) elif cmds.objExists(r9Core.nodeNameStrip(key)): InternalNodes.append(r9Core.nodeNameStrip(key)) else: #use the internal Poses filter and then Match against scene nodes if self.settings.filterIsActive(): filterData=r9Core.FilterNode(nodes,self.settings).ProcessFilter() matchedPairs=self._matchNodesToPoseData(filterData) if matchedPairs: InternalNodes=[node for _,node in matchedPairs] if not InternalNodes: raise StandardError('No Matching Nodes found!!') return InternalNodes
def buildOffsetCloud(self, rootReference=None, raw=False): ''' Build a point cloud up for each node in nodes :param nodes: list of objects to be in the cloud :param rootReference: the node used for the initial pivot location :param raw: build the cloud but DON'T snap the nodes into place - an optimisation for the PoseLoad sequence ''' self.posePointRoot=cmds.ls(cmds.spaceLocator(name='posePointCloud'),l=True)[0] ppcShape=cmds.listRelatives(self.posePointRoot,type='shape')[0] cmds.setAttr("%s.localScaleZ" % ppcShape, 30) cmds.setAttr("%s.localScaleX" % ppcShape, 30) cmds.setAttr("%s.localScaleY" % ppcShape, 30) if self.settings: if self.prioritySnapOnly: self.settings.searchPattern=self.settings.filterPriority self.inputNodes=r9Core.FilterNode(self.inputNodes, self.settings).ProcessFilter() if self.inputNodes: self.inputNodes.reverse() # for the snapping operations if self.mayaUpAxis=='y': cmds.setAttr('%s.rotateOrder' % self.posePointRoot, 2) if rootReference: # and not mesh: r9Anim.AnimFunctions.snap([rootReference,self.posePointRoot]) for node in self.inputNodes: pnt=cmds.spaceLocator(name='pp_%s' % r9Core.nodeNameStrip(node))[0] if not raw: r9Anim.AnimFunctions.snap([node,pnt]) cmds.parent(pnt,self.posePointRoot) self.posePointCloudNodes.append((pnt,node)) cmds.select(self.posePointRoot) if self.mesh: self.shapeSwapMesh() return self.posePointCloudNodes
def _buildSkeletonData(self, rootJnt): ''' :param rootNode: root of the skeleton to process ''' self.skeletonDict = {} if not rootJnt: log.info('skeleton rootJnt joint was not found') return fn = r9Core.FilterNode(rootJnt) fn.settings.nodeTypes = 'joint' fn.settings.incRoots = False skeleton = fn.ProcessFilter() for jnt in skeleton: key = r9Core.nodeNameStrip(jnt) self.skeletonDict[key] = {} self.skeletonDict[key]['attrs'] = {} for attr in [ 'translateX', 'translateY', 'translateZ', 'rotateX', 'rotateY', 'rotateZ' ]: try: self.skeletonDict[key]['attrs'][attr] = cmds.getAttr( '%s.%s' % (jnt, attr)) except: log.debug('%s : attr is invalid in this instance' % attr)
def _buildPoseDict(self, nodes): ''' Build the internal poseDict up from the given nodes. This is the core of the Pose System ''' if self.metaPose: getMetaDict=self.metaRig.getNodeConnectionMetaDataMap # optimisation for i,node in enumerate(nodes): key=r9Core.nodeNameStrip(node) self.poseDict[key]={} self.poseDict[key]['ID']=i # selection order index self.poseDict[key]['longName']=node # longNode name if self.metaPose: self.poseDict[key]['metaData']=getMetaDict(node) # metaSystem the node is wired too channels=r9Anim.getSettableChannels(node,incStatics=True) if channels: self.poseDict[key]['attrs']={} for attr in channels: try: if cmds.getAttr('%s.%s' % (node,attr),type=True)=='TdataCompound': # blendShape weights support attrs=cmds.aliasAttr(node, q=True)[::2] # extract the target channels from the multi for attr in attrs: self.poseDict[key]['attrs'][attr]=cmds.getAttr('%s.%s' % (node,attr)) else: self.poseDict[key]['attrs'][attr]=cmds.getAttr('%s.%s' % (node,attr)) except: log.debug('%s : attr is invalid in this instance' % attr)
def _buildOffsetCloud(self,nodes,rootReference=None,raw=False): ''' Build a point cloud up for each node in nodes @param nodes: list of objects to be in the cloud @param rootReference: the node used for the initial pibot location @param raw: build the cloud but DON'T snap the nodes into place - an optimisation for the PoseLoad sequence ''' self.posePointCloudNodes=[] self.posePointRoot=cmds.ls(cmds.spaceLocator(name='posePointCloud'),l=True)[0] ppcShape=cmds.listRelatives(self.posePointRoot,type='shape')[0] cmds.setAttr( "%s.localScaleZ" % ppcShape, 30) cmds.setAttr( "%s.localScaleX" % ppcShape, 30) cmds.setAttr( "%s.localScaleY" % ppcShape, 30) if self.mayaUpAxis=='y': cmds.setAttr('%s.rotateOrder' % self.posePointRoot, 2) if rootReference:# and not mesh: r9Anim.AnimFunctions.snap([rootReference,self.posePointRoot]) for node in nodes: pnt=cmds.spaceLocator(name='pp_%s' % r9Core.nodeNameStrip(node))[0] if not raw: r9Anim.AnimFunctions.snap([node,pnt]) cmds.parent(pnt,self.posePointRoot) self.posePointCloudNodes.append((pnt,node)) return self.posePointCloudNodes
def _snapNodestoPosePnts(self): ''' snap each MAYA node to it's respective pntCloud point ''' for pnt, node in self.posePointCloudNodes: log.debug('snapping Ctrl : %s > %s : %s' % (r9Core.nodeNameStrip(node), pnt, node)) r9Anim.AnimFunctions.snap([pnt,node])
def _buildPoseDict(self, nodes): """ Build the internal poseDict up from the given nodes. This is the core of the Pose System """ if self.metaPose: getMetaDict = self.metaRig.getNodeConnectionMetaDataMap # optimisation for i, node in enumerate(nodes): key = r9Core.nodeNameStrip(node) self.poseDict[key] = {} self.poseDict[key]["ID"] = i # selection order index self.poseDict[key]["longName"] = node # longNode name if self.metaPose: self.poseDict[key]["metaData"] = getMetaDict(node) # metaSystem the node is wired too channels = r9Anim.getSettableChannels(node, incStatics=True) if channels: self.poseDict[key]["attrs"] = {} for attr in channels: if attr in self.skipAttrs: log.debug("Skipping attr as requested : %s" % attr) continue try: if ( cmds.getAttr("%s.%s" % (node, attr), type=True) == "TdataCompound" ): # blendShape weights support attrs = cmds.aliasAttr(node, q=True)[::2] # extract the target channels from the multi for attr in attrs: self.poseDict[key]["attrs"][attr] = cmds.getAttr("%s.%s" % (node, attr)) else: self.poseDict[key]["attrs"][attr] = cmds.getAttr("%s.%s" % (node, attr)) except: log.debug("%s : attr is invalid in this instance" % attr)
def _snapNodestoPosePnts(self): ''' snap each MAYA node to it's respective pntCloud point ''' for pnt, node in self.posePointCloudNodes: log.debug('snapping Ctrl : %s > %s : %s' % (r9Core.nodeNameStrip(node), pnt, node)) r9Anim.AnimFunctions.snap([pnt, node])
def formatAudioNode_to_Path(self): ''' rename the AudioNode so it ties to the wav name ''' try: cmds.rename(self.audioNode, r9Core.nodeNameStrip(os.path.splitext(os.path.basename(self.path))[0])) except: log.debug('failed to Rename node : %s' % self.audioNode)
def formatAudioNode_to_Path(self): ''' rename the AudioNode so it ties to the wav name ''' try: cmds.rename(self.audioNode, r9Core.nodeNameStrip(os.path.splitext(os.path.basename(self.path))[0])) except: if cmds.referenceQuery(self.audioNode,inr=True): log.info('failed to Rename Referenced Audio Node : %s' % self.audioNode) else: log.info('failed to Rename Audio node : %s' % self.audioNode)
def formatAudioNode_to_Path(self): ''' rename the AudioNode so it ties to the wav name ''' try: cmds.rename( self.audioNode, r9Core.nodeNameStrip( os.path.splitext(os.path.basename(self.path))[0])) except: log.debug('failed to Rename node : %s' % self.audioNode)
def _buildPoseDict(self, nodes): ''' Build the internal poseDict up from the given nodes. This is the core of the Pose System ''' getMirrorID = r9Anim.MirrorHierarchy().getMirrorCompiledID if self.metaPose: getMetaDict = self.metaRig.getNodeConnectionMetaDataMap # optimisation for i, node in enumerate(nodes): key = r9Core.nodeNameStrip(node) self.poseDict[key] = {} self.poseDict[key]['ID'] = i # selection order index self.poseDict[key]['longName'] = node # longNode name mirrorID = getMirrorID(node) if mirrorID: self.poseDict[key]['mirrorID'] = mirrorID if self.metaPose: self.poseDict[key]['metaData'] = getMetaDict( node) # metaSystem the node is wired too channels = r9Anim.getSettableChannels(node, incStatics=True) if channels: self.poseDict[key]['attrs'] = {} for attr in channels: if attr in self.skipAttrs: log.debug('Skipping attr as requested : %s' % attr) continue try: if cmds.getAttr( '%s.%s' % (node, attr), type=True ) == 'TdataCompound': # blendShape weights support attrs = cmds.aliasAttr( node, q=True )[:: 2] # extract the target channels from the multi for attr in attrs: self.poseDict[key]['attrs'][ attr] = cmds.getAttr('%s.%s' % (node, attr)) else: self.poseDict[key]['attrs'][attr] = cmds.getAttr( '%s.%s' % (node, attr)) except: log.debug('%s : attr is invalid in this instance' % attr)
def buildOffsetCloud(self, rootReference=None, raw=False): ''' Build a point cloud up for each node in nodes :param nodes: list of objects to be in the cloud :param rootReference: the node used for the initial pivot location :param raw: build the cloud but DON'T snap the nodes into place - an optimisation for the PoseLoad sequence ''' self.posePointRoot = cmds.ls(cmds.spaceLocator(name='posePointCloud'), l=True)[0] ppcShape = cmds.listRelatives(self.posePointRoot, type='shape')[0] cmds.setAttr("%s.localScaleZ" % ppcShape, 30) cmds.setAttr("%s.localScaleX" % ppcShape, 30) cmds.setAttr("%s.localScaleY" % ppcShape, 30) if self.settings: if self.prioritySnapOnly: self.settings.searchPattern = self.settings.filterPriority self.inputNodes = r9Core.FilterNode(self.inputNodes, self.settings).ProcessFilter() if self.inputNodes: self.inputNodes.reverse() # for the snapping operations if self.mayaUpAxis == 'y': cmds.setAttr('%s.rotateOrder' % self.posePointRoot, 2) if rootReference: # and not mesh: r9Anim.AnimFunctions.snap([rootReference, self.posePointRoot]) for node in self.inputNodes: pnt = cmds.spaceLocator(name='pp_%s' % r9Core.nodeNameStrip(node))[0] if not raw: r9Anim.AnimFunctions.snap([node, pnt]) cmds.parent(pnt, self.posePointRoot) self.posePointCloudNodes.append((pnt, node)) cmds.select(self.posePointRoot) if self.mesh: self.shapeSwapMesh() return self.posePointCloudNodes
def _buildSkeletonData(self, rootJnt): ''' :param rootNode: root of the skeleton to process ''' self.skeletonDict={} if not rootJnt: log.info('skeleton rootJnt joint was not found') return fn=r9Core.FilterNode(rootJnt) fn.settings.nodeTypes='joint' fn.settings.incRoots=False skeleton=fn.ProcessFilter() for jnt in skeleton: key=r9Core.nodeNameStrip(jnt) self.skeletonDict[key]={} self.skeletonDict[key]['attrs']={} for attr in ['translateX','translateY','translateZ', 'rotateX','rotateY','rotateZ']: try: self.skeletonDict[key]['attrs'][attr]=cmds.getAttr('%s.%s' % (jnt,attr)) except: log.debug('%s : attr is invalid in this instance' % attr)
def _buildSkeletonData(self, rootJnt): """ :param rootNode: root of the skeleton to process """ self.skeletonDict = {} if not rootJnt: log.info("skeleton rootJnt joint was not found") return fn = r9Core.FilterNode(rootJnt) fn.settings.nodeTypes = "joint" fn.settings.incRoots = False skeleton = fn.ProcessFilter() for jnt in skeleton: key = r9Core.nodeNameStrip(jnt) self.skeletonDict[key] = {} self.skeletonDict[key]["attrs"] = {} for attr in ["translateX", "translateY", "translateZ", "rotateX", "rotateY", "rotateZ"]: try: self.skeletonDict[key]["attrs"][attr] = cmds.getAttr("%s.%s" % (jnt, attr)) except: log.debug("%s : attr is invalid in this instance" % attr)
def poseLoad(self, nodes, filepath=None, useFilter=True, relativePose=False, relativeRots='projected', relativeTrans='projected', maintainSpaces=False, percent=None): ''' Entry point for the generic PoseLoad. :param nodes: if given load the data to only these. If given and filter=True this is the rootNode for the filter. :param filepath: posefile to load - if not given the pose is loaded from a cached instance on this class. :param useFilter: If the pose has an active Filter_Settings block and this is True then use the filter on the destination hierarchy. :param relativePose: kick in the posePointCloud to align the loaded pose relatively to the selected node. :param relativeRots: 'projected' or 'absolute' - how to calculate the offset. :param relativeTrans: 'projected' or 'absolute' - how to calculate the offset. :param maintainSpaces: this preserves any parentSwitching mismatches between the stored pose and the current rig settings, current spaces are maintained. This only checks those nodes in the snapList and only runs under relative mode. ''' if relativePose and not cmds.ls(sl=True): raise StandardError('Nothing selected to align Relative Pose too') if not type(nodes) == list: nodes = [nodes] # cast to list for consistency #push args to object - means that any poseHandler.py file has access to them self.relativePose = relativePose self.relativeRots = relativeRots self.relativeTrans = relativeTrans self.PosePointCloud = None self.filepath = filepath self.useFilter = useFilter # used in the getNodes call self.maintainSpaces = maintainSpaces nodesToLoad = self._poseLoad_buildcache(nodes) if not self.matchedPairs: raise StandardError('No Matching Nodes found in the PoseFile!') else: if self.relativePose: if self.prioritySnapOnly: #we've already filtered the hierarchy, may as well just filter the results for speed nodesToLoad = r9Core.prioritizeNodeList( nodesToLoad, self.settings.filterPriority, regex=True, prioritysOnly=True) nodesToLoad.reverse() #setup the PosePointCloud ------------------------------------------------- reference = cmds.ls(sl=True, l=True)[0] self.PosePointCloud = PosePointCloud(nodesToLoad) self.PosePointCloud.buildOffsetCloud(reference, raw=True) resetCache = [ cmds.getAttr('%s.translate' % self.PosePointCloud.posePointRoot), cmds.getAttr('%s.rotate' % self.PosePointCloud.posePointRoot) ] if self.maintainSpaces: if self.metaRig: parentSpaceCache = self.getMaintainedAttrs( nodesToLoad, self.metaRig.parentSwitchAttr) elif 'parentSpaces' in self.settings.rigData: parentSpaceCache = self.getMaintainedAttrs( nodesToLoad, self.settings.rigData['parentSpaces']) self._applyPose(percent) if self.relativePose: #snap the poseCloud to the new xform of the referenced node, snap the cloud #to the pose, reset the clouds parent to the cached xform and then snap the #nodes back to the cloud r9Anim.AnimFunctions.snap( [reference, self.PosePointCloud.posePointRoot]) if self.relativeRots == 'projected': if self.mayaUpAxis == 'y': cmds.setAttr( '%s.rx' % self.PosePointCloud.posePointRoot, 0) cmds.setAttr( '%s.rz' % self.PosePointCloud.posePointRoot, 0) elif self.mayaUpAxis == 'z': # f*****g Z!!!!!! cmds.setAttr( '%s.rx' % self.PosePointCloud.posePointRoot, 0) cmds.setAttr( '%s.ry' % self.PosePointCloud.posePointRoot, 0) self.PosePointCloud._snapPosePntstoNodes() if not self.relativeTrans == 'projected': cmds.setAttr( '%s.translate' % self.PosePointCloud.posePointRoot, resetCache[0][0][0], resetCache[0][0][1], resetCache[0][0][2]) if not self.relativeRots == 'projected': cmds.setAttr( '%s.rotate' % self.PosePointCloud.posePointRoot, resetCache[1][0][0], resetCache[1][0][1], resetCache[1][0][2]) if self.relativeRots == 'projected': if self.mayaUpAxis == 'y': cmds.setAttr( '%s.ry' % self.PosePointCloud.posePointRoot, resetCache[1][0][1]) elif self.mayaUpAxis == 'z': # f*****g Z!!!!!! cmds.setAttr( '%s.rz' % self.PosePointCloud.posePointRoot, resetCache[1][0][2]) if self.relativeTrans == 'projected': if self.mayaUpAxis == 'y': cmds.setAttr( '%s.tx' % self.PosePointCloud.posePointRoot, resetCache[0][0][0]) cmds.setAttr( '%s.tz' % self.PosePointCloud.posePointRoot, resetCache[0][0][2]) elif self.mayaUpAxis == 'z': # f*****g Z!!!!!! cmds.setAttr( '%s.tx' % self.PosePointCloud.posePointRoot, resetCache[0][0][0]) cmds.setAttr( '%s.ty' % self.PosePointCloud.posePointRoot, resetCache[0][0][1]) #if maintainSpaces then restore the original parentSwitch attr values #BEFORE pushing the point cloud data back to the rig if self.maintainSpaces and parentSpaceCache: # and self.metaRig: for child, attr, value in parentSpaceCache: log.debug('Resetting parentSwitches : %s.%s = %f' % (r9Core.nodeNameStrip(child), attr, value)) cmds.setAttr('%s.%s' % (child, attr), value) self.PosePointCloud._snapNodestoPosePnts() self.PosePointCloud.delete() cmds.select(reference)
def poseLoad(self, nodes, filepath=None, useFilter=True, relativePose=False, relativeRots='projected', relativeTrans='projected', maintainSpaces=False, percent=None): ''' Entry point for the generic PoseLoad. :param nodes: if given load the data to only these. If given and filter=True this is the rootNode for the filter. :param filepath: posefile to load - if not given the pose is loaded from a cached instance on this class. :param useFilter: If the pose has an active Filter_Settings block and this is True then use the filter on the destination hierarchy. :param relativePose: kick in the posePointCloud to align the loaded pose relatively to the selected node. :param relativeRots: 'projected' or 'absolute' - how to calculate the offset. :param relativeTrans: 'projected' or 'absolute' - how to calculate the offset. :param maintainSpaces: this preserves any parentSwitching mismatches between the stored pose and the current rig settings, current spaces are maintained. This only checks those nodes in the snapList and only runs under relative mode. ''' if relativePose and not cmds.ls(sl=True): raise StandardError('Nothing selected to align Relative Pose too') if not type(nodes)==list: nodes=[nodes] # cast to list for consistency #push args to object - means that any poseHandler.py file has access to them self.relativePose = relativePose self.relativeRots = relativeRots self.relativeTrans = relativeTrans self.PosePointCloud = None self.filepath = filepath self.useFilter = useFilter # used in the getNodes call self.maintainSpaces = maintainSpaces nodesToLoad = self._poseLoad_buildcache(nodes) if not self.matchedPairs: raise StandardError('No Matching Nodes found in the PoseFile!') else: if self.relativePose: if self.prioritySnapOnly: #we've already filtered the hierarchy, may as well just filter the results for speed nodesToLoad=r9Core.prioritizeNodeList(nodesToLoad, self.settings.filterPriority, regex=True, prioritysOnly=True) nodesToLoad.reverse() #setup the PosePointCloud ------------------------------------------------- reference=cmds.ls(sl=True,l=True)[0] self.PosePointCloud=PosePointCloud(nodesToLoad) self.PosePointCloud.buildOffsetCloud(reference, raw=True) resetCache=[cmds.getAttr('%s.translate' % self.PosePointCloud.posePointRoot), cmds.getAttr('%s.rotate' % self.PosePointCloud.posePointRoot)] if self.maintainSpaces: if self.metaRig: parentSpaceCache=self.getMaintainedAttrs(nodesToLoad, self.metaRig.parentSwitchAttr) elif 'parentSpaces' in self.settings.rigData: parentSpaceCache=self.getMaintainedAttrs(nodesToLoad, self.settings.rigData['parentSpaces']) self._applyPose(percent) if self.relativePose: #snap the poseCloud to the new xform of the referenced node, snap the cloud #to the pose, reset the clouds parent to the cached xform and then snap the #nodes back to the cloud r9Anim.AnimFunctions.snap([reference,self.PosePointCloud.posePointRoot]) if self.relativeRots=='projected': if self.mayaUpAxis=='y': cmds.setAttr('%s.rx' % self.PosePointCloud.posePointRoot,0) cmds.setAttr('%s.rz' % self.PosePointCloud.posePointRoot,0) elif self.mayaUpAxis=='z': # f*****g Z!!!!!! cmds.setAttr('%s.rx' % self.PosePointCloud.posePointRoot,0) cmds.setAttr('%s.ry' % self.PosePointCloud.posePointRoot,0) self.PosePointCloud._snapPosePntstoNodes() if not self.relativeTrans=='projected': cmds.setAttr('%s.translate' % self.PosePointCloud.posePointRoot, resetCache[0][0][0], resetCache[0][0][1], resetCache[0][0][2]) if not self.relativeRots=='projected': cmds.setAttr('%s.rotate' % self.PosePointCloud.posePointRoot, resetCache[1][0][0], resetCache[1][0][1], resetCache[1][0][2]) if self.relativeRots=='projected': if self.mayaUpAxis=='y': cmds.setAttr('%s.ry' % self.PosePointCloud.posePointRoot,resetCache[1][0][1]) elif self.mayaUpAxis=='z': # f*****g Z!!!!!! cmds.setAttr('%s.rz' % self.PosePointCloud.posePointRoot,resetCache[1][0][2]) if self.relativeTrans=='projected': if self.mayaUpAxis=='y': cmds.setAttr('%s.tx' % self.PosePointCloud.posePointRoot,resetCache[0][0][0]) cmds.setAttr('%s.tz' % self.PosePointCloud.posePointRoot,resetCache[0][0][2]) elif self.mayaUpAxis=='z': # f*****g Z!!!!!! cmds.setAttr('%s.tx' % self.PosePointCloud.posePointRoot,resetCache[0][0][0]) cmds.setAttr('%s.ty' % self.PosePointCloud.posePointRoot,resetCache[0][0][1]) #if maintainSpaces then restore the original parentSwitch attr values #BEFORE pushing the point cloud data back to the rig if self.maintainSpaces and parentSpaceCache: # and self.metaRig: for child,attr,value in parentSpaceCache: log.debug('Resetting parentSwitches : %s.%s = %f' % (r9Core.nodeNameStrip(child),attr,value)) cmds.setAttr('%s.%s' % (child,attr), value) self.PosePointCloud._snapNodestoPosePnts() self.PosePointCloud.delete() cmds.select(reference)