Exemplo n.º 1
0
 def __setup_controls(self):
     self.up_vector = None
     for i in range(2):
         ctl = self.__create_control(self._side, self._moduleName, i,
                                     self._color, self.mod)
         if not i:
             nme = self._side + '_' + self._moduleName + "Up"
             self.up_vector = node.transform(name=nme,
                                             position=[1, 0, 0],
                                             parent=ctl.transform)
         if i:
             aim = node.aimConstraint(target=self.controls[0].transform,
                                      source=ctl.transform,
                                      aimVector=[0, -1, 0],
                                      upVector=[0, 0, 0],
                                      worldUpObject=self.up_vector,
                                      worldUpType='object')
             self.to_ihi.append(aim)
             attribute.lock_attributes(ctl.transform, ['r'], False, True)
             attribute.lock_n_hide(self.controls[0].transform, ['r'], True)
         self.controls.append(ctl)
         if self._mirror:
             self.__mirror_guides(ctl.transform, i)
     #-- create control chain
     self.__create_chain(self.controls)
Exemplo n.º 2
0
    def __cleanup(self):
        if self._lockGroups:
            attr = ['shearXY', 'shearXZ', 'shearYZ', 'rotateOrder', 'rotateAxisX',
                    'rotateAxisY', 'rotateAxisZ', 'inheritsTransform']
            if self.offsets:
                #--- lock offsets
                for i in self.offsets:
                    attrs = cmds.listAttr(i, keyable=True)
                    if attrs:
                        for j in attr:
                            attrs.append(j)
                        for a in attrs:
                            cmds.setAttr(i + '.' + a, lock=True, keyable=False)
                    attribute.lock_n_hide(i, ['t', 'r'], True)

            #--- lock group
            attrs = cmds.listAttr(self.group, keyable=True)
            for i in attr:
                attrs.append(i)
            if attrs:
                for a in attrs:
                    cmds.setAttr(self.group + '.' + a, lock=True, keyable=False)

            #--- lock transform
            attrs = ['sx', 'sy', 'sz', 'v']
            for i in attr:
                attrs.append(i)
            for a in attrs:
                cmds.setAttr(self.transform + '.' + a, lock=True, keyable=False)
            cmds.setAttr(self.shape + '.ihi', 0)

            #--- lock shape
            attrs = cmds.listAttr(self.shape, channelBox=True)
            if attrs:
                for a in attrs:
                    cmds.setAttr(self.shape + '.' + a, lock=True, keyable=False)
                    cmds.setAttr(self.shape + '.' + a, channelBox=False)
                cmds.setAttr(self.shape + '.ihi', 0)

            if self._withGimbal:
                #--- lock gimbal
                attrs = ['sx', 'sy', 'sz', 'v']
                for i in attr:
                    attrs.append(i)
                for a in attrs:
                    cmds.setAttr(self.gimbal + '.' + a, lock=True, keyable=False)
                cmds.setAttr(self._gshape + '.ihi', 0)

                #--- lock gimbal shape
                attrs = cmds.listAttr(self._gshape, channelBox=True)
                if attrs:
                    for a in attrs:
                        cmds.setAttr(self._gshape + '.' + a, lock=True, keyable=False)
                        cmds.setAttr(self._gshape + '.' + a, channelBox=False)
                    cmds.setAttr(self._gshape + '.ihi', 0)
        cmds.select(clear=True)
Exemplo n.º 3
0
    def __create_controls(self):
        """ Create the flexiPlane controls """
        #--- create main control
        name = self._mod + self._name[0].upper() + self._name[1:]
        self.control_main = controls.Control(side=self._side,
                                             name=name + 'Main',
                                             size=self._size + 0.75,
                                             shape=5,
                                             color=self._color,
                                             orientation=16,
                                             parent=self.main)
        #--- create up control
        self.control_up = controls.Control(side=self._side,
                                           name=name + 'Up',
                                           size=self._size + 0.25,
                                           shape=1,
                                           color=6,
                                           position=[5, 0, 0],
                                           parent=self.global_move)
        #--- create down control
        self.control_down = controls.Control(side=self._side,
                                             name=name + 'Down',
                                             size=self._size + 0.25,
                                             shape=1,
                                             color=6,
                                             position=[-5, 0, 0],
                                             parent=self.global_move)
        #--- create mid control
        self.control_mid = controls.Control(side=self._side,
                                            name=name + 'Mid',
                                            size=self._size + 0.25,
                                            shape=2,
                                            color=self._color,
                                            parent=self.global_move)
        if self._follow:
            node.pointConstraint(
                objA=[self.control_down.transform, self.control_up.transform],
                objB=self.control_mid.group,
                maintainOffset=False)

        #--- create individual joint controls, parented under the follicle
        for i in range(len(self.follicle)):
            j = i + 1
            #--- create main control
            jnt_ctl = controls.Control(side=self._side,
                                       name=name + "FlexiJnt" + ` j `,
                                       size=self._size / 1.5,
                                       shape=1,
                                       color=13,
                                       rotation=[90, 0, 0],
                                       parent=self.follicle[i])
            goe.setAttr(jnt_ctl.group + '.t', 0, 0, 0)
            attribute.lock_n_hide(jnt_ctl.transform, ['t'])
            self.jnt_ctl.append(jnt_ctl)
