示例#1
0
def _makeSharedShape(obj, name, shapeType):
    '''
    shapeType should be either 'sharedShape' or 'kinematicSwitch'
    
    Returns a string of the shape, ex 'Foot_L|sharedShape' (to bypass pymel warnings)
    '''
    shape = cmds.createNode( 'nurbsCurve', p=obj.longName() )
    
    # 2017 added a bunch of keyable attrs so get rid of them if possible.
    for attr in cmds.listAttr(shape, k=True):
        try:
            cmds.setAttr(shape + '.' + attr, k=False, l=True)
        except Exception as e:  # noqa
            #print( e )
            pass
        
    # Make it a valid curve so it doesn't get deleted during optimize scene
    # but lock and hide it.
    mel.eval('''setAttr "%s.cc" -type "nurbsCurve"
             1 1 0 no 3
             2 0 1
             2
             0 0 0
             0 0 0
             ;''' % shape )
    setAttr(shape + '.visibility', False, l=True)  # noqa
    addAttr(shape, ln=core.shape.sharedShapeTag, at='message')
    
    cmds.addAttr( shape, ln=shapeType, at='message' )
    cmds.rename( shape, name )
    return obj.longName() + '|' + name
示例#2
0
def setCurveColor(ctrl, newColor):
    '''
    newColor can an indexed color or you can specify RGB.
    
    NOTE!!! RGB is NOT currently saved.
    '''

    curves = [
        c for c in cmds.listRelatives(ctrl.name(), type='nurbsCurve', f=True)
        if core.shape.isValidNurbsCurve(c)
    ]

    surfaces = cmds.listRelatives(ctrl.name(), type='nurbsSurface', f=True)
    if surfaces:
        curves += surfaces

    for shape in curves:
        try:
            cmds.setAttr(shape + '.overrideEnabled', True)

            if isinstance(newColor, int):
                cmds.setAttr(shape + '.overrideColor', newColor)
                cmds.setAttr(shape + '.overrideRGBColors', False)
            else:
                cmds.setAttr(shape + '.overrideRGBColors', True)
                cmds.setAttr(shape + '.overrideColorRGB', *newColor)

        except Exception:
            pass
示例#3
0
文件: visNode.py 项目: Mikfr83/fossil
def connect(obj, name_level):
    '''
    Hook the given obj's visibility to the `name` attribute on the sharedShape.
    If the attr doesn't exist, it will be made.
    
    Optionanal `level` will determine when the `obj` will become visible.  For
    example, 2 will not be visible at 1, but will at 2 and higher.
    '''

    name, level = name_level  # Probably should just update this eventually to be 3 params

    orig = obj

    zero = pdil.dagObj.zero(obj, apply=False, make=False)
    if zero:
        obj = zero

    shape = get()

    if not shape:
        warning(
            'Unable to add vis control, no object exists named "main" or tagged with ".fossilMainControl"'
        )
        return

    log.debug('Applying vis control to {}, was given {} using {}'.format(
        obj, orig, shape))

    plug = shape + '.' + name
    if not cmds.objExists(plug):
        cmds.addAttr(shape, ln=name, at='short', min=0, max=level, dv=1)
        cmds.setAttr(shape + '.' + name, cb=True)
    elif cmds.getAttr(shape + '.' + name, type=True) not in [
            'bool', 'double', 'float', 'long', 'short'
    ]:
        warning(
            '{0} is not a good name for a vis group since the sharedShape has an attr already that is of the wrong type'
            .format(name))
        return

    if cmds.addAttr(plug, q=True, max=True) < level:
        cmds.addAttr(plug, e=True, max=level)

    if level == 1:
        connectAttr(plug, obj.visibility.name(), f=True)
    else:
        connectAttr(getConditionNode(plug, level).outColorR,
                    obj.visibility,
                    f=True)

    obj.visibility.setKeyable(False)

    if not pdil.sharedShape.find(orig, VIS_NODE_TYPE):
        pdil.sharedShape.use(orig, shape)

    # If we have a main controller, put the container in a subgroup to make
    # the main group more organized.
    ''' 2021-11-25 Taking this out, I think redoing the hierarchery is probalby more confusing that having lots there.
示例#4
0
def _processAttr(plug, dups, forceKeys, staticValues, start, end):
    '''
    Used by `save`
    '''

    crvs = cmds.listConnections(plug, type='animCurve')

    if not crvs:
        if forceKeys:
            setKeyframe(plug, t=start)
            setKeyframe(plug, t=end)
            crvs = cmds.listConnections(plug, type='animCurve')
        else:
            if not cmds.getAttr(plug, lock=True) and not cmds.listConnections(
                    plug, s=True, d=False):
                staticValues[plug] = cmds.getAttr(plug)

    if crvs:
        dup = cmds.duplicate(crvs)[0]
        if not objExists(dup + '.' + TAGGING_ATTR):
            cmds.addAttr(dup, ln=TAGGING_ATTR, dt='string')
        cmds.setAttr(dup + '.' + TAGGING_ATTR, plug, type='string')
        dups.append(dup)
示例#5
0
def connect(obj, name):
    '''
    Hook the given obj's visibility to the `name` attribute on the sharedShape.
    If the attr doesn't exist, it will be made.
    '''

    orig = obj

    zero = core.dagObj.zero(obj, apply=False, make=False)
    if zero:
        obj = zero

    shape = get()
    plug = shape + '.' + name
    if not cmds.objExists(plug):
        cmds.addAttr(shape, ln=name, at='short', min=0, max=1, dv=1)
        cmds.setAttr(shape + '.' + name, cb=True)
    elif cmds.getAttr(shape + '.' + name, type=True) not in [
            'bool', 'double', 'float', 'long', 'short'
    ]:
        warning(
            '{0} is not a good name for a vis group since the sharedShape has an attr already that is of the wrong type'
            .format(name))
        return

    connectAttr(plug, obj.visibility.name(), f=True)
    obj.visibility.setKeyable(False)

    # If we have a main controller, put the container in a subgroup to make
    # the main group more organized.

    visGroupName = '_vis_' + name

    if isinstance(orig, nodeApi.RigController):
        if shortName(orig.container.getParent()) != visGroupName:
            orig.setGroup(visGroupName)
示例#6
0
 
 Optionanal `level` will determine when the `obj` will become visible.  For
 example, 2 will not be visible at 1, but will at 2 and higher.
 '''
 
 orig = obj
 
 zero = core.dagObj.zero(obj, apply=False, make=False)
 if zero:
     obj = zero
 
 shape = get()
 plug = shape + '.' + name
 if not cmds.objExists( plug ):
     cmds.addAttr( shape, ln=name, at='short', min=0, max=level, dv=1 )
     cmds.setAttr( shape + '.' + name, cb=True )
 elif cmds.getAttr( shape + '.' + name, type=True) not in ['bool', 'double', 'float', 'long', 'short']:
     warning( '{0} is not a good name for a vis group since the sharedShape has an attr already that is of the wrong type'.format(name) )
     return
 
 if cmds.addAttr(plug, q=True, max=True) < level:
     cmds.addAttr(plug, e=True, max=level)
 
 if level == 1:
     connectAttr( plug, obj.visibility.name(), f=True)
 else:
     connectAttr( getConditionNode(plug, level).outColorR, obj.visibility, f=True)
     
 obj.visibility.setKeyable(False)
 
 # If we have a main controller, put the container in a subgroup to make