pmdとmqoの入出力ライブラリと、それを使ったBlender2.5向けのaddon。
修訂 | d38cb757bb66218cc332a5f29ea1ef394d6028da (tree) |
---|---|
時間 | 2011-10-15 16:52:40 |
作者 | ousttrue <ousttrue@gmai...> |
Commiter | ousttrue |
implementing export_pmx...
@@ -2,19 +2,27 @@ | ||
2 | 2 | |
3 | 3 | import io |
4 | 4 | from . import bl |
5 | -from . import oneskinmesh | |
5 | +from . import exporter | |
6 | 6 | from .pymeshio import pmx |
7 | 7 | from .pymeshio import common |
8 | 8 | from .pymeshio.pmx import writer |
9 | 9 | |
10 | 10 | |
11 | +def near(x, y, EPSILON=1e-5): | |
12 | + d=x-y | |
13 | + return d>=-EPSILON and d<=EPSILON | |
14 | + | |
15 | + | |
11 | 16 | def create_pmx(ex): |
12 | 17 | 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' | |
15 | 24 | |
16 | 25 | def get_deform(b0, b1, weight): |
17 | - print(b0, b1, weight) | |
18 | 26 | if b0==-1: |
19 | 27 | return pmx.Bdef1(b1, weight) |
20 | 28 | elif b1==-1: |
@@ -35,37 +43,32 @@ def create_pmx(ex): | ||
35 | 43 | ) |
36 | 44 | for pos, attribute, b0, b1, weight in ex.oneSkinMesh.vertexArray.zip()] |
37 | 45 | |
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] | |
62 | 71 | |
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) | |
69 | 72 | return model |
70 | 73 | |
71 | 74 | # IK |
@@ -206,6 +209,9 @@ def create_pmx(ex): | ||
206 | 209 | model.toon_textures[i]=("toon%02d.bmp" % (i+1)).encode('cp932') |
207 | 210 | |
208 | 211 | # rigid body |
212 | + boneNameMap={} | |
213 | + for i, b in enumerate(self.skeleton.bones): | |
214 | + boneNameMap[b.name]=b | |
209 | 215 | rigidNameMap={} |
210 | 216 | for i, obj in enumerate(self.oneSkinMesh.rigidbodies): |
211 | 217 | name=obj[bl.RIGID_NAME] if bl.RIGID_NAME in obj else obj.name |
@@ -303,10 +309,10 @@ def _execute(filepath): | ||
303 | 309 | print("abort. no active object.") |
304 | 310 | return |
305 | 311 | |
306 | - exporter=oneskinmesh.Exporter() | |
307 | - exporter.setup() | |
312 | + ex=exporter.Exporter() | |
313 | + ex.setup() | |
308 | 314 | |
309 | - model=create_pmx(exporter) | |
315 | + model=create_pmx(ex) | |
310 | 316 | bl.object.activate(active) |
311 | 317 | with io.open(filepath, 'wb') as f: |
312 | 318 | writer.write(f, model) |
@@ -181,7 +181,7 @@ class BoneBuilder(object): | ||
181 | 181 | for b in self.bones: |
182 | 182 | # parent index |
183 | 183 | if b.parent_index==None: |
184 | - b.parent_index=0xFFFF | |
184 | + b.parent_index=-1 | |
185 | 185 | else: |
186 | 186 | if b.type==6 or b.type==7: |
187 | 187 | # fix tail bone |