Tooltip: 'Export PMD file for MikuMikuDance.'
"""
__author__= ["ousttrue"]
-__version__= "2.4"
+__version__= "2.5"
__url__=()
__bpydoc__="""
pmd Importer
2.2 20101005: update for Blender2.54.
2.3 20101228: update for Blender2.55.
2.4 20110429: update for Blender2.57b.
+2.5 20110522: implement RigidBody and Constraint.
"""
bl_addon_info = {
except ImportError:
# full python
from .pymeshio import englishmap
- from .pymeshio import mmd as pmd
- pmd.IO=pmd.PMDLoader
+ from .pymeshio import pmd
+
# for 2.5
import bpy
if len(copyMesh.vertices)>0:
# apply transform
copyObj.scale=obj.scale
- bpy.ops.object.scale_apply()
+ bpy.ops.object.transform_apply(scale=True)
copyObj.rotation_euler=obj.rotation_euler
- bpy.ops.object.rotation_apply()
+ bpy.ops.object.transform_apply(rotation=True)
copyObj.location=obj.location
- bpy.ops.object.location_apply()
+ bpy.ops.object.transform_apply(location=True)
# apply modifier
for m in [m for m in copyObj.modifiers]:
if m.type=='SOLIDFY':
def write(self, path):
io=pmd.IO()
- io.setName(toCP932(self.name))
- io.setComment(toCP932(self.comment))
+ io.name=self.name
+ io.comment=self.comment
io.version=1.0
# 頂点
textures=[os.path.basename(path)
for path in bl.material.eachEnalbeTexturePath(m)]
if len(textures)>0:
- material.setTexture(toCP932('*'.join(textures)))
+ material.texture='*'.join(textures)
else:
- material.setTexture(toCP932(""))
+ material.texture=""
# 面
for i in indices:
assert(i<vertexCount)
if not v:
v=[b.name, b.name]
assert(v)
- cp932=v[1].encode('cp932')
- assert(len(cp932)<20)
- bone.setName(cp932)
+ bone.name=v[1]
# english name
bone_english_name=toCP932(b.name)
assert(len(bone_english_name)<20)
- bone.setEnglishName(bone_english_name)
+ bone.english_name=bone_english_name
if len(v)>=3:
# has type
if not v:
v=[m.name, m.name, 0]
assert(v)
- cp932=v[1].encode('cp932')
- morph.setName(cp932)
- morph.setEnglishName(m.name.encode('cp932'))
+ morph.name=v[1]
+ morph.english_name=m.name
m.type=v[2]
morph.type=v[2]
for index, offset in m.offsets:
name=englishmap.getUnicodeBoneGroupName(g[0])
if not name:
name=g[0]
- boneDisplayName.setName(toCP932(name+'\n'))
+ boneDisplayName.name=name+'\n'
# english
englishName=g[0]
- boneDisplayName.setEnglishName(toCP932(englishName+'\n'))
+ boneDisplayName.english_name=englishName+'\n'
# ボーングループメンバー
for i, b in enumerate(self.skeleton.bones):
#assert(len(io.bones)==len(io.bone_display_list)+1)
# English
- io.setEnglishName(toCP932(self.englishName))
- io.setEnglishComment(toCP932(self.englishComment))
+ io.english_name=self.englishName
+ io.english_comment=self.englishComment
# toon
toonMeshObject=None
for i in range(10):
t=bl.material.getTexture(toonMaterial, i)
if t:
- io.getToonTexture(i).setName(toCP932(t.name))
+ io.toon_textures[i]="%s" % t.name
else:
- io.getToonTexture(i).setName(toCP932("toon%02d.bmp\n" % i))
+ io.toon_textures[i]="toon%02d.bmp" % (i+1)
else:
for i in range(10):
- io.getToonTexture(i).setName(toCP932("toon%02d.bmp\n" % i))
+ io.toon_textures[i]="toon%02d.bmp" % (i+1)
# rigid body
rigidNameMap={}
for i, obj in enumerate(self.oneSkinMesh.rigidbodies):
name=obj[RIGID_NAME] if RIGID_NAME in obj else obj.name
- print(name)
- rigidBody=io.addRigidBody()
- rigidBody.setName(name.encode('cp932'))
+ #print(name)
+ rigidBody=pmd.RigidBody(name)
rigidNameMap[name]=i
boneIndex=boneNameMap[obj[RIGID_BONE_NAME]]
if boneIndex==0:
if obj[RIGID_SHAPE_TYPE]==0:
rigidBody.shapeType=pmd.SHAPE_SPHERE
rigidBody.w=obj.scale[0]
+ rigidBody.d=0
+ rigidBody.h=0
elif obj[RIGID_SHAPE_TYPE]==1:
rigidBody.shapeType=pmd.SHAPE_BOX
rigidBody.w=obj.scale[0]
rigidBody.shapeType=pmd.SHAPE_CAPSULE
rigidBody.w=obj.scale[0]
rigidBody.h=obj.scale[2]
+ rigidBody.d=0
+ io.rigidbodies.append(rigidBody)
# constraint
for obj in self.oneSkinMesh.constraints:
- constraint=io.addConstraint()
- constraint.setName(obj[CONSTRAINT_NAME].encode('cp932'))
+ constraint=pmd.Constraint(obj[CONSTRAINT_NAME])
constraint.rigidA=rigidNameMap[obj[CONSTRAINT_A]]
constraint.rigidB=rigidNameMap[obj[CONSTRAINT_B]]
constraint.pos.x=obj.location[0]
constraint.springRot.x=obj[CONSTRAINT_SPRING_ROT][0]
constraint.springRot.y=obj[CONSTRAINT_SPRING_ROT][1]
constraint.springRot.z=obj[CONSTRAINT_SPRING_ROT][2]
+ io.constraints.append(constraint)
# 書き込み
bl.message('write: %s' % path)