Ejemplo n.º 1
0
 def test_getMetaNodes_mTypesAsClass(self):
     #mTypes test passing in Class rather than string
     nodes=sorted(r9Meta.getMetaNodes(mTypes=[r9Meta.MetaRig,r9Meta.MetaFacialRig]),key=lambda x: x.mClass.upper())
     assert [n.mClass for n in nodes]==['MetaFacialRig','MetaRig']
     
     nodes=r9Meta.getMetaNodes(dataType=None, mTypes=[r9Meta.MetaRig])
     assert nodes==['MetaRig_Test']
Ejemplo n.º 2
0
 def test_getMetaNodes_mTypes(self):    
     #mTypes test
     nodes=sorted(r9Meta.getMetaNodes(mTypes=['MetaRig','MetaFacialRig']),key=lambda x: x.mClass.upper())
     assert [n.mClass for n in nodes]==['MetaFacialRig','MetaRig']
     
     nodes=r9Meta.getMetaNodes(dataType=None, mTypes=['MetaRig'])
     assert nodes==['MetaRig_Test']
Ejemplo n.º 3
0
 def test_getMetaNodes_mInstances(self):
     #mInstances tests
     nodes=r9Meta.getMetaNodes(dataType=None, mInstances=['MetaRig'])
     assert nodes==['MetaFacialRig_Test', 'MetaRig_Test']
     nodes=r9Meta.getMetaNodes(mInstances=['MetaRig'])
     assert [n.mNodeID for n in nodes]==['MetaFacialRig_Test', 'MetaRig_Test']
     nodes=r9Meta.getMetaNodes(mInstances=['MetaClass'])
     assert sorted([n.mNode for n in nodes])==['MetaClass_Test',
                                               'MetaFacialRigSupport_Test',
                                               'MetaFacialRig_Test',
                                               'MetaRigSupport_Test',
                                               'MetaRig_Test']  
Ejemplo n.º 4
0
 def test_getMetaNodes_mInstancesAsClass(self):
     #mInstances tests passing in Class rather than string
     nodes=r9Meta.getMetaNodes(dataType=None, mInstances=[r9Meta.MetaRig])
     assert nodes==['MetaFacialRig_Test', 'MetaRig_Test']
     nodes=r9Meta.getMetaNodes(mInstances=[r9Meta.MetaRig])
     assert [n.mNodeID for n in nodes]==['MetaFacialRig_Test', 'MetaRig_Test']
     nodes=r9Meta.getMetaNodes(mInstances=[r9Meta.MetaClass])
     assert sorted([n.mNode for n in nodes])==['MetaClass_Test',
                                               'MetaFacialRigSupport_Test',
                                               'MetaFacialRig_Test',
                                               'MetaRigSupport_Test',
                                               'MetaRig_Test']  
Ejemplo n.º 5
0
 def test_getMetaNodes_mAttrs(self):
     mNodes=r9Meta.getMetaNodes(mAttrs='mirrorSide=1')
     assert sorted([node.mNodeID for node in mNodes])==['L_Arm_System',
                                              'L_Fingers_System',
                                              'L_Leg_System',
                                              'L_Toes_System',
                                              'L_other_System'] 
     mNodes=r9Meta.getMetaNodes(mAttrs=['mirrorSide=1','systemType=Arm'])
     assert sorted([node.mNodeID for node in mNodes])==['L_Arm_System']
     
     mNodes=r9Meta.getMetaNodes(mAttrs=['systemType=Leg'])
     assert sorted([node.mNodeID for node in mNodes])== ['L_Leg_System', 'R_Leg_System']
Ejemplo n.º 6
0
def pushPoseFromLib(poseUIObj):
    mFacial = r9Meta.getMetaNodes(mTypes='Red9_MetaFacialCore')[0]
    posepath = poseUIObj.getPoseDir()
    poseName = os.path.basename(poseUIObj.getPoseSelected())
    print 'posepath', posepath
    print 'poseName', poseName
    mFacial.poses_pull_from_library(posepath, poseName)
Ejemplo n.º 7
0
 def setup(self):
     cmds.file(os.path.join(r9Setup.red9ModulePath(), 'tests', 'testFiles',
                            'MetaRig_anim_jump.mb'),
               open=True,
               f=True)
     self.mRig = r9Meta.getMetaNodes(mTypes=r9Meta.MetaRig)[0]
     self.poseFolder = getPoseFolder()