Exemplo n.º 4
0
 def __setup_scale_attribute(self):
     if not self._addSpaceSwitch:
         return
     for ctl in self._addScaleToControl:
         attribute.lock_n_hide(ctl, ['s'], True)
         for axis in 'xyz':
             if not cmds.listConnections(ctl + '.s' + axis):
                 if not cmds.isConnected(ctl + '.globalScale',
                                         ctl + '.s' + axis):
                     cmds.connectAttr(ctl + '.globalScale',
                                      ctl + '.s' + axis)
         attribute.lock_n_hide(ctl, ['s'], False)
Exemplo n.º 5
0
    def __hide_controls(self):
        if self._hideControls:
            for i in self.controls:
                cmds.setAttr(i.shape + '.v', 0)

        if self._hide:
            if isinstance(self._hide, list):
                for i in self._hide:
                    attribute.lock_n_hide(i, ['v'], True)
                    cmds.setAttr(i + '.v', 0)
            else:
                attribute.lock_n_hide(self._hide, ['v'], True)
                cmds.setAttr(self._hide + '.v', 0)
Exemplo n.º 6
0
 def __lock_attributes(self):
     if not self._lockAttrs:
         return
     for attr in self._lockAttrs.items():
         key = attr[0]
         value = attr[1]
         assert cmds.objExists(key), (
             "lockAttrs: Key object does not exist: " + key)
         for v in value:
             assert (cmds.objExists(key + '.' +
                                    v)), ("lockAttrs: Given key "
                                          "object and value do not "
                                          "exist: " + key + "." + v)
         attribute.lock_n_hide(key, value, False)
Exemplo n.º 7
0
 def __setup(self):
     if not self._parentType:
         return
     if self._parentType == 'parent':
         #--- parent
         for ctl in self.controls:
             attribute.lock_n_hide(ctl.group, ['t', 'r', 's'], True)
             cmds.parent(ctl.group, self.main_control.gimbal)
             attribute.lock_n_hide(ctl.group, ['t', 'r', 's'])
     elif self._parentType == 'constraint':
         #--- constraint
         for ctl in self.controls:
             node.parentConstraint(self.main_control.gimbal, ctl.group)
             for axis in 'xyz':
                 cmds.setAttr(ctl.group + '.s' + axis, lock=False)
                 cmds.connectAttr(
                     self.main_control.transform + '.globalScale',
                     ctl.group + '.s' + axis)
                 cmds.setAttr(ctl.group + '.s' + axis, lock=True)
Exemplo n.º 8
0
Arquivo: goe.py Projeto: jonntd/Public
def setAttr(*args, **kwargs):
    """
    @type  args: *args
    @param args: specify nodes as you would do usually with maya cmds
    """
    assert args, "Please specify an existing node and attr."
    assert cmds.objExists(args[0]), "Please specify an existing node and attr."

    #--- vars
    check = False
    obj = args[0].split('.')[0]
    attr = args[0].split('.')[1]

    #--- unlock the attributes
    compound = cmds.attributeQuery(attr, node=obj, listChildren=True)
    if compound:
        for c in compound:
            if cmds.getAttr(obj + '.' + c, lock=True):
                attribute.lock_n_hide(obj, [c], True)
                check = True
    else:
        if cmds.getAttr(args[0], lock=True):
            attribute.lock_n_hide(obj, [attr], True)
            check = True

    #--- set attribute
    try:
        cmds.setAttr(args[0], args[1], args[2], args[3])
    except:
        cmds.setAttr(args[0], args[1])

    #--- lock the attribute
    if check:
        attribute.lock_n_hide(obj, [attr])
