struct ToonTexture
{
char name[100];
+ std::wstring getName()const;
+ void setName(const char *src);
};
////////////////////////////////////////////////////////////
std::string(name, name+20)));
}
+std::wstring
+ ToonTexture::getName()const
+ {
+ return text::trim(text::to_WideChar(CP_OEMCP,
+ std::string(name, name+100)));
+ }
+
// 38bytes
template<class READER>
void
bool parseToonTextures()
{
for(size_t i=0; i<10; ++i){
- reader_.getString(100);
+ text::copyStringAndFillZero(
+ io_.toon_textures[i].name,
+ reader_.getString(100));
}
return true;
}
strncpy(texture, src, 20);
}
+void ToonTexture::setName(const char *src)
+{
+ strncpy(name, src, 100);
+}
+
} // namespace
} // namespace
return Blender.Material.Get(material_name)
@staticmethod
- def addTexture(material, texture):
- material.mode = material.mode | Blender.Material.Modes.TEXFACE
- material.setTexture(0, texture, Blender.Texture.TexCo.UV)
-
- @staticmethod
- def hasTexture(material):
- return len(material.getTextures())>0
+ def addTexture(m, texture, enable=True):
+ for i in xrange(10):
+ if m.textures[i]:
+ continue
+ if enable:
+ m.mode = m.mode | Blender.Material.Modes.TEXFACE
+ m.setTexture(i, texture, Blender.Texture.TexCo.UV)
+ else:
+ m.setTexture(i, texture)
+ material.setUseTexture(m, i, False)
+ return i
+
+ @staticmethod
+ def getTexture(m, index):
+ return m.textures[index]
+
+ @staticmethod
+ def hasTexture(m):
+ return len(m.getTextures())>0
+
+ @staticmethod
+ def setUseTexture(m, index, enable):
+ enable_textures=set(m.enabledTextures)
+ if enable:
+ enabledTextures.add(index)
+ else;
+ enabledTextures.remove(index)
+ m.enabledTextures=list(enabledTextures)
@staticmethod
def eachTexturePath(m, dirname):
return bpy.data.materials[material_name]
@staticmethod
- def addTexture(material, texture):
- material.add_texture(texture, "UV", "COLOR")
- slot=material.texture_slots[material.active_texture_index]
- slot.blend_type='MULTIPLY'
- slot.map_alpha=True
+ def addTexture(material, texture, enable=True):
+ # search free slot
+ index=None
+ for i, slot in enumerate(material.texture_slots):
+ if not slot:
+ index=i
+ break
+ if index==None:
+ return
+
+ if enable:
+ material.add_texture(texture, "UV", "COLOR")
+ slot=material.texture_slots[index]
+ slot.blend_type='MULTIPLY'
+ slot.map_alpha=True
+ else:
+ material.add_texture(texture)
+ material.use_textures[index]=False
+ return index
+
+ @staticmethod
+ def getTexture(material, index):
+ return material.texture_slots[index]
@staticmethod
def hasTexture(material):
return material.texture_slots[0]
@staticmethod
+ def setUseTexture(material, index, enable):
+ material.use_textures[index]=enable
+
+ @staticmethod
def eachTexturePath(m):
for slot in m.texture_slots:
if slot and slot.texture:
Tooltip: 'Import PMD file for MikuMikuDance.'
"""
__author__= ["ousttrue"]
-__version__= "1.2"
+__version__= "1.8"
__url__=()
__bpydoc__="""
pmd Importer
1.5 20100626: refactoring.
1.6 20100629: sphere map.
1.7 20100703: implement bone group.
+1.8 20100710: implement toon texture.
"""
MMD_SHAPE_GROUP_NAME='_MMD_SHAPE'
def VtoV(v):
return bl.createVector(v.x, v.y, v.z)
+
def convert_coord(pos):
"""
Left handed y-up to Right handed z-up
print('invalid bone index', index)
return l.bones[0].getName()
+
+def __importToonTextures(io, tex_dir):
+ mesh, meshObject=bl.mesh.create('ToonTextures')
+ material=bl.material.create('ToonTextures')
+ bl.mesh.addMaterial(mesh, material)
+ for i in range(10):
+ t=io.getToonTexture(i)
+ path=os.path.join(tex_dir, t.getName())
+ texture, image=bl.texture.create(path)
+ bl.material.addTexture(material, texture, False)
+ return meshObject, material
+
+
def __importShape(obj, l, vertex_map):
if len(l.morph_list)==0:
return
def __import16MaerialAndMesh(meshObject, l,
- material_order, face_map, tex_dir):
+ material_order, face_map, tex_dir, toon_material):
mesh=bl.object.getData(meshObject)
############################################################
break
material=createPmdMaterial(m, material_index)
+ toon_index=bl.material.addTexture(
+ material,
+ bl.material.getTexture(toon_material, m.toon_index).texture,
+ False)
texture_name=m.getTexture()
if texture_name!='':
return vertex_map
-def __importMaterialAndMesh(io, tex_dir):
+def __importMaterialAndMesh(io, tex_dir, toon_material):
"""
@param l[in] mmd.PMDLoader
@param filename[in]
# shapeキーで使われる順に並べなおしたマテリアル16個分の
# メッシュを作成する
vertex_map=__import16MaerialAndMesh(
- meshObject, io, material16, face_map, tex_dir)
+ meshObject, io, material16, face_map, tex_dir, toon_material)
# crete shape key
__importShape(meshObject, io, vertex_map)
root=bl.object.createEmpty(model_name)
# toon textures
- #__importToonTextures(io)
+ tex_dir=os.path.dirname(filename)
+ toonTextures, toonMaterial=__importToonTextures(io, tex_dir)
+ bl.object.makeParent(root, toonTextures)
# import mesh
- mesh_objects=__importMaterialAndMesh(io, os.path.dirname(filename))
+ mesh_objects=__importMaterialAndMesh(io, tex_dir, toonMaterial)
for o in mesh_objects:
bl.object.makeParent(root, o)
// addMaterial
// addBone
// addMorph
+// addIK
+// addBoneDisplay
+// addBoneGroup
+// getToonTexture
+// addRigidBody
+// addConstraint
///////////////////////////////////////////////////////////////////////////////
%extend meshio::pmd::IO {