X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=swig%2Fblender24%2Fpmd_export.py;h=c407b4e0927b6119cec1e62f2ea1b75df794e25e;hb=e3663cdfa9eba5b3809390cbc46516f50cb244bc;hp=d791339de1a065394bf2bcee00c32b61f8647429;hpb=667bba1e13a2f2e888a9b8cbacafa4050a154a85;p=meshio%2Fmeshio.git diff --git a/swig/blender24/pmd_export.py b/swig/blender24/pmd_export.py index d791339..c407b4e 100644 --- a/swig/blender24/pmd_export.py +++ b/swig/blender24/pmd_export.py @@ -7,11 +7,12 @@ Tooltip: 'Export PMD file for MikuMikuDance.' """ __author__= ["ousttrue"] -__version__= "0.2" +__version__= "1.0" __url__=() __bpydoc__=""" 0.1 20100318 first implementation. 0.2 20100519 refactoring. use C extension. +1.0 20100530 implement, basic features. """ import Blender import os @@ -352,7 +353,7 @@ class OneSkinMesh(object): indices=self.vertexArray.getMappedIndices(index) for i in indices: baseMorph.add(i, pos) - indexRelativeMap[i]=relativeIndex + indexRelativeMap[relativeIndex]=i relativeIndex+=1 break print(len(baseMorph.offsets)) @@ -380,13 +381,15 @@ class OneSkinMesh(object): assert(len(morph.offsets)==len(baseMorph.offsets)) # sort skinmap - original=self.morphList[:] - def getIndex(morph): - for i, v in enumerate(englishmap.skinMap): - if v[0]==morph.name: - return i - print(morph) - self.morphList.sort(lambda l, r: getIndex(l)-getIndex(r)) + if len(self.morphList)>1: + original=self.morphList[:] + def getIndex(morph): + for i, v in enumerate(englishmap.skinMap): + if v[0]==morph.name: + return i + #print(morph) + return 0 + self.morphList.sort(lambda l, r: getIndex(l)-getIndex(r)) def __getOrCreateMorph(self, name, type): for m in self.morphList: @@ -611,12 +614,14 @@ class PmdExporter(object): self.__createOneSkinMesh(child) def write(self, path): + print('write') io=pmd.IO() io.name=self.name io.comment="blender export" io.version=1.0 # 頂点 + print('vertices') for pos, normal, uv, b0, b1, weight in self.oneSkinMesh.vertexArray.zip(): # convert right-handed z-up to left-handed y-up v=io.addVertex() @@ -634,6 +639,7 @@ class PmdExporter(object): v.edge_flag=0 # edge flag, 0: enable edge, 1: not edge # 面とマテリアル + print('faces and materials') vertexCount=self.oneSkinMesh.getVertexCount() for m, indices in self.oneSkinMesh.vertexArray.indexArrays.items(): m=Blender.Material.Get(m) @@ -669,6 +675,7 @@ class PmdExporter(object): #io.indices.append(indices[i+2]) # bones + print('bones') for b in self.builder.bones: if b.name.endswith("_t"): if b.name.startswith("arm twist1_") or b.name.startswith("arm twist2_"): @@ -717,6 +724,7 @@ class PmdExporter(object): bone.pos.z=b.pos[1] if not near(b.pos[1], 0) else 0 # IK + print('ik') for ik in self.builder.ik_list: solver=io.addIK() solver.index=self.builder.getIndex(ik.target) @@ -730,6 +738,7 @@ class PmdExporter(object): solver.weight=ik.weight # 表情 + print('shape keys') for i, m in enumerate(self.oneSkinMesh.morphList): # morph morph=io.addMorph() @@ -740,26 +749,51 @@ class PmdExporter(object): morph.name="%s\n" % cp932 morph.english_name="%s\n" % m.name + m.type=v[2] morph.type=v[2] for index, offset in m.offsets: # convert right-handed z-up to left-handed y-up morph.append(index, offset[0], offset[2], offset[1]) morph.vertex_count=len(m.offsets) - # 表情枠 - if i>0: + # 表情枠 + print('display list') + # type==0はbase + for i, m in enumerate(self.oneSkinMesh.morphList): + if m.type==3: + io.face_list.append(i) + for i, m in enumerate(self.oneSkinMesh.morphList): + if m.type==2: + io.face_list.append(i) + for i, m in enumerate(self.oneSkinMesh.morphList): + if m.type==1: + io.face_list.append(i) + for i, m in enumerate(self.oneSkinMesh.morphList): + if m.type==4: io.face_list.append(i) # ボーン表示枠 - boneDisplayName=io.addBoneDisplayName() - boneDisplayName.name="bones\n" - boneDisplayName.english_name="bones\n" - displayIndex=1 + print('bone display list') + def createBoneDisplayName(name, english): + boneDisplayName=io.addBoneDisplayName() + boneDisplayName.name=name.decode('utf-8').encode('cp932') + boneDisplayName.english_name=english + boneDisplayName=createBoneDisplayName("IK\n", "IK\n") + boneDisplayName=createBoneDisplayName("体(上)\n", "Body[u]\n") + boneDisplayName=createBoneDisplayName("髪\n", "Hair\n") + boneDisplayName=createBoneDisplayName("腕\n", "Arms\n") + boneDisplayName=createBoneDisplayName("指\n", "Fingers\n") + boneDisplayName=createBoneDisplayName("体(下)\n", "Body[l]\n") + boneDisplayName=createBoneDisplayName("足\n", "Legs\n") for i, b in enumerate(self.builder.bones): + if i==0: + continue if b.type in [6, 7]: - io.addBoneDisplay(i, displayIndex) + continue + io.addBoneDisplay(i, getBoneDisplayGroup(b)) # English + print('english') io.english_name="blender export" io.english_coment="blender export" @@ -767,8 +801,60 @@ class PmdExporter(object): io.getToonTexture(i).name="toon%02d.bmp\n" % i # 書き込み - return io.write(path.encode(FS_ENCODING)) - + return io.write(path) + + +def getBoneDisplayGroup(bone): + boneGroups=[ + [ # IK + "necktie IK", "hair IK_L", "hair IK_R", "leg IK_L", "leg IK_R", + "toe IK_L", "toe IK_R", + ], + [ # 体(上) + "upper body", "neck", "head", "eye_L", "eye_R", + "necktie1", "necktie2", "necktie3", "eyes", + "eyelight_L", "eyelight_R", + ], + [ # 髪 + "front hair1", "front hair2", "front hair3", + "hair1_L", "hair2_L", "hair3_L", + "hair4_L", "hair5_L", "hair6_L", + "hair1_R", "hair2_R", "hair3_R", + "hair4_R", "hair5_R", "hair6_R", + ], + [ # 腕 + "shoulder_L", "arm_L", "arm twist_L", "elbow_L", + "wrist twist_L", "wrist_L", "sleeve_L", + "shoulder_R", "arm_R", "arm twist_R", "elbow_R", + "wrist twist_R", "wrist_R", "sleeve_R", + ], + [ # 指 + "thumb1_L", "thumb2_L", "fore1_L", "fore2_L", "fore3_L", + "middle1_L", "middle2_L", "middle3_L", + "third1_L", "third2_L", "third3_L", + "little1_L", "little2_L", "little3_L", + "thumb1_R", "thumb2_R", "fore1_R", "fore2_R", "fore3_R", + "middle1_R", "middle2_R", "middle3_R", + "third1_R", "third2_R", "third3_R", + "little1_R", "little2_R", "little3_R", + ], + [ # 体(下) + "lower body", "waist accessory", + "front skirt_L", "back skirt_L", + "front skirt_R", "back skirt_R", + ], + [ # 足 + "leg_L", "knee_L", "ankle_L", + "leg_R", "knee_R", "ankle_R", + ], + ] + index=1 + for g in boneGroups: + if bone.name in g: + return index + index+=1 + print(bone) + return -1 def export_pmd(filename): filename=filename.decode(INTERNAL_ENCODING)