4 Name: 'MikuMikuDance model (.pmd)...'
7 Tooltip: 'Export PMD file for MikuMikuDance.'
9 __author__= ["ousttrue"]
15 This script exports a pmd model.
17 0.1 20100318: first implementation.
18 0.2 20100519: refactoring. use C extension.
19 1.0 20100530: implement basic features.
20 1.1 20100612: integrate 2.4 and 2.5.
21 1.2 20100616: implement rigid body.
22 1.3 20100619: fix rigid body, bone weight.
23 1.4 20100626: refactoring.
24 1.5 20100629: sphere map.
25 1.6 20100710: toon texture & bone group.
26 1.7 20100711: separate vertex with normal or uv.
27 2.0 20100724: update for Blender2.53.
28 2.1 20100731: add full python module.
29 2.2 20101005: update for Blender2.54.
30 2.3 20101228: update for Blender2.55.
31 2.4 20110429: update for Blender2.57b.
32 2.5 20110522: implement RigidBody and Constraint.
36 'category': 'Import/Export',
37 'name': 'Export: MikuMikuDance Model Format (.pmd)',
41 'location': 'File > Export',
42 'description': 'Export to the MikuMikuDance Model Format (.pmd)',
43 'warning': '', # used for warning icon and text in addons panel
44 'wiki_url': 'http://sourceforge.jp/projects/meshio/wiki/FrontPage',
45 'tracker_url': 'http://sourceforge.jp/ticket/newticket.php?group_id=5081',
49 ###############################################################################
51 ###############################################################################
57 from .meshio import pmd, englishmap
58 print('use meshio C module')
61 from .pymeshio import englishmap
62 from .pymeshio import pmd
70 from . import bl25 as bl
74 def setMaterialParams(material, m):
76 material.diffuse.r=m.diffuse_color[0]
77 material.diffuse.g=m.diffuse_color[1]
78 material.diffuse.b=m.diffuse_color[2]
79 material.diffuse.a=m.alpha
81 material.shinness=0 if m.specular_toon_size<1e-5 else m.specular_hardness*10
82 material.specular.r=m.specular_color[0]
83 material.specular.g=m.specular_color[1]
84 material.specular.b=m.specular_color[2]
86 material.ambient.r=m.mirror_color[0]
87 material.ambient.g=m.mirror_color[1]
88 material.ambient.b=m.mirror_color[2]
90 material.flag=1 if m.subsurface_scattering.use else 0
95 return s.encode('cp932')
99 __slots__=['o', 'children']
100 def __init__(self, o):
105 ###############################################################################
106 # Blenderのメッシュをワンスキンメッシュ化する
107 ###############################################################################
108 def near(x, y, EPSILON=1e-5):
110 return d>=-EPSILON and d<=EPSILON
113 class VertexAttribute(object):
115 'nx', 'ny', 'nz', # normal
118 def __init__(self, nx, ny, nz, u, v):
126 return "<vkey: %f, %f, %f, %f, %f>" % (
127 self.nx, self.ny, self.nz, self.u, self.v)
130 return int(100*(self.nx + self.ny + self.nz + self.u + self.v))
132 def __eq__(self, rhs):
133 return self.nx==rhs.nx and self.ny==rhs.ny and self.nz==rhs.nz and self.u==rhs.u and self.v==rhs.v
136 class VertexKey(object):
138 'obj_index', 'index',
141 def __init__(self, obj_index, index):
142 self.obj_index=obj_index
146 return "<vkey: %d, %d>" % (self.obj_index, self.index)
149 return self.index*100+self.obj_index
151 def __eq__(self, rhs):
152 return self.obj_index==rhs.obj_index and self.index==rhs.index
155 class VertexArray(object):
162 'attributes', # normal and uv
163 'b0', 'b1', 'weight',
168 # indexArrays split with each material
181 return "<VertexArray %d positions, %d indexArrays>" % (
182 len(self.positions), len(self.indexArrays))
186 self.positions, self.attributes,
187 self.b0, self.b1, self.weight)
190 keys=[key for key in self.indexArrays.keys()]
193 yield(key, self.indexArrays[key])
195 def __addOrGetIndex(self, obj_index, base_index, pos, normal, uv, b0, b1, weight0):
196 key=VertexKey(obj_index, base_index)
197 attribute=VertexAttribute(
198 normal[0], normal[1], normal[2],
200 if key in self.vertexMap:
201 if attribute in self.vertexMap[key]:
202 return self.vertexMap[key][attribute]
204 return self.__addVertex(self.vertexMap[key],
205 pos, attribute, b0, b1, weight0)
208 self.vertexMap[key]=vertexMapKey
209 return self.__addVertex(vertexMapKey,
210 pos, attribute, b0, b1, weight0)
212 def __addVertex(self, vertexMapKey, pos, attribute, b0, b1, weight0):
213 index=len(self.positions)
214 vertexMapKey[attribute]=index
216 self.positions.append((pos.x, pos.y, pos.z))
218 self.attributes.append(attribute)
222 self.weight.append(weight0)
226 def getMappedIndex(self, obj_name, base_index):
227 return self.vertexMap[VertexKey(self.objectMap[obj_name], base_index)]
229 def addTriangle(self,
230 object_name, material,
231 base_index0, base_index1, base_index2,
237 weight0, weight1, weight2
239 if object_name in self.objectMap:
240 obj_index=self.objectMap[object_name]
242 obj_index=len(self.objectMap)
243 self.objectMap[object_name]=obj_index
244 index0=self.__addOrGetIndex(obj_index, base_index0, pos0, n0, uv0, b0_0, b1_0, weight0)
245 index1=self.__addOrGetIndex(obj_index, base_index1, pos1, n1, uv1, b0_1, b1_1, weight1)
246 index2=self.__addOrGetIndex(obj_index, base_index2, pos2, n2, uv2, b0_2, b1_2, weight2)
248 if not material in self.indexArrays:
249 self.indexArrays[material]=[]
250 self.indexArrays[material]+=[index0, index1, index2]
254 __slots__=['name', 'type', 'offsets']
255 def __init__(self, name, type):
260 def add(self, index, offset):
261 self.offsets.append((index, offset))
264 self.offsets.sort(key=lambda e: e[0])
267 return "<Morph %s>" % self.name
269 class IKSolver(object):
270 __slots__=['target', 'effector', 'length', 'iterations', 'weight']
271 def __init__(self, target, effector, length, iterations, weight):
273 self.effector=effector
275 self.iterations=iterations
284 class DefaultMatrial(object):
288 self.diffuse_color=[1, 1, 1]
291 self.specular_toon_size=0
292 self.specular_hardness=5
293 self.specular_color=[1, 1, 1]
295 self.mirror_color=[1, 1, 1]
297 self.subsurface_scattering=SSS()
299 self.texture_slots=[]
302 class OneSkinMesh(object):
303 __slots__=['vertexArray', 'morphList', 'rigidbodies', 'constraints', ]
305 self.vertexArray=VertexArray()
311 return "<OneSkinMesh %s, morph:%d>" % (
315 def addMesh(self, obj):
316 if not bl.object.isVisible(obj):
320 self.__rigidbody(obj)
321 self.__constraint(obj)
323 def __getWeightMap(self, obj, mesh):
327 def setWeight(i, name, w):
330 if i in secondWeightMap:
332 if w<secondWeightMap[i][1]:
334 elif w<weightMap[i][1]:
336 secondWeightMap[i]=(name, w)
339 weightMap[i]=(name, w)
341 if w>weightMap[i][1]:
343 secondWeightMap[i]=weightMap[i]
344 weightMap[i]=(name, w)
346 secondWeightMap[i]=(name, w)
348 weightMap[i]=(name, w)
350 # ToDo bone weightと関係ないvertex groupを除外する
351 for i, v in enumerate(mesh.vertices):
354 setWeight(i, obj.vertex_groups[g.group].name, g.weight)
357 setWeight(i, obj.vertex_groups[0].name, 1)
363 for i in xrange(len(mesh.vertices)):
364 if i in secondWeightMap:
365 secondWeightMap[i]=(secondWeightMap[i][0], 1.0-weightMap[i][1])
367 weightMap[i]=(weightMap[i][0], 1.0)
368 secondWeightMap[i]=("", 0)
370 print("no weight vertex")
372 secondWeightMap[i]=("", 0)
374 return weightMap, secondWeightMap
376 def __processFaces(self, obj_name, mesh, weightMap, secondWeightMap):
377 default_material=DefaultMatrial()
379 for i, face in enumerate(mesh.faces):
380 faceVertexCount=bl.face.getVertexCount(face)
382 material=mesh.materials[bl.face.getMaterialIndex(face)]
383 except IndexError as e:
384 material=default_material
385 v=[mesh.vertices[index] for index in bl.face.getVertices(face)]
386 uv=bl.mesh.getFaceUV(
387 mesh, i, face, bl.face.getVertexCount(face))
389 if faceVertexCount==3:
391 self.vertexArray.addTriangle(
392 obj_name, material.name,
399 bl.vertex.getNormal(v[2]),
400 bl.vertex.getNormal(v[1]),
401 bl.vertex.getNormal(v[0]),
405 weightMap[v[2].index][0],
406 weightMap[v[1].index][0],
407 weightMap[v[0].index][0],
408 secondWeightMap[v[2].index][0],
409 secondWeightMap[v[1].index][0],
410 secondWeightMap[v[0].index][0],
411 weightMap[v[2].index][1],
412 weightMap[v[1].index][1],
413 weightMap[v[0].index][1]
415 elif faceVertexCount==4:
417 self.vertexArray.addTriangle(
418 obj_name, material.name,
425 bl.vertex.getNormal(v[2]),
426 bl.vertex.getNormal(v[1]),
427 bl.vertex.getNormal(v[0]),
431 weightMap[v[2].index][0],
432 weightMap[v[1].index][0],
433 weightMap[v[0].index][0],
434 secondWeightMap[v[2].index][0],
435 secondWeightMap[v[1].index][0],
436 secondWeightMap[v[0].index][0],
437 weightMap[v[2].index][1],
438 weightMap[v[1].index][1],
439 weightMap[v[0].index][1]
441 self.vertexArray.addTriangle(
442 obj_name, material.name,
449 bl.vertex.getNormal(v[0]),
450 bl.vertex.getNormal(v[3]),
451 bl.vertex.getNormal(v[2]),
455 weightMap[v[0].index][0],
456 weightMap[v[3].index][0],
457 weightMap[v[2].index][0],
458 secondWeightMap[v[0].index][0],
459 secondWeightMap[v[3].index][0],
460 secondWeightMap[v[2].index][0],
461 weightMap[v[0].index][1],
462 weightMap[v[3].index][1],
463 weightMap[v[2].index][1]
466 def __mesh(self, obj):
467 if bl.RIGID_SHAPE_TYPE in obj:
469 if bl.CONSTRAINT_A in obj:
472 bl.message("export: %s" % obj.name)
474 # メッシュのコピーを生成してオブジェクトの行列を適用する
475 copyMesh, copyObj=bl.object.duplicate(obj)
476 if len(copyMesh.vertices)>0:
481 copyObj.scale=obj.scale
482 bpy.ops.object.transform_apply(scale=True)
483 copyObj.rotation_euler=obj.rotation_euler
484 bpy.ops.object.transform_apply(rotation=True)
485 copyObj.location=obj.location
486 bpy.ops.object.transform_apply(location=True)
487 except AttributeError as e:
489 copyObj.scale=obj.scale
490 bpy.ops.object.scale_apply()
491 copyObj.rotation_euler=obj.rotation_euler
492 bpy.ops.object.rotation_apply()
493 copyObj.location=obj.location
494 bpy.ops.object.location_apply()
496 copyMesh.transform(obj.matrix_world)
499 for m in [m for m in copyObj.modifiers]:
500 if m.type=='SOLIDFY':
502 elif m.type=='ARMATURE':
504 elif m.type=='MIRROR':
505 bpy.ops.object.modifier_apply(modifier=m.name)
509 weightMap, secondWeightMap=self.__getWeightMap(copyObj, copyMesh)
510 self.__processFaces(obj.name, copyMesh, weightMap, secondWeightMap)
511 bl.object.delete(copyObj)
513 def createEmptyBasicSkin(self):
514 self.__getOrCreateMorph('base', 0)
516 def __skin(self, obj):
517 if not bl.object.hasShapeKey(obj):
521 blenderMesh=bl.object.getData(obj)
525 vg=bl.object.getVertexGroup(obj, bl.MMD_SHAPE_GROUP_NAME)
529 for b in bl.object.getShapeKeys(obj):
530 if b.name==bl.BASE_SHAPE_NAME:
531 baseMorph=self.__getOrCreateMorph('base', 0)
536 v=bl.shapekey.getByIndex(b, index)
537 pos=[v[0], v[1], v[2]]
539 indices=self.vertexArray.getMappedIndex(obj.name, index)
540 for attribute, i in indices.items():
545 baseMorph.add(i, pos)
546 indexRelativeMap[i]=relativeIndex
551 #print(basis.name, len(baseMorph.offsets))
553 if len(baseMorph.offsets)==0:
557 for b in bl.object.getShapeKeys(obj):
558 if b.name==bl.BASE_SHAPE_NAME:
562 morph=self.__getOrCreateMorph(b.name, 4)
564 for index, src, dst in zip(
565 xrange(len(blenderMesh.vertices)),
566 bl.shapekey.get(basis),
568 offset=[dst[0]-src[0], dst[1]-src[1], dst[2]-src[2]]
569 if offset[0]==0 and offset[1]==0 and offset[2]==0:
572 indices=self.vertexArray.getMappedIndex(obj.name, index)
573 for attribute, i in indices.items():
577 morph.add(indexRelativeMap[i], offset)
578 assert(len(morph.offsets)<len(baseMorph.offsets))
581 original=self.morphList[:]
583 for i, v in enumerate(englishmap.skinMap):
587 return len(englishmap.skinMap)
588 self.morphList.sort(key=getIndex)
590 def __rigidbody(self, obj):
591 if not bl.RIGID_SHAPE_TYPE in obj:
593 self.rigidbodies.append(obj)
595 def __constraint(self, obj):
596 if not bl.CONSTRAINT_A in obj:
598 self.constraints.append(obj)
600 def __getOrCreateMorph(self, name, type):
601 for m in self.morphList:
605 self.morphList.append(m)
608 def getVertexCount(self):
609 return len(self.vertexArray.positions)
613 __slots__=['index', 'name', 'ik_index',
614 'pos', 'tail', 'parent_index', 'tail_index', 'type', 'isConnect']
615 def __init__(self, name, pos, tail, isConnect):
620 self.parent_index=None
623 self.isConnect=isConnect
626 def __eq__(self, rhs):
627 return self.index==rhs.index
630 return "<Bone %s %d>" % (self.name, self.type)
632 class BoneBuilder(object):
633 __slots__=['bones', 'boneMap', 'ik_list', 'bone_groups',]
640 def getBoneGroup(self, bone):
641 for i, g in enumerate(self.bone_groups):
645 print('no gorup', bone)
648 def build(self, armatureObj):
652 bl.message("build skeleton")
653 armature=bl.object.getData(armatureObj)
658 for g in bl.object.boneGroups(armatureObj):
659 self.bone_groups.append((g.name, []))
664 for b in armature.bones.values():
668 bl.bone.getHeadLocal(b),
669 bl.bone.getTailLocal(b),
672 self.__getBone(bone, b)
674 for b in armature.bones.values():
676 self.__checkConnection(b, None)
681 pose = bl.object.getPose(armatureObj)
682 for b in pose.bones.values():
686 self.__assignBoneGroup(b, b.bone_group)
687 for c in b.constraints:
688 if bl.constraint.isIKSolver(c):
692 target=self.__boneByName(bl.constraint.ikTarget(c))
699 link=self.__boneByName(b.name)
704 chainLength=bl.constraint.ikChainLen(c)
705 for i in range(chainLength):
707 chainBone=self.__boneByName(e.name)
709 chainBone.ik_index=target.index
712 IKSolver(target, link, chainLength,
713 int(bl.constraint.ikItration(c) * 0.1),
714 bl.constraint.ikRotationWeight(c)
724 for i, v in enumerate(englishmap.boneMap):
725 if v[0]==ik.target.name:
727 return len(englishmap.boneMap)
728 self.ik_list.sort(key=getIndex)
730 def __assignBoneGroup(self, poseBone, boneGroup):
732 for g in self.bone_groups:
733 if g[0]==boneGroup.name:
734 g[1].append(poseBone.name)
736 def __checkConnection(self, b, p):
737 if bl.bone.isConnected(b):
738 parent=self.__boneByName(p.name)
739 parent.isConnect=True
742 self.__checkConnection(c, b)
748 boneMap=englishmap.boneMap
749 original=self.bones[:]
751 for i, k_v in enumerate(boneMap):
752 if k_v[0]==bone.name:
757 self.bones.sort(key=getIndex)
760 for i, b in enumerate(self.bones):
761 src=original.index(b)
764 b.index=sortMap[b.index]
766 b.parent_index=sortMap[b.parent_index]
768 b.tail_index=sortMap[b.tail_index]
770 b.ik_index=sortMap[b.ik_index]
778 if b.parent_index==None:
779 b.parent_index=0xFFFF
781 if b.type==6 or b.type==7:
783 parent=self.bones[b.parent_index]
784 #print('parnet', parent.name)
785 parent.tail_index=b.index
788 if b.tail_index==None:
793 def getIndex(self, bone):
794 for i, b in enumerate(self.bones):
799 def indexByName(self, name):
804 return self.getIndex(self.__boneByName(name))
808 def __boneByName(self, name):
809 return self.boneMap[name]
811 def __getBone(self, parent, b):
812 if len(b.children)==0:
816 for i, c in enumerate(b.children):
818 bl.bone.getHeadLocal(c),
819 bl.bone.getTailLocal(c),
820 bl.bone.isConnected(c))
823 bone.parent_index=parent.index
825 if bone.isConnect or (not parent.tail_index and parent.tail==bone.pos):
826 parent.tail_index=bone.index
827 self.__getBone(bone, c)
829 def __addBone(self, bone):
830 bone.index=len(self.bones)
831 self.bones.append(bone)
832 self.boneMap[bone.name]=bone
835 class PmdExporter(object):
847 self.armatureObj=None
851 for o in bl.object.each():
852 object_node_map[o]=Node(o)
853 for o in bl.object.each():
854 node=object_node_map[o]
856 object_node_map[node.o.parent].children.append(node)
859 root=object_node_map[bl.object.getActive()]
861 self.englishName=o.name
862 self.englishComment=o[bl.MMD_COMMENT] if bl.MMD_COMMENT in o else 'blender export\n'
863 self.name=o[bl.MMD_MB_NAME] if bl.MMD_MB_NAME in o else 'Blenderエクスポート'
864 self.comment=o[bl.MMD_MB_COMMENT] if bl.MMD_MB_COMMENT in o else 'Blnderエクスポート\n'
867 self.oneSkinMesh=OneSkinMesh()
868 self.__createOneSkinMesh(root)
869 bl.message(self.oneSkinMesh)
870 if len(self.oneSkinMesh.morphList)==0:
872 self.oneSkinMesh.createEmptyBasicSkin()
875 self.skeleton=BoneBuilder()
876 self.skeleton.build(self.armatureObj)
878 def __createOneSkinMesh(self, node):
879 ############################################################
880 # search armature modifier
881 ############################################################
882 for m in node.o.modifiers:
883 if bl.modifier.isType(m, 'ARMATURE'):
884 armatureObj=bl.modifier.getArmatureObject(m)
885 if not self.armatureObj:
886 self.armatureObj=armatureObj
887 elif self.armatureObj!=armatureObj:
888 print("warning! found multiple armature. ignored.",
891 if node.o.type.upper()=='MESH':
892 self.oneSkinMesh.addMesh(node.o)
894 for child in node.children:
895 self.__createOneSkinMesh(child)
897 def write(self, path):
900 io.comment=self.comment
904 for pos, attribute, b0, b1, weight in self.oneSkinMesh.vertexArray.zip():
905 # convert right-handed z-up to left-handed y-up
910 # convert right-handed z-up to left-handed y-up
911 v.normal.x=attribute.nx
912 v.normal.y=attribute.nz
913 v.normal.z=attribute.ny
915 v.uv.y=1.0-attribute.v # reverse vertical
916 v.bone0=self.skeleton.indexByName(b0)
917 v.bone1=self.skeleton.indexByName(b1)
918 v.weight0=int(100*weight)
919 v.edge_flag=0 # edge flag, 0: enable edge, 1: not edge
922 vertexCount=self.oneSkinMesh.getVertexCount()
923 for material_name, indices in self.oneSkinMesh.vertexArray.each():
924 #print('material:', material_name)
926 m=bl.material.get(material_name)
927 except KeyError as e:
930 material=io.addMaterial()
931 setMaterialParams(material, m)
933 material.vertex_count=len(indices)
934 def get_texture_name(texture):
935 pos=texture.replace("\\", "/").rfind("/")
939 return texture[pos+1:]
940 textures=[get_texture_name(path)
941 for path in bl.material.eachEnalbeTexturePath(m)]
944 material.texture='*'.join(textures)
949 assert(i<vertexCount)
950 for i in xrange(0, len(indices), 3):
952 io.indices.append(indices[i])
953 io.indices.append(indices[i+1])
954 io.indices.append(indices[i+2])
958 for i, b in enumerate(self.skeleton.bones):
962 boneNameMap[b.name]=i
963 v=englishmap.getUnicodeBoneName(b.name)
970 bone_english_name=toCP932(b.name)
971 if len(bone_english_name)>=20:
972 print(bone_english_name)
973 #assert(len(bone_english_name)<20)
974 bone.english_name=bone_english_name
979 b.ik_index=self.skeleton.indexByName('eyes')
984 bone.parent_index=b.parent_index
985 bone.tail_index=b.tail_index
986 bone.ik_index=b.ik_index
988 # convert right-handed z-up to left-handed y-up
989 bone.pos.x=b.pos[0] if not near(b.pos[0], 0) else 0
990 bone.pos.y=b.pos[2] if not near(b.pos[2], 0) else 0
991 bone.pos.z=b.pos[1] if not near(b.pos[1], 0) else 0
994 for ik in self.skeleton.ik_list:
996 solver.index=self.skeleton.getIndex(ik.target)
997 solver.target=self.skeleton.getIndex(ik.effector)
998 solver.length=ik.length
999 b=self.skeleton.bones[ik.effector.parent_index]
1000 for i in xrange(solver.length):
1001 solver.children.append(self.skeleton.getIndex(b))
1002 b=self.skeleton.bones[b.parent_index]
1003 solver.iterations=ik.iterations
1004 solver.weight=ik.weight
1007 for i, m in enumerate(self.oneSkinMesh.morphList):
1011 v=englishmap.getUnicodeSkinName(m.name)
1013 v=[m.name, m.name, 0]
1016 morph.english_name=m.name
1019 for index, offset in m.offsets:
1020 # convert right-handed z-up to left-handed y-up
1021 morph.append(index, offset[0], offset[2], offset[1])
1022 morph.vertex_count=len(m.offsets)
1026 for i, m in enumerate(self.oneSkinMesh.morphList):
1028 io.face_list.append(i)
1029 for i, m in enumerate(self.oneSkinMesh.morphList):
1031 io.face_list.append(i)
1032 for i, m in enumerate(self.oneSkinMesh.morphList):
1034 io.face_list.append(i)
1035 for i, m in enumerate(self.oneSkinMesh.morphList):
1037 io.face_list.append(i)
1040 for g in self.skeleton.bone_groups:
1041 boneDisplayName=io.addBoneGroup()
1043 name=englishmap.getUnicodeBoneGroupName(g[0])
1046 boneDisplayName.name=name+'\n'
1049 boneDisplayName.english_name=englishName+'\n'
1052 for i, b in enumerate(self.skeleton.bones):
1055 if b.type in [6, 7]:
1057 io.addBoneDisplay(i, self.skeleton.getBoneGroup(b))
1059 #assert(len(io.bones)==len(io.bone_display_list)+1)
1062 io.english_name=self.englishName
1063 io.english_comment=self.englishComment
1067 for o in bl.object.each():
1069 if o.name.startswith(bl.TOON_TEXTURE_OBJECT):
1075 toonMesh=bl.object.getData(toonMeshObject)
1076 toonMaterial=bl.mesh.getMaterial(toonMesh, 0)
1078 t=bl.material.getTexture(toonMaterial, i)
1080 io.toon_textures[i]="%s" % t.name
1082 io.toon_textures[i]="toon%02d.bmp" % (i+1)
1085 io.toon_textures[i]="toon%02d.bmp" % (i+1)
1089 for i, obj in enumerate(self.oneSkinMesh.rigidbodies):
1090 name=obj[bl.RIGID_NAME] if bl.RIGID_NAME in obj else obj.name
1092 rigidBody=pmd.RigidBody(name)
1093 rigidNameMap[name]=i
1094 boneIndex=boneNameMap[obj[bl.RIGID_BONE_NAME]]
1097 bone=self.skeleton.bones[0]
1099 bone=self.skeleton.bones[boneIndex]
1100 rigidBody.boneIndex=boneIndex
1101 rigidBody.position.x=obj.location.x-bone.pos[0]
1102 rigidBody.position.y=obj.location.z-bone.pos[2]
1103 rigidBody.position.z=obj.location.y-bone.pos[1]
1104 rigidBody.rotation.x=-obj.rotation_euler[0]
1105 rigidBody.rotation.y=-obj.rotation_euler[2]
1106 rigidBody.rotation.z=-obj.rotation_euler[1]
1107 rigidBody.processType=obj[bl.RIGID_PROCESS_TYPE]
1108 rigidBody.group=obj[bl.RIGID_GROUP]
1109 rigidBody.target=obj[bl.RIGID_INTERSECTION_GROUP]
1110 rigidBody.weight=obj[bl.RIGID_WEIGHT]
1111 rigidBody.linearDamping=obj[bl.RIGID_LINEAR_DAMPING]
1112 rigidBody.angularDamping=obj[bl.RIGID_ANGULAR_DAMPING]
1113 rigidBody.restitution=obj[bl.RIGID_RESTITUTION]
1114 rigidBody.friction=obj[bl.RIGID_FRICTION]
1115 if obj[bl.RIGID_SHAPE_TYPE]==0:
1116 rigidBody.shapeType=pmd.SHAPE_SPHERE
1117 rigidBody.w=obj.scale[0]
1120 elif obj[bl.RIGID_SHAPE_TYPE]==1:
1121 rigidBody.shapeType=pmd.SHAPE_BOX
1122 rigidBody.w=obj.scale[0]
1123 rigidBody.d=obj.scale[1]
1124 rigidBody.h=obj.scale[2]
1125 elif obj[bl.RIGID_SHAPE_TYPE]==2:
1126 rigidBody.shapeType=pmd.SHAPE_CAPSULE
1127 rigidBody.w=obj.scale[0]
1128 rigidBody.h=obj.scale[2]
1130 io.rigidbodies.append(rigidBody)
1133 for obj in self.oneSkinMesh.constraints:
1135 constraint=pmd.Constraint(obj[bl.CONSTRAINT_NAME])
1136 constraint.rigidA=rigidNameMap[obj[bl.CONSTRAINT_A]]
1137 constraint.rigidB=rigidNameMap[obj[bl.CONSTRAINT_B]]
1138 constraint.pos.x=obj.location[0]
1139 constraint.pos.y=obj.location[2]
1140 constraint.pos.z=obj.location[1]
1141 constraint.rot.x=-obj.rotation_euler[0]
1142 constraint.rot.y=-obj.rotation_euler[2]
1143 constraint.rot.z=-obj.rotation_euler[1]
1144 constraint.constraintPosMin.x=obj[bl.CONSTRAINT_POS_MIN][0]
1145 constraint.constraintPosMin.y=obj[bl.CONSTRAINT_POS_MIN][1]
1146 constraint.constraintPosMin.z=obj[bl.CONSTRAINT_POS_MIN][2]
1147 constraint.constraintPosMax.x=obj[bl.CONSTRAINT_POS_MAX][0]
1148 constraint.constraintPosMax.y=obj[bl.CONSTRAINT_POS_MAX][1]
1149 constraint.constraintPosMax.z=obj[bl.CONSTRAINT_POS_MAX][2]
1150 constraint.constraintRotMin.x=obj[bl.CONSTRAINT_ROT_MIN][0]
1151 constraint.constraintRotMin.y=obj[bl.CONSTRAINT_ROT_MIN][1]
1152 constraint.constraintRotMin.z=obj[bl.CONSTRAINT_ROT_MIN][2]
1153 constraint.constraintRotMax.x=obj[bl.CONSTRAINT_ROT_MAX][0]
1154 constraint.constraintRotMax.y=obj[bl.CONSTRAINT_ROT_MAX][1]
1155 constraint.constraintRotMax.z=obj[bl.CONSTRAINT_ROT_MAX][2]
1156 constraint.springPos.x=obj[bl.CONSTRAINT_SPRING_POS][0]
1157 constraint.springPos.y=obj[bl.CONSTRAINT_SPRING_POS][1]
1158 constraint.springPos.z=obj[bl.CONSTRAINT_SPRING_POS][2]
1159 constraint.springRot.x=obj[bl.CONSTRAINT_SPRING_ROT][0]
1160 constraint.springRot.y=obj[bl.CONSTRAINT_SPRING_ROT][1]
1161 constraint.springRot.z=obj[bl.CONSTRAINT_SPRING_ROT][2]
1162 io.constraints.append(constraint)
1165 bl.message('write: %s' % path)
1166 return io.write(path)
1169 def _execute(filepath=''):
1170 active=bl.object.getActive()
1172 print("abort. no active object.")
1174 exporter=PmdExporter()
1177 exporter.write(filepath)
1178 bl.object.activate(active)