X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=pymeshio%2Fpmx%2F__init__.py;h=42b15f6a8685d2dafff36200b3ecf0fbda84394e;hb=cf6ec3e04ee67bbe635510486475961ed32e46f2;hp=90caeb27f1cac93cee11aadf7d6b08fb3f53acac;hpb=5a4345eae3881ebaf867bd0ad6cf46d8cf833163;p=meshio%2Fpymeshio.git diff --git a/pymeshio/pmx/__init__.py b/pymeshio/pmx/__init__.py index 90caeb2..42b15f6 100644 --- a/pymeshio/pmx/__init__.py +++ b/pymeshio/pmx/__init__.py @@ -74,39 +74,49 @@ class Bone(object): 'ik', ] def __init__(self, - name: str, - english_name: str, - position: common.Vector3, - parent_index: int, - layer: int, - flag: int + name, + english_name, + position, + parent_index, + layer, + flag ): - self.name=name, + self.name=name self.english_name=english_name self.position=position self.parent_index=parent_index self.layer=layer self.flag=flag - def getConnectionFlag(self) -> int: + def __eq__(self, rhs): + return ( + self.name==rhs.name + and self.english_name==rhs.english_name + and self.position==rhs.position + and self.parent_index==rhs.parent_index + and self.layer==rhs.layer + and self.flag==rhs.flag + ) + + def getConnectionFlag(self): return self.flag & 0x0001 - def getIkFlag(self) -> int: + def getIkFlag(self): return (self.flag & 0x0020) >> 5 - def getRotationFlag(self) -> int: + def getRotationFlag(self): return (self.flag & 0x0100) >> 8 - def getTranslationFlag(self) -> int: + def getTranslationFlag(self): return (self.flag & 0x0200) >> 9 - def getFixedAxisFlag(self) -> int: + def getFixedAxisFlag(self): return (self.flag & 0x0400) >> 10 - def getLocalCoordinateFlag(self) -> int: + def getLocalCoordinateFlag(self): return (self.flag & 0x0800) >> 11 - def getExternalParentDeformFlag(self) -> int: + def getExternalParentDeformFlag(self): return (self.flag & 0x2000) >> 13 @@ -119,7 +129,7 @@ class Material(object): 'name', 'english_name', 'diffuse_color', - 'diffuse_alpha', + 'alpha', 'specular_color', 'specular_factor', 'ambient_color', @@ -127,33 +137,33 @@ class Material(object): 'edge_color', 'edge_size', 'texture_index', - 'sphia_texture_index', - 'sphia_mode', + 'sphere_texture_index', + 'sphere_mode', 'toon_sharing_flag', 'toon_texture_index', 'comment', - 'index_count', + 'vertex_count', ] def __init__(self, - name: str, - english_name: str, - diffuse_color: common.RGB, - diffuse_alpha: float, - specular_color: common.RGB, - specular_factor: float, - ambient_color: common.RGB, - flag: int, - edge_color: common.RGBA, - edge_size: float, - texture_index: int, - sphia_texture_index: int, - sphia_mode: int, - toon_sharing_flag: int + name, + english_name, + diffuse_color, + alpha, + specular_color, + specular_factor, + ambient_color, + flag, + edge_color, + edge_size, + texture_index, + sphere_texture_index, + sphere_mode, + toon_sharing_flag ): self.name=name self.english_name=english_name self.diffuse_color=diffuse_color - self.diffuse_alpha=diffuse_alpha + self.alpha=alpha self.specular_color=specular_color self.specular_factor=specular_factor self.ambient_color=ambient_color @@ -161,13 +171,39 @@ class Material(object): self.edge_color=edge_color self.edge_size=edge_size self.texture_index=texture_index - self.sphia_texture_index=sphia_texture_index - self.sphia_mode=sphia_mode + self.sphere_texture_index=sphere_texture_index + self.sphere_mode=sphere_mode self.toon_sharing_flag=toon_sharing_flag # self.toon_texture_index=None - self.comment='' - self.index_count=0 + self.comment=name.__class__() # unicode + self.vertex_count=0 + + def __eq__(self, rhs): + return ( + self.name==rhs.name + and self.english_name==rhs.english_name + and self.diffuse_color==rhs.diffuse_color + and self.alpha==rhs.alpha + and self.specular_color==rhs.specular_color + and self.specular_factor==rhs.specular_factor + and self.ambient_color==rhs.ambient_color + and self.flag==rhs.flag + and self.edge_color==rhs.edge_color + and self.edge_size==rhs.edge_size + and self.texture_index==rhs.texture_index + and self.sphere_texture_index==rhs.sphere_texture_index + and self.sphere_mode==rhs.sphere_mode + and self.toon_sharing_flag==rhs.toon_sharing_flag + and self.toon_texture_index==rhs.toon_texture_index + and self.comment==rhs.comment + and self.vertex_count==rhs.vertex_count + ) + + def __str__(self): + return ("".format( + name=self.english_name + )) class Deform(object): @@ -179,9 +215,12 @@ class Bdef1(object): Attributes: see __init__ """ - __slots__=[ 'bone_index'] - def __init__(self, bone_index: int): - self.bone_index=bone_index + __slots__=[ 'index0'] + def __init__(self, index0): + self.index0=index0 + + def __eq__(self, rhs): + return self.index0==rhs.index0 class Bdef2(object): @@ -191,13 +230,20 @@ class Bdef2(object): """ __slots__=[ 'index0', 'index1', 'weight0'] def __init__(self, - index0: int, - index1: int, - weight0: float): + index0, + index1, + weight0): self.index0=index0 self.index1=index1 self.weight0=weight0 + def __eq__(self, rhs): + return ( + self.index0==rhs.index0 + and self.index1==rhs.index1 + and self.weight0==rhs.weight0 + ) + class Vertex(object): """pmx vertex @@ -206,17 +252,26 @@ class Vertex(object): """ __slots__=[ 'position', 'normal', 'uv', 'deform', 'edge_factor' ] def __init__(self, - position: common.Vector3, - normal: common.Vector3, - uv: common.Vector2, - deform: Deform, - edge_factor: float): + position, + normal, + uv, + deform, + edge_factor): self.position=position self.normal=normal self.uv=uv self.deform=deform self.edge_factor=edge_factor + def __eq__(self, rhs): + return ( + self.position==rhs.position + and self.normal==rhs.normal + and self.uv==rhs.uv + and self.deform==rhs.deform + and self.edge_factor==rhs.edge_factor + ) + class Morph(object): """pmx morph @@ -242,6 +297,15 @@ class Morph(object): self.morph_type=morph_type self.offsets=[] + def __eq__(self, rhs): + return ( + self.name==rhs.name + and self.english_name==rhs.english_name + and self.panel==rhs.panel + and self.morph_type==rhs.morph_type + and self.offsets==rhs.offsets + ) + class VerexMorphOffset(object): """pmx vertex morph offset @@ -258,6 +322,12 @@ class VerexMorphOffset(object): self.vertex_index=vertex_index self.position_offset=position_offset + def __eq__(self, rhs): + return ( + self.vertex_index==rhs.vertex_index + and self.position_offset==rhs.position_offset + ) + class DisplaySlot(object): """pmx display slot @@ -280,30 +350,13 @@ class DisplaySlot(object): self.special_flag=special_flag self.refrences=[] - -class Shape(object): - pass - - -class SphereShape(Shape): - __slots__=['radius'] - def __init__(self, radius): - self.radius=radius - - -class CapsuleShape(Shape): - __slots__=['short_radius', 'long_radius'] - def __init__(self, short_radius, long_radius): - self.short_radius=short_radius - self.long_radius=long_radius - - -class BoxShape(Shape): - __slots__=['x', 'y', 'z'] - def __init__(self, x, y, z): - self.x=x - self.y=y - self.z=z + 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 + ) class RigidBodyParam(object): @@ -331,6 +384,15 @@ class RigidBodyParam(object): self.restitution=restitution self.friction=friction + def __eq__(self, rhs): + return ( + self.mass==rhs.mass + and self.linear_damping==rhs.linear_damping + and self.angular_damping==rhs.angular_damping + and self.restitution==rhs.restitution + and self.friction==rhs.friction + ) + class RigidBody(object): """pmx rigidbody @@ -340,7 +402,7 @@ class RigidBody(object): english_name: bone_index: collision_group: - no_collision_flag: + no_collision_group: shape: param: mode: @@ -350,8 +412,11 @@ class RigidBody(object): 'english_name', 'bone_index', 'collision_group', - 'no_collision_flag', - 'shape', + 'no_collision_group', + 'shape_type', + 'shape_size', + 'shape_position', + 'shape_rotation', 'param', 'mode', ] @@ -360,7 +425,7 @@ class RigidBody(object): english_name, bone_index, collision_group, - no_collision_flag, + no_collision_group, shape_type, shape_size, shape_position, @@ -376,21 +441,29 @@ class RigidBody(object): self.english_name=english_name self.bone_index=bone_index self.collision_group=collision_group - self.no_collision_flag=no_collision_flag - if shape_type==0: - self.shape=SphereShape(shape_size.x) - elif shape_type==1: - self.shape=BoxShape(shape_size.x, shape_size.y, shape_size.z) - elif shape_type==2: - self.shape=CapsuleShape(shape_size.x, shape_size.y) - else: - raise pymeshio.common.ParseException( - "unknown shape_type: {0}".format(shape_type)) + self.no_collision_group=no_collision_group + self.shape_type=shape_type + self.shape_size=shape_size + self.shape_position=shape_position + self.shape_rotation=shape_rotation self.param=RigidBodyParam(mass, linear_damping, angular_damping, restitution, friction) self.mode=mode + def __eq__(self, rhs): + return ( + self.name==rhs.name + and self.english_name==rhs.english_name + and self.bone_index==rhs.bone_index + and self.collision_group==rhs.collision_group + and self.no_collision_group==rhs.no_collision_group + and self.shape_type==rhs.shape_type + and self.shape_size==rhs.shape_size + and self.param==rhs.param + and self.mode==rhs.mode + ) + class Joint(object): """pmx joint @@ -452,6 +525,23 @@ class Joint(object): self.spring_constant_translation=spring_constant_translation self.spring_constant_rotation=spring_constant_rotation + def __eq__(self, rhs): + return ( + self.name==rhs.name + and self.english_name==rhs.english_name + and self.joint_type==rhs.joint_type + and self.rigidbody_index_a==rhs.rigidbody_index_a + and self.rigidbody_index_b==rhs.rigidbody_index_b + and self.position==rhs.position + and self.rotation==rhs.rotation + and self.translation_limit_min==rhs.translation_limit_min + and self.translation_limit_max==rhs.translation_limit_max + and self.rotation_limit_min==rhs.rotation_limit_min + and self.rotation_limit_max==rhs.rotation_limit_max + and self.spring_constant_translation==rhs.spring_constant_translation + and self.spring_constant_rotation==rhs.spring_constant_rotation + ) + class Model(object): """pmx data representation @@ -498,6 +588,33 @@ class Model(object): self.textures=[] self.materials=[] self.bones=[] + self.morphs=[] + self.display_slots=[] self.rigidbodies=[] self.joints=[] + def __str__(self): + return (''.format( + version=self.version, + name=self.english_name, + vertices=len(self.vertices) + )) + + def __eq__(self, rhs): + return ( + self.version==rhs.version + and self.name==rhs.name + and self.english_name==rhs.english_name + and self.comment==rhs.comment + and self.english_comment==rhs.english_comment + and self.vertices==rhs.vertices + and self.indices==rhs.indices + and self.textures==rhs.textures + and self.materials==rhs.materials + and self.bones==rhs.bones + and self.morphs==rhs.morphs + and self.display_slots==rhs.display_slots + and self.rigidbodies==rhs.rigidbodies + and self.joints==rhs.joints + ) +