Ejemplo n.º 8
0
    def _bake(cls, namespace):
        source_rig = None
        dest_rig = None
        source_root = None
        meta_nodes = getMetaNodes(mTypes='MsvMetaRig')
        if meta_nodes:
            for obj in meta_nodes:
                # print 'obj rig: %s, rig: %s' % (obj.rigName, rig_name)
                # if obj.rigName == rig_name:
                if obj.nameSpaceFull().startswith(namespace):
                    dest_rig = obj
                else:
                    _source_rig = obj
                    _source_root = _source_rig.get_export_root()
                    if _source_root:
                        source_root = _source_root
                        source_rig = _source_rig

        if not source_root:
            root_name = dest_rig.get_export_root().split('|')[-1].split(
                ':')[-1]
            for jnt in mc.ls(type='joint'):
                if not mc.reference(
                        jnt, q=True,
                        isNodeReferenced=True) and not jnt.startswith(
                            namespace) and jnt.endswith(root_name):
                    source_root = jnt

        binder_rigs = r9Meta.getMetaNodes("MsvAnimationBinderRig")

        # source root (new rig) name is C_pelvis, Marker
        # but the dest root (old rig) name is root, marker, etc, so don't use name matching
        dest_root = [
            joint for joint in binder_rigs[0].get_root_joints()
            if mc.listRelatives(joint, c=True, type='joint')
        ][0]

        anim_binder.bind_skeletons(source_root, dest_root)

        dest_root_node = dest_rig.get_export_root()
        if mc.nodeType(dest_root_node) == 'reference':
            # We reference the skeleton into rig file
            # and the Meta rig node will store the reference node instead of the root joint
            # ps: the reference node is parent node of root joint
            joint_nodes = [
                node for node in mc.referenceQuery(
                    dest_root_node, nodes=True, dp=True)
                if mc.nodeType(node) == 'joint'
            ]
            joint_node = joint_nodes[0].split('|')[-1]
            dest_root_node = cls._get_root_parent(joint_node)
        else:
            # dest_root_node is u'|Thanator_Rig:main_Grp|Thanator_Rig:output_Grp|Thanator_Rig:C_pelvis'
            # always to select it's root parent node
            dest_root_node = dest_root_node.split('|')[1]

        ctrls = cls._get_bound_ctrls(dest_root_node)
        # anim_binder.bake_binder_data(dest_root_node)
        self._bake_binder_data()
        return source_rig, dest_rig, ctrls
def pushPoseFromLib(poseUIObj):
    mFacial = r9Meta.getMetaNodes(mTypes='Red9_MetaFacialCore')[0]
    posepath = poseUIObj.getPoseDir()
    poseName = os.path.basename(poseUIObj.getPoseSelected())
    print 'posepath', posepath
    print 'poseName', poseName
    mFacial.poses_pull_from_library(posepath, poseName)
Ejemplo n.º 10
0
    def setup(self):
        cmds.file(os.path.join(r9Setup.red9ModulePath(), 'tests', 'testFiles', 'MetaRig_anim_jump.mb'), open=True, f=True)
        self.mRig = r9Meta.getMetaNodes(mTypes=r9Meta.MetaRig)[0]
        self.poseFolder = getPoseFolder()

        # make our PoseData object with the unitTest config loaded
        filterNode = r9Core.FilterNode_Settings()
        filterNode.read(red9MetaRigConfig)
        self.poseData = r9Pose.PoseData(filterNode)
Ejemplo n.º 11
0
 def test_registerMClassNodeMapping(self):
     '''
     test the registry functions for nodeTypes
     '''
     cmds.file(new=True,f=True)
     r9Meta.MetaClass(name='standardNetworkMetaNode')
     assert [cmds.nodeType(n.mNode) for n in r9Meta.getMetaNodes()]==['network']   
      
     #register transforms to the NodeTypes
     r9Meta.registerMClassNodeMapping(nodeTypes='transform')
     assert r9Meta.getMClassNodeTypes()==['network', 'transform']
     new=r9Meta.MetaClass(name='newTransformMetaNode', nodeType='transform')
     assert [cmds.nodeType(n.mNode) for n in r9Meta.getMetaNodes()]==['network','transform']  
     
     #reset the NodeTypes
     r9Meta.resetMClassNodeTypes()
     assert r9Meta.getMClassNodeTypes()==['network']
     assert [cmds.nodeType(n.mNode) for n in r9Meta.getMetaNodes()]==['network'] 
Ejemplo n.º 12
0
 def setup(self):
     cmds.file(os.path.join(r9Setup.red9ModulePath(),'tests','testFiles','MetaRig_anim_jump.mb'),open=True,f=True)
     self.mRig = r9Meta.getMetaNodes(mTypes=r9Meta.MetaRig)[0]
     self.poseFolder = getPoseFolder()
     
     #make our PoseData object with the unitTest config loaded
     filterNode=r9Core.FilterNode_Settings()
     filterNode.read(red9MetaRigConfig)
     self.poseData=r9Pose.PoseData(filterNode)
Ejemplo n.º 13
0
def verify_sceneBlocks():
    """
    Gather all rig blocks data in scene

    :parameters:

    :returns
        metalist(list)
    """
    _str_func = 'verify_sceneBlocks'

    for mBlock in r9Meta.getMetaNodes(mTypes='cgmRigBlock',
                                      nTypes=['transform', 'network']):
        mBlock.atUtils('verify_blockAttrs', queryMode=False)
Ejemplo n.º 14
0
def get_from_scene():
    """
    Gather all rig blocks data in scene

    :parameters:

    :returns
        metalist(list)
    """
    _str_func = 'get_from_scene'

    _ml_rigBlocks = r9Meta.getMetaNodes(mTypes='cgmRigBlock',
                                        nTypes=['transform', 'network'])

    return _ml_rigBlocks
