Exemple #1
0
def exportProxy24(obj, plist, fp):
    proxy = mh2proxy.readProxyFile(obj, plist, True)
    if not proxy:
        return
    faces = mh2proxy.oldStyleFaces(obj)
    tmpl = open("shared/mhx/templates/proxy24.mhx", "rU")
    for line in tmpl:
        words = line.split()
        if len(words) == 0:
            fp.write(line)
        elif words[0] == 'mesh':
            fp.write("mesh %s %s\n" % (proxy.name, proxy.name))
        elif words[0] == 'object':
            fp.write("object %s Mesh %s\n" % (proxy.name, proxy.name))
        elif words[0] == 'v':
            for bary in proxy.realVerts:
                (x, y, z) = mh2proxy.proxyCoord(bary)
                fp.write("v %.4g %.4g %.4g ;\n" % (x, -z, y))
        elif words[0] == 'f':
            for (f, g) in proxy.faces:
                fp.write("    f")
                for v in f:
                    fp.write(" %d" % v)
                fp.write(" ;\n")
            fn = 0
            for mat in proxy.materials:
                fp.write("    fx %d %d 1 ;\n" % (fn, mat))
                fn += 1
        elif words[0] == 'vt':
            for f in proxy.texFaces:
                fp.write("    vt")
                for v in f:
                    uv = proxy.texVerts[v]
                    fp.write(" %.4g %.4g" % (uv[0], uv[1]))
                fp.write(" ;\n")
        elif words[0] == 'vertgroup':
            copyVertGroups("shared/mhx/templates/vertexgroups-24.mhx", fp,
                           proxy)
        elif words[0] == 'shapekey':
            fp.write("  ShapeKey Basis Sym\n  end ShapeKey\n")
            copyShapeKeys("shared/mhx/templates/shapekeys-bodylanguage25.mhx",
                          fp, proxy, False)
            copyShapeKeys("shared/mhx/templates/shapekeys-extra24.mhx", fp,
                          proxy, False)
            copyShapeKeys("shared/mhx/templates/shapekeys-body25.mhx", fp,
                          proxy, False)
            writeIpo(fp)
        else:
            fp.write(line)
    tmpl.close()
    return
def exportProxy24(obj, plist, fp):
    proxy = mh2proxy.readProxyFile(obj, plist, True)
    if not proxy:
        return
    faces = mhx_main.loadFacesIndices(obj)
    tmpl = open("shared/mhx/templates/proxy24.mhx", "rU")
    for line in tmpl:
        words= line.split()
        if len(words) == 0:
            fp.write(line)
        elif words[0] == 'mesh':
            fp.write("mesh %s %s\n" % (proxy.name, proxy.name))
        elif words[0] == 'object':
            fp.write("object %s Mesh %s\n" % (proxy.name, proxy.name))
        elif words[0] == 'v':
            for bary in proxy.realVerts:
                (x,y,z) = mh2proxy.proxyCoord(bary)
                fp.write("v %.6g %.6g %.6g ;\n" % (x, -z, y))
        elif words[0] == 'f':
            for (f,g) in proxy.faces:
                fp.write("    f")
                for v in f:
                    fp.write(" %d" % v)
                fp.write(" ;\n")
            fn = 0
            for mat in proxy.materials:
                fp.write("    fx %d %d 1 ;\n" % (fn,mat))
                fn += 1
        elif words[0] == 'vt':
            for f in proxy.texFaces:
                fp.write("    vt")
                for v in f:
                    uv = proxy.texVerts[v]
                    fp.write(" %.6g %.6g" %(uv[0], uv[1]))
                fp.write(" ;\n")
        elif words[0] == 'vertgroup':
            mhx_main.copyVertGroups("shared/mhx/templates/vertexgroups-24.mhx", fp, proxy)    
        elif words[0] == 'shapekey':
            fp.write("  ShapeKey Basis Sym\n  end ShapeKey\n")
            if mhx_main.BODY_LANGUAGE:
                copyShapeKeys("shared/mhx/templates/shapekeys-bodylanguage25.mhx", fp, proxy, False)    
            else:
                copyShapeKeys("shared/mhx/templates/shapekeys-facial25.mhx", fp, proxy, False)    
            copyShapeKeys("shared/mhx/templates/shapekeys-extra24.mhx", fp, proxy, False)    
            copyShapeKeys("shared/mhx/templates/shapekeys-body25.mhx", fp, proxy, False)    
            writeIpo(fp)
        else:
            fp.write(line)
    tmpl.close()
    return
