#!/usr/bin/env python\r
# coding: utf-8\r
"""\r
-pmx file io library.\r
+========================\r
+MikuMikuDance PMX format\r
+========================\r
+\r
+file format\r
+~~~~~~~~~~~\r
+* PMDEditor's Lib/PMX仕様/PMX仕様.txt\r
+\r
+specs\r
+~~~~~\r
+* textencoding: unicode\r
+* coordinate: left handed y-up(DirectX)\r
+* uv origin: \r
+* face: only triangle\r
+* backculling: \r
\r
-pmx file format:\r
- PMDEditor's Lib/PMX仕様/PMX仕様.txt\r
"""\r
__author__="ousttrue"\r
__license__="zlib"\r
'ik',\r
]\r
def __init__(self,\r
- name: str,\r
- english_name: str,\r
- position: common.Vector3,\r
- parent_index: int,\r
- layer: int,\r
- flag: int\r
+ name,\r
+ english_name,\r
+ position,\r
+ parent_index,\r
+ layer,\r
+ flag\r
):\r
- self.name=name,\r
+ self.name=name\r
self.english_name=english_name\r
self.position=position\r
self.parent_index=parent_index\r
self.layer=layer\r
self.flag=flag\r
\r
- def getConnectionFlag(self) -> int:\r
+ def __eq__(self, rhs):\r
+ return (\r
+ self.name==rhs.name\r
+ and self.english_name==rhs.english_name\r
+ and self.position==rhs.position\r
+ and self.parent_index==rhs.parent_index\r
+ and self.layer==rhs.layer\r
+ and self.flag==rhs.flag\r
+ )\r
+\r
+ def getConnectionFlag(self):\r
return self.flag & 0x0001\r
\r
- def getIkFlag(self) -> int:\r
+ def getIkFlag(self):\r
return (self.flag & 0x0020) >> 5\r
\r
- def getRotationFlag(self) -> int:\r
+ def getRotationFlag(self):\r
return (self.flag & 0x0100) >> 8\r
\r
- def getTranslationFlag(self) -> int:\r
+ def getTranslationFlag(self):\r
return (self.flag & 0x0200) >> 9\r
\r
- def getFixedAxisFlag(self) -> int:\r
+ def getFixedAxisFlag(self):\r
return (self.flag & 0x0400) >> 10\r
\r
- def getLocalCoordinateFlag(self) -> int:\r
+ def getLocalCoordinateFlag(self):\r
return (self.flag & 0x0800) >> 11\r
\r
- def getExternalParentDeformFlag(self) -> int:\r
+ def getExternalParentDeformFlag(self):\r
return (self.flag & 0x2000) >> 13\r
\r
\r
'name',\r
'english_name',\r
'diffuse_color',\r
- 'diffuse_alpha',\r
+ 'alpha',\r
'specular_color',\r
'specular_factor',\r
'ambient_color',\r
'edge_color',\r
'edge_size',\r
'texture_index',\r
- 'sphia_texture_index',\r
- 'sphia_mode',\r
+ 'sphere_texture_index',\r
+ 'sphere_mode',\r
'toon_sharing_flag',\r
'toon_texture_index',\r
'comment',\r
- 'index_count',\r
+ 'vertex_count',\r
]\r
def __init__(self,\r
- name: str,\r
- english_name: str,\r
- diffuse_color: common.RGB,\r
- diffuse_alpha: float,\r
- specular_color: common.RGB,\r
- specular_factor: float,\r
- ambient_color: common.RGB,\r
- flag: int,\r
- edge_color: common.RGBA,\r
- edge_size: float,\r
- texture_index: int,\r
- sphia_texture_index: int,\r
- sphia_mode: int,\r
- toon_sharing_flag: int\r
+ name,\r
+ english_name,\r
+ diffuse_color,\r
+ alpha,\r
+ specular_color,\r
+ specular_factor,\r
+ ambient_color,\r
+ flag,\r
+ edge_color,\r
+ edge_size,\r
+ texture_index,\r
+ sphere_texture_index,\r
+ sphere_mode,\r
+ toon_sharing_flag\r
):\r
self.name=name\r
self.english_name=english_name\r
self.diffuse_color=diffuse_color\r
- self.diffuse_alpha=diffuse_alpha\r
+ self.alpha=alpha\r
self.specular_color=specular_color\r
self.specular_factor=specular_factor\r
self.ambient_color=ambient_color\r
self.edge_color=edge_color\r
self.edge_size=edge_size\r
self.texture_index=texture_index\r
- self.sphia_texture_index=sphia_texture_index\r
- self.sphia_mode=sphia_mode\r
+ self.sphere_texture_index=sphere_texture_index\r
+ self.sphere_mode=sphere_mode\r
self.toon_sharing_flag=toon_sharing_flag\r
#\r
self.toon_texture_index=None\r
- self.comment=''\r
- self.index_count=0\r
+ self.comment=name.__class__() # unicode\r
+ self.vertex_count=0\r
+\r
+ def __eq__(self, rhs):\r
+ return (\r
+ self.name==rhs.name\r
+ and self.english_name==rhs.english_name\r
+ and self.diffuse_color==rhs.diffuse_color\r
+ and self.alpha==rhs.alpha\r
+ and self.specular_color==rhs.specular_color\r
+ and self.specular_factor==rhs.specular_factor\r
+ and self.ambient_color==rhs.ambient_color\r
+ and self.flag==rhs.flag\r
+ and self.edge_color==rhs.edge_color\r
+ and self.edge_size==rhs.edge_size\r
+ and self.texture_index==rhs.texture_index\r
+ and self.sphere_texture_index==rhs.sphere_texture_index\r
+ and self.sphere_mode==rhs.sphere_mode\r
+ and self.toon_sharing_flag==rhs.toon_sharing_flag\r
+ and self.toon_texture_index==rhs.toon_texture_index\r
+ and self.comment==rhs.comment\r
+ and self.vertex_count==rhs.vertex_count\r
+ )\r
+\r
+ def __str__(self):\r
+ return ("<pmx.Material {name}>".format(\r
+ name=self.english_name\r
+ ))\r
\r
\r
class Deform(object):\r
\r
Attributes: see __init__\r
"""\r
- __slots__=[ 'bone_index']\r
- def __init__(self, bone_index: int):\r
- self.bone_index=bone_index\r
+ __slots__=[ 'index0']\r
+ def __init__(self, index0):\r
+ self.index0=index0\r
+\r
+ def __eq__(self, rhs):\r
+ return self.index0==rhs.index0\r
\r
\r
class Bdef2(object):\r
"""\r
__slots__=[ 'index0', 'index1', 'weight0']\r
def __init__(self, \r
- index0: int,\r
- index1: int,\r
- weight0: float):\r
+ index0,\r
+ index1,\r
+ weight0):\r
self.index0=index0\r
self.index1=index1\r
self.weight0=weight0\r
\r
+ def __eq__(self, rhs):\r
+ return (\r
+ self.index0==rhs.index0\r
+ and self.index1==rhs.index1\r
+ and self.weight0==rhs.weight0\r
+ )\r
+\r
\r
class Vertex(object):\r
"""pmx vertex\r
"""\r
__slots__=[ 'position', 'normal', 'uv', 'deform', 'edge_factor' ]\r
def __init__(self, \r
- position: common.Vector3, \r
- normal: common.Vector3, \r
- uv: common.Vector2, \r
- deform: Deform, \r
- edge_factor: float):\r
+ position, \r
+ normal, \r
+ uv, \r
+ deform, \r
+ edge_factor):\r
self.position=position \r
self.normal=normal\r
self.uv=uv\r
self.deform=deform\r
self.edge_factor=edge_factor\r
\r
+ def __eq__(self, rhs):\r
+ return (\r
+ self.position==rhs.position\r
+ and self.normal==rhs.normal\r
+ and self.uv==rhs.uv\r
+ and self.deform==rhs.deform\r
+ and self.edge_factor==rhs.edge_factor\r
+ )\r
+\r
+\r
+class Morph(object):\r
+ """pmx morph\r
+\r
+ Attributes:\r
+ name: \r
+ english_name: \r
+ panel:\r
+ morph_type:\r
+ offsets:\r
+ """\r
+ __slots__=[\r
+ 'name',\r
+ 'english_name',\r
+ 'panel',\r
+ 'morph_type',\r
+ 'offsets',\r
+ ]\r
+ def __init__(self, name, english_name, panel, morph_type):\r
+ self.name=name\r
+ self.english_name=english_name\r
+ self.panel=panel\r
+ self.morph_type=morph_type\r
+ self.offsets=[]\r
+\r
+ def __eq__(self, rhs):\r
+ return (\r
+ self.name==rhs.name\r
+ and self.english_name==rhs.english_name\r
+ and self.panel==rhs.panel\r
+ and self.morph_type==rhs.morph_type\r
+ and self.offsets==rhs.offsets\r
+ )\r
+\r
+\r
+class VerexMorphOffset(object):\r
+ """pmx vertex morph offset\r
+\r
+ Attributes:\r
+ vertex_index:\r
+ position_offset: Vector3\r
+ """\r
+ __slots__=[\r
+ 'vertex_index',\r
+ 'position_offset',\r
+ ]\r
+ def __init__(self, vertex_index, position_offset):\r
+ self.vertex_index=vertex_index\r
+ self.position_offset=position_offset\r
+\r
+ def __eq__(self, rhs):\r
+ return (\r
+ self.vertex_index==rhs.vertex_index \r
+ and self.position_offset==rhs.position_offset\r
+ )\r
+\r
+\r
+class DisplaySlot(object):\r
+ """pmx display slot\r
+\r
+ Attributes:\r
+ name: \r
+ english_name: \r
+ special_flag:\r
+ refrences: list of (ref_type, ref_index)\r
+ """\r
+ __slots__=[\r
+ 'name',\r
+ 'english_name',\r
+ 'special_flag',\r
+ 'refrences',\r
+ ]\r
+ def __init__(self, name, english_name, special_flag):\r
+ self.name=name\r
+ self.english_name=english_name\r
+ self.special_flag=special_flag\r
+ self.refrences=[]\r
+\r
+ def __eq__(self, rhs):\r
+ return (\r
+ self.name==rhs.name\r
+ and self.english_name==rhs.english_name\r
+ and self.special_flag==rhs.special_flag\r
+ and self.refrences==rhs.refrences\r
+ )\r
+\r
+\r
+class RigidBodyParam(object):\r
+ """pmx rigidbody param(for bullet)\r
+\r
+ Attributes:\r
+ mass:\r
+ linear_damping:\r
+ angular_damping:\r
+ restitution:\r
+ friction:\r
+ """\r
+ __slots__=[\r
+ 'mass',\r
+ 'linear_damping',\r
+ 'angular_damping',\r
+ 'restitution',\r
+ 'friction',\r
+ ]\r
+ def __init__(self, mass, \r
+ linear_damping, angular_damping, restitution, friction):\r
+ self.mass=mass\r
+ self.linear_damping=linear_damping\r
+ self.angular_damping=angular_damping\r
+ self.restitution=restitution\r
+ self.friction=friction\r
+\r
+ def __eq__(self, rhs):\r
+ return (\r
+ self.mass==rhs.mass\r
+ and self.linear_damping==rhs.linear_damping\r
+ and self.angular_damping==rhs.angular_damping\r
+ and self.restitution==rhs.restitution\r
+ and self.friction==rhs.friction\r
+ )\r
+\r
+\r
+class RigidBody(object):\r
+ """pmx rigidbody\r
+\r
+ Attributes:\r
+ name: \r
+ english_name: \r
+ bone_index:\r
+ collision_group:\r
+ no_collision_group:\r
+ shape:\r
+ param:\r
+ mode:\r
+ """\r
+ __slots__=[\r
+ 'name',\r
+ 'english_name',\r
+ 'bone_index',\r
+ 'collision_group',\r
+ 'no_collision_group',\r
+ 'shape_type',\r
+ 'shape_size',\r
+ 'shape_position',\r
+ 'shape_rotation',\r
+ 'param',\r
+ 'mode',\r
+ ]\r
+ def __init__(self,\r
+ name,\r
+ english_name,\r
+ bone_index,\r
+ collision_group,\r
+ no_collision_group,\r
+ shape_type,\r
+ shape_size,\r
+ shape_position,\r
+ shape_rotation,\r
+ mass,\r
+ linear_damping,\r
+ angular_damping,\r
+ restitution,\r
+ friction,\r
+ mode\r
+ ):\r
+ self.name=name\r
+ self.english_name=english_name\r
+ self.bone_index=bone_index\r
+ self.collision_group=collision_group\r
+ self.no_collision_group=no_collision_group\r
+ self.shape_type=shape_type\r
+ self.shape_size=shape_size\r
+ self.shape_position=shape_position\r
+ self.shape_rotation=shape_rotation\r
+ self.param=RigidBodyParam(mass,\r
+ linear_damping, angular_damping,\r
+ restitution, friction)\r
+ self.mode=mode\r
+\r
+ def __eq__(self, rhs):\r
+ return (\r
+ self.name==rhs.name\r
+ and self.english_name==rhs.english_name\r
+ and self.bone_index==rhs.bone_index\r
+ and self.collision_group==rhs.collision_group\r
+ and self.no_collision_group==rhs.no_collision_group\r
+ and self.shape_type==rhs.shape_type\r
+ and self.shape_size==rhs.shape_size\r
+ and self.param==rhs.param\r
+ and self.mode==rhs.mode\r
+ )\r
+\r
+\r
+class Joint(object):\r
+ """pmx joint\r
+\r
+ Attributes:\r
+ name: \r
+ english_name: \r
+ joint_type:\r
+ rigidbody_index_a:\r
+ rigidbody_index_b:\r
+ position: Vector3\r
+ rotation: Vector3\r
+ translation_limit_min: Vector3\r
+ translation_limit_max: Vector3\r
+ rotation_limit_min: Vector3\r
+ rotation_limit_max: Vector3\r
+ spring_constant_translation: Vector3\r
+ spring_constant_rotation: Vector3\r
+ """\r
+ __slots__=[\r
+ 'name',\r
+ 'english_name',\r
+ 'joint_type',\r
+ 'rigidbody_index_a',\r
+ 'rigidbody_index_b',\r
+ 'position',\r
+ 'rotation',\r
+ 'translation_limit_min',\r
+ 'translation_limit_max',\r
+ 'rotation_limit_min',\r
+ 'rotation_limit_max',\r
+ 'spring_constant_translation',\r
+ 'spring_constant_rotation',\r
+ ]\r
+ def __init__(self, name, english_name,\r
+ joint_type,\r
+ rigidbody_index_a,\r
+ rigidbody_index_b,\r
+ position,\r
+ rotation,\r
+ translation_limit_min,\r
+ translation_limit_max,\r
+ rotation_limit_min,\r
+ rotation_limit_max,\r
+ spring_constant_translation,\r
+ spring_constant_rotation\r
+ ):\r
+ self.name=name\r
+ self.english_name=english_name\r
+ self.joint_type=joint_type\r
+ self.rigidbody_index_a=rigidbody_index_a\r
+ self.rigidbody_index_b=rigidbody_index_b\r
+ self.position=position\r
+ self.rotation=rotation\r
+ self.translation_limit_min=translation_limit_min\r
+ self.translation_limit_max=translation_limit_max\r
+ self.rotation_limit_min=rotation_limit_min\r
+ self.rotation_limit_max=rotation_limit_max\r
+ self.spring_constant_translation=spring_constant_translation\r
+ self.spring_constant_rotation=spring_constant_rotation\r
+\r
+ def __eq__(self, rhs):\r
+ return (\r
+ self.name==rhs.name\r
+ and self.english_name==rhs.english_name\r
+ and self.joint_type==rhs.joint_type\r
+ and self.rigidbody_index_a==rhs.rigidbody_index_a\r
+ and self.rigidbody_index_b==rhs.rigidbody_index_b\r
+ and self.position==rhs.position\r
+ and self.rotation==rhs.rotation\r
+ and self.translation_limit_min==rhs.translation_limit_min\r
+ and self.translation_limit_max==rhs.translation_limit_max\r
+ and self.rotation_limit_min==rhs.rotation_limit_min\r
+ and self.rotation_limit_max==rhs.rotation_limit_max\r
+ and self.spring_constant_translation==rhs.spring_constant_translation\r
+ and self.spring_constant_rotation==rhs.spring_constant_rotation\r
+ )\r
+\r
\r
class Model(object):\r
"""pmx data representation\r
textures:\r
materials:\r
bones:\r
+ morph:\r
+ display_slots:\r
+ rigidbodies:\r
+ joints:\r
"""\r
__slots__=[\r
'version', # pmx version\r
'textures',\r
'materials',\r
'bones',\r
+ 'morphs',\r
+ 'display_slots',\r
+ 'rigidbodies',\r
+ 'joints',\r
]\r
def __init__(self, version):\r
self.version=version\r
self.textures=[]\r
self.materials=[]\r
self.bones=[]\r
+ self.morphs=[]\r
+ self.display_slots=[]\r
+ self.rigidbodies=[]\r
+ self.joints=[]\r
+\r
+ def __str__(self):\r
+ return ('<pmx-{version} "{name}" {vertices}vertices>'.format(\r
+ version=self.version,\r
+ name=self.english_name,\r
+ vertices=len(self.vertices)\r
+ ))\r
+\r
+ def __eq__(self, rhs):\r
+ return (\r
+ self.version==rhs.version\r
+ and self.name==rhs.name\r
+ and self.english_name==rhs.english_name\r
+ and self.comment==rhs.comment\r
+ and self.english_comment==rhs.english_comment\r
+ and self.vertices==rhs.vertices\r
+ and self.indices==rhs.indices\r
+ and self.textures==rhs.textures\r
+ and self.materials==rhs.materials\r
+ and self.bones==rhs.bones\r
+ and self.morphs==rhs.morphs\r
+ and self.display_slots==rhs.display_slots\r
+ and self.rigidbodies==rhs.rigidbodies\r
+ and self.joints==rhs.joints\r
+ )\r
\r