Ejemplo n.º 15
0
def removeAttrFromHUD(node, attr):
    """
    remove attrs from the MetaHUD
    """
    currentHUDs = r9Meta.getMetaNodes(mTypes=r9Meta.MetaHUDNode,
                                      mAttrs='mNodeID=CBMonitorHUD')
    if currentHUDs:
        metaHUD = currentHUDs[0]
        if attr:
            metaHUD.killHud()
            monitoredAttr = '%s_%s' % (r9Core.nodeNameStrip(node), attr)
            print 'removing attr :', attr, monitoredAttr
            try:
                metaHUD.removeMonitoredAttr(monitoredAttr)
            except:
                pass
        metaHUD.refreshHud()
Ejemplo n.º 16
0
def removeAttrFromHUD(node, attr):
    """
    remove attrs from the MetaHUD
    """
    currentHUDs = r9Meta.getMetaNodes(mTypes=r9Meta.MetaHUDNode,
                                      mAttrs='mNodeID=CBMonitorHUD')
    if currentHUDs:
        metaHUD=currentHUDs[0]
        if attr:
            metaHUD.killHud()
            monitoredAttr='%s_%s' % (r9Core.nodeNameStrip(node), attr)
            print 'removing attr :', attr, monitoredAttr
            try:
                metaHUD.removeMonitoredAttr(monitoredAttr)
            except:
                pass
        metaHUD.refreshHud()
Ejemplo n.º 17
0
def addAttrToHUD(node, attr):
    """
    adds node.attr to the HUD using Red9_Meta.MetaHUDNode
    """
    currentHUDs = r9Meta.getMetaNodes(mTypes=r9Meta.MetaHUDNode,
                                      mAttrs='mNodeID=CBMonitorHUD')
    
    if not currentHUDs:
        metaHUD = r9Meta.MetaHUDNode(name='CBMonitorHUD')
    else:
        metaHUD = currentHUDs[0]
    
    monitoredAttr='%s_%s' % (r9Core.nodeNameStrip(node), attr)
    metaHUD.addMonitoredAttr(monitoredAttr,
                             value=mc.getAttr('%s.%s' % (node, attr)),
                             refresh=False)
    mc.connectAttr('%s.%s' % (node, attr), '%s.%s' % (metaHUD.mNode, monitoredAttr))
    metaHUD.refreshHud()
Ejemplo n.º 18
0
    def test_longJsonDumps(self):
        '''
        Test the handling of LONG serialized Json data - testing the 16bit string attrTemplate handling
        NOTE: if you set a string to over 32,767 chars and don't lock the attr once made, selecting
        the textField in the AttributeEditor will truncate the data, hence this test!
        '''
        data= "x" * 40000
        self.MClass.addAttr('json_test', data)
        assert len(self.MClass.json_test)==40000
        
        #save the file and reload to ensure the attr is consistent
        cmds.file(rename=os.path.join(r9Setup.red9ModulePath(),'tests','testFiles','deleteMe.ma'))
        cmds.file(save=True,type='mayaAscii')
        cmds.file(new=True,f=True)
        cmds.file(os.path.join(r9Setup.red9ModulePath(),'tests','testFiles','deleteMe.ma'),open=True,f=True)

        mClass=r9Meta.getMetaNodes()[0]
        assert len(mClass.json_test)
Ejemplo n.º 19
0
def get_scene_block_heirarchy(asMeta=True):
    _str_func = 'get_scene_block_heirarchy'

    _md_heirachy = {}
    _ml_rigBlocks = r9Meta.getMetaNodes(mTypes='cgmRigBlock',
                                        nTypes=['transform', 'network'])

    for mBlock in _ml_rigBlocks:  #...find our roots
        if not mBlock.p_blockParent:
            log.debug("|{0}| >> Root: {1}".format(_str_func, mBlock.mNode))
            if asMeta:
                k = mBlock
            else:
                k = mBlock.mNode
            _md_heirachy[k] = mBlock.getBlockHeirarchyBelow(asMeta=asMeta)

    #cgmGEN.walk_dat(_md_heirachy, _str_func)
    return _md_heirachy
Ejemplo n.º 20
0
def addAttrToHUD(node, attr):
    """
    adds node.attr to the HUD using Red9_Meta.MetaHUDNode
    """
    currentHUDs = r9Meta.getMetaNodes(mTypes=r9Meta.MetaHUDNode,
                                      mAttrs='mNodeID=CBMonitorHUD')

    if not currentHUDs:
        metaHUD = r9Meta.MetaHUDNode(name='CBMonitorHUD')
    else:
        metaHUD = currentHUDs[0]

    monitoredAttr = '%s_%s' % (r9Core.nodeNameStrip(node), attr)
    metaHUD.addMonitoredAttr(monitoredAttr,
                             value=mc.getAttr('%s.%s' % (node, attr)),
                             refresh=False)
    mc.connectAttr('%s.%s' % (node, attr),
                   '%s.%s' % (metaHUD.mNode, monitoredAttr))
    metaHUD.refreshHud()
