Пример #1
0
def TryLoadExternalUVs():
    with mayaUtils.DebugTimer('TryLoadExternalUVs'):
        mainMesh = mayaUtils.FindMeshByWildcard('Genesis8Female*',
                                                checkForMatWithName='Torso')

        if mainMesh is None:
            print 'Error! Can`t find body(Torso) mesh'
            return

        cmds.delete(mainMesh, constructionHistory=True)

        uvMeshFile = os.path.join(env.GetIntermediateFullPath(),
                                  env.BASE_FEMALE_MESH_WITH_UV1_NAME + '.obj')
        uvMeshFileExist = os.path.exists(uvMeshFile)

        print 'UV mesh file: {} Exist: {}'.format(uvMeshFile, uvMeshFileExist)
        if not uvMeshFileExist:
            print 'ABORTED: no uv mesh file found'
            return

        uvMesh = cmds.file(uvMeshFile, i=True, returnNewNodes=True)[0]
        uvMesh = cmds.rename(uvMesh, 'UV_Source')
        cmds.xform(uvMesh, absolute=True, translation=[0, 0, 100])

        cmds.polyUVSet(mainMesh, create=True, uvSet='Tesselation_UV')
        cmds.transferAttributes(uvMesh,
                                mainMesh,
                                transferPositions=0,
                                transferNormals=0,
                                transferUVs=1,
                                sourceUvSet='map1',
                                targetUvSet='Tesselation_UV',
                                sampleSpace=5)
        cmds.delete(mainMesh, constructionHistory=True)
        cmds.delete(uvMesh)
Пример #2
0
def TryLoadExternalBaseMeshBodyMorph():
    with mayaUtils.DebugTimer('TryLoadExternalBaseMeshBodyMorph'):
        mainMesh = mayaUtils.FindMeshByWildcard('Genesis8Female*',
                                                checkForMatWithName='Torso')

        if mainMesh is None:
            print 'Error! Can`t find body(Torso) mesh'
            return
        #Mesh unskinned on this stage so we can safely delete all history
        cmds.delete(mainMesh, constructionHistory=True)

        bodyMorphFile = os.path.join(env.GetIntermediateFullPath(),
                                     env.PROCESSED_BASE_MESH_NAME + '.obj')
        bodyMorphExist = os.path.exists(bodyMorphFile)
        print 'Body morph file: {} Exist: {}'.format(bodyMorphFile,
                                                     bodyMorphExist)
        if not bodyMorphExist:
            print 'ABORTED: no body morph file found'
            return

        morphMesh = cmds.file(bodyMorphFile, i=True, returnNewNodes=True)[0]
        morphMesh = cmds.rename(morphMesh, 'BodyMorph')
        cmds.xform(morphMesh, absolute=True, translation=[0, 0, 100])

        bs = cmds.blendShape([morphMesh, mainMesh])
        cmds.blendShape(bs, edit=True, weight=[0, 1.0])

        cmds.delete(mainMesh, constructionHistory=True)
        cmds.delete(morphMesh)
Пример #3
0
def SetVertexColorForBorderVertices():
    with mayaUtils.DebugTimer('SetVertexColorForBorderVertices'):
        skinList = cmds.ls(type='skinCluster')
        cmds.select(clear=True)

        for s in skinList:
            cmds.select(clear=True)
            mesh = mayaUtils.GetMeshFromSkinCluster(s)
            cmds.select(mesh)
            cmds.selectType(polymeshFace=True)
            cmds.polySelectConstraint(mode=3, type=8,
                                      where=1)  # to get border vertices
            borderVerts = cmds.polyListComponentConversion(tv=True)
            cmds.polySelectConstraint(mode=0, sh=0, bo=0)
            cmds.select(clear=True)

            allVerts = cmds.polyListComponentConversion(mesh, tv=True)
            mayaUtils.SetVertexColors(allVerts, (1, 1, 1))
            mayaUtils.SetVertexColors(borderVerts, (0, 1, 1))

        cmds.select(clear=True)

        shape = mayaUtils.FindMeshByWildcard(
            'FemaleBody*', checkForMatWithName='Body')  #new name is 'Body'
        if shape:
            MaskShellsEdgesForTesselation(shape, 0)
            MaskShellsEdgesForTesselation(shape, 1)
            MaskShellsEdgesForTesselation(shape, 2)
            MaskShellsEdgesForTesselation(shape, 3)
            MaskShellsEdgesForTesselation(shape, 4)
