コード例 #1
0
ファイル: rigging_utils.py プロジェクト: sgodanas/cgm_tools
def color_mesh(target=None, mode='puppetmesh'):
    _str_func = "color_mesh"
    if not target:
        raise ValueError, "|{0}|  >> Must have a target".format(_str_func)
    l_targets = VALID.listArg(target)

    _shader, _set = getControlShader(None, 'puppetmesh', False, False, False)

    for t in l_targets:
        log.debug("|{0}| >> t: {1} ...".format(_str_func, t))
        _type = VALID.get_mayaType(t)
        log.debug("|{0}| >> shapes: {1} ...".format(_str_func,
                                                    TRANS.shapes_get(t, True)))
        log.debug("|{0}| >> type: {1} ...".format(_str_func, _type))

        mc.sets(t, edit=True, remove='initialShadingGroup')

        if _type in ['nurbsSurface', 'mesh']:
            mc.sets(t, e=True, forceElement=_set)
        else:
            for s in TRANS.shapes_get(t, True):
                log.debug("|{0}| >> s: {1} ...".format(_str_func, s))
                _type = VALID.get_mayaType(s)
                if _type in ['nurbsSurface', 'mesh']:
                    mc.sets(s, edit=True, forceElement=_set)
                    mc.sets(s, remove='initialShadingGroup')
                    try:
                        mc.disconnectAttr(
                            '{0}.instObjGroups.objectGroups'.format(s),
                            'initialShadingGroup.dagSetMembers')
                    except:
                        pass
                else:
                    log.debug("|{0}|  >> Not a valid target: {1} | {2}".format(
                        _str_func, s, _type))
        mc.sets(t, edit=True, remove='initialShadingGroup')
    return True
コード例 #2
0
def fbx_cleaner(delete = False, spaceString = '03FBXASC032'):
    """
    Find all the sill attributes fbx adds on import

    :parameters:
        delete | whether to delete all userDefined attrs or not
        spaceString | Search string for what fbx did with spaces from max or other app. Replaces with underscore
    """
    _str_func = 'fbx_cleaner'
    log.debug("|{0}| >> ...".format(_str_func))

    _res = {}
    for o in mc.ls():
        _res[o] = []
        _l = mc.listAttr(o,userDefined=True) or []
        for a in _l:
            _res[o].append(a)
        _shapes = TRANS.shapes_get(o)

        if _shapes:
            for s in _shapes:
                _res[s] = []
                _l = mc.listAttr(s,userDefined=True) or []
                for a in _l:
                    _res[s].append(a)

    print cgmGEN._str_hardBreak
    l_renamed = []
    for k,l in _res.iteritems():
        if l:
            print cgmGEN._str_subLine
            print(cgmGEN._str_baseStart * 2 + " node: '{0}' | attrs: {1}...".format(k,len(l)))
            for i,a in enumerate(l):
                print("   {0} | '{1}'".format(i,a))
                if delete:
                    ATTR.delete(k,a)
        if spaceString:
            if spaceString in NAMES.get_base(k) and k not in l_renamed:
                new = mc.rename(k, NAMES.get_base(k).replace(spaceString,'_'))
                print(" Rename  {0} | '{1}'".format(k,new))
                l_renamed.append(k)


    print cgmGEN._str_hardBreak
