Ejemplo n.º 1
0
def writeMaterial(fp, stuff, human):
    fp.write("newmtl %s\n" % stuff.name)
    diffuse = (0.8, 0.8, 0.8)
    spec = (1, 1, 1)
    if stuff.material:
        for (key, value) in stuff.material.settings:
            if key == "diffuse_color":
                diffuse = value
            elif key == "specular_color":
                spec = value
    fp.write(
    "Kd %.4f %.4f %.4f\n" % (diffuse[0], diffuse[1], diffuse[2]) +
    "Ks %.4f %.4f %.4f\n" % (spec[0], spec[1], spec[2])
    )
    if stuff.type:
        if stuff.texture:
            textures = [stuff.texture]
        else:
            return
    else:
        path = "data/textures"
        file = export_config.getOutFileName("texture.png", path, True, human, the.Config)
        textures = [(path, os.path.basename(file))]
    for (folder, texfile) in textures:  
        path = export_config.getOutFileName(texfile, folder, True, human, the.Config)        
        (fname, ext) = os.path.splitext(texfile)  
        name = "%s_%s" % (fname, ext[1:])
        if the.Config.separatefolder:
            texpath = "textures/"+texfile
        else:
            texpath = texfile
        fp.write("map_Kd %s\n" % texpath)
    return
Ejemplo n.º 2
0
def writeMultiMaterials(uvset, human, config, fp):
    folder = os.path.dirname(human.uvset.filename)
    log.debug("Folder %s", folder)
    for mat in uvset.materials:
        for tex in mat.textures:
            name = os.path.basename(tex.file)
            fp.write("Image %s\n" % name)
            #file = export_config.getOutFileName(tex, "data/textures", True, human, config)
            file = export_config.getOutFileName(name, folder, True, human,
                                                config)
            fp.write("  Filename %s ;\n" % file + "  alpha_mode 'PREMUL' ;\n" +
                     "end Image\n\n" + "Texture %s IMAGE\n" % name +
                     "  Image %s ;\n" % name + "end Texture\n\n")

        fp.write("Material %s_%s\n" % (the.Human, mat.name))
        alpha = False
        for (key, value) in mat.settings:
            if key == "alpha":
                alpha = True
                fp.write("  use_transparency True ;\n" +
                         "  use_raytrace False ;\n" +
                         "  use_shadows False ;\n" +
                         "  use_transparent_shadows False ;\n" +
                         "  alpha %s ;\n" % value)
            elif key in ["diffuse_color", "specular_color"]:
                fp.write("  %s Array %s %s %s ;\n" %
                         (key, value[0], value[1], value[2]))
            elif key in ["diffuse_intensity", "specular_intensity"]:
                fp.write("  %s %s ;\n" % (key, value))
        if not alpha:
            fp.write("  use_transparent_shadows True ;\n")

        n = 0
        for tex in mat.textures:
            name = os.path.basename(tex.file)
            if len(tex.types) > 0:
                (key, value) = tex.types[0]
            else:
                (key, value) = ("diffuse", "1")
            (type, use, factor, flags) = TexInfo[key]
            diffuse = False
            fp.write("  MTex %d %s UV %s\n" % (n, name, type) +
                     "    texture Refer Texture %s ;\n" % name)
            for (key, value) in tex.types:
                (type, use, factor, flags) = TexInfo[key]
                if flags & TX_SCALE:
                    scale = "*theScale"
                else:
                    scale = ""
                fp.write("    %s True ;\n" % use + "    %s %s%s ;\n" %
                         (factor, value, scale))
                if flags & TX_BW:
                    fp.write("    use_rgb_to_intensity True ;\n")
                if key == "diffuse":
                    diffuse = True
            if not diffuse:
                fp.write("    use_map_color_diffuse False ;\n")
            fp.write("  end MTex\n")
            n += 1
        fp.write("end Material\n\n")