Ejemplo n.º 21
0
def get_scene_module_heirarchy(asMeta=True):
    _str_func = 'get_scene_module_heirarchy'

    _md_heirachy = {}
    _ml_puppets = r9Meta.getMetaNodes(mTypes=['cgmRigPuppet'],
                                      nTypes=['transform', 'network'])

    for mPuppet in _ml_puppets:  #...find our roots
        if asMeta:
            k = mPuppet
        else:
            k = mPuppet.mNode

        ml_initialModules = mPuppet.UTILS.modules_get(mPuppet)

        if not ml_initialModules:
            _md_heirachy[k] = {}
        else:
            _md_heirachy[k] = get_puppet_heirarchy_context(
                ml_initialModules[0], 'root', asList=False, report=False)

    #cgmGEN.walk_dat(_md_heirachy, _str_func)
    return _md_heirachy
mLambert.diffuse     #>>0.5
mLambert.color       #>>(0.5, 0.5, 0.5)
mLambert.color=(1,0.2,0.2) #sets the compound float3 attr

mLambert.diffuse=0.7 #sets the diffuse directly
mLambert.diffuse     #>>0.7


'''
General
===============================================================
Generic call to find all mClass nodes in the scene. This also takes
a type argument so you can return only nodes of a given class type
NOTE: 'type' the given class type must exist as a key in the RED9_META_REGISTRY 
'''
mClass = r9Meta.getMetaNodes()
mClass = r9Meta.getMetaNodes(dataType='mClass',mTypes='MetaRig')
#Return only MetaRig class objects. If the dataType isn't 'mClass' then we
#return the standard MayaNodes, else we return the mClass initialized to the class object

#Connect the selected Maya Nodes to the mClass node under a Multi-Message attr 'mirrorLeft'
node.connectChildren(cmds.ls(sl=True),'mirrorLeft')
node.mirrorLeft    #will now return all connected nodes to the message attr

#Connect the selected Maya Node to the mClass node under a NON Multi-Message attr 'simpleChild'
#this is what most of the MRig calls use as a single connection describes a single MayaNode
node.connectChild(cmds.ls(sl=True)[0],'simpleChild')
node.simpleChild    #will now return all connected nodes to the message attr

r9Meta.getConnectedMetaNodes(nodes, source=True, destination=True, dataType='mClass')
Ejemplo n.º 23
0
 def setup(self):
     cmds.file(os.path.join(r9Setup.red9ModulePath(),'tests','testFiles','Meta_Network_WalkTest.ma'),open=True,f=True)
     self.mRig=r9Meta.getMetaNodes(mTypes='MetaRig')[0]
Ejemplo n.º 24
0
 def test_getMetaNodes_mAttrs(self):
     assert r9Meta.getMetaNodes(mAttrs='version=1')[0].mNodeID=='MetaRig_Test'
Ejemplo n.º 25
0
#>>Instance query =========================================================================
#Okay, now let's search some stuff
#First, a call just to see some info about meta class inheritance as registered in the subclass registry
r9Meta.getMClassInstances(r9Meta.MetaClass)

#...make it more readable
for o in r9Meta.getMClassInstances(r9Meta.MetaClass):print o
#...as you can see there are a lot of subclasses. What if we just wanted to see subclasses to cgmObject
for o in r9Meta.getMClassInstances(cgmMeta.cgmObject):print o#...quite a few less

#>>getMetaNodes =========================================================================
#...just to make seeing stuff a little easier, we're gonna make a little pass through function
def _res(l):
    for o in l:print o

_res(r9Meta.getMetaNodes())#...returns all metaNodes in the scene
_res(r9Meta.getMetaNodes(dataType = ''))#...returns as dag strings
_res(r9Meta.getMetaNodes(mTypes = 'cgmObject'))#...only returns a given meta type
_res(r9Meta.getMetaNodes(mTypes = r9Meta.MetaClass))#...only returns a given meta type
_res(r9Meta.getMetaNodes(mInstances = 'cgmNode'))#...returns both the cgmNode in the scene and the cgmObject as it's a subclass to cgmNode

_res(r9Meta.getMetaNodes(mAttrs = 'tx=0'))#...get any nodes with a tx value of 1
_res(r9Meta.getMetaNodes(mAttrs = 'testAttr=2'))#...get our set attr
_res(r9Meta.getMetaNodes(mAttrs = 'NOT:testAttr=2'))#...get any nodes that don't have this value


#...relational 
_res(n1.getChildren())#...can see all our children of our 'parent' node
_res(n1.getChildren(asMeta = True))#...can get data as meta
n1.getChildren(cAttrs = ['childNode'])#....cAttrs checks the wiring
n1.getChildren(cAttrs = ['childNode2'])
Ejemplo n.º 26
0
 def test_getMetaNodes(self):
     nodes=sorted(r9Meta.getMetaNodes(),key=lambda x: x.mClass.upper())
     assert [n.mClass for n in nodes]==['MetaClass','MetaFacialRig','MetaFacialRigSupport','MetaRig','MetaRigSupport']
