コード例 #1
0
def shaders_getUnused(delete=False):
    ml = []
    for _type in ['lambert','blinn','phong','phongE']:
        for mObj in cgmMeta.asMeta(mc.ls(type = _type),noneValid=True) or []:
            if mObj in ml:
                continue
            log.info(cgmGEN.logString_sub("shaders_getUnused", mObj))
            
            if mObj.p_nameBase is '{0}1'.format(_type):
                log.info("default shader {0}".format(mObj))                
                continue
            
            try:
                for o in ATTR.get_driven("{0}.outColor".format(mObj.mNode),getNode=1):
                    if VALID.get_mayaType(o) == 'shadingEngine':
                        l = mc.sets(o, q=True) 
                        if not l:
                            log.info("Unused shader | {0}".format(mObj))
                            ml.append(mObj)
            except Exception,err:
                print err
コード例 #2
0
ファイル: node_utils.py プロジェクト: liudger/cgmTools
def optimize(nodeTypes='multiplyDivide'):
    _str_func = 'optimize'
    log.debug("|{0}| >>  ".format(_str_func) + '-' * 80)

    _nodeTypes = VALID.listArg(nodeTypes)
    d_modeToNodes = {}
    d_modeToPlugs = {}
    l_oldNodes = []

    for t in _nodeTypes:
        if t in ['plusMinusAverage']:
            raise ValueError, "Don't handle type: {0}".format(t)
        nodes = mc.ls(type=t)
        l_oldNodes.extend(nodes)
        for n in nodes:
            _mode = ATTR.get(n, 'operation')
            _operator = ATTR.get_enumValueString(n, 'operation')
            #d_operator_to_NodeType[t][_mode]

            if not d_modeToNodes.get(_mode):
                d_modeToNodes[_mode] = []
            d_modeToNodes[_mode].append(n)

            d_plugs = {}
            d_plugValues = {}
            for i, inPlug in enumerate(d_node_to_input[t]['in']):
                d_plugs[i] = ATTR.get_children(n, inPlug) or []
                for p in d_plugs[i]:
                    c = ATTR.get_driver(n, p, False, skipConversionNodes=True)
                    if c:
                        d_plugValues[p] = c
                    else:
                        d_plugValues[p] = ATTR.get(n, p)

            l_outs = ATTR.get_children(n, d_node_to_input[t]['out']) or []
            for p in l_outs:
                d_plugValues[p] = ATTR.get_driven(n,
                                                  p,
                                                  False,
                                                  skipConversionNodes=True)

            #pprint.pprint(d_modeToNodes)
            #pprint.pprint(d_plugs)
            #print l_outs
            #print cgmGeneral._str_subLine
            #pprint.pprint(d_plugValues)

            for i in range(len(l_outs)):
                _out = d_plugValues[l_outs[i]]
                if _out:
                    d_set = {'out': _out, 'in': []}
                    log.debug("|{0}| >> Output found on: {1} ".format(
                        _str_func, _out))
                    _keys = d_plugs.keys()
                    _keys.sort()
                    for k in _keys:
                        d_set['in'].append(d_plugValues[d_plugs[k][i]])
                        #d_set['in'].append(d_plugs[k][i])
                    #pprint.pprint(d_set)

                    if not d_modeToPlugs.get(_mode):
                        d_modeToPlugs[_mode] = []
                    d_modeToPlugs[_mode].append(d_set)

            #    if VALID.stringArg()

    l_inPlugs = ['input1', 'input2']
    l_outplugs = [u'output']
    l_new = []
    _cnt = 0

    for operator, d_sets in d_modeToPlugs.iteritems():
        if operator == 1:
            for nodeSet in d_sets:
                newNode = mc.createNode('multDoubleLinear')
                newNode = mc.rename(newNode,
                                    'optimize_{0}_mdNode'.format(_cnt))
                _cnt += 1
                l_new.append(newNode)

                _ins = d_set['in']
                _outs = d_set['out']

                for iii, inPlug in enumerate(_ins):
                    if mc.objExists(inPlug):
                        ATTR.connect(inPlug,
                                     "{0}.{1}".format(newNode, l_inPlugs[iii]))
                    else:
                        ATTR.set(newNode, l_inPlugs[iii], inPlug)

                for out in _outs:
                    ATTR.connect("{0}.output".format(newNode), out)

        #pprint.pprint(d_setsSorted)
        print len(d_sets)
        #print len(d_setsSorted)
    """
    
    l_inPlugs = {0: [u'input1X', u'input1Y', u'input1Z'],
               1: [u'input2X', u'input2Y', u'input2Z']}
    l_outplugs = [u'outputX', u'outputY', u'outputZ']
    
    for operator,d_sets in d_modeToPlugs.iteritems():
        d_setsSorted = LISTS. get_chunks(d_sets,3)
        for nodeSet in d_setsSorted:
            newNode = mc.createNode('multiplyDivide')
            newNode = mc.rename(newNode,'optimize_{0}_mdNode'.format(_cnt))
            _cnt+=1
            l_new.append(newNode)
            ATTR.set(newNode,'operation',operator)
            
            for i,d_set in enumerate(nodeSet):
                _ins = d_set['in']
                _outs = d_set['out']
                
                for iii,inPlug in enumerate(_ins):
                    if mc.objExists(inPlug):
                        ATTR.connect(inPlug, "{0}.{1}".format(newNode, l_inPlugs[iii][i]))
                    else:
                        ATTR.set(newNode,l_inPlugs[iii][i], inPlug)
                    
                for out in _outs:
                    ATTR.connect("{0}.{1}".format(newNode, l_outplugs[i]), out)
                    
        #pprint.pprint(d_setsSorted)
        print len(d_sets)
        print len(d_setsSorted)
        """
    mc.delete(l_oldNodes)
    return len(l_new)
コード例 #3
0
ファイル: rigging_utils.py プロジェクト: sgodanas/cgm_tools
                _rgb = get_RGB_fromHSV(_hsv[0], _hsv[1], _hsv[2])
                ATTR.set(_node, 'diffuse', .75)

            ATTR.set(_node, 'colorR', _rgb[0])
            ATTR.set(_node, 'colorG', _rgb[1])
            ATTR.set(_node, 'colorB', _rgb[2])

            if transparent:
                ATTR.set(_node, 'ambientColorR', _rgb[0] * .1)
                ATTR.set(_node, 'ambientColorG', _rgb[1] * .1)
                ATTR.set(_node, 'ambientColorB', _rgb[2] * .1)
                ATTR.set(_node, 'transparency', .5)
                ATTR.set(_node, 'incandescence', 0)

    if not _set:
        _set = ATTR.get_driven(_node, 'outColor', True)[0]

    return _node, _set


def get_HSV_fromRGB(rValue=0, gValue=0, bValue=0, getNode=False):
    _node = mc.createNode('rgbToHsv')
    ATTR.set(_node, 'inRgbR', COREMATH.Clamp(float(rValue), 0, 1.0))
    ATTR.set(_node, 'inRgbG', COREMATH.Clamp(float(gValue), 0, 1.0))
    ATTR.set(_node, 'inRgbB', COREMATH.Clamp(float(bValue), 0, 1.0))
    res = ATTR.get(_node, 'outHsv')[0]

    if getNode:
        return _node, res

    mc.delete(_node)