• R/O
  • HTTP
  • SSH
  • HTTPS

pymeshio: コミット

pmdとmqoの入出力ライブラリと、それを使ったBlender2.5向けのaddon。


コミットメタ情報

リビジョンd38cb757bb66218cc332a5f29ea1ef394d6028da (tree)
日時2011-10-15 16:52:40
作者ousttrue <ousttrue@gmai...>
コミッターousttrue

ログメッセージ

implementing export_pmx...

変更サマリ

差分

--- a/blender26-meshio/export_pmx.py
+++ b/blender26-meshio/export_pmx.py
@@ -2,19 +2,27 @@
22
33 import io
44 from . import bl
5-from . import oneskinmesh
5+from . import exporter
66 from .pymeshio import pmx
77 from .pymeshio import common
88 from .pymeshio.pmx import writer
99
1010
11+def near(x, y, EPSILON=1e-5):
12+ d=x-y
13+ return d>=-EPSILON and d<=EPSILON
14+
15+
1116 def create_pmx(ex):
1217 model=pmx.Model()
13- model.name=ex.name
14- model.comment=ex.comment
18+
19+ o=ex.root.o
20+ model.english_name=o.name
21+ model.name=o[bl.MMD_MB_NAME] if bl.MMD_MB_NAME in o else 'Blenderエクスポート'
22+ model.comment=o[bl.MMD_MB_COMMENT] if bl.MMD_MB_COMMENT in o else 'Blnderエクスポート\n'
23+ model.english_comment=o[bl.MMD_COMMENT] if bl.MMD_COMMENT in o else 'blender export\n'
1524
1625 def get_deform(b0, b1, weight):
17- print(b0, b1, weight)
1826 if b0==-1:
1927 return pmx.Bdef1(b1, weight)
2028 elif b1==-1:
@@ -35,37 +43,32 @@ def create_pmx(ex):
3543 )
3644 for pos, attribute, b0, b1, weight in ex.oneSkinMesh.vertexArray.zip()]
3745
38- # bones
39- boneNameMap={}
40- for i, b in enumerate(self.skeleton.bones):
41-
42- # name
43- boneNameMap[b.name]=i
44- v=englishmap.getUnicodeBoneName(b.name)
45- if not v:
46- v=[b.name, b.name]
47- assert(v)
48- bone=pmx.Bone(v[1])
49- bone.english_name=b.name
50-
51- if len(v)>=3:
52- # has type
53- if v[2]==5:
54- b.ik_index=self.skeleton.indexByName('eyes')
55- bone.type=v[2]
56- else:
57- bone.type=b.type
58-
59- bone.parent_index=b.parent_index
60- bone.tail_index=b.tail_index
61- bone.ik_index=b.ik_index
46+ def create_bone(b):
47+ return pmx.Bone(
48+ name=b.name,
49+ english_name=b.name,
50+ # convert right-handed z-up to left-handed y-up
51+ position=common.Vector3(
52+ b.pos[0] if not near(b.pos[0], 0) else 0,
53+ b.pos[2] if not near(b.pos[2], 0) else 0,
54+ b.pos[1] if not near(b.pos[1], 0) else 0
55+ ),
56+ parent_index=b.parent_index,
57+ layer=0,
58+ flag=0,
59+ tail_position=None,
60+ tail_index=b.tail_index,
61+ effect_index=-1,
62+ effect_factor=0.0,
63+ fixed_axis=None,
64+ local_x_vector=None,
65+ local_z_vector=None,
66+ external_key=-1,
67+ ik=None
68+ )
69+ model.bones=[create_bone(b)
70+ for b in ex.skeleton.bones]
6271
63- # convert right-handed z-up to left-handed y-up
64- bone.pos.x=b.pos[0] if not near(b.pos[0], 0) else 0
65- bone.pos.y=b.pos[2] if not near(b.pos[2], 0) else 0
66- bone.pos.z=b.pos[1] if not near(b.pos[1], 0) else 0
67-
68- model.bones.append(bone)
6972 return model
7073
7174 # IK
@@ -206,6 +209,9 @@ def create_pmx(ex):
206209 model.toon_textures[i]=("toon%02d.bmp" % (i+1)).encode('cp932')
207210
208211 # rigid body
212+ boneNameMap={}
213+ for i, b in enumerate(self.skeleton.bones):
214+ boneNameMap[b.name]=b
209215 rigidNameMap={}
210216 for i, obj in enumerate(self.oneSkinMesh.rigidbodies):
211217 name=obj[bl.RIGID_NAME] if bl.RIGID_NAME in obj else obj.name
@@ -303,10 +309,10 @@ def _execute(filepath):
303309 print("abort. no active object.")
304310 return
305311
306- exporter=oneskinmesh.Exporter()
307- exporter.setup()
312+ ex=exporter.Exporter()
313+ ex.setup()
308314
309- model=create_pmx(exporter)
315+ model=create_pmx(ex)
310316 bl.object.activate(active)
311317 with io.open(filepath, 'wb') as f:
312318 writer.write(f, model)
--- a/blender26-meshio/exporter/bonebuilder.py
+++ b/blender26-meshio/exporter/bonebuilder.py
@@ -181,7 +181,7 @@ class BoneBuilder(object):
181181 for b in self.bones:
182182 # parent index
183183 if b.parent_index==None:
184- b.parent_index=0xFFFF
184+ b.parent_index=-1
185185 else:
186186 if b.type==6 or b.type==7:
187187 # fix tail bone
旧リポジトリブラウザで表示