Exemple #3
0
def copyFile25(human, tmplName, fp, proxy, config, proxyData):
    tmpl = open(tmplName)
    if tmpl == None:
        log.error("*** Cannot open %s", tmplName)
        return

    obj = human.meshData
    bone = None
    #faces = loadFacesIndices(obj)
    ignoreLine = False
    for line in tmpl:
        words = line.split()
        if len(words) == 0:
            fp.write(line)
        elif words[0] == '***':
            key = words[1]

            if key == 'refer-human':
                if len(words) > 3:
                    suffix = words[3]
                else:
                    suffix = ""
                fp.write("    %s Refer Object %s%s ;\n" %
                         (words[2], the.Human, suffix))

            elif key == 'rig-bones':
                fp.write("Armature %s %s   Normal \n" % (the.Human, the.Human))
                mhx_rig.writeArmature(fp, config, config.armatureBones)

            elif key == 'human-object':
                if words[2] == 'Mesh':
                    fp.write("Object %sMesh MESH %sMesh\n" %
                             (the.Human, the.Human) +
                             "  Property MhxOffsetX %.4f ;\n" % the.Origin[0] +
                             "  Property MhxOffsetY %.4f ;\n" % the.Origin[1] +
                             "  Property MhxOffsetZ %.4f ;\n" % the.Origin[2])
                elif words[2] == 'ControlRig':
                    fp.write("Object %s ARMATURE %s\n" %
                             (the.Human, the.Human) +
                             "  Property MhxVersion %d ;\n" % MINOR_VERSION)

            elif key == 'rig-poses':
                fp.write("Pose %s\n" % the.Human)
                mhx_rig.writeControlPoses(fp, config)
                fp.write("  ik_solver 'LEGACY' ;\nend Pose\n")

            elif key == 'rig-actions':
                fp.write("Pose %s\nend Pose\n" % the.Human)
                mhx_rig.writeAllActions(fp, config)

            elif key == 'if-true':
                value = eval(words[2])
                log.debug("if %s %s", words[2], value)
                fp.write("#if %s\n" % value)

            elif key == 'rig-drivers':
                if config.rigtype == "mhx":
                    fp.write("AnimationData %s True\n" % the.Human)
                    mhx_rig.writeAllDrivers(fp, config)
                    rigDriversEnd(fp)

            elif key == 'rig-correct':
                fp.write("CorrectRig %s ;\n" % the.Human)

            elif key == 'recalc-roll':
                if config.rigtype == "mhx":
                    fp.write("  RecalcRoll %s ;\n" % config.recalcRoll)

            elif key == 'ProxyMesh':
                writeProxyMesh(fp, proxy, config, proxyData)

            elif key == 'ProxyObject':
                writeProxyObject(fp, proxy)

            elif key == 'ProxyLayers':
                fp.write("layers Array ")
                for n in range(20):
                    if n == proxy.layer:
                        fp.write("1 ")
                    else:
                        fp.write("0 ")
                fp.write(";\n")

            elif key == 'MeshAnimationData':
                writeHideAnimationData(fp, "", the.Human)

            elif key == 'ProxyAnimationData':
                writeHideAnimationData(fp, the.Human, proxy.name)

            elif key == 'toggleCage':
                if proxy and proxy.cage:
                    fp.write("  draw_type 'WIRE' ;\n" + "  #if False\n")
                elif config.cage:
                    fp.write("  #if toggle&T_Cage\n")
                else:
                    fp.write("  #if False\n")

            elif key == 'ProxyVerts':
                ox = the.Origin[0]
                oy = the.Origin[1]
                oz = the.Origin[2]
                for bary in proxy.realVerts:
                    (x, y, z) = mh2proxy.proxyCoord(bary)
                    fp.write("  v %.4f %.4f %.4f ;\n" %
                             (x - ox, -z + oz, y - oy))

            elif key == 'Verts':
                proxy = None
                fp.write("Mesh %sMesh %sMesh\n  Verts\n" %
                         (the.Human, the.Human))
                ox = the.Origin[0]
                oy = the.Origin[1]
                oz = the.Origin[2]
                for v in obj.verts:
                    fp.write("  v %.4f %.4f %.4f ;\n" %
                             (v.co[0] - ox, -v.co[2] + oz, v.co[1] - oy))

            elif key == 'ProxyFaces':
                for (f, g) in proxy.faces:
                    fp.write("    f")
                    for v in f:
                        fp.write(" %s" % v)
                    fp.write(" ;\n")
                if proxy.faceNumbers:
                    for ftn in proxy.faceNumbers:
                        fp.write(ftn)
                else:
                    fp.write("    ftall 0 1 ;\n")

            elif key == 'Faces':
                for f in obj.faces:
                    fv = f.verts
                    if f.isTriangle():
                        fp.write("    f %d %d %d ;\n" %
                                 (fv[0].idx, fv[1].idx, fv[2].idx))
                    else:
                        fp.write("    f %d %d %d %d ;\n" %
                                 (fv[0].idx, fv[1].idx, fv[2].idx, fv[3].idx))
                fp.write("#if False\n")

            elif key == 'EndFaces':
                writeFaceNumbers(fp, human, config, proxyData)

            elif key == 'FTTriangles':
                for f in obj.faces:
                    if f.isTriangle():
                        fp.write("    mn %d 1 ;\n" % f.idx)

            elif key == 'ProxyUVCoords':
                layers = list(proxy.uvtexLayerName.keys())
                layers.sort()
                for layer in layers:
                    try:
                        texfaces = proxy.texFacesLayers[layer]
                        texverts = proxy.texVertsLayers[layer]
                    except KeyError:
                        continue
                    fp.write('  MeshTextureFaceLayer %s\n' %
                             proxy.uvtexLayerName[layer] + '    Data \n')
                    for f in texfaces:
                        fp.write("    vt")
                        for v in f:
                            uv = texverts[v]
                            fp.write(" %.4g %.4g" % (uv[0], uv[1]))
                        fp.write(" ;\n")
                    fp.write('    end Data\n' + '  end MeshTextureFaceLayer\n')

            elif key == 'TexVerts':
                if human.uvset:
                    for ft in human.uvset.texFaces:
                        fp.write("    vt")
                        for vt in ft:
                            uv = human.uvset.texVerts[vt]
                            fp.write(" %.4g %.4g" % (uv[0], uv[1]))
                        fp.write(" ;\n")
                else:
                    for f in obj.faces:
                        uv0 = obj.texco[f.uv[0]]
                        uv1 = obj.texco[f.uv[1]]
                        uv2 = obj.texco[f.uv[2]]
                        if f.isTriangle():
                            fp.write(
                                "    vt %.4g %.4g %.4g %.4g %.4g %.4g ;\n" %
                                (uv0[0], uv0[1], uv1[0], uv1[1], uv2[0],
                                 uv2[1]))
                        else:
                            uv3 = obj.texco[f.uv[3]]
                            fp.write(
                                "    vt %.4g %.4g %.4g %.4g %.4g %.4g %.4g %.4g ;\n"
                                % (uv0[0], uv0[1], uv1[0], uv1[1], uv2[0],
                                   uv2[1], uv3[0], uv3[1]))

            elif key == 'Material':
                fp.write("Material %s%s\n" % (the.Human, words[2]))

            elif key == 'Materials':
                writeBaseMaterials(fp, human, config, proxyData)

            elif key == 'ProxyMaterials':
                if proxy.useBaseMaterials:
                    writeBaseMaterials(fp, human, config, proxyData)
                elif proxy.material:
                    fp.write("  Material %s%s ;\n" %
                             (the.Human, proxy.material.name))

            elif key == 'VertexGroup':
                writeVertexGroups(fp, config, proxy)

            elif key == 'group':
                writeGroups(fp, proxyData)

            elif key == 'mesh-shapeKey':
                writeShapeKeys(fp, human, "%sMesh" % the.Human, config, None)

            elif key == 'proxy-shapeKey':
                fp.write("#if toggle&T_Cage\n")
                proxyShapes('Cage', human, config, proxyData, fp)
                fp.write("#endif\n#if toggle&T_Proxy\n")
                proxyShapes('Proxy', human, config, proxyData, fp)
                fp.write("#endif\n#if toggle&T_Clothes\n")
                proxyShapes('Clothes', human, config, proxyData, fp)
                fp.write("#endif\n")

            elif key == 'ProxyModifiers':
                writeProxyModifiers(fp, proxy)

            elif key == 'MTex':
                n = nMasks + int(words[2])
                fp.write("  MTex %d %s %s %s\n" %
                         (n, words[3], words[4], words[5]))

            elif key == 'SkinStart':
                nMasks = writeSkinStart(fp, proxy, config, proxyData)

            elif key == 'curves':
                mhx_rig.writeAllCurves(fp, config)

            elif key == 'properties':
                mhx_rig.writeAllProperties(fp, words[2], config)
                writeHideProp(fp, the.Human)
                for proxy in proxyData.values():
                    writeHideProp(fp, proxy.name)
                if config.customshapes:
                    mhx_custom.listCustomFiles(config)
                for path, name in config.customShapeFiles:
                    fp.write("  DefProp Float %s 0 %s  min=-1.0,max=2.0 ;\n" %
                             (name, name[3:]))

            elif key == 'material-drivers':
                fp.write("  use_textures Array")
                for n in range(nMasks):
                    fp.write(" 1")
                for n in range(3):
                    fp.write(" 1")
                fp.write(" ;\n")
                fp.write("  AnimationData %sMesh True\n" % the.Human)
                #armature.drivers.writeTextureDrivers(fp, rig_panel_25.BodyLanguageTextureDrivers)
                writeMaskDrivers(fp, config, proxyData)
                fp.write("  end AnimationData\n")

            elif key == 'Filename':
                file = export_config.getOutFileName(words[2], words[3], True,
                                                    human, config)
                fp.write("  Filename %s ;\n" % file)

            else:
                raise NameError("Unknown *** %s" % words[1])
        else:
            fp.write(line)

    log.message("    %s copied", tmplName)
    tmpl.close()

    return