Пример #4
0
def RenameNewSkeleton():
    with mayaUtils.DebugTimer('RenameNewSkeleton'):
        newRoot = cmds.ls('DAZ_root', type='joint')
        newJoints = cmds.listRelatives(newRoot, allDescendents=True)
        newJoints.append(newRoot[0])

        for j in newJoints:
            newName = j[4:]
            mayaUtils.RenameJoint(j, newName)
Пример #5
0
def TriangulateAllSkinnedMeshes():
    with mayaUtils.DebugTimer('TriangulateAllSkinnedMeshes'):
        cmds.select(clear=True)
        skinList = cmds.ls(type='skinCluster') or []
        for s in skinList:
            mesh = mayaUtils.GetMeshFromSkinCluster(s)
            cmds.polyTriangulate(mesh)
            cmds.bakePartialHistory(mesh, prePostDeformers=True)
        cmds.select(clear=True)
Пример #6
0
def RenameSkeletonJoints():
    with mayaUtils.DebugTimer('RenameSkeletonJoints'):
        #first rename original pevis joint if exist (for animation retargetting mode) as it has same name 'pelvis' as our new joint
        mayaUtils.RenameJoint('pelvis', 'original_pelvis_to_delete')
        renamingDictionary = GetRenamingDict()
        for oldName, newName in renamingDictionary.iteritems():
            mayaUtils.RenameJoint(oldName, newName)

        RenameChildren('lowerface')
        RenameChildren('upperface')
Пример #7
0
def AlighnTwistJoints(prefix='DAZ_'):
    with mayaUtils.DebugTimer('AlighnTwistJoints'):
        twistJoints = cmds.ls(prefix + '*_twist*', type='joint')
        for j in twistJoints:
            oldPos = cmds.joint(j, q=True, position=True, relative=True)
            newPos = [oldPos[0], 0.0, 0.0]
            print '\tAlighning joint {0} oldPos={1}, newPos ={2}'.format(
                j, oldPos, newPos)
            cmds.joint(j, e=True, position=newPos, relative=True)
            cmds.joint(j, e=True, orientation=[0.0, 0.0, 0.0])
            cmds.xform(j, rotation=[0.0, 0.0, 0.0])
Пример #8
0
def CreateIkJoints(pCreateConstraint=True):
    with mayaUtils.DebugTimer('CreateIkJoints'):
        CreateIkJoint('root', 'root', 'ik_foot_root')
        CreateIkJoint('foot_r', 'ik_foot_root', 'ik_foot_r', pCreateConstraint)
        CreateIkJoint('foot_l', 'ik_foot_root', 'ik_foot_l', pCreateConstraint)

        CreateIkJoint('root', 'root', 'ik_hand_root', False)
        CreateIkJoint('hand_r', 'ik_hand_root', 'ik_hand_gun',
                      pCreateConstraint)
        CreateIkJoint('hand_r', 'ik_hand_gun', 'ik_hand_r', pCreateConstraint)
        CreateIkJoint('hand_l', 'ik_hand_gun', 'ik_hand_l', pCreateConstraint)
Пример #9
0
def JointOrientToRotation(skeletonRoot):
    with mayaUtils.DebugTimer('JointOrientToRotation'):
        jointsList = mayaUtils.GetHierarchy(skeletonRoot)
        cmds.makeIdentity(jointsList, n=0, s=0, r=1, t=0, apply=True, pn=0)

        for j in jointsList:
            #remember
            orient = cmds.joint(j, q=True, orientation=True)
            #reset
            cmds.joint(j, e=True, orientation=[0, 0, 0])
            cmds.xform(j, relative=True, rotation=orient)
