• R/O
  • HTTP
  • SSH
  • HTTPS

pymeshio: Commit

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


Commit MetaInfo

Revision5d8a713d1daaa9dcaac772e7677d8e0f1419806a (tree)
Time2011-10-13 01:47:48
Authorousttrue <ousttrue@gmai...>
Commiterousttrue

Log Message

pmx bug fix

Change Summary

Incremental Difference

--- a/blender26-meshio/bl.py
+++ b/blender26-meshio/bl.py
@@ -255,6 +255,7 @@ class object:
255255 g=pose.bone_groups.active
256256 g.name=name
257257 g.color_set=color_set
258+ return g
258259
259260 @staticmethod
260261 def boneGroups(o):
@@ -595,15 +596,17 @@ class armature:
595596 bpy.ops.object.mode_set(mode='EDIT', toggle=False)
596597
597598 @staticmethod
598- def createIkConstraint(armature_object, p_bone, effector_name, ik):
599+ def createIkConstraint(armature_object, p_bone, effector_name,
600+ chain, weight, iterations):
599601 constraint = p_bone.constraints.new('IK')
600- constraint.chain_count=len(ik.children)
602+ constraint.chain_count=len(chain)
601603 constraint.target=armature_object
602604 constraint.subtarget=effector_name
603605 constraint.use_tail=False
606+ # ToDo
604607 # 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
607610 return constraint
608611
609612 @staticmethod
--- a/blender26-meshio/import_pmd.py
+++ b/blender26-meshio/import_pmd.py
@@ -303,7 +303,8 @@ def __importArmature(l):
303303 effector_name=l.bones[ik.index].name.decode('cp932')
304304
305305 constraint=bl.armature.createIkConstraint(armature_object,
306- p_bone, effector_name, ik)
306+ p_bone, effector_name,
307+ ik.children, ik.weight, ik.iterations)
307308
308309 bl.armature.makeEditable(armature_object)
309310 bl.armature.update(armature)
--- a/blender26-meshio/import_pmx.py
+++ b/blender26-meshio/import_pmx.py
@@ -48,7 +48,7 @@ def __create_a_material(m, name, textures_and_images):
4848 texture_index=bl.material.addTexture(material, textures_and_images[m.texture_index][0])
4949 return material
5050
51-def __create_armature(bones):
51+def __create_armature(bones, display_slots):
5252 """
5353 armatureを作成する
5454
@@ -58,8 +58,8 @@ def __create_armature(bones):
5858 """
5959 armature, armature_object=bl.armature.create()
6060
61- bl.armature.makeEditable(armature_object)
6261 # create bones
62+ bl.armature.makeEditable(armature_object)
6363 def create_bone(b):
6464 bone=bl.armature.createBone(armature, b.name)
6565 # bone position
@@ -74,6 +74,7 @@ def __create_armature(bones):
7474
7575 # build skeleton
7676 for b, bone in zip(bones, bl_bones):
77+ assert(b.name==bone.name)
7778 if b.parent_index!=-1:
7879 print("%s -> %s" % (bones[b.parent_index].name, b.name))
7980 parent_bone=bl_bones[b.parent_index]
@@ -85,11 +86,38 @@ def __create_armature(bones):
8586 bl.bone.setConnected(tail_bone)
8687 else:
8788 print("no parent %s" % b.name)
89+ bl.armature.update(armature)
8890
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)
90104 bl.armature.update(armature)
105+
106+ # create bone group
91107 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)
92119
120+ bl.enterObjectMode()
93121 return armature_object
94122
95123 def _execute(filepath):
@@ -117,7 +145,7 @@ def _execute(filepath):
117145 root_object[bl.MMD_COMMENT]=model.english_comment
118146
119147 # armatureを作る
120- armature_object=__create_armature(model.bones)
148+ armature_object=__create_armature(model.bones, model.display_slots)
121149 if armature_object:
122150 bl.object.makeParent(root_object, armature_object)
123151
--- a/pymeshio/pmx/__init__.py
+++ b/pymeshio/pmx/__init__.py
@@ -74,11 +74,11 @@ class Ik(Diff):
7474 'limit_radian',
7575 'link',
7676 ]
77- def __init__(self, target_index, loop, limit_radian, link=[]):
77+ def __init__(self, target_index, loop, limit_radian, link=None):
7878 self.target_index=target_index
7979 self.loop=loop
8080 self.limit_radian=limit_radian
81- self.link=link
81+ self.link=link or []
8282
8383 def __eq__(self, rhs):
8484 return (
@@ -470,12 +470,12 @@ class Morph(Diff):
470470 'morph_type',
471471 'offsets',
472472 ]
473- def __init__(self, name, english_name, panel, morph_type, offsets=[]):
473+ def __init__(self, name, english_name, panel, morph_type, offsets=None):
474474 self.name=name
475475 self.english_name=english_name
476476 self.panel=panel
477477 self.morph_type=morph_type
478- self.offsets=offsets
478+ self.offsets=offsets or []
479479
480480 def __eq__(self, rhs):
481481 return (
@@ -533,26 +533,29 @@ class DisplaySlot(Diff):
533533 name:
534534 english_name:
535535 special_flag:
536- refrences: list of (ref_type, ref_index)
536+ references: list of (ref_type, ref_index)
537537 """
538538 __slots__=[
539539 'name',
540540 'english_name',
541541 'special_flag',
542- 'refrences',
542+ 'references',
543543 ]
544- def __init__(self, name, english_name, special_flag, refrences=[]):
544+ def __init__(self, name, english_name, special_flag, references=None):
545545 self.name=name
546546 self.english_name=english_name
547547 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))
549552
550553 def __eq__(self, rhs):
551554 return (
552555 self.name==rhs.name
553556 and self.english_name==rhs.english_name
554557 and self.special_flag==rhs.special_flag
555- and self.refrences==rhs.refrences
558+ and self.references==rhs.references
556559 )
557560
558561 def __ne__(self, rhs):
@@ -562,7 +565,7 @@ class DisplaySlot(Diff):
562565 self._diff(rhs, 'name')
563566 self._diff(rhs, 'english_name')
564567 self._diff(rhs, 'special_flag')
565- #self._diff_array(rhs, 'refrences')
568+ #self._diff_array(rhs, 'references')
566569
567570
568571 class RigidBodyParam(Diff):
--- a/pymeshio/pmx/reader.py
+++ b/pymeshio/pmx/reader.py
@@ -226,10 +226,10 @@ class Reader(common.BinaryReader):
226226 for _ in range(display_count):
227227 display_type=self.read_int(1)
228228 if display_type==0:
229- display_slot.refrences.append(
229+ display_slot.references.append(
230230 (display_type, self.read_bone_index()))
231231 elif display_type==1:
232- display_slot.refrences.append(
232+ display_slot.references.append(
233233 (display_type, self.read_morph_index()))
234234 else:
235235 raise common.ParseException(
--- a/pymeshio/pmx/writer.py
+++ b/pymeshio/pmx/writer.py
@@ -211,8 +211,8 @@ class Writer(common.BinaryWriter):
211211 self.write_text(s.name)
212212 self.write_text(s.english_name)
213213 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:
216216 self.write_int(r[0], 1)
217217 if r[0]==0:
218218 self.write_bone_index(r[1])
Show on old repository browser