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.
24 MMD_SHAPE_GROUP_NAME='_MMD_SHAPE'
25 BASE_SHAPE_NAME='Basis'
26 RIGID_SHAPE_TYPE='rigid_shape_type'
27 RIGID_PROCESS_TYPE='rigid_process_type'
28 RIGID_BONE_NAME='rigid_bone_name'
29 #RIGID_LOCATION='rigid_loation'
30 RIGID_GROUP='ribid_group'
31 RIGID_INTERSECTION_GROUP='rigid_intersection_group'
32 RIGID_WEIGHT='rigid_weight'
33 RIGID_LINEAR_DAMPING='rigid_linear_damping'
34 RIGID_ANGULAR_DAMPING='rigid_angular_damping'
35 RIGID_RESTITUTION='rigid_restitution'
36 RIGID_FRICTION='rigid_friction'
37 CONSTRAINT_A='const_a'
38 CONSTRAINT_B='const_b'
39 CONSTRAINT_POS_MIN='const_pos_min'
40 CONSTRAINT_POS_MAX='const_pos_max'
41 CONSTRAINT_ROT_MIN='const_rot_min'
42 CONSTRAINT_ROT_MAX='const_rot_max'
43 CONSTRAINT_SPRING_POS='const_spring_pos'
44 CONSTRAINT_SPRING_ROT='const_spring_rot'
47 ###############################################################################
49 ###############################################################################
54 from meshio import pmd, englishmap
57 return sys.version_info[0]<3
62 from Blender import Mathutils
70 from bpy.props import *
80 __slots__=['o', 'children']
81 def __init__(self, o):
86 ###############################################################################
87 # Blenderのメッシュをワンスキンメッシュ化する
88 ###############################################################################
89 def near(x, y, EPSILON=1e-5):
91 return d>=-EPSILON and d<=EPSILON
94 class VertexKey(object):
101 'nx', 'ny', 'nz', # 法線
105 def __init__(self, obj, index, x, y, z, nx, ny, nz, u, v):
118 return "<vkey: %f, %f, %f, %f, %f, %f, %f, %f>" % (
119 self.x, self.y, self.z, self.nx, self.ny, self.nz, self.u, self.v)
122 #return int((self.x+self.y+self.z+self.nx+self.ny+self.nz+self.u+self.v)*100)
123 return int((self.x+self.y+self.z)*100)
125 def __eq__(self, rhs):
126 #return near(self.x, rhs.x) and near(self.y, rhs.y) and near(self.z, rhs.z) and near(self.nx, rhs.nx) and near(self.ny, rhs.ny) and near(self.nz, rhs.nz) and near(self.u, rhs.u) and near(self.v, rhs.v)
127 #return near(self.x, rhs.x) and near(self.y, rhs.y) and near(self.z, rhs.z)
128 #return self.x==rhs.x and self.y==rhs.y and self.z==rhs.z
129 return self.obj==rhs.obj and self.index==rhs.index
132 class VertexArray(object):
137 # マテリアル毎に分割したインデックス配列
152 return "<VertexArray %d vertices, %d indexArrays>" % (
153 len(self.vertices), len(self.indexArrays))
157 self.vertices, self.normals, self.uvs,
158 self.b0, self.b1, self.weight)
160 def __getIndex(self, obj, base_index, pos, normal, uv, b0, b1, weight0):
166 pos[0], pos[1], pos[2],
167 normal[0], normal[1], normal[2],
169 if key in self.vertexMap:
171 index=self.vertexMap[key]
173 index=len(self.vertices)
175 self.vertexMap[key]=index
177 self.vertices.append((pos.x, pos.y, pos.z))
178 self.normals.append((normal.x, normal.y, normal.z))
179 self.uvs.append((uv[0], uv[1]))
182 self.weight.append(weight0)
185 if not base_index in self.indexMap:
186 self.indexMap[base_index]=set()
187 self.indexMap[base_index].add(index)
192 def getMappedIndices(self, base_index):
193 return self.indexMap[base_index]
195 def addTriangle(self,
197 base_index0, base_index1, base_index2,
203 weight0, weight1, weight2
205 if not material in self.indexArrays:
206 self.indexArrays[material]=[]
208 index0=self.__getIndex(obj, base_index0, pos0, n0, uv0, b0_0, b1_0, weight0)
209 index1=self.__getIndex(obj, base_index1, pos1, n1, uv1, b0_1, b1_1, weight1)
210 index2=self.__getIndex(obj, base_index2, pos2, n2, uv2, b0_2, b1_2, weight2)
212 self.indexArrays[material]+=[index0, index1, index2]
216 __slots__=['name', 'type', 'offsets']
217 def __init__(self, name, type):
222 def add(self, index, offset):
223 self.offsets.append((index, offset))
227 self.offsets.sort(lambda l, r: l[0]-r[0])
229 self.offsets.sort(key=lambda e: e[0])
232 return "<Morph %s>" % self.name
234 class IKSolver(object):
235 __slots__=['target', 'effector', 'length', 'iterations', 'weight']
236 def __init__(self, target, effector, length, iterations, weight):
238 self.effector=effector
240 self.iterations=iterations
244 class OneSkinMesh(object):
245 __slots__=['obj_index', 'scene', 'vertexArray', 'morphList',
249 def __init__(self, scene):
250 self.vertexArray=VertexArray()
258 return "<OneSkinMesh %s, morph:%d>" % (
262 def addMesh(self, obj):
263 if bl.objectIsVisible(obj):
268 self.__rigidbody(obj)
269 self.__constraint(obj)
271 def __mesh(self, obj):
275 if RIGID_SHAPE_TYPE in obj:
277 if CONSTRAINT_A in obj:
280 print("export", obj.name)
281 mesh=bl.objectGetData(obj)
284 def setWeight(i, name, w):
287 if i in secondWeightMap:
289 if w<secondWeightMap[i]:
293 secondWeightMap[i]=(name, w)
296 weightMap[i]=(name, w)
298 if w>weightMap[i][1]:
300 secondWeightMap[i]=weightMap[i]
301 weightMap[i]=(name, w)
303 secondWeightMap[i]=(name, w)
305 weightMap[i]=(name, w)
308 for name in bl.meshVertexGroupNames(obj):
309 for i, w in mesh.getVertsFromGroup(name, 1):
310 setWeight(i, name, w)
312 for i, v in enumerate(mesh.verts):
314 setWeight(i, obj.vertex_groups[g.group].name, g.weight)
317 for i in xrange(len(mesh.verts)):
318 #for i, name_weight in weightMap.items():
319 if i in secondWeightMap:
320 secondWeightMap[i]=(secondWeightMap[i][0], 1.0-weightMap[i][1])
322 weightMap[i]=(weightMap[i][0], 1.0)
323 secondWeightMap[i]=("", 0)
325 print("no weight vertex")
327 secondWeightMap[i]=("", 0)
329 # メッシュのコピーを生成してオブジェクトの行列を適用する
330 copyMesh, copyObj=bl.objectDuplicate(self.scene, obj)
331 if len(copyMesh.verts)==0:
334 for i, face in enumerate(copyMesh.faces):
335 faceVertexCount=bl.faceVertexCount(face)
336 material=copyMesh.materials[bl.faceMaterialIndex(face)]
337 v=[copyMesh.verts[index] for index in bl.faceVertices(face)]
338 uv=bl.meshFaceUv(copyMesh, i, face)
339 if faceVertexCount==3:
341 self.vertexArray.addTriangle(
342 self.obj_index, material.name,
343 v[0].index, v[1].index, v[2].index,
344 v[0].co, v[1].co, v[2].co,
346 #v0.no, v1.no, v2.no,
351 weightMap[v[0].index][0],
352 weightMap[v[1].index][0],
353 weightMap[v[2].index][0],
354 secondWeightMap[v[0].index][0],
355 secondWeightMap[v[1].index][0],
356 secondWeightMap[v[2].index][0],
357 weightMap[v[0].index][1],
358 weightMap[v[1].index][1],
359 weightMap[v[2].index][1]
361 elif faceVertexCount==4:
363 self.vertexArray.addTriangle(
364 self.obj_index, material.name,
365 v[0].index, v[1].index, v[2].index,
366 v[0].co, v[1].co, v[2].co,
367 #v0.no, v1.no, v2.no,
372 weightMap[v[0].index][0],
373 weightMap[v[1].index][0],
374 weightMap[v[2].index][0],
375 secondWeightMap[v[0].index][0],
376 secondWeightMap[v[1].index][0],
377 secondWeightMap[v[2].index][0],
378 weightMap[v[0].index][1],
379 weightMap[v[1].index][1],
380 weightMap[v[2].index][1]
382 self.vertexArray.addTriangle(
383 self.obj_index, material.name,
384 v[2].index, v[3].index, v[0].index,
385 v[2].co, v[3].co, v[0].co,
386 #v2.no, v3.no, v0.no,
391 weightMap[v[2].index][0],
392 weightMap[v[3].index][0],
393 weightMap[v[0].index][0],
394 secondWeightMap[v[2].index][0],
395 secondWeightMap[v[3].index][0],
396 secondWeightMap[v[0].index][0],
397 weightMap[v[2].index][1],
398 weightMap[v[3].index][1],
399 weightMap[v[0].index][1]
401 bl.objectDelete(self.scene, copyObj)
404 def __skin(self, obj):
405 if not bl.objectHasShapeKey(obj):
409 blenderMesh=bl.objectGetData(obj)
413 vg=bl.meshVertexGroup(obj, MMD_SHAPE_GROUP_NAME)
417 for b in bl.objectShapeKeys(obj):
418 if b.name==BASE_SHAPE_NAME:
419 baseMorph=self.__getOrCreateMorph('base', 0)
424 v=bl.shapeKeyGet(b, index)
425 pos=[v[0], v[1], v[2]]
426 indices=self.vertexArray.getMappedIndices(index)
432 baseMorph.add(i, pos)
433 indexRelativeMap[i]=relativeIndex
438 print(basis.name, len(baseMorph.offsets))
440 if len(baseMorph.offsets)==0:
444 for b in bl.objectShapeKeys(obj):
445 if b.name==BASE_SHAPE_NAME:
449 morph=self.__getOrCreateMorph(b.name, 4)
451 for index, src, dst in zip(
452 xrange(len(blenderMesh.verts)),
455 offset=[dst[0]-src[0], dst[1]-src[1], dst[2]-src[2]]
456 if offset[0]==0 and offset[1]==0 and offset[2]==0:
459 indices=self.vertexArray.getMappedIndices(index)
464 morph.add(indexRelativeMap[i], offset)
467 original=self.morphList[:]
469 for i, v in enumerate(englishmap.skinMap):
474 self.morphList.sort(lambda l, r: getIndex(l)-getIndex(r))
476 self.morphList.sort(key=getIndex)
478 def __rigidbody(self, obj):
481 if not RIGID_SHAPE_TYPE in obj:
483 self.rigidbodies.append(obj)
485 def __constraint(self, obj):
488 if not CONSTRAINT_A in obj:
490 self.constraints.append(obj)
492 def __getOrCreateMorph(self, name, type):
493 for m in self.morphList:
497 self.morphList.append(m)
500 def getVertexCount(self):
501 return len(self.vertexArray.vertices)
505 __slots__=['index', 'name', 'ik_index',
506 'pos', 'tail', 'parent_index', 'tail_index', 'type', 'isConnect']
507 def __init__(self, name, pos, tail):
512 self.parent_index=None
518 def __eq__(self, rhs):
519 return self.index==rhs.index
522 return "<Bone %s %d>" % (self.name, self.type)
524 class BoneBuilder(object):
525 __slots__=['bones', 'boneMap', 'ik_list']
531 def build(self, armatureObj):
535 print("gather bones")
536 armature=bl.objectGetData(armatureObj)
537 for b in armature.bones.values():
544 self.__getBone(bone, b)
546 for b in armature.bones.values():
547 if not b.parent and b.name!='center':
553 self.__getBone(bone, b)
555 print("check connection")
556 for b in armature.bones.values():
558 self.__checkConnection(b, None)
561 pose = bl.objectGetPose(armatureObj)
562 for b in pose.bones.values():
563 for c in b.constraints:
564 if bl.constraintIsIKSolver(c):
568 target=self.__boneByName(bl.ikTarget(c))
575 link=self.__boneByName(b.name)
580 chainLength=bl.ikChainLen(c)
581 for i in range(chainLength):
583 chainBone=self.__boneByName(e.name)
585 chainBone.ik_index=target.index
588 IKSolver(target, link, chainLength,
589 int(bl.ikItration(c) * 0.1),
590 bl.ikRotationWeight(c)
593 def __checkConnection(self, b, p):
594 if bl.boneIsConnected(b):
595 parent=self.__boneByName(p.name)
596 parent.isConnect=True
599 self.__checkConnection(c, b)
601 def sortBy(self, boneMap):
605 original=self.bones[:]
607 for i, k_v in enumerate(boneMap):
608 if k_v[0]==bone.name:
613 self.bones.sort(lambda l, r: getIndex(l)-getIndex(r))
615 self.bones.sort(key=getIndex)
618 for i, b in enumerate(self.bones):
619 src=original.index(b)
622 b.index=sortMap[b.index]
624 b.parent_index=sortMap[b.parent_index]
626 b.tail_index=sortMap[b.tail_index]
628 b.ik_index=sortMap[b.ik_index]
636 if b.parent_index==None:
637 b.parent_index=0xFFFF
639 if b.type==6 or b.type==7:
641 parent=self.bones[b.parent_index]
642 parent.tail_index=b.index
645 if b.tail_index==None:
650 def getIndex(self, bone):
651 for i, b in enumerate(self.bones):
656 def indexByName(self, name):
657 return self.getIndex(self.__boneByName(name))
659 def __boneByName(self, name):
660 return self.bones[self.boneMap[name]]
662 def __getBone(self, parent, b):
663 if len(b.children)==0:
667 for i, c in enumerate(b.children):
673 bone.parent_index=parent.index
675 parent.tail_index=bone.index
676 self.__getBone(bone, c)
678 def __addBone(self, bone):
679 bone.index=len(self.bones)
680 self.bones.append(bone)
681 self.boneMap[bone.name]=bone.index
684 class PmdExporter(object):
686 def setup(self, scene):
687 self.armatureObj=None
692 for o in scene.objects:
693 object_node_map[o]=Node(o)
694 for o in scene.objects:
695 #for node in object_node_map.values():
696 node=object_node_map[o]
698 object_node_map[node.o.parent].children.append(node)
701 root=object_node_map[scene.objects.active]
704 self.oneSkinMesh=OneSkinMesh(scene)
705 self.__createOneSkinMesh(root)
706 print(self.oneSkinMesh)
707 self.name=root.o.name
710 self.builder=BoneBuilder()
711 self.builder.build(self.armatureObj)
712 self.builder.sortBy(englishmap.boneMap)
714 for i, v in enumerate(englishmap.boneMap):
715 if v[0]==ik.target.name:
717 return len(englishmap.boneMap)
719 self.builder.ik_list.sort(lambda l, r: getIndex(l)-getIndex(r))
721 self.builder.ik_list.sort(key=getIndex)
724 def __createOneSkinMesh(self, node):
725 ############################################################
726 # search armature modifier
727 ############################################################
728 for m in node.o.modifiers:
729 if bl.modifierIsArmature(m):
730 armatureObj=bl.armatureModifierGetObject(m)
731 if not self.armatureObj:
732 self.armatureObj=armatureObj
733 elif self.armatureObj!=armatureObj:
734 print("warning! found multiple armature. ignored.",
737 if node.o.type.upper()=='MESH':
738 self.oneSkinMesh.addMesh(node.o)
740 for child in node.children:
741 self.__createOneSkinMesh(child)
743 def write(self, path):
746 io.comment="blender export"
750 for pos, normal, uv, b0, b1, weight in self.oneSkinMesh.vertexArray.zip():
751 # convert right-handed z-up to left-handed y-up
761 v.bone0=self.builder.boneMap[b0] if b0 in self.builder.boneMap else 0
762 v.bone1=self.builder.boneMap[b1] if b1 in self.builder.boneMap else 0
763 v.weight0=int(100*weight)
764 v.edge_flag=0 # edge flag, 0: enable edge, 1: not edge
767 vertexCount=self.oneSkinMesh.getVertexCount()
768 for material_name, indices in self.oneSkinMesh.vertexArray.indexArrays.items():
769 m=bl.materialGet(self.scene, material_name)
771 material=io.addMaterial()
773 material.diffuse.r=m.R
774 material.diffuse.g=m.G
775 material.diffuse.b=m.B
776 material.diffuse.a=m.alpha
777 material.sinness=0 if m.spec<1e-5 else m.spec*10
778 material.specular.r=m.specR
779 material.specular.g=m.specG
780 material.specular.b=m.specB
781 material.ambient.r=m.mirR
782 material.ambient.g=m.mirG
783 material.ambient.b=m.mirB
784 material.flag=1 if m.enableSSS else 0
786 material.diffuse.r=m.diffuse_color[0]
787 material.diffuse.g=m.diffuse_color[1]
788 material.diffuse.b=m.diffuse_color[2]
789 material.diffuse.a=m.alpha
790 material.sinness=0 if m.specular_hardness<1e-5 else m.specular_hardness*10
791 material.specular.r=m.specular_color[0]
792 material.specular.g=m.specular_color[1]
793 material.specular.b=m.specular_color[2]
794 material.ambient.r=m.mirror_color[0]
795 material.ambient.g=m.mirror_color[1]
796 material.ambient.b=m.mirror_color[2]
797 material.flag=1 if m.subsurface_scattering.enabled else 0
799 material.vertex_count=len(indices)
800 material.toon_index=0
805 assert(i<vertexCount)
806 for i in xrange(0, len(indices), 3):
808 io.indices.append(indices[i])
809 io.indices.append(indices[i+1])
810 io.indices.append(indices[i+2])
814 for i, b in enumerate(self.builder.bones):
818 boneNameMap[b.name]=i
819 v=englishmap.getUnicodeBoneName(b.name)
821 cp932=v[1].encode('cp932')
822 assert(len(cp932)<20)
826 bone_english_name=b.name
827 assert(len(bone_english_name)<20)
828 bone.english_name=bone_english_name
833 b.ik_index=self.builder.indexByName('eyes')
838 bone.parent_index=b.parent_index
839 bone.tail_index=b.tail_index
840 bone.ik_index=b.ik_index
842 # convert right-handed z-up to left-handed y-up
843 bone.pos.x=b.pos[0] if not near(b.pos[0], 0) else 0
844 bone.pos.y=b.pos[2] if not near(b.pos[2], 0) else 0
845 bone.pos.z=b.pos[1] if not near(b.pos[1], 0) else 0
848 for ik in self.builder.ik_list:
850 solver.index=self.builder.getIndex(ik.target)
851 solver.target=self.builder.getIndex(ik.effector)
852 solver.length=ik.length
853 b=self.builder.bones[ik.effector.parent_index]
854 for i in xrange(solver.length):
855 solver.children.append(self.builder.getIndex(b))
856 b=self.builder.bones[b.parent_index]
857 solver.iterations=ik.iterations
858 solver.weight=ik.weight
861 for i, m in enumerate(self.oneSkinMesh.morphList):
865 v=englishmap.getUnicodeSkinName(m.name)
867 cp932=v[1].encode('cp932')
869 morph.setEnglishName(m.name.encode('cp932'))
872 for index, offset in m.offsets:
873 # convert right-handed z-up to left-handed y-up
874 morph.append(index, offset[0], offset[2], offset[1])
875 morph.vertex_count=len(m.offsets)
879 for i, m in enumerate(self.oneSkinMesh.morphList):
881 io.face_list.append(i)
882 for i, m in enumerate(self.oneSkinMesh.morphList):
884 io.face_list.append(i)
885 for i, m in enumerate(self.oneSkinMesh.morphList):
887 io.face_list.append(i)
888 for i, m in enumerate(self.oneSkinMesh.morphList):
890 io.face_list.append(i)
893 def createBoneDisplayName(name, english):
894 boneDisplayName=io.addBoneDisplayName()
896 boneDisplayName.name=name.decode('utf-8').encode('cp932')
897 boneDisplayName.english_name=english
899 boneDisplayName.setName(name.encode('cp932'))
900 boneDisplayName.setEnglishName(english.encode('cp932'))
901 boneDisplayName=createBoneDisplayName("IK\n", "IK\n")
902 boneDisplayName=createBoneDisplayName("体(上)\n", "Body[u]\n")
903 boneDisplayName=createBoneDisplayName("髪\n", "Hair\n")
904 boneDisplayName=createBoneDisplayName("腕\n", "Arms\n")
905 boneDisplayName=createBoneDisplayName("指\n", "Fingers\n")
906 boneDisplayName=createBoneDisplayName("体(下)\n", "Body[l]\n")
907 boneDisplayName=createBoneDisplayName("足\n", "Legs\n")
908 for i, b in enumerate(self.builder.bones):
913 io.addBoneDisplay(i, getBoneDisplayGroup(b))
916 io.english_name="blender export"
917 io.english_coment="blender export"
921 io.getToonTexture(i).name="toon%02d.bmp\n" % i
925 for i, obj in enumerate(self.oneSkinMesh.rigidbodies):
926 rigidBody=io.addRigidBody()
927 rigidBody.setName(obj.name.encode('cp932'))
928 rigidNameMap[obj.name]=i
929 boneIndex=boneNameMap[obj[RIGID_BONE_NAME]]
932 bone=self.builder.bones[0]
934 bone=self.builder.bones[boneIndex]
935 rigidBody.boneIndex=boneIndex
936 #rigidBody.position.x=obj[RIGID_LOCATION][0]
937 #rigidBody.position.y=obj[RIGID_LOCATION][1]
938 #rigidBody.position.z=obj[RIGID_LOCATION][2]
939 rigidBody.position.x=obj.location.x-bone.pos[0]
940 rigidBody.position.y=obj.location.z-bone.pos[2]
941 rigidBody.position.z=obj.location.y-bone.pos[1]
942 rigidBody.rotation.x=-obj.rotation_euler[0]
943 rigidBody.rotation.y=-obj.rotation_euler[2]
944 rigidBody.rotation.z=-obj.rotation_euler[1]
945 rigidBody.processType=obj[RIGID_PROCESS_TYPE]
946 rigidBody.group=obj[RIGID_GROUP]
947 rigidBody.target=obj[RIGID_INTERSECTION_GROUP]
948 rigidBody.weight=obj[RIGID_WEIGHT]
949 rigidBody.linearDamping=obj[RIGID_LINEAR_DAMPING]
950 rigidBody.angularDamping=obj[RIGID_ANGULAR_DAMPING]
951 rigidBody.restitution=obj[RIGID_RESTITUTION]
952 rigidBody.friction=obj[RIGID_FRICTION]
953 if obj[RIGID_SHAPE_TYPE]==0:
954 rigidBody.shapeType=pmd.SHAPE_SPHERE
955 rigidBody.w=obj.scale[0]
956 elif obj[RIGID_SHAPE_TYPE]==1:
957 rigidBody.shapeType=pmd.SHAPE_BOX
958 rigidBody.w=obj.scale[0]
959 rigidBody.d=obj.scale[1]
960 rigidBody.h=obj.scale[2]
961 elif obj[RIGID_SHAPE_TYPE]==2:
962 rigidBody.shapeType=pmd.SHAPE_CAPSULE
963 rigidBody.w=obj.scale[0]
964 rigidBody.h=obj.scale[2]
967 for obj in self.oneSkinMesh.constraints:
968 constraint=io.addConstraint()
969 constraint.setName(obj.name[1:].encode('cp932'))
970 constraint.rigidA=rigidNameMap[obj[CONSTRAINT_A]]
971 constraint.rigidB=rigidNameMap[obj[CONSTRAINT_B]]
972 constraint.pos.x=obj.location[0]
973 constraint.pos.y=obj.location[2]
974 constraint.pos.z=obj.location[1]
975 constraint.rot.x=-obj.rotation_euler[0]
976 constraint.rot.y=-obj.rotation_euler[2]
977 constraint.rot.z=-obj.rotation_euler[1]
978 constraint.constraintPosMin.x=obj[CONSTRAINT_POS_MIN][0]
979 constraint.constraintPosMin.y=obj[CONSTRAINT_POS_MIN][1]
980 constraint.constraintPosMin.z=obj[CONSTRAINT_POS_MIN][2]
981 constraint.constraintPosMax.x=obj[CONSTRAINT_POS_MAX][0]
982 constraint.constraintPosMax.y=obj[CONSTRAINT_POS_MAX][1]
983 constraint.constraintPosMax.z=obj[CONSTRAINT_POS_MAX][2]
984 constraint.constraintRotMin.x=obj[CONSTRAINT_ROT_MIN][0]
985 constraint.constraintRotMin.y=obj[CONSTRAINT_ROT_MIN][1]
986 constraint.constraintRotMin.z=obj[CONSTRAINT_ROT_MIN][2]
987 constraint.constraintRotMax.x=obj[CONSTRAINT_ROT_MAX][0]
988 constraint.constraintRotMax.y=obj[CONSTRAINT_ROT_MAX][1]
989 constraint.constraintRotMax.z=obj[CONSTRAINT_ROT_MAX][2]
990 constraint.springPos.x=obj[CONSTRAINT_SPRING_POS][0]
991 constraint.springPos.y=obj[CONSTRAINT_SPRING_POS][1]
992 constraint.springPos.z=obj[CONSTRAINT_SPRING_POS][2]
993 constraint.springRot.x=obj[CONSTRAINT_SPRING_ROT][0]
994 constraint.springRot.y=obj[CONSTRAINT_SPRING_ROT][1]
995 constraint.springRot.z=obj[CONSTRAINT_SPRING_ROT][2]
999 return io.write(path)
1002 def getBoneDisplayGroup(bone):
1005 "necktie IK", "hair IK_L", "hair IK_R", "leg IK_L", "leg IK_R",
1006 "toe IK_L", "toe IK_R",
1009 "upper body", "neck", "head", "eye_L", "eye_R",
1010 "necktie1", "necktie2", "necktie3", "eyes",
1011 "eyelight_L", "eyelight_R",
1014 "front hair1", "front hair2", "front hair3",
1015 "hair1_L", "hair2_L", "hair3_L",
1016 "hair4_L", "hair5_L", "hair6_L",
1017 "hair1_R", "hair2_R", "hair3_R",
1018 "hair4_R", "hair5_R", "hair6_R",
1021 "shoulder_L", "arm_L", "arm twist_L", "elbow_L",
1022 "wrist twist_L", "wrist_L", "sleeve_L",
1023 "shoulder_R", "arm_R", "arm twist_R", "elbow_R",
1024 "wrist twist_R", "wrist_R", "sleeve_R",
1027 "thumb1_L", "thumb2_L", "fore1_L", "fore2_L", "fore3_L",
1028 "middle1_L", "middle2_L", "middle3_L",
1029 "third1_L", "third2_L", "third3_L",
1030 "little1_L", "little2_L", "little3_L",
1031 "thumb1_R", "thumb2_R", "fore1_R", "fore2_R", "fore3_R",
1032 "middle1_R", "middle2_R", "middle3_R",
1033 "third1_R", "third2_R", "third3_R",
1034 "little1_R", "little2_R", "little3_R",
1037 "lower body", "waist accessory",
1038 "front skirt_L", "back skirt_L",
1039 "front skirt_R", "back skirt_R",
1042 "leg_L", "knee_L", "ankle_L",
1043 "leg_R", "knee_R", "ankle_R",
1047 for g in boneGroups:
1055 def __execute(filename, scene):
1056 if not scene.objects.active:
1057 print("abort. no active object.")
1060 bl.progress_start('pmd_export')
1061 active=bl.objectGetActive(scene)
1062 exporter=PmdExporter()
1063 exporter.setup(scene)
1064 exporter.write(filename)
1065 bl.objectActivate(scene, active)
1066 bl.progress_finish()
1071 def execute_24(filename):
1072 filename=filename.decode(bl.INTERNAL_ENCODING)
1073 print("pmd exporter: %s" % filename)
1075 Blender.Window.WaitCursor(1)
1076 t = Blender.sys.time()
1078 scene = bpy.data.scenes.active
1079 __execute(filename, scene)
1081 print('finished in %.2f seconds' % (Blender.sys.time()-t))
1083 Blender.Window.WaitCursor(0)
1085 Blender.Window.FileSelector(
1087 'Export Metasequoia PMD',
1088 Blender.sys.makename(ext='.pmd'))
1092 def execute_25(*args):
1096 class EXPORT_OT_pmd(bpy.types.Operator):
1097 '''Save a Metasequoia PMD file.'''
1098 bl_idname = "export_scene.pmd"
1099 bl_label = 'Export PMD'
1101 # List of operator properties, the attributes will be assigned
1102 # to the class instance from the operator settings before calling.
1104 path = StringProperty(
1106 description="File path used for exporting the PMD file",
1110 filename = StringProperty(
1112 description="Name of the file.")
1113 directory = StringProperty(
1115 description="Directory of the file.")
1117 check_existing = BoolProperty(
1118 name="Check Existing",
1119 description="Check and warn on overwriting existing files",
1121 options=set('HIDDEN'))
1123 def execute(self, context):
1125 self.properties.path,
1130 def invoke(self, context, event):
1132 wm.add_fileselect(self)
1133 return 'RUNNING_MODAL'
1136 def menu_func(self, context):
1137 #default_path=bpy.data.filename.replace(".blend", ".pmd")
1138 self.layout.operator(
1139 EXPORT_OT_pmd.bl_idname,
1140 text="Miku Miku Dance Model(.pmd)")#.path=default_path
1143 bpy.types.register(EXPORT_OT_pmd)
1144 bpy.types.INFO_MT_file_export.append(menu_func)
1147 bpy.types.unregister(EXPORT_OT_pmd)
1148 bpy.types.INFO_MT_file_export.remove(menu_func)
1150 if __name__ == "__main__":