Пример #10
0
def TryLoadExternalMorphTargets():
    with mayaUtils.DebugTimer('TryLoadExternalMorphTargets'):
        mainMesh = mayaUtils.FindMeshByWildcard('Genesis8Female*',
                                                checkForMatWithName='Torso')

        if mainMesh is None:
            print 'Error! Can`t find body(Torso) mesh'
            return

        subDirs = fileUtils.GetSubdirNames(env.GetIntermediateFullPath())

        blendShapeDeformer = None

        for subDir in subDirs:
            if not fileUtils.IsDirStartWithPrefixes(subDir,
                                                    env.MORPH_TARGET_PREFIXES):
                print 'SKIPPING directory {}. Reason - unresolved name (should starts with \'{}\')'.format(
                    subDir, env.MORPH_TARGET_PREFIXES)
                continue

            fullSubdirPath = os.path.join(env.GetIntermediateFullPath(),
                                          subDir)
            morphMeshFile = os.path.join(fullSubdirPath,
                                         env.PROCESSED_BASE_MESH_NAME + '.obj')
            morphMeshExist = os.path.exists(morphMeshFile)
            print 'Dir: {} SubD mesh: {} Exist: {}'.format(
                subDir, morphMeshFile, morphMeshExist)
            if not morphMeshExist:
                print 'SKIPPING...'
                continue

            morphMesh = cmds.file(morphMeshFile, i=True,
                                  returnNewNodes=True)[0]
            morphMesh = cmds.rename(morphMesh,
                                    subDir)  # name new blendshape as it folder
            cmds.xform(morphMesh, absolute=True, translation=[0, 0, 100])

            blendShapeDeformer = mayaUtils.GetBlendShape(mainMesh)

            if blendShapeDeformer is None:
                blendShapeDeformer = cmds.blendShape(mainMesh)[0]

            weightsCount = cmds.blendShape(
                blendShapeDeformer, q=True,
                weightCount=True)  # Index for next added blendshape
            cmds.blendShape(blendShapeDeformer,
                            edit=True,
                            target=(mainMesh, weightsCount, morphMesh, 1.0))
            cmds.delete(morphMesh)
Пример #11
0
def OptimizeBodyMaterials():
    with mayaUtils.DebugTimer('OptimizeBodyMaterials'):
        shape = mayaUtils.FindMeshByWildcard('Genesis8Female*',
                                             checkForMatWithName='Torso')

        if shape is None:
            print 'Error! Can`t find body(Torso) shape'
            return

        mayaUtils.AppendShadingGroupByMat(shape, 'Face', 'Lips')
        mayaUtils.AppendShadingGroupByMat(shape, 'Face', 'Ears')
        mayaUtils.AppendShadingGroupByMat(shape, 'Face', 'EyeSocket')

        mayaUtils.AppendShadingGroupByMat(shape, 'Legs', 'Toenails')
        mayaUtils.AppendShadingGroupByMat(shape, 'Arms', 'Fingernails')

        mayaUtils.AppendShadingGroupByMat(shape, 'Torso', 'Legs')
        mayaUtils.AppendShadingGroupByMat(shape, 'Torso', 'Arms')
        mayaUtils.AppendShadingGroupByMat(shape, 'Torso', 'Face')

        mayaUtils.AppendShadingGroupByMat(shape, 'Mouth', 'Teeth')

        mayaUtils.AppendShadingGroupByMat(shape, 'EyeMoisture',
                                          'Cornea')  # useful eyes
        mayaUtils.AppendShadingGroupByMat(shape, 'Pupils',
                                          'Irises')  # not used
        mayaUtils.AppendShadingGroupByMat(shape, 'Pupils',
                                          'Sclera')  # not used

        eyesShape = mayaUtils.DetachSkinnedMeshByMat(shape,
                                                     ['EyeMoisture', 'Pupils'],
                                                     '_Eyes')

        mayaUtils.DeleteFacesByMat(eyesShape, ['Pupils'])
        unusedEyesFaces = selUtils.GetFacesOutsideCenterUVRange(eyesShape)
        cmds.delete(unusedEyesFaces)

        mayaUtils.RenameMaterial('Torso', 'Body')
        mayaUtils.RenameMaterial('EyeMoisture', 'Eyes')

        mayaUtils.RenameMaterial('EyeLashes*', 'FemaleEyeLashes')

        SafeBakePartialHistoryKeepBlendShapes(shape)

        if eyesShape:
            cmds.bakePartialHistory(eyesShape, prePostDeformers=True)

        mayaUtils.CleanUnusedInfluensesOnAllSkinClusters()