Exemplo n.º 9
0
Arquivo: goe.py Projeto: jonntd/Public
def setAttr(*args, **kwargs):
    """
    @type  args: *args
    @param args: specify nodes as you would do usually with maya cmds
    """
    assert args, "Please specify an existing node and attr."
    assert cmds.objExists(args[0]), "Please specify an existing node and attr."

    #--- vars
    check = False
    obj = args[0].split('.')[0]
    attr = args[0].split('.')[1]

    #--- unlock the attributes
    compound = cmds.attributeQuery(attr, node=obj, listChildren=True)
    if compound:
        for c in compound:
            if cmds.getAttr(obj + '.' + c, lock=True):
                attribute.lock_n_hide(obj, [c], True)
                check = True
    else:
        if cmds.getAttr(args[0], lock=True):
            attribute.lock_n_hide(obj, [attr], True)
            check = True

    #--- set attribute
    try:
        cmds.setAttr(args[0], args[1], args[2], args[3])
    except:
        cmds.setAttr(args[0], args[1])

    #--- lock the attribute
    if check:
        attribute.lock_n_hide(obj, [attr])
Exemplo n.º 10
0
def three_joint_ik(jointChain=[],
                   ikParent=None,
                   pvControl=None,
                   pvGroup=None,
                   offset=1):
    """
    @type  jointChain: list
    @param jointChain: specify three joints in a proper order.

    @type  ikParent: string
    @param ikParent: specify the control to parent the ikHandle to

    @type  pvControl: string
    @param pvControl: specify the poleVector control

    @type  pvGroup: string
    @param pvGroup: specify the poleVector group
    """
    #--- jointChain
    assert jointChain, "Please specify an existing startJoint!"

    if not pvControl:
        pvControl = cmds.createNode('transform')
        if not pvGroup:
            pvGroup = pvControl

    jointpos = list()
    #--- create joint chain
    for num, jnt in enumerate(jointChain):
        j = num + 1
        pos = cmds.xform(jnt, query=True, translation=True, worldSpace=True)
        jointpos.append(pos)
        if not j == len(jointChain):
            attribute.lock_attributes(jointChain[j], ['t', 'r', 's', 'v'])
            child = cmds.listRelatives(jnt, type='transform')
            if not child or not child[0] == jointChain[j]:
                cmds.parent(jointChain[j], jnt)
            attribute.lock_attributes(jointChain[j], ['r'], False)
        attribute.lock_attributes(jnt, ['r'], False)

    #--- calculate the polevector position
    attribute.lock_n_hide(pvGroup, ['t', 'r'], True)
    pvpos = goemath.calculate_polevector(jointpos[0], jointpos[1], jointpos[2], offset)
    cmds.xform(pvGroup, translation=(pvpos.x, pvpos.y, pvpos.z), worldSpace=True)
    cmds.setAttr(pvGroup + '.r', 0, 0, 0)
    attribute.lock_n_hide(pvGroup, ['t', 'r'])

    #--- compose name
    ikname = ikParent.split('_')[0] + '_' + ikParent.split('_')[1] + '_IKH'
    ikeff = ikParent.split('_')[0] + '_' + ikParent.split('_')[1] + '_EFF'

    #--- create ikHandle
    ik = cmds.ikHandle(startJoint=jointChain[0], endEffector=jointChain[-1],
                       solver='ikRPsolver', name=ikname)
    eff = cmds.rename(ik[1], ikeff)
    ik.pop(1)
    ik.append(eff)

    #--- create the poleVectorConstraint
    pvc = cmds.poleVectorConstraint(pvControl, ik[0])[0]

    #--- parent to ikParent
    cmds.parent(ik[0], ikParent)
    cmds.setAttr(ik[0] + '.t', 0, 0, 0)
    cmds.setAttr(ik[0] + '.r', 0, 0, 0)

    #--- cleanup
    for i in [ik[0], ik[1], 'ikRPsolver', pvc]:
        cmds.setAttr(i + '.ihi', 0)
        attribute.lock_all(i)
    return ik