コード例 #3
0
def get_list(context='selection', mType=None, getTransform=False):
    """
    Get contextual data for updating a transform
    
    :parameters
        context(string): 
            selection
            children
            heirarchy
            scene
            buffer
        mType
        getTransform

    :returns
        list(list)
    """
    _str_func = "get_list"
    _l_context = []
    _context = context.lower()

    log.debug("|{0}| >> context: {1} | mType: {2}".format(
        _str_func, _context, mType))

    if _context == 'selection':
        log.debug("|{0}| >> selection mode...".format(_str_func))
        if mType:
            if mType == 'shape':
                _bfr = mc.ls(os=True, shortNames=False)
                for o in _bfr:
                    _l_context.extend(TRANS.shapes_get(o, True))
            else:
                _l_context = mc.ls(os=True,
                                   type=mType,
                                   shortNames=False,
                                   flatten=True)
        else:
            _l_context = mc.ls(os=True, shortNames=False, flatten=True)
    elif _context == 'scene':
        log.debug("|{0}| >> scene mode...".format(_str_func))
        if mType is not None:
            _l_context = mc.ls(type=mType, shortNames=False)
        else:
            _l_context = mc.ls(shortNames=False)
            #raise Exception,"Really shouldn't use this without a specific object type..."

    elif _context == 'children':
        log.debug("|{0}| >> children mode...".format(_str_func))

        _sel = mc.ls(sl=True, shortNames=False)
        for o in _sel:
            if mType:
                if mc.ls(o, type=mType, shortNames=False):
                    _l_context.append(o)
            else:
                _l_context.append(o)

            if mType:
                try:
                    _buffer = mc.listRelatives(
                        o, allDescendents=True, type=mType,
                        fullPath=True) or []
                except:
                    _buffer = []
            else:
                _buffer = mc.listRelatives(
                    o, allDescendents=True, fullPath=True) or []
            for o2 in _buffer:
                if o2 not in _l_context:
                    _l_context.append(o2)

    elif _context == 'heirarchy':
        log.debug("|{0}| >> heirarchy mode...".format(_str_func))

        _sel = mc.ls(sl=True, shortNames=False)
        for o in _sel:
            if mType:
                if mc.ls(o, type=mType, shortNames=False):
                    _l_context.append(o)
            else:
                _l_context.append(o)

            _parents = SEARCH.get_all_parents(o)
            _buffer = []
            if _parents:
                root = _parents[-1]  #...get the top of the tree
                if mType:
                    if mc.ls(root, type=mType, shortNames=False):
                        _l_context.append(root)
                else:
                    _l_context.append(root)

                if mType:
                    try:
                        _buffer = mc.listRelatives(root,
                                                   allDescendents=True,
                                                   type=mType,
                                                   fullPath=True) or []
                    except:
                        _buffer = []
                else:
                    _buffer = mc.listRelatives(
                        root, allDescendents=True, fullPath=True) or []
                for o2 in _buffer:
                    if o2 not in _l_context:
                        _l_context.append(o2)
            else:
                if mType:
                    try:
                        _buffer = mc.listRelatives(
                            o, allDescendents=True, type=mType,
                            fullPath=True) or []
                    except:
                        _buffer = []
                else:
                    _buffer = mc.listRelatives(
                        o, allDescendents=True, fullPath=True) or []
                for o2 in _buffer:
                    if o2 not in _l_context:
                        _l_context.append(o2)

    else:
        log.warning("|{0}| >> context unkown: {1}...".format(
            _str_func, _context))
        return False

    if getTransform:
        for i, o in enumerate(_l_context):
            _trans = SEARCH.get_transform(o)
            if _trans:
                _l_context[i] = _trans
    return _l_context
コード例 #4
0
ファイル: rigging_utils.py プロジェクト: sgodanas/cgm_tools
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())
コード例 #5
0
ファイル: rigging_utils.py プロジェクト: sgodanas/cgm_tools
def create_axisProxy(obj=None):
    """
    Make a local axis box around a given object so that you can then 
    
    """
    try:
        _str_func = 'create_axisProxy'
        _dag = VALID.getTransform(obj)
        if not _dag:
            raise ValueError, "Must have a dag node. Obj: {0}".format(obj)
        if VALID.is_shape(obj):
            l_shapes = [obj]
        else:
            l_shapes = TRANS.shapes_get(_dag, True)

        _parent = TRANS.parent_get(_dag)
        _dup = mc.duplicate(l_shapes, po=False, rc=True)[0]
        #TRANS.pivots_recenter(_dup)
        _dup = TRANS.parent_set(_dup, False)
        ATTR.set_standardFlags(_dup, lock=False, keyable=True)
        #Get some values...
        l_reset = ['t', 'r', 's', 'shear', 'rotateAxis']
        t = ATTR.get(_dup, 'translate')
        r = ATTR.get(_dup, 'rotate')
        s = ATTR.get(_dup, 'scale')
        ra = ATTR.get(_dup, 'rotateAxis')
        if ATTR.has_attr(_dup, 'jointOrient'):
            l_reset.append('jointOrient')
            jo = ATTR.get(_dup, 'jointOrient')
        o = TRANS.orient_get(_dup)
        shear = ATTR.get(_dup, 'shear')
        _scaleLossy = TRANS.scaleLossy_get(_dag)

        #Reset our stuff before we make our bb...
        ATTR.reset(_dup, l_reset)
        _size = POS.get_bb_size(_dup, True)

        #_proxy = create_proxyGeo('cube',COREMATH.list_div(_scaleLossy,_size))
        _proxy = create_proxyGeo('cube', _size)
        mc.makeIdentity(_proxy, apply=True, scale=True)

        #Now Put it back
        _dup = TRANS.parent_set(_dup, TRANS.parent_get(_dag))
        _proxy = TRANS.parent_set(_proxy, _dup)

        #_dup = TRANS.parent_set(_dup, TRANS.parents_get(_dag))
        SNAP.go(_dup, _dag)
        #ATTR.set(_dup,'s',(0,0,0))
        ATTR.reset(_dup, ['s', 'shear'])

        ATTR.reset(_proxy, ['t', 'r', 's', 'shear', 'rotateAxis'])
        _proxy = TRANS.parent_set(_proxy, _dag)
        ATTR.reset(_proxy, ['t', 'r', 's', 'shear', 'rotateAxis'])
        #match_transform(_proxy,_dag)

        #SNAP.go(_proxy,_dag,pivot='bb')

        #cgmGEN.func_snapShot(vars())

        _proxy = TRANS.parent_set(_proxy, False)
        mc.delete(_dup)
        #match_transform(_proxy,_dag)
        return mc.rename(_proxy,
                         "{0}_localAxisProxy".format(NAMES.get_base(_dag)))
    except Exception, err:
        cgmGEN.cgmExceptCB(Exception, err, msg=vars())
