X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=pymeshio%2Fpmx%2F__init__.py;h=42b15f6a8685d2dafff36200b3ecf0fbda84394e;hb=cf6ec3e04ee67bbe635510486475961ed32e46f2;hp=cfdf03b8751c9f82b9a56543c6de98628ca1875f;hpb=cf6a57e413e260b09d373c9a499512f8fbcdce0c;p=meshio%2Fpymeshio.git diff --git a/pymeshio/pmx/__init__.py b/pymeshio/pmx/__init__.py index cfdf03b..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,296 @@ 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 + + Attributes: + name: + english_name: + panel: + morph_type: + offsets: + """ + __slots__=[ + 'name', + 'english_name', + 'panel', + 'morph_type', + 'offsets', + ] + def __init__(self, name, english_name, panel, morph_type): + self.name=name + self.english_name=english_name + self.panel=panel + 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 + + Attributes: + vertex_index: + position_offset: Vector3 + """ + __slots__=[ + 'vertex_index', + 'position_offset', + ] + def __init__(self, vertex_index, position_offset): + 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 + + Attributes: + name: + english_name: + special_flag: + refrences: list of (ref_type, ref_index) + """ + __slots__=[ + 'name', + 'english_name', + 'special_flag', + 'refrences', + ] + def __init__(self, name, english_name, special_flag): + self.name=name + self.english_name=english_name + self.special_flag=special_flag + self.refrences=[] + + 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): + """pmx rigidbody param(for bullet) + + Attributes: + mass: + linear_damping: + angular_damping: + restitution: + friction: + """ + __slots__=[ + 'mass', + 'linear_damping', + 'angular_damping', + 'restitution', + 'friction', + ] + def __init__(self, mass, + linear_damping, angular_damping, restitution, friction): + self.mass=mass + self.linear_damping=linear_damping + self.angular_damping=angular_damping + 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 + + Attributes: + name: + english_name: + bone_index: + collision_group: + no_collision_group: + shape: + param: + mode: + """ + __slots__=[ + 'name', + 'english_name', + 'bone_index', + 'collision_group', + 'no_collision_group', + 'shape_type', + 'shape_size', + 'shape_position', + 'shape_rotation', + 'param', + 'mode', + ] + def __init__(self, + name, + english_name, + bone_index, + collision_group, + no_collision_group, + shape_type, + shape_size, + shape_position, + shape_rotation, + mass, + linear_damping, + angular_damping, + restitution, + friction, + mode + ): + self.name=name + self.english_name=english_name + self.bone_index=bone_index + self.collision_group=collision_group + 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 + + Attributes: + name: + english_name: + joint_type: + rigidbody_index_a: + rigidbody_index_b: + position: Vector3 + rotation: Vector3 + translation_limit_min: Vector3 + translation_limit_max: Vector3 + rotation_limit_min: Vector3 + rotation_limit_max: Vector3 + spring_constant_translation: Vector3 + spring_constant_rotation: Vector3 + """ + __slots__=[ + 'name', + 'english_name', + 'joint_type', + 'rigidbody_index_a', + 'rigidbody_index_b', + 'position', + 'rotation', + 'translation_limit_min', + 'translation_limit_max', + 'rotation_limit_min', + 'rotation_limit_max', + 'spring_constant_translation', + 'spring_constant_rotation', + ] + def __init__(self, name, english_name, + joint_type, + rigidbody_index_a, + rigidbody_index_b, + position, + rotation, + translation_limit_min, + translation_limit_max, + rotation_limit_min, + rotation_limit_max, + spring_constant_translation, + spring_constant_rotation + ): + self.name=name + self.english_name=english_name + self.joint_type=joint_type + self.rigidbody_index_a=rigidbody_index_a + self.rigidbody_index_b=rigidbody_index_b + self.position=position + self.rotation=rotation + self.translation_limit_min=translation_limit_min + self.translation_limit_max=translation_limit_max + self.rotation_limit_min=rotation_limit_min + self.rotation_limit_max=rotation_limit_max + 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 @@ -231,6 +556,10 @@ class Model(object): textures: materials: bones: + morph: + display_slots: + rigidbodies: + joints: """ __slots__=[ 'version', # pmx version @@ -243,6 +572,10 @@ class Model(object): 'textures', 'materials', 'bones', + 'morphs', + 'display_slots', + 'rigidbodies', + 'joints', ] def __init__(self, version): self.version=version @@ -255,4 +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 + )