Exemplo n.º 11
0
def three_joint_ik(jointChain=[],
                   ikParent=None,
                   pvControl=None,
                   pvGroup=None,
                   offset=1):
    """
    @type  jointChain: list
    @param jointChain: specify three joints in a proper order.

    @type  ikParent: string
    @param ikParent: specify the control to parent the ikHandle to

    @type  pvControl: string
    @param pvControl: specify the poleVector control

    @type  pvGroup: string
    @param pvGroup: specify the poleVector group
    """
    #--- jointChain
    assert jointChain, "Please specify an existing startJoint!"

    if not pvControl:
        pvControl = cmds.createNode('transform')
        if not pvGroup:
            pvGroup = pvControl

    jointpos = list()
    #--- create joint chain
    for num, jnt in enumerate(jointChain):
        j = num + 1
        pos = cmds.xform(jnt, query=True, translation=True, worldSpace=True)
        jointpos.append(pos)
        if not j == len(jointChain):
            attribute.lock_attributes(jointChain[j], ['t', 'r', 's', 'v'])
            child = cmds.listRelatives(jnt, type='transform')
            if not child or not child[0] == jointChain[j]:
                cmds.parent(jointChain[j], jnt)
            attribute.lock_attributes(jointChain[j], ['r'], False)
        attribute.lock_attributes(jnt, ['r'], False)

    #--- calculate the polevector position
    attribute.lock_n_hide(pvGroup, ['t', 'r'], True)
    pvpos = goemath.calculate_polevector(jointpos[0], jointpos[1], jointpos[2],
                                         offset)
    cmds.xform(pvGroup,
               translation=(pvpos.x, pvpos.y, pvpos.z),
               worldSpace=True)
    cmds.setAttr(pvGroup + '.r', 0, 0, 0)
    attribute.lock_n_hide(pvGroup, ['t', 'r'])

    #--- compose name
    ikname = ikParent.split('_')[0] + '_' + ikParent.split('_')[1] + '_IKH'
    ikeff = ikParent.split('_')[0] + '_' + ikParent.split('_')[1] + '_EFF'

    #--- create ikHandle
    ik = cmds.ikHandle(startJoint=jointChain[0],
                       endEffector=jointChain[-1],
                       solver='ikRPsolver',
                       name=ikname)
    eff = cmds.rename(ik[1], ikeff)
    ik.pop(1)
    ik.append(eff)

    #--- create the poleVectorConstraint
    pvc = cmds.poleVectorConstraint(pvControl, ik[0])[0]

    #--- parent to ikParent
    cmds.parent(ik[0], ikParent)
    cmds.setAttr(ik[0] + '.t', 0, 0, 0)
    cmds.setAttr(ik[0] + '.r', 0, 0, 0)

    #--- cleanup
    for i in [ik[0], ik[1], 'ikRPsolver', pvc]:
        cmds.setAttr(i + '.ihi', 0)
        attribute.lock_all(i)
    return ik
Exemplo n.º 12
0
 def __setup_controls(self):
     #--- showAll
     if not cmds.objExists(self.root + '.showAll'):
         attribute.lock_all(self.root)
         cmds.addAttr(self.root, longName='showAll', attributeType='short',
                      defaultValue=1, min=0, max=1)
         cmds.setAttr(self.root + '.showAll', edit=True, channelBox=True)
         attribute.lock_n_hide(self.root, ['v'], True)
         cmds.connectAttr(self.root + '.showAll', self.root + '.v')
         attribute.lock_n_hide(self.root, ['v'])
     #--- showGeo
     if not cmds.objExists(self.geo_grp + '.showGeo'):
         attribute.lock_all(self.geo_grp)
         cmds.addAttr(self.geo_grp, longName='showGeo',
                      attributeType='short', defaultValue=1, min=0, max=1)
         cmds.setAttr(self.geo_grp + '.showGeo', edit=True, channelBox=True)
         attribute.lock_n_hide(self.geo_grp, ['v'], True)
         cmds.connectAttr(self.geo_grp + '.showGeo', self.geo_grp + '.v')
         attribute.lock_n_hide(self.geo_grp, ['v'])
     #--- showRig
     if not cmds.objExists(self.rig_grp + '.showRig'):
         attribute.lock_all(self.rig_grp)
         cmds.addAttr(self.rig_grp, longName='showRig',
                      attributeType='short', defaultValue=1, min=0, max=1)
         cmds.setAttr(self.rig_grp + '.showRig', edit=True, channelBox=True)
         attribute.lock_n_hide(self.rig_grp, ['v'], True)
         cmds.connectAttr(self.rig_grp + '.showRig', self.rig_grp + '.v')
         attribute.lock_n_hide(self.rig_grp, ['v'])
     #--- showCurrent
     if not cmds.objExists(self.rig_grp + '.showCurrent'):
         cmds.addAttr(self.rig_grp, longName='showCurrent',
                      attributeType='short', defaultValue=0, min=0, max=1)
         cmds.setAttr(self.rig_grp + '.showCurrent',
                      edit=True, channelBox=True)
         attribute.lock_n_hide(self.current_asset.shape, ['v'], True)
         cmds.connectAttr(self.rig_grp + '.showCurrent',
                          self.current_asset.shape + '.v')
     #--- globalScale
     if not cmds.objExists(self.main_control.transform + '.globalScale'):
         cmds.addAttr(self.main_control.transform, longName='globalScale',
                      attributeType='float', defaultValue=1,
                      min=0, keyable=True)
         for axis in 'xyz':
             attribute.lock_n_hide(self.main_control.transform, ['s'], True)
             cmds.connectAttr(self.main_control.transform + '.globalScale',
                              self.main_control.transform + '.s' + axis)
             attribute.lock_n_hide(self.main_control.transform, ['s'])