Пример #12
0
def AddNippleJointsAndAimBreast():
    with mayaUtils.DebugTimer('AddNippleJointsAndAimBreast'):
        cmds.select(clear=True)

        baseMeshFile = os.path.join(env.GetIntermediateFullPath(),
                                    env.PROCESSED_BASE_MESH_NAME + '.obj')
        baseMeshExist = os.path.exists(baseMeshFile)
        print 'Base Mesh file: {} Exist: {}'.format(baseMeshFile,
                                                    baseMeshExist)
        if not baseMeshExist:
            print 'ABORTED: no Base Mesh file found'
            return

        baseMesh = cmds.file(baseMeshFile, i=True, returnNewNodes=True)[0]
        baseMesh = cmds.rename(baseMesh, 'BaseMeshForNipplesCoordinatesLookUp')
        leftNipplePos = mayaUtils.UvCoordToWorld(k_LEFT_NIPPLE_UV[0],
                                                 k_LEFT_NIPPLE_UV[1], baseMesh)
        rightNipplePos = mayaUtils.UvCoordToWorld(k_RIGHT_NIPPLE_UV[0],
                                                  k_RIGHT_NIPPLE_UV[1],
                                                  baseMesh)
        cmds.delete(baseMesh)

        for side in ['l', 'r']:
            breastJoint = 'breast_' + side
            nippleJoint = 'nipple_' + side
            nipplePos = leftNipplePos if side == 'l' else rightNipplePos
            cmds.select(clear=True)
            nippleJoint = cmds.joint(name=nippleJoint)  #create unparented
            cmds.xform(nippleJoint, absolute=True,
                       translation=nipplePos)  #and set position in worldspace
            cmds.select(clear=True)
            print nippleJoint
            if side == 'l':
                constraint = cmds.aimConstraint(nippleJoint,
                                                breastJoint,
                                                worldUpType='scene',
                                                aimVector=[0, -1, 0],
                                                upVector=[0, 0, 1])
            else:
                constraint = cmds.aimConstraint(nippleJoint,
                                                breastJoint,
                                                worldUpType='scene',
                                                aimVector=[0, 1, 0],
                                                upVector=[0, 0, -1])
            cmds.delete(constraint)
            cmds.parent(nippleJoint, breastJoint)
            cmds.joint(nippleJoint, e=True,
                       orientation=[0, 0, 0])  #reset joint orietnation
Пример #13
0
def DuplicateSkeletonJoints(oldSkeletonRoot, newJointsPrefix):
    with mayaUtils.DebugTimer('Duplicating skeleton'):
        jointsList = mayaUtils.GetHierarchy(oldSkeletonRoot)
        #print jointsList

        for j in jointsList:
            #print j
            pos = cmds.joint(j, q=True, absolute=True)
            oldName = cmds.joint(j, q=True, name=True)
            oldOrientation = cmds.joint(j, q=True, orientation=True)

            newName = newJointsPrefix + oldName

            cmds.select(clear=True)
            newJoint = cmds.joint(p=pos, name=newName)
            cmds.xform(newJoint, r=True, ro=oldOrientation)
Пример #14
0
def MakeBendCorrectiveJoints():
    with mayaUtils.DebugTimer('MakeBendCorrectiveJoints'):
        MakeBendCorrectiveJoint('knee_bend_l', 'calf_l', 'thigh_l',
                                ['thigh_twist_01_l', 'calf_l'])
        MakeBendCorrectiveJoint('knee_bend_r', 'calf_r', 'thigh_r',
                                ['thigh_twist_01_r', 'calf_r'])

        MakeBendCorrectiveJoint('butt_bend_l', 'thigh_l', 'pelvis')
        MakeBendCorrectiveJoint('butt_bend_r', 'thigh_r', 'pelvis')

        MakeBendCorrectiveJoint('shoulder_bend_l', 'upperarm_l', 'clavicle_l')
        MakeBendCorrectiveJoint('shoulder_bend_r', 'upperarm_r', 'clavicle_r')

        MakeBendCorrectiveJoint('elbow_bend_l', 'lowerarm_l', 'upperarm_l',
                                ['upperarm_twist_01_l', 'lowerarm_l'])
        MakeBendCorrectiveJoint('elbow_bend_r', 'lowerarm_r', 'upperarm_r',
                                ['upperarm_twist_01_r', 'lowerarm_r'])
Пример #15
0
def RenameAndCombineMeshes():
    with mayaUtils.DebugTimer('RenameAndCombineMeshes'):
        #Main
        bodyList = cmds.ls('Genesis8FemaleFBX*Shape',
                           type='transform',
                           objectsOnly=True,
                           long=True)
        if bodyList:
            cmds.rename(bodyList[0], 'FemaleBody')

        #
        #EYES
        #
        eyesList = cmds.ls('*Eyes',
                           type='transform',
                           objectsOnly=True,
                           long=True)

        if eyesList and len(eyesList) > 1:
            print '\tCombining {0}'.format(eyesList)
            cmds.polyUniteSkinned(eyesList, ch=False)
            cmds.rename('FemaleEyes')
            cmds.select(clear=True)
            #clear orphane transforms if exist
            for o in eyesList:
                if cmds.objExists(o):
                    cmds.delete(o)
        elif eyesList and len(eyesList) == 1:
            cmds.rename(eyesList[0], 'FemaleEyes')
            print '\t Renaming SINGLE EYES object'
        else:
            print '\t No EYES meshes to combine'

        #Main
        eyelashesList = cmds.ls('*Eyelashes*Shape',
                                type='transform',
                                objectsOnly=True,
                                long=True)
        if eyelashesList:
            cmds.rename(eyelashesList[0], 'FemaleEyelashes')
