X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=pymeshio%2Fpmx%2F__init__.py;h=e367e46973bdbb9d20c0c25d545b0627a653641a;hb=924bae1667aea0f57dd3de11b1248c12bc9a95d1;hp=7afe5f2227b3fa2e4711c208d181990b8df2b8e1;hpb=1a59747c66623ef3b6b66412d25ffc4e613cd893;p=meshio%2Fpymeshio.git diff --git a/pymeshio/pmx/__init__.py b/pymeshio/pmx/__init__.py index 7afe5f2..e367e46 100644 --- a/pymeshio/pmx/__init__.py +++ b/pymeshio/pmx/__init__.py @@ -26,7 +26,7 @@ __versioon__="1.0.0" import io import os import struct -from pymeshio import common +from .. import common @@ -46,8 +46,8 @@ class Diff(object): def _diff_array(self, rhs, key): la=getattr(self, key) ra=getattr(rhs, key) - if len(la)!=len(la): - raise DifferenceException(key) + if len(la)!=len(ra): + raise DifferenceException("%s diffrence %d with %d" % (key, len(la), len(ra))) for i, (l, r) in enumerate(zip(la, ra)): if isinstance(l, Diff): try: @@ -74,11 +74,11 @@ class Ik(Diff): 'limit_radian', 'link', ] - def __init__(self, target_index, loop, limit_radian, link=[]): + def __init__(self, target_index, loop, limit_radian, link=None): self.target_index=target_index self.loop=loop self.limit_radian=limit_radian - self.link=link + self.link=link or [] def __eq__(self, rhs): return ( @@ -104,11 +104,11 @@ class IkLink(Diff): 'limit_min', 'limit_max', ] - def __init__(self, bone_index, limit_angle, limit_min=common.Vector3(), limit_max=common.Vector3()): + def __init__(self, bone_index, limit_angle, limit_min=None, limit_max=None): self.bone_index=bone_index self.limit_angle=limit_angle - self.limit_min=limit_min - self.limit_max=limit_max + self.limit_min=limit_min or common.Vector3() + self.limit_max=limit_max or common.Vector3() def __eq__(self, rhs): return ( @@ -155,13 +155,13 @@ class Bone(Diff): parent_index, layer, flag, - tail_position=common.Vector3(), + tail_position=None, tail_index=-1, effect_index=-1, effect_factor=0.0, - fixed_axis=common.Vector3(), - local_x_vector=common.Vector3(), - local_z_vector=common.Vector3(), + fixed_axis=None, + local_x_vector=None, + local_z_vector=None, external_key=-1, ik=None ): @@ -171,13 +171,13 @@ class Bone(Diff): self.parent_index=parent_index self.layer=layer self.flag=flag - self.tail_position=tail_position + self.tail_position=tail_position or common.Vector3() self.tail_index=tail_index self.effect_index=effect_index self.effect_factor=effect_factor - self.fixed_axis=fixed_axis - self.local_x_vector=local_x_vector - self.local_z_vector=local_z_vector + self.fixed_axis=fixed_axis or common.Vector3() + self.local_x_vector=local_x_vector or common.Vector3() + self.local_z_vector=local_z_vector or common.Vector3() self.external_key=external_key self.ik=ik @@ -215,25 +215,28 @@ class Bone(Diff): self._diff(rhs, 'ik') def getConnectionFlag(self): - return self.flag & 0x0001 + return (self.flag & 0x0001)!=0 + + def getVisibleFlag(self): + return (self.flag & 0x0008)!=0 def getIkFlag(self): - return (self.flag & 0x0020) >> 5 + return (self.flag & 0x0020)!=0 def getRotationFlag(self): - return (self.flag & 0x0100) >> 8 + return (self.flag & 0x0100)!=0 def getTranslationFlag(self): - return (self.flag & 0x0200) >> 9 + return (self.flag & 0x0200)!=0 def getFixedAxisFlag(self): - return (self.flag & 0x0400) >> 10 + return (self.flag & 0x0400)!=0 def getLocalCoordinateFlag(self): - return (self.flag & 0x0800) >> 11 + return (self.flag & 0x0800)!=0 def getExternalParentDeformFlag(self): - return (self.flag & 0x2000) >> 13 + return (self.flag & 0x2000)!=0 class Material(Diff): @@ -467,12 +470,12 @@ class Morph(Diff): 'morph_type', 'offsets', ] - def __init__(self, name, english_name, panel, morph_type): + def __init__(self, name, english_name, panel, morph_type, offsets=None): self.name=name self.english_name=english_name self.panel=panel self.morph_type=morph_type - self.offsets=[] + self.offsets=offsets or [] def __eq__(self, rhs): return ( @@ -489,12 +492,12 @@ class Morph(Diff): def diff(self, rhs): self._diff(rhs, 'name') self._diff(rhs, 'english_name') - self._diff(rhs, 'panel') + #self._diff(rhs, 'panel') self._diff(rhs, 'morph_type') self._diff_array(rhs, 'offsets') -class VerexMorphOffset(Diff): +class VertexMorphOffset(Diff): """pmx vertex morph offset Attributes: @@ -519,8 +522,8 @@ class VerexMorphOffset(Diff): return not self.__eq__(rhs) def diff(self, rhs): - self._diff(rhs, 'name') - self._diff(rhs, 'english_name') + self._diff(rhs, 'vertex_index') + self._diff(rhs, 'position_offset') class DisplaySlot(Diff): @@ -530,26 +533,29 @@ class DisplaySlot(Diff): name: english_name: special_flag: - refrences: list of (ref_type, ref_index) + references: list of (ref_type, ref_index) """ __slots__=[ 'name', 'english_name', 'special_flag', - 'refrences', + 'references', ] - def __init__(self, name, english_name, special_flag): + def __init__(self, name, english_name, special_flag, references=None): self.name=name self.english_name=english_name self.special_flag=special_flag - self.refrences=[] + self.references=references or [] + + def __str__(self): + return "" % (self.name, len(self.references)) def __eq__(self, rhs): return ( self.name==rhs.name and self.english_name==rhs.english_name and self.special_flag==rhs.special_flag - and self.refrences==rhs.refrences + and self.references==rhs.references ) def __ne__(self, rhs): @@ -559,7 +565,7 @@ class DisplaySlot(Diff): self._diff(rhs, 'name') self._diff(rhs, 'english_name') self._diff(rhs, 'special_flag') - self._diff_array(rhs, 'refrences') + #self._diff_array(rhs, 'references') class RigidBodyParam(Diff): @@ -824,6 +830,7 @@ class Model(Diff): bullet physics joint list """ __slots__=[ + 'path', 'version', 'name', 'english_name', @@ -840,6 +847,7 @@ class Model(Diff): 'joints', ] def __init__(self, version=2.0): + self.path='' self.version=version self.name='' self.english_name=''