Ejemplo n.º 3
0
def writeImages(obj, fp, stuff, human):
    if stuff.type:
        if stuff.texture:
            textures = [stuff.texture]
        else:
            return
        human = None
    else:
        path = "data/textures"
        texfile = "texture.png"
        textures = [(path, os.path.basename(texfile))]
    for (folder, texname) in textures: 
        path = export_config.getOutFileName(texname, folder, True, human, the.Config)        
        texfile = os.path.basename(path)
        (fname, ext) = os.path.splitext(texname)  
        name = "%s_%s" % (fname, ext[1:])
        if the.Config.separatefolder:
            texpath = "textures/"+texfile
        else:
            texpath = path
        fp.write(
        '    <image id="%s" name="%s">\n' % (name, name) +
        '      <init_from>%s</init_from>\n' % texpath +
        '    </image>\n'
        )
    return
Ejemplo n.º 4
0
def addMaskImage(fp, config, mask):
    (folder, file) = mask
    path = export_config.getOutFileName(file, folder, True, None, config)
    fp.write("Image %s\n" % file + "  Filename %s ;\n" % path +
             "  alpha_mode 'PREMUL' ;\n" + "end Image\n\n" +
             "Texture %s IMAGE\n" % file + "  Image %s ;\n" % file +
             "end Texture\n\n")
    return
Ejemplo n.º 5
0
def addMaskImage(fp, config, mask):            
    (folder, file) = mask
    path = export_config.getOutFileName(file, folder, True, None, config)
    fp.write(
"Image %s\n" % file +
"  Filename %s ;\n" % path +
"  alpha_mode 'PREMUL' ;\n" +
"end Image\n\n" +
"Texture %s IMAGE\n" % file  +
"  Image %s ;\n" % file +
"end Texture\n\n")
    return
Ejemplo n.º 6
0
def writeTexture(fp, key, texture, human, cfg):
    if not texture:
        return
    (folder, texfile) = texture
    path = export_config.getOutFileName(texfile, folder, True, human, cfg)
    (fname, ext) = os.path.splitext(texfile)
    name = "%s_%s" % (fname, ext[1:])
    if cfg.separatefolder:
        texpath = "textures/" + texfile
    else:
        texpath = texfile
    fp.write("%s %s\n" % (key, texpath))
Ejemplo n.º 7
0
def addMaskImage(fp, mask):            
    (folder, file) = mask
    path = export_config.getOutFileName(file, folder, True, None, the.Config)
    fp.write(
"Image %s\n" % file +
"  Filename %s ;\n" % path +
"  use_premultiply True ;\n" +
"end Image\n\n" +
"Texture %s IMAGE\n" % file  +
"  Image %s ;\n" % file +
"end Texture\n\n")
    return
Ejemplo n.º 8
0
def writeTexture(fp, key, texture, human, cfg):
    if not texture:
        return
    (folder, texfile) = texture
    path = export_config.getOutFileName(texfile, folder, True, human, cfg)        
    (fname, ext) = os.path.splitext(texfile)  
    name = "%s_%s" % (fname, ext[1:])
    if cfg.separatefolder:
        texpath = "textures/"+texfile
    else:
        texpath = texfile
    fp.write("%s %s\n" % (key, texpath))
Ejemplo n.º 9
0
def writeProxyTexture(fp, texture, mat, extra, config):
    (folder, name) = texture
    tex = os.path.join(folder, name)
    #print(the.Human)
    log.debug("Tex %s", tex)
    texname = the.Human + os.path.basename(tex)
    fromDir = os.path.dirname(tex)
    texfile = export_config.getOutFileName(tex, fromDir, True, None, config)
    fp.write("Image %s\n" % texname + "  Filename %s ;\n" % texfile +
             "  alpha_mode 'PREMUL' ;\n" + "end Image\n\n" +
             "Texture %s IMAGE\n" % texname + "  Image %s ;\n" % texname)
    writeProxyMaterialSettings(fp, mat.textureSettings)
    fp.write(extra)
    fp.write("end Texture\n\n")
    return (tex, texname)