Exemple #4
0
def copyFile25(human, tmplName, fp, proxy, config, proxyData):
    tmpl = open(tmplName)
    if tmpl == None:
        log.error("*** Cannot open %s", tmplName)
        return

    obj = human.meshData
    bone = None
    #faces = loadFacesIndices(obj)
    ignoreLine = False
    for line in tmpl:
        words= line.split()
        if len(words) == 0:
            fp.write(line)
        elif words[0] == '***':
            key = words[1]

            if key == 'refer-human':
                if len(words) > 3:
                    suffix = words[3]
                else:
                    suffix = ""
                fp.write("    %s Refer Object %s%s ;\n" % (words[2], the.Human, suffix))

            elif key == 'rig-bones':
                fp.write("Armature %s %s   Normal \n" % (the.Human, the.Human))
                mhx_rig.writeArmature(fp, config, config.armatureBones)

            elif key == 'human-object':
                if words[2] == 'Mesh':
                    fp.write(
                        "Object %sMesh MESH %sMesh\n"  % (the.Human, the.Human) +
                        "  Property MhxOffsetX %.4f ;\n" % the.Origin[0] +
                        "  Property MhxOffsetY %.4f ;\n" % the.Origin[1] +
                        "  Property MhxOffsetZ %.4f ;\n" % the.Origin[2])
                elif words[2] == 'ControlRig':
                    fp.write(
                        "Object %s ARMATURE %s\n"  % (the.Human, the.Human) +
                        "  Property MhxVersion %d ;\n" % MINOR_VERSION)

            elif key == 'rig-poses':
                fp.write("Pose %s\n" % the.Human)
                mhx_rig.writeControlPoses(fp, config)
                fp.write("  ik_solver 'LEGACY' ;\nend Pose\n")

            elif key == 'rig-actions':
                fp.write("Pose %s\nend Pose\n" % the.Human)
                mhx_rig.writeAllActions(fp, config)

            elif key == 'if-true':
                value = eval(words[2])
                log.debug("if %s %s", words[2], value)
                fp.write("#if %s\n" % value)

            elif key == 'rig-drivers':
                if config.rigtype == "mhx":
                    fp.write("AnimationData %s True\n" % the.Human)
                    mhx_rig.writeAllDrivers(fp, config)
                    rigDriversEnd(fp)

            elif key == 'rig-correct':
                fp.write("CorrectRig %s ;\n" % the.Human)

            elif key == 'recalc-roll':
                if config.rigtype == "mhx":
                    fp.write("  RecalcRoll %s ;\n" % config.recalcRoll)

            elif key == 'ProxyMesh':
                writeProxyMesh(fp, proxy, config, proxyData)

            elif key == 'ProxyObject':
                writeProxyObject(fp, proxy)

            elif key == 'ProxyLayers':
                fp.write("layers Array ")
                for n in range(20):
                    if n == proxy.layer:
                        fp.write("1 ")
                    else:
                        fp.write("0 ")
                fp.write(";\n")

            elif key == 'MeshAnimationData':
                writeHideAnimationData(fp, "", the.Human)

            elif key == 'ProxyAnimationData':
                writeHideAnimationData(fp, the.Human, proxy.name)

            elif key == 'toggleCage':
                if proxy and proxy.cage:
                    fp.write(
                    "  draw_type 'WIRE' ;\n" +
                    "  #if False\n")
                elif config.cage:                    
                    fp.write("  #if toggle&T_Cage\n")
                else:
                    fp.write("  #if False\n")

            elif key == 'ProxyVerts':
                ox = the.Origin[0]
                oy = the.Origin[1]
                oz = the.Origin[2]
                for bary in proxy.realVerts:
                    (x,y,z) = mh2proxy.proxyCoord(bary)
                    fp.write("  v %.4f %.4f %.4f ;\n" % (x-ox, -z+oz, y-oy))

            elif key == 'Verts':
                proxy = None
                fp.write("Mesh %sMesh %sMesh\n  Verts\n" % (the.Human, the.Human))
                ox = the.Origin[0]
                oy = the.Origin[1]
                oz = the.Origin[2]
                for v in obj.verts:
                    fp.write("  v %.4f %.4f %.4f ;\n" % (v.co[0]-ox, -v.co[2]+oz, v.co[1]-oy))

            elif key == 'ProxyFaces':
                for (f,g) in proxy.faces:
                    fp.write("    f")
                    for v in f:
                        fp.write(" %s" % v)
                    fp.write(" ;\n")
                if proxy.faceNumbers:
                    for ftn in proxy.faceNumbers:
                        fp.write(ftn)
                else:
                    fp.write("    ftall 0 1 ;\n")

            elif key == 'Faces':
                for f in obj.faces:
                    fv = f.verts
                    if f.isTriangle():
                        fp.write("    f %d %d %d ;\n" % (fv[0].idx, fv[1].idx, fv[2].idx))
                    else:
                        fp.write("    f %d %d %d %d ;\n" % (fv[0].idx, fv[1].idx, fv[2].idx, fv[3].idx))
                fp.write("#if False\n")

            elif key == 'EndFaces':
                writeFaceNumbers(fp, human, config, proxyData)

            elif key == 'FTTriangles':
                for f in obj.faces:
                    if f.isTriangle():
                        fp.write("    mn %d 1 ;\n" % f.idx)

            elif key == 'ProxyUVCoords':
                layers = list(proxy.uvtexLayerName.keys())
                layers.sort()
                for layer in layers:
                    try:
                        texfaces = proxy.texFacesLayers[layer]
                        texverts = proxy.texVertsLayers[layer]
                    except KeyError:
                        continue
                    fp.write(                   
                        '  MeshTextureFaceLayer %s\n' % proxy.uvtexLayerName[layer] +
                        '    Data \n')
                    for f in texfaces:
                        fp.write("    vt")
                        for v in f:
                            uv = texverts[v]
                            fp.write(" %.4g %.4g" % (uv[0], uv[1]))
                        fp.write(" ;\n")
                    fp.write(
                        '    end Data\n' +
                        '  end MeshTextureFaceLayer\n')

            elif key == 'TexVerts':
                if human.uvset:
                    for ft in human.uvset.texFaces:
                        fp.write("    vt")
                        for vt in ft:
                            uv = human.uvset.texVerts[vt]
                            fp.write(" %.4g %.4g" %(uv[0], uv[1]))
                        fp.write(" ;\n")
                else:
                    for f in obj.faces:
                        uv0 = obj.texco[f.uv[0]]
                        uv1 = obj.texco[f.uv[1]]
                        uv2 = obj.texco[f.uv[2]]
                        if f.isTriangle():
                            fp.write("    vt %.4g %.4g %.4g %.4g %.4g %.4g ;\n" % (uv0[0], uv0[1], uv1[0], uv1[1], uv2[0], uv2[1]))
                        else:
                            uv3 = obj.texco[f.uv[3]]
                            fp.write("    vt %.4g %.4g %.4g %.4g %.4g %.4g %.4g %.4g ;\n" % (uv0[0], uv0[1], uv1[0], uv1[1], uv2[0], uv2[1], uv3[0], uv3[1]))

            elif key == 'Material':
                fp.write("Material %s%s\n" % (the.Human, words[2]))

            elif key == 'Materials':
                writeBaseMaterials(fp, human, config, proxyData)

            elif key == 'ProxyMaterials':
                if proxy.useBaseMaterials:
                    writeBaseMaterials(fp, human, config, proxyData)
                elif proxy.material:
                    fp.write("  Material %s%s ;\n" % (the.Human, proxy.material.name))

            elif key == 'VertexGroup':
                writeVertexGroups(fp, config, proxy)

            elif key == 'group':
                writeGroups(fp, proxyData)

            elif key == 'mesh-shapeKey':
                writeShapeKeys(fp, human, "%sMesh" % the.Human, config, None)

            elif key == 'proxy-shapeKey':
                fp.write("#if toggle&T_Cage\n")
                proxyShapes('Cage', human, config, proxyData, fp)
                fp.write("#endif\n#if toggle&T_Proxy\n")
                proxyShapes('Proxy', human, config, proxyData, fp)
                fp.write("#endif\n#if toggle&T_Clothes\n")
                proxyShapes('Clothes', human, config, proxyData, fp)
                fp.write("#endif\n")

            elif key == 'ProxyModifiers':
                writeProxyModifiers(fp, proxy)

            elif key == 'MTex':
                n = nMasks + int(words[2])
                fp.write("  MTex %d %s %s %s\n" % (n, words[3], words[4], words[5]))

            elif key == 'SkinStart':
                nMasks = writeSkinStart(fp, proxy, config, proxyData)

            elif key == 'curves':
                mhx_rig.writeAllCurves(fp, config)

            elif key == 'properties':
                mhx_rig.writeAllProperties(fp, words[2], config)
                writeHideProp(fp, the.Human)
                for proxy in proxyData.values():
                    writeHideProp(fp, proxy.name)
                if config.customshapes: 
                    mhx_custom.listCustomFiles(config)                            
                for path,name in config.customShapeFiles:
                    fp.write("  DefProp Float %s 0 %s  min=-1.0,max=2.0 ;\n" % (name, name[3:]))

            elif key == 'material-drivers':
                fp.write("  use_textures Array")
                for n in range(nMasks):
                    fp.write(" 1")
                for n in range(3):
                    fp.write(" 1")
                fp.write(" ;\n")
                fp.write("  AnimationData %sMesh True\n" % the.Human)
                #armature.drivers.writeTextureDrivers(fp, rig_panel_25.BodyLanguageTextureDrivers)
                writeMaskDrivers(fp, config, proxyData)
                fp.write("  end AnimationData\n")

            elif key == 'Filename':
                file = export_config.getOutFileName(words[2], words[3], True, human, config)
                fp.write("  Filename %s ;\n" % file)

            else:
                raise NameError("Unknown *** %s" % words[1])
        else:
            fp.write(line)

    log.message("    %s copied", tmplName)
    tmpl.close()

    return