Пример #16
0
def DestroyUnusedJoints(pbDestroyToes):
    with mayaUtils.DebugTimer('DestroyUnusedJoints'):
        #mayaUtils.CleanUnusedInfluensesOnAllSkinClusters()
        mayaUtils.DestroyMiddleJoint('lMetatarsals')
        mayaUtils.DestroyMiddleJoint('rMetatarsals')
        #to match EPIC skeleton
        mayaUtils.DestroyMiddleJoint('pelvis')
        #spine1
        #mayaUtils.TransferJointWeights('abdomenLower', 'abdomenUpper', 0.33)#transfer 33 persent to child
        mayaUtils.DestroyMiddleJoint(
            'chestUpper')  # and 67 percent to parent then delete
        #Neck
        mayaUtils.TransferJointWeights('neckUpper', 'head',
                                       0.33)  #transfer 33 persent to child
        mayaUtils.DestroyMiddleJoint('neckUpper')

        for jointToRemove in k_CARPAL_JOINTS_TO_REMOVE:
            mayaUtils.DestroyMiddleJoint(jointToRemove)

        #end to match EPIC skeleton
        if pbDestroyToes:
            mayaUtils.DestroyJointChildren('lToe')
            mayaUtils.DestroyJointChildren('rToe')
Пример #17
0
def FixNewJointsOrientation():
    with mayaUtils.DebugTimer('FixNewJointsOrientation'):
        # Root
        mayaUtils.RotateJoint("DAZ_root", 0, 0, 0)

        # Spine
        CopyJointPosition('DAZ_pelvis', 'DAZ_thigh_l', 'yz')

        mayaUtils.RotateJoint("DAZ_pelvis", -90, 0, 90)
        mayaUtils.RotateJoint("DAZ_spine_01", -90, 0, 90)
        AimJointForUnreal('DAZ_spine_01', 'DAZ_spine_02')

        mayaUtils.RotateJoint("DAZ_spine_02", -90, 0, 90)
        AimJointForUnreal('DAZ_spine_02', 'DAZ_spine_03')

        mayaUtils.RotateJoint("DAZ_spine_03", -90, 0, 90)
        AimJointForUnreal('DAZ_spine_03', 'DAZ_neck_01')

        mayaUtils.RotateJoint("DAZ_breast_l", -90, 0, 0)
        mayaUtils.RotateJoint("DAZ_breast_r", 90, 0, 0)

        mayaUtils.RotateJoint("DAZ_neck_01", -90, 0, 90)
        AimJointForUnreal('DAZ_neck_01', 'DAZ_head')
        mayaUtils.RotateJoint("DAZ_head", -90, 0, 90)

        # Leg Left
        mayaUtils.RotateJoint("DAZ_thigh_l", -90, 0, 90)
        mayaUtils.RotateJoint("DAZ_thigh_twist_01_l", -90, 0, 90)
        mayaUtils.RotateJoint("DAZ_calf_l", -90, 0, 90)
        # copy rotation from Leg
        cmds.xform('DAZ_foot_l',
                   absolute=True,
                   rotation=cmds.xform('calf_l',
                                       q=True,
                                       absolute=True,
                                       rotation=True))
        mayaUtils.RotateJoint("DAZ_foot_l", -90, 0, 90)
        AimFootJoint('DAZ_foot_l',
                     'DAZ_ball_l',
                     inAimVector=[0, -1, 0],
                     inUpVector=[1, 0, 0])
        mayaUtils.RotateJoint("DAZ_ball_l", 0, -90,
                              0)  #TODO near but not ideal

        # Leg Right
        mayaUtils.RotateJoint("DAZ_thigh_r", 90, 0, -90)
        mayaUtils.RotateJoint("DAZ_thigh_twist_01_r", 90, 0, -90)
        mayaUtils.RotateJoint("DAZ_calf_r", 90, 0, -90)
        # copy rotation from Leg
        cmds.xform('DAZ_foot_r',
                   absolute=True,
                   rotation=cmds.xform('calf_r',
                                       q=True,
                                       absolute=True,
                                       rotation=True))
        mayaUtils.RotateJoint("DAZ_foot_r", 90, 0, -90)
        AimFootJoint('DAZ_foot_r',
                     'DAZ_ball_r',
                     inAimVector=[0, 1, 0],
                     inUpVector=[-1, 0, 0])
        mayaUtils.RotateJoint("DAZ_ball_r", 180, 90, 0)

        # Arm Left

        #TODO TEST
        CopyJointPosition('DAZ_clavicle_l', 'DAZ_spine_03', 'z')
        mayaUtils.RotateJoint("DAZ_clavicle_l", -90)

        AimJointForUnreal('DAZ_clavicle_l', 'DAZ_upperarm_l')
        mayaUtils.RotateJoint("DAZ_upperarm_l", -90)
        mayaUtils.RotateJoint("DAZ_upperarm_twist_01_l", -90)
        mayaUtils.RotateJoint("DAZ_lowerarm_l", -90)
        mayaUtils.RotateJoint("DAZ_lowerarm_twist_01_l", -90)
        mayaUtils.RotateJoint("DAZ_hand_l", -180)

        mayaUtils.RotateJoint('DAZ_thumb_01_l', -90)
        mayaUtils.RotateJoint('DAZ_thumb_02_l', -90)
        mayaUtils.RotateJoint('DAZ_thumb_03_l', -90)

        #mayaUtils.RotateJoint('DAZ_HandIndex0_L', 90)
        mayaUtils.RotateJoint('DAZ_index_01_l', 180)
        mayaUtils.RotateJoint('DAZ_index_02_l', 180)
        mayaUtils.RotateJoint('DAZ_index_03_l', 180)

        #mayaUtils.RotateJoint('DAZ_HandMid0_L', 90)
        mayaUtils.RotateJoint('DAZ_middle_01_l', 180)
        mayaUtils.RotateJoint('DAZ_middle_02_l', 180)
        mayaUtils.RotateJoint('DAZ_middle_03_l', 180)

        #mayaUtils.RotateJoint('DAZ_HandRing0_L', 90)
        mayaUtils.RotateJoint('DAZ_ring_01_l', 180)
        mayaUtils.RotateJoint('DAZ_ring_02_l', 180)
        mayaUtils.RotateJoint('DAZ_ring_03_l', 180)

        #mayaUtils.RotateJoint('DAZ_HandPinky0_L', 90)
        mayaUtils.RotateJoint('DAZ_pinky_01_l', 180)
        mayaUtils.RotateJoint('DAZ_pinky_02_l', 180)
        mayaUtils.RotateJoint('DAZ_pinky_03_l', 180)

        # Arm Right
        #TODO TEST
        CopyJointPosition('DAZ_clavicle_r', 'DAZ_spine_03', 'z')

        mayaUtils.RotateJoint("DAZ_clavicle_r", 90)
        AimJointForUnreal('DAZ_clavicle_r',
                          'DAZ_upperarm_r',
                          inAimVector=[-1.0, 0.0, 0.0])
        mayaUtils.RotateJoint("DAZ_upperarm_r", 90)
        mayaUtils.RotateJoint("DAZ_upperarm_twist_01_r", 90)
        mayaUtils.RotateJoint("DAZ_lowerarm_r", 90)
        mayaUtils.RotateJoint("DAZ_lowerarm_twist_01_r", 90)
        mayaUtils.RotateJoint("DAZ_hand_r", 0)

        mayaUtils.RotateJoint('DAZ_thumb_01_r', 90)
        mayaUtils.RotateJoint('DAZ_thumb_02_r', 90)
        mayaUtils.RotateJoint('DAZ_thumb_03_r', 90)

        #mayaUtils.RotateJoint('DAZ_HandIndex0_R', -90, 180)
        mayaUtils.RotateJoint('DAZ_index_01_r', 0)
        mayaUtils.RotateJoint('DAZ_index_02_r', 0)
        mayaUtils.RotateJoint('DAZ_index_03_r', 0)

        #mayaUtils.RotateJoint('DAZ_HandMid0_R', -90, 180)
        mayaUtils.RotateJoint('DAZ_middle_01_r', 0)
        mayaUtils.RotateJoint('DAZ_middle_02_r', 0)
        mayaUtils.RotateJoint('DAZ_middle_03_r', 0)

        #mayaUtils.RotateJoint('DAZ_HandRing0_R', -90, 180)
        mayaUtils.RotateJoint('DAZ_ring_01_r', 0)
        mayaUtils.RotateJoint('DAZ_ring_02_r', 0)
        mayaUtils.RotateJoint('DAZ_ring_03_r', 0)

        #mayaUtils.RotateJoint('DAZ_HandPinky0_R', -90, 180)
        mayaUtils.RotateJoint('DAZ_pinky_01_r', 0)
        mayaUtils.RotateJoint('DAZ_pinky_02_r', 0)
        mayaUtils.RotateJoint('DAZ_pinky_03_r', 0)

        #Toes
        for t in [
                'toebig_01', 'toebig_02', 'toeindex_01', 'toeindex_02',
                'toemid_01', 'toemid_02', 'toering_01', 'toering_02',
                'toepinky_01', 'toepinky_02'
        ]:
            mayaUtils.RotateJoint('DAZ_' + t + '_l', 0, 90)
            mayaUtils.RotateJoint('DAZ_' + t + '_r', 0, -90)

        # facial rig
        mayaUtils.RotateJoint("DAZ_tongue_01", 0, -90, 0)
        mayaUtils.RotateJoint("DAZ_tongue_02", 0, -90, 0)
        mayaUtils.RotateJoint("DAZ_tongue_03", 0, -90, 0)
        mayaUtils.RotateJoint("DAZ_tongue_04", 0, -90, 0)

        mayaUtils.RotateJoint("DAZ_eye_l", 0, -90, 180)
        mayaUtils.RotateJoint("DAZ_eye_r", 0, -90, 180)

        # selecting original joints of face rig
        children = cmds.listRelatives('DAZ_head', allDescendents=True) or []

        for child in children:
            if child in ['DAZ_eye_l', 'DAZ_eye_r'
                         ] or child.startswith('DAZ_tongue_'):
                continue  # skip already rotated
            mayaUtils.RotateJoint('DAZ_' + child, 0, -90,
                                  0)  # but rotating skeleton copy

        cmds.select(clear=True)
