Beispiel #1
0
    def testHasTag(self):
        tagName = 'someGreatTag'
        tagAttr = nodeTag.getTagAttr(tagName)

        self.assertFalse(nodeTag.hasTag(self.xform,tagName))
        self.assertFalse(nodeTag.hasTag(self.xform,tagAttr))

        nodeTag.setTag(self.xform, tagName, {})

        self.assertTrue(nodeTag.hasTag(self.xform,tagName))
        self.assertTrue(nodeTag.hasTag(self.xform,tagAttr))
Beispiel #2
0
def isStorableXform(xform):
    """
    Is the node tagged as a storableXform node?
    """
    if nodeTag.hasTag(xform, STORABLE_TAG_NAME):
        return True
    return False
Beispiel #3
0
def setStorableXformAttrs(xform, **kwargs):
    """
    Set the tag on the node.  Any kwargs passed will be set;
    others will be left at the current value if one exists, or set
    to the default value if non-existant

    @keyword categories: node categories
    @type categories: list of strings

    """
    tagD = {'categories': [],
            'worldSpace': False}

    if nodeTag.hasTag(xform, STORABLE_TAG_NAME):
        tagD = nodeTag.getTag(xform, STORABLE_TAG_NAME)

    categories = kwargs.get('categories', tagD['categories'])
    worldSpace = kwargs.get('worldSpace', tagD['worldSpace'])

    assert isinstance(categories, list) or isinstance(categories, tuple)


    d = {'worldSpace': bool(worldSpace),
         'categories': list(categories)}

    nodeTag.setTag(xform, STORABLE_TAG_NAME, d)
Beispiel #4
0
def setLockTag(ctl, **kwargs):
    """
    Add new lock information to the lock tag of a control.  Create the tag
    if it does not exist

    @keyword unlockedUnkeyable: channels that are unlcoked but not keyable
    @keyword uu: unlockedUnkeyable alias
    @keyword unlockedKeyable: channels that are unlcoked but not keyable
    @keyword uk: unlockedKeyable alias
    @keyword lockedKeyable: channels that are unlcoked but not keyable
    @keyword lk: lockedKeyable alias

    update locking information on controls.  This is used to toggle locking when rig nodes are
    locked
    """

    if nodeTag.hasTag(ctl, LOCKS_TAG_NAME):
        current = nodeTag.getTag(ctl, LOCKS_TAG_NAME)
    else:
        current = copy.deepcopy(_defaultLocks)

    for long_, short in [('unlockedUnkeyable', 'uu'),
                          ('unlockedKeyable', 'uk'),
                          ('lockedKeyable', 'lk')]:

        val = set(kwargs.get(long_, kwargs.get(short, [])))
        current[long_] = list(val.union(current[long_]))

    nodeTag.setTag(ctl, LOCKS_TAG_NAME, current)
Beispiel #5
0
def addStorableXformCategory(xform, *categories):
    if not nodeTag.hasTag(xform, STORABLE_TAG_NAME):
        raise RuntimeError("%s is not a storable node" % xform)

    tagD = nodeTag.getTag(xform, STORABLE_TAG_NAME)
    tagD['categories'].extend(categories)
    tagD['categories'] = list(set(tagD['categories']))
    nodeTag.setTag(xform, STORABLE_TAG_NAME, tagD)
    return xform
Beispiel #6
0
def setEditable(ctl, state):
    """
    Add an intermediate xform node to a control.  The control's editable
    state can be toggled, and transformation differences to the 'editor' node
    will be flushed down to the shape level and recorded in the control data
    @param ctl: the control to make editable
    @type ctl: str
    @param state: True or False
    @type state: bool

    @return: True if state was changed, else False
    """
    editor = getEditor(ctl)
    if editor and state:
        return False
    elif not editor and not state:
        return False

    info  = getInfo(ctl)
    if state:
        editor = MC.createNode('transform', name='%s_editor' % ctl, parent=None)

        if nodeTag.hasTag(ctl, '%s_editor' % LOCKS_TAG_NAME):
            tag = nodeTag.getTag(ctl, '%s_editor' % LOCKS_TAG_NAME)
            nodeTag.rmTag(ctl, '%s_editor' % LOCKS_TAG_NAME)
            nodeTag.setTag(editor, LOCKS_TAG_NAME, tag)

        MC.parent(editor, ctl)
        MC.setAttr('%s.t' % editor, *info['t'], type='double3')
        MC.setAttr('%s.r' % editor, *info['r'], type='double3')
        MC.setAttr('%s.s' % editor, *info['s'], type='double3')
        MC.setAttr("%s.shear" % editor, 0,0,0, type='double3')
        utils.parentShape(editor, ctl, deleteChildXform=False)

    else:
        if nodeTag.hasTag(editor, LOCKS_TAG_NAME):
            editorLocks = nodeTag.getTag(editor, LOCKS_TAG_NAME)
            nodeTag.setTag(ctl, '%s_editor' % LOCKS_TAG_NAME, editorLocks)

        setInfo(ctl, info)
        utils.parentShape(ctl, editor, deleteChildXform=True)
    return True
Beispiel #7
0
def getLockTag(node):
    """
    Get the lock tag of a node.  If the node is not tagged,
    the default empty lock tag is returned
    @param node: the node to query
    @type node: str

    @return: lock tag dictionary
    @rtype: dict
    """
    if not nodeTag.hasTag(node, LOCKS_TAG_NAME):
        return copy.deepcopy(_defaultLocks)

    return nodeTag.getTag(node, LOCKS_TAG_NAME)
Beispiel #8
0
def getStorableXformInfo(xform):
    """
    Get information needed to record the state of a transform node to rebuild
    it, duplicate it, etc
    """

    if not nodeTag.hasTag(xform, STORABLE_TAG_NAME):
        raise RuntimeError("%s is not a storable node" % xform)

    recordableTag = nodeTag.getTag(xform, STORABLE_TAG_NAME)
    result = {}
    result.update(recordableTag)

    result['nodeType'] = MC.objectType(xform)

    worldSpace = result['worldSpace']
    result['matrix'] = MC.xform(xform, q=1, m=1, ws=worldSpace)

    result['rotateOrder'] = MC.getAttr('%s.rotateOrder' % xform)

    if result['nodeType'] == 'joint':
        result['radius'] = MC.getAttr('%s.radius' % (xform))
        result['jointOrient']  = MC.getAttr('%s.jointOrient' % xform)[0]
        result['rotation'] = MC.xform(xform, q=1, ro=1, ws=result['worldSpace'])

    par = MC.listRelatives(xform, parent=1, pa=1)
    if par:
        par = par[0]

    result['parent'] = par

    #get control info
    if isControl(xform):
        result['controlArgs'] = getInfo(xform)
        _logger.debug('controlArgsType: %s' % str(type(result['controlArgs'])))
    return result
Beispiel #9
0
def isControl(xform):
    if nodeTag.hasTag(xform, CONTROL_TAG_NAME):
        return True