pmdとmqoの入出力ライブラリと、それを使ったBlender2.5向けのaddon。
Revision | 5d8a713d1daaa9dcaac772e7677d8e0f1419806a (tree) |
---|---|
Time | 2011-10-13 01:47:48 |
Author | ousttrue <ousttrue@gmai...> |
Commiter | ousttrue |
pmx bug fix
@@ -255,6 +255,7 @@ class object: | ||
255 | 255 | g=pose.bone_groups.active |
256 | 256 | g.name=name |
257 | 257 | g.color_set=color_set |
258 | + return g | |
258 | 259 | |
259 | 260 | @staticmethod |
260 | 261 | def boneGroups(o): |
@@ -595,15 +596,17 @@ class armature: | ||
595 | 596 | bpy.ops.object.mode_set(mode='EDIT', toggle=False) |
596 | 597 | |
597 | 598 | @staticmethod |
598 | - def createIkConstraint(armature_object, p_bone, effector_name, ik): | |
599 | + def createIkConstraint(armature_object, p_bone, effector_name, | |
600 | + chain, weight, iterations): | |
599 | 601 | constraint = p_bone.constraints.new('IK') |
600 | - constraint.chain_count=len(ik.children) | |
602 | + constraint.chain_count=len(chain) | |
601 | 603 | constraint.target=armature_object |
602 | 604 | constraint.subtarget=effector_name |
603 | 605 | constraint.use_tail=False |
606 | + # ToDo | |
604 | 607 | # not used. place folder when export. |
605 | - constraint.weight=ik.weight | |
606 | - constraint.iterations=ik.iterations * 10 | |
608 | + #constraint.weight=weight | |
609 | + #constraint.iterations=iterations * 10 | |
607 | 610 | return constraint |
608 | 611 | |
609 | 612 | @staticmethod |
@@ -303,7 +303,8 @@ def __importArmature(l): | ||
303 | 303 | effector_name=l.bones[ik.index].name.decode('cp932') |
304 | 304 | |
305 | 305 | constraint=bl.armature.createIkConstraint(armature_object, |
306 | - p_bone, effector_name, ik) | |
306 | + p_bone, effector_name, | |
307 | + ik.children, ik.weight, ik.iterations) | |
307 | 308 | |
308 | 309 | bl.armature.makeEditable(armature_object) |
309 | 310 | bl.armature.update(armature) |
@@ -48,7 +48,7 @@ def __create_a_material(m, name, textures_and_images): | ||
48 | 48 | texture_index=bl.material.addTexture(material, textures_and_images[m.texture_index][0]) |
49 | 49 | return material |
50 | 50 | |
51 | -def __create_armature(bones): | |
51 | +def __create_armature(bones, display_slots): | |
52 | 52 | """ |
53 | 53 | armatureを作成する |
54 | 54 |
@@ -58,8 +58,8 @@ def __create_armature(bones): | ||
58 | 58 | """ |
59 | 59 | armature, armature_object=bl.armature.create() |
60 | 60 | |
61 | - bl.armature.makeEditable(armature_object) | |
62 | 61 | # create bones |
62 | + bl.armature.makeEditable(armature_object) | |
63 | 63 | def create_bone(b): |
64 | 64 | bone=bl.armature.createBone(armature, b.name) |
65 | 65 | # bone position |
@@ -74,6 +74,7 @@ def __create_armature(bones): | ||
74 | 74 | |
75 | 75 | # build skeleton |
76 | 76 | for b, bone in zip(bones, bl_bones): |
77 | + assert(b.name==bone.name) | |
77 | 78 | if b.parent_index!=-1: |
78 | 79 | print("%s -> %s" % (bones[b.parent_index].name, b.name)) |
79 | 80 | parent_bone=bl_bones[b.parent_index] |
@@ -85,11 +86,38 @@ def __create_armature(bones): | ||
85 | 86 | bl.bone.setConnected(tail_bone) |
86 | 87 | else: |
87 | 88 | print("no parent %s" % b.name) |
89 | + bl.armature.update(armature) | |
88 | 90 | |
89 | - # fix | |
91 | + # create ik constraint | |
92 | + bl.enterObjectMode() | |
93 | + pose = bl.object.getPose(armature_object) | |
94 | + for b, bone in zip(bones, bl_bones): | |
95 | + if b.getIkFlag(): | |
96 | + ik=b.ik | |
97 | + assert(len(ik.link)<16) | |
98 | + p_bone=pose.bones[bones[ik.target_index].name] | |
99 | + assert(p_bone) | |
100 | + constraint=bl.armature.createIkConstraint( | |
101 | + armature_object, p_bone, bone.name, | |
102 | + ik.link, ik.limit_radian, ik.loop) | |
103 | + bl.armature.makeEditable(armature_object) | |
90 | 104 | bl.armature.update(armature) |
105 | + | |
106 | + # create bone group | |
91 | 107 | bl.enterObjectMode() |
108 | + pose = bl.object.getPose(armature_object) | |
109 | + for i, ds in enumerate(display_slots): | |
110 | + print(ds) | |
111 | + g=bl.object.createBoneGroup(armature_object, ds.name, "THEME%02d" % (i+1)) | |
112 | + for t, index in ds.references: | |
113 | + if t==0: | |
114 | + name=bones[index].name | |
115 | + try: | |
116 | + pose.bones[name].bone_group=g | |
117 | + except KeyError as e: | |
118 | + print("pose %s is not found" % name) | |
92 | 119 | |
120 | + bl.enterObjectMode() | |
93 | 121 | return armature_object |
94 | 122 | |
95 | 123 | def _execute(filepath): |
@@ -117,7 +145,7 @@ def _execute(filepath): | ||
117 | 145 | root_object[bl.MMD_COMMENT]=model.english_comment |
118 | 146 | |
119 | 147 | # armatureを作る |
120 | - armature_object=__create_armature(model.bones) | |
148 | + armature_object=__create_armature(model.bones, model.display_slots) | |
121 | 149 | if armature_object: |
122 | 150 | bl.object.makeParent(root_object, armature_object) |
123 | 151 |
@@ -74,11 +74,11 @@ class Ik(Diff): | ||
74 | 74 | 'limit_radian', |
75 | 75 | 'link', |
76 | 76 | ] |
77 | - def __init__(self, target_index, loop, limit_radian, link=[]): | |
77 | + def __init__(self, target_index, loop, limit_radian, link=None): | |
78 | 78 | self.target_index=target_index |
79 | 79 | self.loop=loop |
80 | 80 | self.limit_radian=limit_radian |
81 | - self.link=link | |
81 | + self.link=link or [] | |
82 | 82 | |
83 | 83 | def __eq__(self, rhs): |
84 | 84 | return ( |
@@ -470,12 +470,12 @@ class Morph(Diff): | ||
470 | 470 | 'morph_type', |
471 | 471 | 'offsets', |
472 | 472 | ] |
473 | - def __init__(self, name, english_name, panel, morph_type, offsets=[]): | |
473 | + def __init__(self, name, english_name, panel, morph_type, offsets=None): | |
474 | 474 | self.name=name |
475 | 475 | self.english_name=english_name |
476 | 476 | self.panel=panel |
477 | 477 | self.morph_type=morph_type |
478 | - self.offsets=offsets | |
478 | + self.offsets=offsets or [] | |
479 | 479 | |
480 | 480 | def __eq__(self, rhs): |
481 | 481 | return ( |
@@ -533,26 +533,29 @@ class DisplaySlot(Diff): | ||
533 | 533 | name: |
534 | 534 | english_name: |
535 | 535 | special_flag: |
536 | - refrences: list of (ref_type, ref_index) | |
536 | + references: list of (ref_type, ref_index) | |
537 | 537 | """ |
538 | 538 | __slots__=[ |
539 | 539 | 'name', |
540 | 540 | 'english_name', |
541 | 541 | 'special_flag', |
542 | - 'refrences', | |
542 | + 'references', | |
543 | 543 | ] |
544 | - def __init__(self, name, english_name, special_flag, refrences=[]): | |
544 | + def __init__(self, name, english_name, special_flag, references=None): | |
545 | 545 | self.name=name |
546 | 546 | self.english_name=english_name |
547 | 547 | self.special_flag=special_flag |
548 | - self.refrences=refrences | |
548 | + self.references=references or [] | |
549 | + | |
550 | + def __str__(self): | |
551 | + return "<DisplaySlots %s(%d)>" % (self.name, len(self.references)) | |
549 | 552 | |
550 | 553 | def __eq__(self, rhs): |
551 | 554 | return ( |
552 | 555 | self.name==rhs.name |
553 | 556 | and self.english_name==rhs.english_name |
554 | 557 | and self.special_flag==rhs.special_flag |
555 | - and self.refrences==rhs.refrences | |
558 | + and self.references==rhs.references | |
556 | 559 | ) |
557 | 560 | |
558 | 561 | def __ne__(self, rhs): |
@@ -562,7 +565,7 @@ class DisplaySlot(Diff): | ||
562 | 565 | self._diff(rhs, 'name') |
563 | 566 | self._diff(rhs, 'english_name') |
564 | 567 | self._diff(rhs, 'special_flag') |
565 | - #self._diff_array(rhs, 'refrences') | |
568 | + #self._diff_array(rhs, 'references') | |
566 | 569 | |
567 | 570 | |
568 | 571 | class RigidBodyParam(Diff): |
@@ -226,10 +226,10 @@ class Reader(common.BinaryReader): | ||
226 | 226 | for _ in range(display_count): |
227 | 227 | display_type=self.read_int(1) |
228 | 228 | if display_type==0: |
229 | - display_slot.refrences.append( | |
229 | + display_slot.references.append( | |
230 | 230 | (display_type, self.read_bone_index())) |
231 | 231 | elif display_type==1: |
232 | - display_slot.refrences.append( | |
232 | + display_slot.references.append( | |
233 | 233 | (display_type, self.read_morph_index())) |
234 | 234 | else: |
235 | 235 | raise common.ParseException( |
@@ -211,8 +211,8 @@ class Writer(common.BinaryWriter): | ||
211 | 211 | self.write_text(s.name) |
212 | 212 | self.write_text(s.english_name) |
213 | 213 | self.write_int(s.special_flag, 1) |
214 | - self.write_int(len(s.refrences), 4) | |
215 | - for r in s.refrences: | |
214 | + self.write_int(len(s.references), 4) | |
215 | + for r in s.references: | |
216 | 216 | self.write_int(r[0], 1) |
217 | 217 | if r[0]==0: |
218 | 218 | self.write_bone_index(r[1]) |