Ejemplo n.º 27
0
#...make it more readable
for o in r9Meta.getMClassInstances(r9Meta.MetaClass):
    print o
#...as you can see there are a lot of subclasses. What if we just wanted to see subclasses to cgmObject
for o in r9Meta.getMClassInstances(cgmMeta.cgmObject):
    print o  #...quite a few less


#>>getMetaNodes =========================================================================
#...just to make seeing stuff a little easier, we're gonna make a little pass through function
def _res(l):
    for o in l:
        print o


_res(r9Meta.getMetaNodes())  #...returns all metaNodes in the scene
_res(r9Meta.getMetaNodes(dataType=''))  #...returns as dag strings
_res(r9Meta.getMetaNodes(
    mTypes='cgmObject'))  #...only returns a given meta type
_res(r9Meta.getMetaNodes(
    mTypes=r9Meta.MetaClass))  #...only returns a given meta type
_res(
    r9Meta.getMetaNodes(mInstances='cgmNode')
)  #...returns both the cgmNode in the scene and the cgmObject as it's a subclass to cgmNode

_res(
    r9Meta.getMetaNodes(mAttrs='tx=0'))  #...get any nodes with a tx value of 1
_res(r9Meta.getMetaNodes(mAttrs='testAttr=2'))  #...get our set attr
_res(r9Meta.getMetaNodes(
    mAttrs='NOT:testAttr=2'))  #...get any nodes that don't have this value
Ejemplo n.º 28
0
mLambert = r9Meta.MetaClass('lambert1')
#mLambert is just a Python MetaNode and doesn't exist as a MayaNode
mLambert.diffuse  #>>0.5
mLambert.color  #>>(0.5, 0.5, 0.5)
mLambert.color = (1, 0.2, 0.2)  #sets the compound float3 attr

mLambert.diffuse = 0.7  #sets the diffuse directly
mLambert.diffuse  #>>0.7
'''
General
===============================================================
Generic call to find all mClass nodes in the scene. This also takes
a type argument so you can return only nodes of a given class type
NOTE: 'type' the given class type must exist as a key in the RED9_META_REGISTRY 
'''
mClass = r9Meta.getMetaNodes()
mClass = r9Meta.getMetaNodes(dataType='mClass', mTypes='MetaRig')
#Return only MetaRig class objects. If the dataType isn't 'mClass' then we
#return the standard MayaNodes, else we return the mClass initialized to the class object

#Connect the selected Maya Nodes to the mClass node under a Multi-Message attr 'mirrorLeft'
node.connectChildren(cmds.ls(sl=True), 'mirrorLeft')
node.mirrorLeft  #will now return all connected nodes to the message attr

#Connect the selected Maya Node to the mClass node under a NON Multi-Message attr 'simpleChild'
#this is what most of the MRig calls use as a single connection describes a single MayaNode
node.connectChild(cmds.ls(sl=True)[0], 'simpleChild')
node.simpleChild  #will now return all connected nodes to the message attr