コード例 #6
0
ファイル: rigging_utils.py プロジェクト: sgodanas/cgm_tools
def colorControl(target=None,
                 direction='center',
                 controlType='main',
                 pushToShapes=True,
                 rgb=True,
                 shaderSetup=True,
                 shaderOnly=False,
                 transparent=False,
                 proxy=False,
                 directProxy=False):
    """
    Sets the override color on shapes and more
    
    :parameters
        target(str): What to color - shape or transform with shapes
        direction
        controlType
        pushToShapes
        rgb
        shaderSetup
        transparent
        proxy - offsets the color down to not match curve color exactly
        directProxy(bool) - Setpu transparent shader for 'invisible' controls
        

    :returns
        info(dict)
    """

    _str_func = "color_control"
    if not target:
        raise ValueError, "|{0}|  >> Must have a target".format(_str_func)
    l_targets = VALID.listArg(target)

    if rgb:
        _color = SHARED._d_side_colors[direction][controlType]
    else:
        _color = SHARED._d_side_colors_index[direction][controlType]

    _shader = False
    _set = False

    if shaderSetup:
        _shader, _set = getControlShader(direction, controlType, transparent,
                                         proxy, directProxy)

    for t in l_targets:
        log.debug("|{0}| >> t: {1} ...".format(_str_func, t))
        _type = VALID.get_mayaType(t)
        log.debug("|{0}| >> shapes: {1} ...".format(_str_func,
                                                    TRANS.shapes_get(t, True)))
        log.debug("|{0}| >> type: {1} ...".format(_str_func, _type))

        if not shaderOnly:
            if rgb:
                override_color(t, _color, pushToShapes=pushToShapes)
            else:
                _v = SHARED._d_colors_to_index[_color]
                override_color(t, index=_v, pushToShapes=pushToShapes)

        if shaderSetup:
            mc.sets(t, edit=True, remove='initialShadingGroup')

            if _type in ['nurbsSurface', 'mesh']:
                mc.sets(t, e=True, forceElement=_set)
            else:
                for s in TRANS.shapes_get(t, True):
                    log.debug("|{0}| >> s: {1} ...".format(_str_func, s))
                    _type = VALID.get_mayaType(s)
                    if _type in ['nurbsSurface', 'mesh']:
                        mc.sets(s, edit=True, forceElement=_set)
                        mc.sets(s, remove='initialShadingGroup')
                        try:
                            mc.disconnectAttr(
                                '{0}.instObjGroups.objectGroups'.format(s),
                                'initialShadingGroup.dagSetMembers')
                        except:
                            pass

                    else:
                        log.debug(
                            "|{0}|  >> Not a valid target: {1} | {2}".format(
                                _str_func, s, _type))

        mc.sets(t, edit=True, remove='initialShadingGroup')
    return True
コード例 #7
0
cgmMeta.cgmObject(_rootRoot).getListPathTo(_root)
TRANS.get_listPathTo(_rootRoot, _root,False)

cgmMeta.cgmObject(_root).getListPathTo(_rootRoot)
TRANS.get_listPathTo(_root, _rootRoot,False)

TRANS.is_parentTo(_root,TRANS.parents_get(_root)[0])


_root = 'NotBatman_master_block'
_root = 'NotBatman_master_block|curveShape2'
_root = 'NotBatman_master_block.cv[50]'
_root = 'NotBatman_master_block.ep[26]'
_root = 'NotBatman_master_block2'
TRANS.sibblings_get(_root,False)
TRANS.shapes_get(_root)
TRANS.get_rootList()

#...transform matrix stuff...
_v = [1,1,1]
TRANS.worldMatrix_get(_root,True)

TRANS.transformDirection(_root,_v)
TRANS.transformPoint(_root,_v)
TRANS.transformInverseDirection(_root,_v)
TRANS.transformInversePoint(_root,_v)
TRANS.euclidVector3Arg([0,0,0])


#...creation
TRANS.child_create(_root)
コード例 #8
0
ファイル: puppet_utils.py プロジェクト: sgodanas/cgm_tools
            l_dat.extend(mModule.rigNull.getMessage('rigNodes'))
        except Exception, err:
            log.error("{0} | {1}".format(mModule, err))

    if attr and value is not None:
        int_lenNodes = len(l_dat)
        if progressBar:
            cgmUI.progressBar_start(progressBar, int_lenNodes + 1)
        for i, node in enumerate(l_dat):
            if progressBar:
                cgmUI.progressBar_set(progressBar,
                                      status=node,
                                      progress=i,
                                      vis=True)
            try:
                _shapes = TRANS.shapes_get(node)
                if _shapes:
                    for s in _shapes:
                        ATTR.set(node, attr, value)
                ATTR.set(node, attr, value)
            except Exception, err:
                log.error("{0} | {1}".format(node, err))

    if progressBar and progressEnd:
        cgmUI.progressBar_end(progressBar)

    return l_dat


@cgmGEN.Timer
def rig_connectAll(self, mode='connect', progressBar=None, progressEnd=True):