コード例 #1
0
 def shapeSwapMesh(self):
     '''
     Swap the mesh Geo so it's a shape under the PPC transform root
     TODO: Make sure that the duplicate message link bug is covered!!
     '''
     cmds.duplicate(self.mesh, rc=True, n=self.refMesh)[0]
     r9Core.LockChannels().processState(self.refMesh,['tx','ty','tz','rx','ry','rz','sx','sy','sz'],\
                                        mode='fullkey',hierarchy=False)
     try:
         #turn on the overrides so the duplicate geo can be selected
         cmds.setAttr("%s.overrideDisplayType" % self.refMeshShape, 0)
         cmds.setAttr("%s.overrideEnabled" % self.refMeshShape, 1)
         cmds.setAttr("%s.overrideLevelOfDetail" % self.refMeshShape, 0)
     except:
         log.debug('Couldnt set the draw overrides for the refGeo')
     cmds.parent(self.refMesh, self.posePointRoot)
     cmds.makeIdentity(self.refMesh, apply=True, t=True, r=True)
     cmds.parent(self.refMeshShape, self.posePointRoot, r=True, s=True)
     cmds.delete(self.refMesh)
コード例 #2
0
def bind_skeletons(source,
                   dest,
                   method='connect',
                   scales=False,
                   verbose=False,
                   unlock=False,
                   bindroot=True):
    '''
    From 2 given root joints search through each hierarchy for child joints, match
    them based on node name, then connect their trans/rots directly, or
    parentConstrain them. Again cmds for speed

    :param source: the root node of the driving skeleton
    :param dest: the root node of the driven skeleton
    :param method: the method used for the connection, either 'connect' or 'constrain'
    :param scale: do we bind the scales of the destination skel to the source??
    :param unlock: if True force unlock the required transform attrs on the destination skeleton first
    '''

    sourceJoints = cmds.listRelatives(source, ad=True, f=True, type='joint')
    destJoints = cmds.listRelatives(dest, ad=True, f=True, type='joint')

    if verbose:
        result = cmds.confirmDialog(
            title='Bind Skeletons SCALES',
            message=
            ("Would you also like to process the SCALE channels within the bind?"
             ),
            button=['Yes', 'No'],
            messageAlign='center',
            icon='question',
            dismissString='Cancel')
        if result == 'Yes':
            scales = True
        else:
            scales = False

    # parent constrain the root nodes regardless of bindType, fixes issues where
    # we have additional rotated parent groups on the source
    if bindroot:
        cmds.parentConstraint(source, dest)
        if scales:
            cmds.scaleConstraint(source, dest, mo=True)

    # attrs to 'connect' and also to ensure are unlocked
    attrs = [
        'rotateX', 'rotateY', 'rotateZ', 'translateX', 'translateY',
        'translateZ'
    ]
    if scales:
        attrs = attrs + ['scaleX', 'scaleY', 'scaleZ', 'inverseScale']
    if unlock:
        r9Core.LockChannels().processState(dest,
                                           attrs=attrs,
                                           mode='fullkey',
                                           hierarchy=True)

    for sJnt, dJnt in match_given_hierarchys(sourceJoints, destJoints):
        if method == 'connect':
            for attr in attrs:
                try:
                    cmds.connectAttr('%s.%s' % (sJnt, attr),
                                     '%s.%s' % (dJnt, attr),
                                     f=True)
                except:
                    pass
        elif method == 'constrain':
            # need to see if the channels are open if not, change this binding code
            try:
                cmds.parentConstraint(sJnt, dJnt, mo=True)
            except:
                chns = r9Anim.getSettableChannels(dJnt)
                if all([
                        'translateX' in chns, 'translateY' in chns,
                        'translateZ' in chns
                ]):
                    cmds.pointConstraint(sJnt, dJnt, mo=True)
                elif all(
                    ['rotateX' in chns, 'rotateY' in chns, 'rotateZ' in chns]):
                    cmds.orientConstraint(sJnt, dJnt, mo=True)
                else:
                    log.info('Failed to Bind joints: %s >> %s' % (sJnt, dJnt))

            # if we have incoming scale connections then run the scaleConstraint
            if scales:  # and cmds.listConnections('%s.sx' % sJnt):
                try:
                    cmds.scaleConstraint(sJnt, dJnt, mo=True)
                    # turn off the compensation so that the rig can still be scaled correctly by the MasterNode
                    # cmds.setAttr('%s.segmentScaleCompensate' % dJnt, 0)
                except:
                    print('failed : scales ', dJnt)