r9Meta.getConnectedMetaNodes(nodes,
                             source=True,
Ejemplo n.º 29
0
 def setup(self):
     cmds.file(os.path.join(r9Setup.red9ModulePath(),'tests','testFiles','MetaRig_anim_jump.mb'),open=True,f=True)
     self.mRig = r9Meta.getMetaNodes(mTypes=r9Meta.MetaRig)[0]
     self.poseFolder = getPoseFolder()
Ejemplo n.º 30
0
def process_blocks_rig(f = None, blocks = None, postProcesses = False):
    _str_func = 'process_blocks_rig'
    #cgmGEN.log_start(_str_func)
    
    mFile = PATHS.Path(f)
    
    if not mFile.exists():
        raise ValueError,"Invalid file: {0}".format(f)
    
    _path = mFile.asFriendly()
    
    log.info("Good Path: {0}".format(_path))
    """
    if 'template' in _path:
        _newPath = _path.replace('template','build')
    else:"""
    _name = mFile.name()
    _d = mFile.up().asFriendly()
    log.debug(cgmGEN.logString_msg(_str_func,_name))
    _newPath = os.path.join(_d,_name+'_BUILD.{0}'.format(mFile.getExtension()))        

    log.info("New Path: {0}".format(_newPath))
    
    #cgmGEN.logString_msg(_str_func,'File Open...')
    mc.file(_path, open = 1, f = 1)
    
    #cgmGEN.logString_msg(_str_func,'Process...')
    t1 = time.time()
    
    try:
        if not blocks:
            #cgmGEN.logString_sub(_str_func,'No blocks arg')
            
            ml_masters = r9Meta.getMetaNodes(mTypes = 'cgmRigBlock',
                                             nTypes=['transform','network'],
                                             mAttrs='blockType=master')
    
            for mMaster in ml_masters:
                #cgmGEN.logString_sub(_str_func,mMaster)
        
                RIGBLOCKS.contextual_rigBlock_method_call(mMaster, 'below', 'atUtils','changeState','rig',forceNew=False)
    
                ml_context = BLOCKGEN.get_rigBlock_heirarchy_context(mMaster,'below',True,False)
                l_fails = []
        
                for mSubBlock in ml_context:
                    _state =  mSubBlock.getState(False)
                    if _state != 4:
                        l_fails.append(mSubBlock)
                        
                if l_fails:
                    log.info('The following failed...')
                    pprint.pprint(l_fails)
                    raise ValueError,"Modules failed to rig: {0}".format(l_fails)
        
                log.info("Begin Rig Prep cleanup...")
                '''
        
                Begin Rig Prep process
        
                '''
                mPuppet = mMaster.moduleTarget#...when mBlock is your masterBlock
                
                if postProcesses:
                    log.info('mirror_verify...')
                    mPuppet.atUtils('mirror_verify')
                    log.info('collect worldSpace...')
                    mPuppet.atUtils('collect_worldSpaceObjects')
                    log.info('qss...')
                    mPuppet.atUtils('qss_verify',puppetSet=1,bakeSet=1,deleteSet=1,exportSet=1)
                    log.info('proxyMesh...')
                    mPuppet.atUtils('proxyMesh_verify')
                    log.info('ihi...')
                    mPuppet.atUtils('rigNodes_setAttr','ihi',0)
                    log.info('rig connect...')
                    mPuppet.atUtils('rig_connectAll')
                    log.info('...')
                    
                    if cgmGEN.__mayaVersion__ >= 2018:
                        log.info('controller_verify...')
                        mPuppet.atUtils('controller_verify')
                        log.info('...')
                        
                        

    except Exception,err:
        log.error(err)
Ejemplo n.º 31
0
def createMRSRig(folderPath):
    cgm.core._  #reload()

    fileList = mc.getFileList(folder=folderPath)

    if not folderPath.endswith('\\'):
        folderPath = folderPath + '\\'

    if not 'MRSRigs' in mc.getFileList(folder=folderPath):
        mc.sysFile(folderPath + 'MRSRigs', md=1)
        newFolderPath = folderPath + 'MRSRigs\\'

    for _file in fileList:
        try:
            if (_file.endswith('.ma')):

                mc.file(folderPath + _file, open=1, f=1)

                log.info("Working on... " + _file)

                ml_masters = r9Meta.getMetaNodes(
                    mTypes='cgmRigBlock',
                    nTypes=['transform', 'network'],
                    mAttrs='blockType=master')

                for mBlock in ml_masters:

                    log.info(mBlock)

                    RIGBLOCKS.contextual_rigBlock_method_call(mBlock,
                                                              'below',
                                                              'atUtils',
                                                              'changeState',
                                                              'rig',
                                                              forceNew=False)
                    mBlock.moduleTarget  #<< link to puppet
                    '''
                    This is the start of the puppet calls

                    '''

                    #If more than one Rig exists Do:
                    #if len(ml_masters):raise ValueError,"Too many masters: {0}".format(ml_masters)

                    #rig call if you prefer as a for loop: build rig, check rig
                    ml_context = BLOCKGEN.get_rigBlock_heirarchy_context(
                        mBlock, 'below', True, False)
                    pprint.pprint(ml_context)

                    log.info('Begin Rig Build')

                    ml_context = BLOCKGEN.get_rigBlock_heirarchy_context(
                        mBlock, 'below', True, False)
                    l_fails = []

                    for mSubBlock in ml_context:
                        _state = mSubBlock.getState(False)
                        if _state != 4:
                            l_fails.append(mSubBlock)
                    if l_fails:
                        log.info('The following failed...')
                        pprint.pprint(l_fails)
                        raise ValueError, "Modules failed to rig: {0}".format(
                            l_fails)

                    log.info("Begin Rig Prep cleanup...")
                    '''

                    Begin Rig Prep process

                    '''

                    mPuppet = mBlock.moduleTarget  #...when mBlock is your masterBlock

                    log.info('mirror_verify...')
                    mPuppet.atUtils('mirror_verify')
                    log.info('collect worldSpace...')
                    mPuppet.atUtils('collect_worldSpaceObjects')
                    log.info('qss...')
                    mPuppet.atUtils('qss_verify',
                                    puppetSet=1,
                                    bakeSet=1,
                                    deleteSet=1,
                                    exportSet=1)
                    log.info('proxyMesh...')
                    mPuppet.atUtils('proxyMesh_verify')
                    log.info('ihi...')
                    mPuppet.atUtils('rigNodes_setAttr', 'ihi', 0)
                    log.info('rig connect...')
                    mPuppet.atUtils('rig_connectAll')

                #Save the scene in the new folder.

                log.info("Saving out the new scene...")

                newFile = mc.file(rename=newFolderPath +
                                  _file.split('_template')[0] + "_rig.ma")
                mc.file(save=1, type='mayaAscii')

                log.info("Saved new scene " + newFile)

            else:
                log.info("There was an error creating new file...")
        except Exception, err:
            log.error("File failed: {0}".format(_file))
            cgmGEN.cgmException(Exception, err)
Ejemplo n.º 32
0
def process_blocks_rig(f=None, blocks=None, postProcesses=1, **kws):
    _str_func = 'process_blocks_rig'
    #cgmGEN.log_start(_str_func)

    mFile = PATHS.Path(f)

    if not mFile.exists():
        raise ValueError, "Invalid file: {0}".format(f)

    _path = mFile.asFriendly()

    log.info("Good Path: {0}".format(_path))
    """
    if 'template' in _path:
        _newPath = _path.replace('template','build')
    else:"""
    _name = mFile.name()
    _d = mFile.up().asFriendly()
    log.debug(cgmGEN.logString_msg(_str_func, _name))
    _newPath = os.path.join(_d,
                            _name + '_BUILD.{0}'.format(mFile.getExtension()))

    log.info("New Path: {0}".format(_newPath))

    #cgmGEN.logString_msg(_str_func,'File Open...')
    mc.file(_path, open=1, f=1)

    #cgmGEN.logString_msg(_str_func,'Process...')
    T1 = time.time()

    get_time = cgmGEN.get_timeString

    try:
        if not blocks:
            #cgmGEN.logString_sub(_str_func,'No blocks arg')

            ml_masters = r9Meta.getMetaNodes(mTypes='cgmRigBlock',
                                             nTypes=['transform', 'network'],
                                             mAttrs='blockType=master')

            for mMaster in ml_masters:
                #cgmGEN.logString_sub(_str_func,mMaster)

                RIGBLOCKS.contextual_rigBlock_method_call(mMaster,
                                                          'below',
                                                          'atUtils',
                                                          'changeState',
                                                          'rig',
                                                          forceNew=False)

                ml_context = BLOCKGEN.get_rigBlock_heirarchy_context(
                    mMaster, 'below', True, False)
                l_fails = []

                for mSubBlock in ml_context:
                    _state = mSubBlock.getState(False)
                    if _state != 4:
                        l_fails.append(mSubBlock)

                if l_fails:
                    log.info('The following failed...')
                    pprint.pprint(l_fails)
                    raise ValueError, "Modules failed to rig: {0}".format(
                        l_fails)

                log.info("Begin Rig Prep cleanup...")
                '''
        
                Begin Rig Prep process
        
                '''
                mPuppet = mMaster.moduleTarget  #...when mBlock is your masterBlock

                #str(datetime.timedelta(seconds=v))

                if postProcesses:
                    l_timeReports = []

                    if kws.get('mirrorVerify', 1):
                        print(cgmGEN._str_hardBreak)

                        log.info('mirror_verify...')
                        t1 = time.clock()
                        mPuppet.atUtils('mirror_verify', 1)
                        t2 = time.clock()
                        l_timeReports.append(
                            ['mirrorVerify', get_time(t2 - t1)])

                    if kws.get('gatherSpaceDrivers', 1):
                        log.info('collect worldSpace...')
                        t1 = time.clock()
                        mPuppet.atUtils('collect_worldSpaceObjects')
                        t2 = time.clock()
                        l_timeReports.append(
                            ['gatherSpaceDrivers',
                             get_time(t2 - t1)])

                    if kws.get('qss', 1):
                        print(cgmGEN._str_hardBreak)

                        log.info('qss...')
                        t1 = time.clock()
                        mPuppet.atUtils('qss_verify',
                                        puppetSet=1,
                                        bakeSet=1,
                                        deleteSet=1,
                                        exportSet=1)
                        t2 = time.clock()
                        l_timeReports.append(['qss', get_time(t2 - t1)])

                    if kws.get('deleteUnusedShaders'):
                        print(cgmGEN._str_hardBreak)

                        log.info('Delete unused shaders...')
                        t1 = time.clock()
                        MRSPOST.shaders_getUnused(delete=True)
                        t2 = time.clock()
                        l_timeReports.append(
                            ['deleteUnusedShaders',
                             get_time(t2 - t1)])

                    if kws.get('deleteCGMLightGroup'):
                        print(cgmGEN._str_hardBreak)

                        log.info('Delete cgm shaders...')
                        t1 = time.clock()
                        try:
                            mc.delete('cgmLightGroup')
                        except:
                            pass

                        t2 = time.clock()
                        l_timeReports.append(
                            ['deleteUnusedShaders',
                             get_time(t2 - t1)])

                    if kws.get('proxyMesh', 1):
                        print(cgmGEN._str_hardBreak)

                        log.info('proxyMesh...')
                        t1 = time.clock()
                        mPuppet.atUtils('proxyMesh_verify', 1)
                        t2 = time.clock()
                        l_timeReports.append(['proxyMesh', get_time(t2 - t1)])

                    if kws.get('puppetMesh', 1):
                        print(cgmGEN._str_hardBreak)

                        log.info('puppetMesh...')
                        t1 = time.clock()
                        mPuppet.atUtils('puppetMesh_create', **{
                            'unified': True,
                            'skin': True
                        })
                        t2 = time.clock()
                        l_timeReports.append(['puppetMesh', get_time(t2 - t1)])

                    if kws.get('hideVisSub', 1):
                        print(cgmGEN._str_hardBreak)

                        log.info('hideVisSub...')
                        t1 = time.clock()

                        for i, mSubBlock in enumerate(ml_context):
                            if not i:
                                continue
                            try:
                                mSubBlock.moduleTarget.rigNull.settings.visSub = 0
                            except Exception, err:
                                log.error(mSubBlock)
                                log.error(err)

                        t2 = time.clock()
                        l_timeReports.append(['hideVisSub', get_time(t2 - t1)])

                    if kws.get('hideJointAxis'):
                        print(cgmGEN._str_hardBreak)

                        log.info('Hide axis on all joints...')
                        t1 = time.clock()

                        for mObj in cgmMeta.asMeta(mc.ls(type='joint')):
                            mObj.displayLocalAxis = 0
                        t2 = time.clock()
                        l_timeReports.append(
                            ['hideJointAxis',
                             get_time(t2 - t1)])

                    if kws.get('removeRefs'):
                        print(cgmGEN._str_hardBreak)

                        log.info('Remove Refs...')
                        t1 = time.clock()

                        MRSPOST.refs_remove()

                        t2 = time.clock()
                        l_timeReports.append(['removeRefs', get_time(t2 - t1)])
                    if kws.get('ihi', 1):
                        print(cgmGEN._str_hardBreak)

                        log.info('ihi...')
                        t1 = time.clock()

                        mPuppet.atUtils('rigNodes_setAttr', 'ihi', 0)

                        t2 = time.clock()
                        l_timeReports.append(['ihi', get_time(t2 - t1)])
                    if kws.get('connectRig', 1):
                        print(cgmGEN._str_hardBreak)

                        log.info('rig connect...')
                        t1 = time.clock()

                        mPuppet.atUtils('rig_connectAll')

                        t2 = time.clock()
                        l_timeReports.append(['connectRig', get_time(t2 - t1)])
                    log.info('...')

                    if kws.get('controllerVerify', 1):
                        print(cgmGEN._str_hardBreak)

                        if cgmGEN.__mayaVersion__ >= 2018:
                            log.info('controller_verify...')
                            t1 = time.clock()

                            mPuppet.atUtils('controller_verify')
                            log.info('...')

                            t2 = time.clock()
                            l_timeReports.append(
                                ['controllerVerify',
                                 get_time(t2 - t1)])

                    if kws.get('blocksGather', 1):
                        print(cgmGEN._str_hardBreak)

                        t1 = time.clock()
                        mGrp = BUILDERUTILS.gather_rigBlocks()

                        if kws.get('blocksParent', 1):
                            mGrp.p_parent = mPuppet
                            mGrp.v = False
                        t2 = time.clock()
                        l_timeReports.append(
                            ['blocksGather', get_time(t2 - t1)])

                    if kws.get('worldGather'):
                        print(cgmGEN._str_hardBreak)

                        log.info('Gathering world dags...')
                        t1 = time.clock()

                        MRSPOST.gather_worldStuff()
                        t2 = time.clock()
                        l_timeReports.append(
                            ['worldGather', get_time(t2 - t1)])

                    if kws.get('deleteUnusedLayers'):
                        print(cgmGEN._str_hardBreak)
                        log.info('Deleting Unused Layers...')
                        t1 = time.clock()

                        MRSPOST.layers_getUnused(delete=True)
                        t2 = time.clock()
                        l_timeReports.append(
                            ['deleteUnusedLayers',
                             get_time(t2 - t1)])
                    print(cgmGEN._str_hardBreak)
                    print(cgmGEN.logString_sub("Batch", 'Times'))
                    for i, pair_time in enumerate(l_timeReports):
                        print(" {0} | ['{1}'] | {2} ".format(
                            i, pair_time[0], pair_time[1]))

    except Exception, err:
        log.error(err)
p1 = cgmPM.cgmPuppet(name='bob')
p1.connectModule(leg)
pFactory.animSetAttr(m1.modulePuppet, 'visSub', 1, True)
#>>> Morphy Puppet
#=======================================================
Morphy = cgmPM.cgmPuppet('Morphy_puppetNetwork')
Morphy.p_nameShort
Morphy.getModules()
Morphy.mirrorMe()
Morphy.puppetSet.select()

obj = mc.ls(sl=True)[0] or False
obj = ''
objList = []
mTypes = ['cgmPuppet', 'cgmMorpheusPuppet', 'cgmMorpheusMakerNetwork']
r9Meta.getMetaNodes(mAttrs='mClass', mTypes=mTypes, dataType='')
a = cgmMeta.getMetaNodesInitializeOnly(
    mTypes=['cgmPuppet', 'cgmMorpheusPuppet', 'cgmMorpheusMakerNetwork'],
    dataType='')
a = r9Meta.getMetaNodes(
    mTypes=['cgmMorpheusMakerNetwork', 'cgmPuppet', 'cgmMorpheusPuppet'],
    dataType='mClass',
    initializeOnly=True)
log.info(a)
from cgm.core.lib import nameTools

#>>> Rig Block - eye
#=======================================================
nameTools.log.setLevel(nameTools.logging.INFO)
nameTools.log.setLevel(nameTools.logging.DEBUG)
cgmPM.log.setLevel(cgmPM.logging.INFO)