OSDN Git Service

implement pmd_export texture.
authorousttrue <ousttrue@gmail.com>
Tue, 29 Jun 2010 15:45:52 +0000 (00:45 +0900)
committerousttrue <ousttrue@gmail.com>
Tue, 29 Jun 2010 15:45:52 +0000 (00:45 +0900)
include/pmd.h
src/pmd.cpp
swig/blender/bl24.py
swig/blender/bl25.py
swig/blender/mqo_export.py
swig/blender/pmd_export.py

index 75e4f47..f4f8ac7 100644 (file)
@@ -105,6 +105,7 @@ struct Material
        char texture[20];
 
        std::wstring getTexture()const;
+       void setTexture(const char *src);
 };
 inline std::ostream &operator<<(std::ostream &os,
                const Material &rhs)
index 23059ab..2f11d0f 100755 (executable)
@@ -816,6 +816,11 @@ void Constraint::setName(const char *src)
        strncpy(name, src, 20);
 }
 
+void Material::setTexture(const char *src)
+{
+       strncpy(texture, src, 20);
+}
+
 
 } // namespace
 } // namespace
index 0bdd6e7..5d4fceb 100755 (executable)
@@ -313,24 +313,13 @@ class material:
         return len(material.getTextures())>0
 
     @staticmethod
-    def getTexturePath(m, dirname):
-        tex=""
-        aplane=""
-        # texture
+    def eachTexturePath(m, dirname):
         for texture in m.getTextures():
             if texture and texture.tex and texture.tex.getImage():
                 image=texture.tex.getImage()
                 if not image:
                     continue
-                imagePath=Blender.sys.expandpath(image.getFilename())
-                if len(dirname)>0 and imagePath.startswith(dirname):
-                    # 相対パスに変換する
-                    imagePath=imagePath[len(dirname)+1:len(imagePath)]
-                if texture.mtCol>0:
-                    tex=" tex(\"%s\")" % imagePath
-                elif texture.mtAlpha>0:
-                    aplane=" aplane(\"%s\")" % imagePath
-        return tex, aplane
+                yield image.getFilename()
 
 
 class mesh:
index 3cfd60c..c297838 100755 (executable)
@@ -301,10 +301,7 @@ class material:
         return material.texture_slots[0]
 
     @staticmethod
-    def getTexturePath(m, dirname):
-        tex=""
-        aplane=""
-        # texture
+    def eachTexturePath(m):
         for slot in m.texture_slots:
             if slot and slot.texture:
                 texture=slot.texture
@@ -312,18 +309,7 @@ class material:
                     image=texture.image
                     if not image:
                         continue
-                    imagePath=image.filename
-                    if len(dirname)>0 and imagePath.startswith(dirname):
-                        # \e$BAjBP%Q%9$KJQ49$9$k\e(B
-                        imagePath=imagePath[len(dirname)+1:len(imagePath)]
-                    #imagePath=Blender.sys.expandpath(
-                    #        imagePath).replace("\\", '/')
-                    if slot.map_colordiff:
-                        tex=" tex(\"%s\")" % imagePath
-                    elif slot.map_alpha:
-                        aplane=" aplane(\"%s\")" % imagePath
-        return tex, aplane
-
+                    yield image.filename
 
 class mesh:
     @staticmethod
index f135187..1c5b1f2 100644 (file)
@@ -161,15 +161,14 @@ class MqoExporter(object):
         # each material    \r
         io.write("Material %d {\r\n" % (len(self.materials)))\r
         for m in self.materials:\r
-            tex, aplane=bl.material.getTexturePath(m, dirname)\r
-            if len(tex):\r
-                # textureがある場合は下地を白に\r
-                io.write("\"%s\" shader(3) col(1 1 1 1)" % m.name)\r
-            else:\r
-                # 無い場合はそのまま\r
-                io.write(materialToMqo(m))\r
-            io.write(tex)\r
-            io.write(aplane)\r
+            io.write(materialToMqo(m))\r
+            # ToDo separated alpha texture\r
+            for filename in bl.material.eachTexturePath(m):\r
+                if len(dirname)>0 and filename.startswith(dirname):\r
+                    # 相対パスに変換する\r
+                    filename=filename[len(dirname)+1:]\r
+                io.write(" tex(\"%s\")" % filename)\r
+                break\r
             io.write("\r\n") \r
         # end of chunk\r
         io.write("}\r\n") \r
index d473d7a..8e9b4bd 100644 (file)
@@ -87,6 +87,10 @@ if isBlender24():
         # flag
         material.flag=1 if m.enableSSS else 0
 
+    def toCP932(s):
+        return s
+
+
 else:
     # for 2.5
     import bpy
@@ -116,6 +120,10 @@ else:
         # flag
         material.flag=1 if m.subsurface_scattering.enabled else 0
 
+    def toCP932(s):
+        return s.encode('cp932')
+
+
 class Node(object):
     __slots__=['o', 'children']
     def __init__(self, o):
@@ -847,8 +855,10 @@ class PmdExporter(object):
 
             material.vertex_count=len(indices)
             material.toon_index=0
-            # ToDo
-            material.texture=""
+            textures=[os.path.basename(path) 
+                for path in bl.material.eachTexturePath(m)]
+            if len(textures)>0:
+                material.setTexture(toCP932('*'.join(textures)))
             # 面
             for i in indices:
                 assert(i<vertexCount)