Пример #18
0
def RecreateHierarchy(oldSkeletonRoot, newJointsPrefix):
    with mayaUtils.DebugTimer('Recreating hierarchy'):
        jointsList = cmds.listRelatives(
            oldSkeletonRoot, allDescendents=True,
            type="joint")  #Root is already unparrented, we dont need it

        for j in jointsList:
            parent = cmds.listRelatives(j, parent=True, type='joint')
            if not parent:
                continue
            oldName = cmds.joint(j, q=True, name=True)
            oldParentName = cmds.joint(parent, q=True, name=True)
            newName = newJointsPrefix + oldName
            newParentName = newJointsPrefix + oldParentName
            if oldName == 'thigh_l' or oldName == 'thigh_r':  #connect legs to Hips, not to OLD pelvis
                newParentName = newJointsPrefix + 'pelvis'
            elif oldName == 'ball_l':
                newParentName = newJointsPrefix + 'foot_l'  #not to lMetatarsals
            elif oldName == 'ball_r':
                newParentName = newJointsPrefix + 'foot_r'  #not to rMetatarsals
            elif oldName == 'head':
                newParentName = newJointsPrefix + 'neck_01'  #not to neckUpper
            elif oldName == 'clavicle_l' or oldName == 'clavicle_r' or oldName == 'neck_01':
                newParentName = newJointsPrefix + 'spine_03'  #not to chestupper

            #FIX Hand Carpal Bones (for animation retargetting mode)
            if oldParentName in k_CARPAL_JOINTS_TO_REMOVE:
                carpalParent = cmds.listRelatives(parent,
                                                  parent=True,
                                                  type='joint')
                if carpalParent:
                    carpalParentName = cmds.joint(carpalParent,
                                                  q=True,
                                                  name=True)
                    newParentName = newJointsPrefix + carpalParentName  #not to carpal, to it parent (hand)

            #print newParentName
            cmds.parent(newName, newParentName)

            print '\tParenting {0} to {1}'.format(newName, newParentName)

        twistJoints = cmds.ls(newJointsPrefix + '*_twist*')
        for j in twistJoints:
            parent = cmds.listRelatives(j, parent=True)
            children = cmds.listRelatives(j)
            if children is not None:
                for child in children:
                    print 'Reparenting twist joint {0} child {1} to {2}'.format(
                        j, child, parent[0])
                    cmds.parent(child, parent[0])

        #Remove unused bones if exists (for animation retargeting mode)
        unusedList = [
            'lMetatarsals', 'rMetatarsals', 'chestUpper', 'neckUpper',
            'original_pelvis_to_delete'
        ]
        unusedList.extend(k_CARPAL_JOINTS_TO_REMOVE)
        for j in unusedList:
            print j
            if cmds.objExists(newJointsPrefix + j):  #still use prefix
                cmds.delete(newJointsPrefix + j)
                print 'Deleting joint {0}'.format(newJointsPrefix + j)
