From 27731d958ce5b65b60bf05cbed0e19707144b030 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 30 Jun 2010 00:45:52 +0900 Subject: [PATCH] implement pmd_export texture. --- include/pmd.h | 1 + src/pmd.cpp | 5 +++++ swig/blender/bl24.py | 15 ++------------- swig/blender/bl25.py | 18 ++---------------- swig/blender/mqo_export.py | 17 ++++++++--------- swig/blender/pmd_export.py | 14 ++++++++++++-- 6 files changed, 30 insertions(+), 40 deletions(-) diff --git a/include/pmd.h b/include/pmd.h index 75e4f47..f4f8ac7 100644 --- a/include/pmd.h +++ b/include/pmd.h @@ -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) diff --git a/src/pmd.cpp b/src/pmd.cpp index 23059ab..2f11d0f 100755 --- a/src/pmd.cpp +++ b/src/pmd.cpp @@ -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 diff --git a/swig/blender/bl24.py b/swig/blender/bl24.py index 0bdd6e7..5d4fceb 100755 --- a/swig/blender/bl24.py +++ b/swig/blender/bl24.py @@ -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: diff --git a/swig/blender/bl25.py b/swig/blender/bl25.py index 3cfd60c..c297838 100755 --- a/swig/blender/bl25.py +++ b/swig/blender/bl25.py @@ -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): - # $BAjBP%Q%9$KJQ49$9$k(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 diff --git a/swig/blender/mqo_export.py b/swig/blender/mqo_export.py index f135187..1c5b1f2 100644 --- a/swig/blender/mqo_export.py +++ b/swig/blender/mqo_export.py @@ -161,15 +161,14 @@ class MqoExporter(object): # each material io.write("Material %d {\r\n" % (len(self.materials))) for m in self.materials: - tex, aplane=bl.material.getTexturePath(m, dirname) - if len(tex): - # textureがある場合は下地を白に - io.write("\"%s\" shader(3) col(1 1 1 1)" % m.name) - else: - # 無い場合はそのまま - io.write(materialToMqo(m)) - io.write(tex) - io.write(aplane) + io.write(materialToMqo(m)) + # ToDo separated alpha texture + for filename in bl.material.eachTexturePath(m): + if len(dirname)>0 and filename.startswith(dirname): + # 相対パスに変換する + filename=filename[len(dirname)+1:] + io.write(" tex(\"%s\")" % filename) + break io.write("\r\n") # end of chunk io.write("}\r\n") diff --git a/swig/blender/pmd_export.py b/swig/blender/pmd_export.py index d473d7a..8e9b4bd 100644 --- a/swig/blender/pmd_export.py +++ b/swig/blender/pmd_export.py @@ -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