Exemple #5
0
def setupRig(obj, config, proxyData):
    the.RigHead = {}
    the.RigTail = {}
    config.vertexWeights = []
    config.customShapes = {}
    config.poseInfo = {}

    log.message("setupRig %s", config.rigtype)
    if config.rigtype == 'mhx':
        config.boneGroups = [
            ('Master', 'THEME13'),
            ('Spine', 'THEME05'),
            ('FK_L', 'THEME09'),
            ('FK_R', 'THEME02'),
            ('IK_L', 'THEME03'),
            ('IK_R', 'THEME04'),
        ]
        config.recalcRoll = "['Foot_L','Toe_L','Foot_R','Toe_R','DfmFoot_L','DfmToe_L','DfmFoot_R','DfmToe_R']"
        #config.recalcRoll = []
        config.gizmoFiles = [
            "./shared/mhx/templates/custom-shapes25.mhx",
            "./shared/mhx/templates/panel_gizmo25.mhx",
            "./shared/mhx/templates/gizmos25.mhx"
        ]

        config.objectProps = [("MhxRig", '"MHX"')]
        config.armatureProps = []
        config.headName = 'Head'
        config.preservevolume = False

        config.vertexGroupFiles = ["head", "bones", "palm", "tight"]
        if config.skirtrig == "own":
            config.vertexGroupFiles.append("skirt-rigged")
        elif config.skirtrig == "inh":
            config.vertexGroupFiles.append("skirt")

        if config.malerig:
            config.vertexGroupFiles.append("male")

        joints = (
            rig_joints_25.DeformJoints + rig_body_25.BodyJoints +
            rig_body_25.FloorJoints + rig_arm_25.ArmJoints +
            rig_shoulder_25.ShoulderJoints + rig_finger_25.FingerJoints +
            rig_leg_25.LegJoints +
            #rig_toe_25.ToeJoints +
            rig_face_25.FaceJoints)

        headsTails = (
            rig_body_25.BodyHeadsTails + rig_shoulder_25.ShoulderHeadsTails +
            rig_arm_25.ArmHeadsTails + rig_finger_25.FingerHeadsTails +
            rig_leg_25.LegHeadsTails +
            #rig_toe_25.ToeHeadsTails +
            rig_face_25.FaceHeadsTails)

        config.armatureBones = list(rig_body_25.BodyArmature1)
        if config.advancedspine:
            config.armatureBones += rig_body_25.BodyArmature2Advanced
        else:
            config.armatureBones += rig_body_25.BodyArmature2Simple
        config.armatureBones += rig_body_25.BodyArmature3
        if config.advancedspine:
            config.armatureBones += rig_body_25.BodyArmature4Advanced
        else:
            config.armatureBones += rig_body_25.BodyArmature4Simple
        config.armatureBones += rig_body_25.BodyArmature5

        config.armatureBones += (
            rig_shoulder_25.ShoulderArmature1 +
            rig_shoulder_25.ShoulderArmature2 + rig_arm_25.ArmArmature +
            rig_finger_25.FingerArmature + rig_leg_25.LegArmature +
            #rig_toe_25.ToeArmature +
            rig_face_25.FaceArmature)

    elif config.rigtype == "rigify":
        config.boneGroups = []
        config.recalcRoll = []
        config.vertexGroupFiles = ["head", "rigify"]
        config.gizmoFiles = [
            "./shared/mhx/templates/panel_gizmo25.mhx",
            "./shared/mhx/templates/rigify_gizmo25.mhx"
        ]
        config.headName = 'head'
        config.preservevolume = True
        faceArmature = swapParentNames(rig_face_25.FaceArmature, {
            'Head': 'head',
            'MasterFloor': None
        })

        joints = (rig_joints_25.DeformJoints + rig_body_25.BodyJoints +
                  rig_body_25.FloorJoints + rigify_rig.RigifyJoints +
                  rig_face_25.FaceJoints)

        headsTails = (rigify_rig.RigifyHeadsTails + rig_face_25.FaceHeadsTails)

        config.armatureBones = (rigify_rig.RigifyArmature + faceArmature)

        config.objectProps = rigify_rig.RigifyObjectProps + [
            ("MhxRig", '"Rigify"')
        ]
        config.armatureProps = rigify_rig.RigifyArmatureProps

    else:
        rigfile = "data/rigs/%s.rig" % config.rigtype
        (locations, boneList,
         config.vertexWeights) = read_rig.readRigFile(rigfile, obj)
        joints = (rig_joints_25.DeformJoints + rig_body_25.FloorJoints +
                  rig_face_25.FaceJoints)
        headsTails = []
        config.armatureBones = []
        #if config.facepanel:
        #    joints += rig_panel_25.PanelJoints
        #    headsTails += rig_panel_25.PanelHeadsTails
        #    config.armatureBones += rig_panel_25.PanelArmature
        newSetupJoints(obj, joints)
        moveOriginToFloor(config)
        for (bone, head, tail) in headsTails:
            the.RigHead[bone] = findLocation(head)
            the.RigTail[bone] = findLocation(tail)

        appendRigBones(boneList, obj, "", L_MAIN, [], config)
        log.debug("BL %s", str(boneList[0]))
        config.boneGroups = []
        config.recalcRoll = []
        config.vertexGroupFiles = []
        config.gizmoFiles = []
        config.headName = 'Head'
        config.objectProps = [("MhxRig", '"%s"' % config.rigtype)]
        config.armatureProps = []
        config.customProps = []
        log.message("Default rig %s", config.rigtype)
        return
    """        
    if config.facepanel:            
        joints += rig_panel_25.PanelJoints
        headsTails += rig_panel_25.PanelHeadsTails
        config.armatureBones += rig_panel_25.PanelArmature
    """

    if config.rigtype == 'mhx':
        if config.skirtrig == "own":
            joints += rig_skirt_25.SkirtJoints
            headsTails += rig_skirt_25.SkirtHeadsTails
            config.armatureBones += rig_skirt_25.SkirtArmature
        if config.malerig:
            config.armatureBones += rig_body_25.MaleArmature

    (custJoints, custHeadsTails, custArmature,
     config.customProps) = mhx_custom.setupCustomRig(config)
    joints += custJoints
    headsTails += custHeadsTails
    config.armatureBones += custArmature

    newSetupJoints(obj, joints)
    moveOriginToFloor(config)

    if config.rigtype == 'mhx':
        rig_body_25.BodyDynamicLocations()
    for (bone, head, tail) in headsTails:
        the.RigHead[bone] = findLocation(head)
        the.RigTail[bone] = findLocation(tail)

    #print "H1", the.RigHead["UpLeg_L"]
    #print "T1", the.RigTail["UpLeg_L"]

    if not config.clothesrig:
        return
    body = the.RigHead.keys()
    for proxy in proxyData.values():
        if proxy.rig:
            verts = []
            for bary in proxy.realVerts:
                verts.append(mh2proxy.proxyCoord(bary))
            (locations, boneList, weights) = read_rig.readRigFile(proxy.rig,
                                                                  obj,
                                                                  verts=verts)
            proxy.weights = prefixWeights(weights, proxy.name, body)
            appendRigBones(boneList, obj, proxy.name, L_CLO, body, config)
    return