Exemplo n.º 13
0
 def __setup(self):
     if not self._hook:
         self._hook = self.main_control.gimbal
     for i, ctl in enumerate(self.controls):
         if self._controlChain:
             j = i + 1
             if not i:
                 if self._hookLastControl:
                     if ctl == self.controls[-1]:
                         return
                 attribute.lock_n_hide(self.controls[i].group,
                                       ['t', 'r', 's'], True)
                 if self._hook:
                     cmds.parent(self.controls[i].group, self._hook)
                 attribute.lock_n_hide(self.controls[i].group,
                                       ['t', 'r', 's'])
             if not j == len(self.controls):
                 try:
                     if self._hookLastControl:
                         if ctl == self.controls[-1]:
                             return
                     attribute.lock_n_hide(self.controls[j].group,
                                           ['t', 'r', 's'], True)
                     cmds.parent(self.controls[j].group, ctl.transform)
                     attribute.lock_n_hide(self.controls[j].group,
                                           ['t', 'r', 's'])
                 except:
                     pass
         else:
             if self._hookLastControl:
                 if ctl == self.controls[-1]:
                     return
             attribute.lock_n_hide(ctl.group, ['t', 'r', 's'], True)
             if self._hook:
                 cmds.parent(ctl.group, self._hook)
             attribute.lock_n_hide(ctl.group, ['t', 'r', 's'])
Exemplo n.º 14
0
 def __setup_controls(self):
     #--- showAll
     if not cmds.objExists(self.root + '.showAll'):
         attribute.lock_all(self.root)
         cmds.addAttr(self.root,
                      longName='showAll',
                      attributeType='short',
                      defaultValue=1,
                      min=0,
                      max=1)
         cmds.setAttr(self.root + '.showAll', edit=True, channelBox=True)
         attribute.lock_n_hide(self.root, ['v'], True)
         cmds.connectAttr(self.root + '.showAll', self.root + '.v')
         attribute.lock_n_hide(self.root, ['v'])
     #--- showGeo
     if not cmds.objExists(self.geo_grp + '.showGeo'):
         attribute.lock_all(self.geo_grp)
         cmds.addAttr(self.geo_grp,
                      longName='showGeo',
                      attributeType='short',
                      defaultValue=1,
                      min=0,
                      max=1)
         cmds.setAttr(self.geo_grp + '.showGeo', edit=True, channelBox=True)
         attribute.lock_n_hide(self.geo_grp, ['v'], True)
         cmds.connectAttr(self.geo_grp + '.showGeo', self.geo_grp + '.v')
         attribute.lock_n_hide(self.geo_grp, ['v'])
     #--- showRig
     if not cmds.objExists(self.rig_grp + '.showRig'):
         attribute.lock_all(self.rig_grp)
         cmds.addAttr(self.rig_grp,
                      longName='showRig',
                      attributeType='short',
                      defaultValue=1,
                      min=0,
                      max=1)
         cmds.setAttr(self.rig_grp + '.showRig', edit=True, channelBox=True)
         attribute.lock_n_hide(self.rig_grp, ['v'], True)
         cmds.connectAttr(self.rig_grp + '.showRig', self.rig_grp + '.v')
         attribute.lock_n_hide(self.rig_grp, ['v'])
     #--- showCurrent
     if not cmds.objExists(self.rig_grp + '.showCurrent'):
         cmds.addAttr(self.rig_grp,
                      longName='showCurrent',
                      attributeType='short',
                      defaultValue=0,
                      min=0,
                      max=1)
         cmds.setAttr(self.rig_grp + '.showCurrent',
                      edit=True,
                      channelBox=True)
         attribute.lock_n_hide(self.current_asset.shape, ['v'], True)
         cmds.connectAttr(self.rig_grp + '.showCurrent',
                          self.current_asset.shape + '.v')
     #--- globalScale
     if not cmds.objExists(self.main_control.transform + '.globalScale'):
         cmds.addAttr(self.main_control.transform,
                      longName='globalScale',
                      attributeType='float',
                      defaultValue=1,
                      min=0,
                      keyable=True)
         for axis in 'xyz':
             attribute.lock_n_hide(self.main_control.transform, ['s'], True)
             cmds.connectAttr(self.main_control.transform + '.globalScale',
                              self.main_control.transform + '.s' + axis)
             attribute.lock_n_hide(self.main_control.transform, ['s'])