Пример #19
0
def PostprocessGenitaliaObject(genitaliaMeshWildcard):
    with mayaUtils.DebugTimer(
            'PostprocessGenitaliaObject(genitaliaMeshWildcard={0})'.format(
                genitaliaMeshWildcard)):
        genitaliaMesh = mayaUtils.FindMeshByWildcard(genitaliaMeshWildcard)
        if not genitaliaMesh:
            print 'Genitalia mesh not found. Aborted'
            return

        print 'Processing {0}'.format(genitaliaMesh)

        genitaliaMesh = cmds.rename(genitaliaMesh,
                                    'FemaleGenitalia')  #rename to proper name

        #replace material with original torso mat
        facesWithTorsoMat = mayaUtils.GetFacesByMatsWildcard(
            genitaliaMesh, 'Torso*')
        mayaUtils.AssignObjectListToShader(facesWithTorsoMat,
                                           'Body')  #use new material name
        # mayaUtils.ArrangeUVByMat(genitaliaMesh, 'Body', su=0.5, sv=0.5, u=0.5, v=0.5)
        mayaUtils.AppendShadingGroupByMat(genitaliaMesh, 'Anus', 'V****a')
        mayaUtils.RenameMaterial('Anus', 'BodyGenitalia')
        cmds.bakePartialHistory(genitaliaMesh, prePostDeformers=True)

        bodyMesh = mayaUtils.FindMeshByWildcard('FemaleBody' + '*',
                                                checkForMatWithName='Body')

        if not bodyMesh:
            print '{0} mesh not found. Aborted'
            return

        cmds.select(clear=True)
        borderVertsList = mayaUtils.GetBorderVertices(genitaliaMesh)
        borderVertsList = cmds.filterExpand(borderVertsList,
                                            sm=31,
                                            expand=True)

        bodySkinCluster = mayaUtils.GetSkinCluster(bodyMesh)
        genitaliaSkinCluster = mayaUtils.GetSkinCluster(genitaliaMesh)

        #transfer attributes manually
        for v in borderVertsList:
            pos = cmds.pointPosition(v, world=True)
            #print pos
            closestVert = mayaUtils.GetClosestVertex(bodyMesh, pos)
            closestVertPos = cmds.xform(closestVert, t=True, ws=True, q=True)
            closestVertNormal = cmds.polyNormalPerVertex(closestVert,
                                                         query=True,
                                                         xyz=True)

            # set position
            cmds.move(closestVertPos[0],
                      closestVertPos[1],
                      closestVertPos[2],
                      v,
                      absolute=True,
                      worldSpace=True)
            # set normal
            cmds.polyNormalPerVertex(v,
                                     xyz=(closestVertNormal[0],
                                          closestVertNormal[1],
                                          closestVertNormal[2]))

            referenceVertInfluences = cmds.skinPercent(bodySkinCluster,
                                                       closestVert,
                                                       query=True,
                                                       transform=None,
                                                       ignoreBelow=0.00001)

            targetInfluences = cmds.skinCluster(genitaliaSkinCluster,
                                                query=True,
                                                influence=True)

            targetTransformValues = []

            for i in referenceVertInfluences:
                if i not in targetInfluences:
                    cmds.skinCluster(genitaliaSkinCluster,
                                     e=True,
                                     addInfluence=i,
                                     weight=0.0)
                    #print i
                referenceInfluenceValuePerVertex = cmds.skinPercent(
                    bodySkinCluster,
                    closestVert,
                    query=True,
                    transform=i,
                    transformValue=True)
                targetTransformValues.append(
                    (i, referenceInfluenceValuePerVertex))

            #print targetTransformValues

            # set weight
            cmds.skinPercent(genitaliaSkinCluster,
                             v,
                             transformValue=targetTransformValues)

        cmds.bakePartialHistory(genitaliaMesh, prePostDeformers=True)