Ejemplo n.º 10
0
def writeProxyTexture(fp, texture, mat, extra):        
    (folder,name) = texture
    tex = os.path.join(folder,name)
    #print(the.Human)
    print("Tex", tex)
    texname = the.Human + os.path.basename(tex)
    fromDir = os.path.dirname(tex)
    texfile = export_config.getOutFileName(tex, fromDir, True, None, the.Config)
    fp.write(
"Image %s\n" % texname +
"  Filename %s ;\n" % texfile +
"  use_premultiply True ;\n" +
"end Image\n\n" +
"Texture %s IMAGE\n" % texname +
"  Image %s ;\n" % texname)
    writeProxyMaterialSettings(fp, mat.textureSettings)             
    fp.write(extra)
    fp.write("end Texture\n\n")
    return (tex, texname)
Ejemplo n.º 11
0
def writeProxyTexture(fp, texture, mat, extra, config):        
    (folder,name) = texture
    tex = os.path.join(folder,name)
    #print(the.Human)
    log.debug("Tex %s", tex)
    texname = the.Human + os.path.basename(tex)
    fromDir = os.path.dirname(tex)
    texfile = export_config.getOutFileName(tex, fromDir, True, None, config)
    fp.write(
"Image %s\n" % texname +
"  Filename %s ;\n" % texfile +
"  alpha_mode 'PREMUL' ;\n" +
"end Image\n\n" +
"Texture %s IMAGE\n" % texname +
"  Image %s ;\n" % texname)
    writeProxyMaterialSettings(fp, mat.textureSettings)             
    fp.write(extra)
    fp.write("end Texture\n\n")
    return (tex, texname)
Ejemplo n.º 12
0
def writeImages(obj, fp, stuff, human):
    if stuff.texture:
        textures = [stuff.texture]
    else:
        textures = []

    for (folder, texname) in textures:
        path = export_config.getOutFileName(texname, folder, True, human,
                                            the.Config)
        texfile = os.path.basename(path)
        (fname, ext) = os.path.splitext(texname)
        name = "%s_%s" % (fname, ext[1:])
        if the.Config.separatefolder:
            texpath = "textures/" + texfile
        else:
            texpath = path
        fp.write('    <image id="%s" name="%s">\n' % (name, name) +
                 '      <init_from>%s</init_from>\n' % texpath +
                 '    </image>\n')
    return
Ejemplo n.º 13
0
def copyProxyMaterialFile(fp, pair, mat, proxy, config, proxyData):
    prxList = sortedMasks(config, proxyData)
    nMasks = countMasks(proxy, prxList)
    tex = None

    (folder, file) = pair
    folder = os.path.realpath(os.path.expanduser(folder))
    infile = os.path.join(folder, file)
    tmpl = open(infile, "rU")
    for line in tmpl:
        words = line.split()
        if len(words) == 0:
            fp.write(line)
        elif words[0] == 'Texture':
            words[1] = the.Human + words[1]
            for word in words:
                fp.write("%s " % word)
            fp.write("\n")
            tex = os.path.join(folder, words[1])
        elif words[0] == 'Material':
            words[1] = the.Human + words[1]
            for word in words:
                fp.write("%s " % word)
            fp.write("\n")
            addProxyMaskMTexs(fp, mat, proxy, prxList, tex)
        elif words[0] == 'MTex':
            words[2] = the.Human + words[2]
            for word in words:
                fp.write("%s " % word)
            fp.write("\n")
        elif words[0] == 'Filename':
            file = export_config.getOutFileName(words[1], folder, True, None,
                                                config)
            fp.write("  Filename %s ;\n" % file)
        else:
            fp.write(line)
    tmpl.close()
    return