Exemple #6
0
def setupRig(obj, config, proxyData):
    the.RigHead = {}
    the.RigTail = {}
    config.vertexWeights = []
    config.customShapes = {}
    config.poseInfo = {}

    log.message("setupRig %s", config.rigtype)
    if config.rigtype == 'mhx':
        config.boneGroups = [
            ('Master', 'THEME13'),
            ('Spine', 'THEME05'),
            ('FK_L', 'THEME09'),
            ('FK_R', 'THEME02'),
            ('IK_L', 'THEME03'),
            ('IK_R', 'THEME04'),
        ]
        config.recalcRoll = "['Foot_L','Toe_L','Foot_R','Toe_R','DfmFoot_L','DfmToe_L','DfmFoot_R','DfmToe_R']"
        #config.recalcRoll = []
        config.gizmoFiles = ["./shared/mhx/templates/custom-shapes25.mhx", 
                      "./shared/mhx/templates/panel_gizmo25.mhx",
                      "./shared/mhx/templates/gizmos25.mhx"]

        config.objectProps = [("MhxRig", '"MHX"')]
        config.armatureProps = []
        config.headName = 'Head'
        config.preservevolume = False
        
        config.vertexGroupFiles = ["head", "bones", "palm", "tight"]
        if config.skirtrig == "own":
            config.vertexGroupFiles.append("skirt-rigged")    
        elif config.skirtrig == "inh":
            config.vertexGroupFiles.append("skirt")    

        if config.malerig:
            config.vertexGroupFiles.append( "male" )
                                                        
        joints = (
            rig_joints_25.DeformJoints +
            rig_body_25.BodyJoints +
            rig_body_25.FloorJoints +
            rig_arm_25.ArmJoints +
            rig_shoulder_25.ShoulderJoints +
            rig_finger_25.FingerJoints +
            rig_leg_25.LegJoints +
            #rig_toe_25.ToeJoints +
            rig_face_25.FaceJoints
        )            
        
        headsTails = (
            rig_body_25.BodyHeadsTails +
            rig_shoulder_25.ShoulderHeadsTails +
            rig_arm_25.ArmHeadsTails +
            rig_finger_25.FingerHeadsTails +
            rig_leg_25.LegHeadsTails +
            #rig_toe_25.ToeHeadsTails +
            rig_face_25.FaceHeadsTails
        )

        config.armatureBones = list(rig_body_25.BodyArmature1)
        if config.advancedspine:
            config.armatureBones += rig_body_25.BodyArmature2Advanced
        else:
            config.armatureBones += rig_body_25.BodyArmature2Simple
        config.armatureBones += rig_body_25.BodyArmature3
        if config.advancedspine:
            config.armatureBones += rig_body_25.BodyArmature4Advanced
        else:
            config.armatureBones += rig_body_25.BodyArmature4Simple
        config.armatureBones += rig_body_25.BodyArmature5

        config.armatureBones += (
            rig_shoulder_25.ShoulderArmature1 +
            rig_shoulder_25.ShoulderArmature2 +
            rig_arm_25.ArmArmature +            
            rig_finger_25.FingerArmature +
            rig_leg_25.LegArmature +
            #rig_toe_25.ToeArmature +
            rig_face_25.FaceArmature
        )

    elif config.rigtype == "rigify":
        config.boneGroups = []
        config.recalcRoll = []              
        config.vertexGroupFiles = ["head", "rigify"]
        config.gizmoFiles = ["./shared/mhx/templates/panel_gizmo25.mhx",
                          "./shared/mhx/templates/rigify_gizmo25.mhx"]
        config.headName = 'head'
        config.preservevolume = True
        faceArmature = swapParentNames(rig_face_25.FaceArmature, 
                           {'Head' : 'head', 'MasterFloor' : None} )
            
        joints = (
            rig_joints_25.DeformJoints +
            rig_body_25.BodyJoints +
            rig_body_25.FloorJoints +
            rigify_rig.RigifyJoints +
            rig_face_25.FaceJoints
        )
        
        headsTails = (
            rigify_rig.RigifyHeadsTails +
            rig_face_25.FaceHeadsTails
        )

        config.armatureBones = (
            rigify_rig.RigifyArmature +
            faceArmature
        )

        config.objectProps = rigify_rig.RigifyObjectProps + [("MhxRig", '"Rigify"')]
        config.armatureProps = rigify_rig.RigifyArmatureProps

    else:
        rigfile = "data/rigs/%s.rig" % config.rigtype
        (locations, boneList, config.vertexWeights) = read_rig.readRigFile(rigfile, obj)        
        joints = (
            rig_joints_25.DeformJoints +
            rig_body_25.FloorJoints +
            rig_face_25.FaceJoints
        )
        headsTails = []
        config.armatureBones = []
        #if config.facepanel:            
        #    joints += rig_panel_25.PanelJoints
        #    headsTails += rig_panel_25.PanelHeadsTails
        #    config.armatureBones += rig_panel_25.PanelArmature
        newSetupJoints(obj, joints)        
        moveOriginToFloor(config)
        for (bone, head, tail) in headsTails:
            the.RigHead[bone] = findLocation(head)
            the.RigTail[bone] = findLocation(tail)

        appendRigBones(boneList, obj, "", L_MAIN, [], config)
        log.debug("BL %s", str(boneList[0]))
        config.boneGroups = []
        config.recalcRoll = []              
        config.vertexGroupFiles = []
        config.gizmoFiles = []
        config.headName = 'Head'
        config.objectProps = [("MhxRig", '"%s"' % config.rigtype)]
        config.armatureProps = []
        config.customProps = []
        log.message("Default rig %s", config.rigtype)
        return

    """        
    if config.facepanel:            
        joints += rig_panel_25.PanelJoints
        headsTails += rig_panel_25.PanelHeadsTails
        config.armatureBones += rig_panel_25.PanelArmature
    """
    
    if config.rigtype == 'mhx':
        if config.skirtrig == "own":
            joints += rig_skirt_25.SkirtJoints
            headsTails += rig_skirt_25.SkirtHeadsTails
            config.armatureBones += rig_skirt_25.SkirtArmature        
        if config.malerig:
            config.armatureBones += rig_body_25.MaleArmature        

    (custJoints, custHeadsTails, custArmature, config.customProps) = mhx_custom.setupCustomRig(config)
    joints += custJoints
    headsTails += custHeadsTails
    config.armatureBones += custArmature
    
    newSetupJoints(obj, joints)
    moveOriginToFloor(config)    

    if config.rigtype == 'mhx':
        rig_body_25.BodyDynamicLocations()
    for (bone, head, tail) in headsTails:
        the.RigHead[bone] = findLocation(head)
        the.RigTail[bone] = findLocation(tail)
        
    #print "H1", the.RigHead["UpLeg_L"]
    #print "T1", the.RigTail["UpLeg_L"]

    if not config.clothesrig:
        return
    body = the.RigHead.keys()
    for proxy in proxyData.values():
        if proxy.rig:
            verts = []
            for bary in proxy.realVerts:
                verts.append(mh2proxy.proxyCoord(bary))
            (locations, boneList, weights) = read_rig.readRigFile(proxy.rig, obj, verts=verts) 
            proxy.weights = prefixWeights(weights, proxy.name, body)
            appendRigBones(boneList, obj, proxy.name, L_CLO, body, config)
    return