Ejemplo n.º 14
0
def copyProxyMaterialFile(fp, pair, mat, proxy, config, proxyData):
    prxList = sortedMasks(config, proxyData)
    nMasks = countMasks(proxy, prxList)
    tex = None
    
    (folder, file) = pair
    folder = os.path.realpath(os.path.expanduser(folder))
    infile = os.path.join(folder, file)
    tmpl = open(infile, "rU")
    for line in tmpl:
        words= line.split()
        if len(words) == 0:
            fp.write(line)
        elif words[0] == 'Texture':
            words[1] = the.Human + words[1]
            for word in words:
                fp.write("%s " % word)
            fp.write("\n")
            tex = os.path.join(folder,words[1])
        elif words[0] == 'Material':
            words[1] = the.Human + words[1]
            for word in words:
                fp.write("%s " % word)
            fp.write("\n")
            addProxyMaskMTexs(fp, mat, proxy, prxList, tex)
        elif words[0] == 'MTex':
            words[2] = the.Human + words[2]
            for word in words:
                fp.write("%s " % word)
            fp.write("\n")                
        elif words[0] == 'Filename':
            file = export_config.getOutFileName(words[1], folder, True, None, config)
            fp.write("  Filename %s ;\n" % file)
        else:
            fp.write(line)
    tmpl.close()
    return
Ejemplo n.º 15
0
def writeMultiMaterials(uvset, human, config, fp):
    folder = os.path.dirname(human.uvset.filename)
    log.debug("Folder %s", folder)
    for mat in uvset.materials:
        for tex in mat.textures:
            name = os.path.basename(tex.file)
            fp.write("Image %s\n" % name)
            #file = export_config.getOutFileName(tex, "data/textures", True, human, config)
            file = export_config.getOutFileName(name, folder, True, human, config)
            fp.write(
                "  Filename %s ;\n" % file +
                "  alpha_mode 'PREMUL' ;\n" +
                "end Image\n\n" +
                "Texture %s IMAGE\n" % name +
                "  Image %s ;\n" % name +
                "end Texture\n\n")
            
        fp.write("Material %s_%s\n" % (the.Human, mat.name))
        alpha = False
        for (key, value) in mat.settings:
            if key == "alpha":
                alpha = True
                fp.write(
                "  use_transparency True ;\n" +
                "  use_raytrace False ;\n" +
                "  use_shadows False ;\n" +
                "  use_transparent_shadows False ;\n" +
                "  alpha %s ;\n" % value)
            elif key in ["diffuse_color", "specular_color"]:
                fp.write("  %s Array %s %s %s ;\n" % (key, value[0], value[1], value[2]))
            elif key in ["diffuse_intensity", "specular_intensity"]:
                fp.write("  %s %s ;\n" % (key, value))
        if not alpha:
            fp.write("  use_transparent_shadows True ;\n")
                
        n = 0
        for tex in mat.textures:
            name = os.path.basename(tex.file)
            if len(tex.types) > 0:
                (key, value) = tex.types[0]
            else:
                (key, value) = ("diffuse", "1")
            (type, use, factor, flags) = TexInfo[key]
            diffuse = False
            fp.write(
                "  MTex %d %s UV %s\n" % (n, name, type) +
                "    texture Refer Texture %s ;\n" % name)            
            for (key, value) in tex.types:
                (type, use, factor, flags) = TexInfo[key]
                if flags & TX_SCALE:
                    scale = "*theScale"
                else:
                    scale = ""
                fp.write(
                "    %s True ;\n" % use +
                "    %s %s%s ;\n" % (factor, value, scale))
                if flags & TX_BW:
                    fp.write("    use_rgb_to_intensity True ;\n")
                if key == "diffuse":
                    diffuse = True
            if not diffuse:
                fp.write("    use_map_color_diffuse False ;\n")
            fp.write("  end MTex\n")
            n += 1
        fp.write("end Material\n\n")
Ejemplo n.º 16
0
 def __init__(self, filename, folder):     
     Rna.__init__(self, filename, 'IMAGE')
     self.filepath = export_config.getOutFileName(filename, folder, True, the.Human, the.Config)        
Ejemplo n.º 17
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
Ejemplo n.º 18
0
 def __init__(self, filename, folder):
     Rna.__init__(self, filename, 'IMAGE')
     self.filepath = export_config.getOutFileName(filename, folder, True,
                                                  the.Human, the.Config)
Ejemplo n.º 19
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