4 http://blog.goo.ne.jp/torisu_tetosuki/e/209ad341d3ece2b1b4df24abf619d6e4
10 import pymeshio.common
22 weight0: bone0 influence
25 __slots__=['pos', 'normal', 'uv', 'bone0', 'bone1', 'weight0', 'edge_flag']
26 def __init__(self, pos, normal, uv,
27 bone0, bone1, weight0, edge_flag):
34 self.edge_flag=edge_flag
37 return "<%s %s %s, (%d, %d, %d)>" % (
41 self.bone0, self.bone1, self.weight0)
43 def __getitem__(self, key):
54 class Material(object):
55 """pmd material struct.
60 specular_factor: float
65 vertex_count: indices length
66 texture_file: texture file path
69 'diffuse_color', 'alpha',
70 'specular_factor', 'specular_color', 'ambient_color',
71 'toon_index', 'edge_flag',
72 'vertex_count', 'texture_file',
74 def __init__(self, diffuse_color, alpha,
75 specular_factor, specular_color, ambient_color,
76 toon_index, edge_flag, vertex_count, texture_file):
77 self.diffuse_color=diffuse_color
79 self.specular_factor=specular_factor
80 self.specular_color=specular_color
81 self.ambient_color=ambient_color
82 self.toon_index=toon_index
83 self.edge_flag=edge_flag
84 self.vertex_count=vertex_count
85 self.texture_file=texture_file
88 return "<Material [%f, %f, %f, %f]>" % (
89 self.diffuse[0], self.diffuse[1],
90 self.diffuse[2], self.diffuse[3],
95 """pmd material struct.
123 __slots__=['name', 'index', 'type', 'parent', 'ik', 'pos',
124 'children', 'english_name', 'ik_index',
125 'parent_index', 'tail_index', 'tail',
127 def __init__(self, name=b'bone', type=0):
131 self.parent_index=0xFFFF
133 self.tail=pymeshio.common.Vector3(0, 0, 0)
136 self.pos=pymeshio.common.Vector3(0, 0, 0)
141 return self.parent_index!=0xFFFF
144 return self.tail_index!=0
146 def display(self, indent=[]):
149 for i, is_end in enumerate(indent):
153 prefix+=' ' if is_end else ' |'
154 uni='%s +%s(%s)' % (prefix, unicode(self), self.english_name)
155 print(uni.encode(ENCODING))
157 uni='%s(%s)' % (unicode(self), self.english_name)
158 print(uni.encode(ENCODING))
160 child_count=len(self.children)
161 for i in range(child_count):
162 child=self.children[i]
164 child.display(indent+[False])
167 child.display(indent+[True])
170 class Bone_Rotate(Bone):
172 def __init__(self, name):
173 super(Bone_Rotate, self).__init__(name, 0)
175 return '<ROTATE %s>' % (self.name)
177 class Bone_RotateMove(Bone):
179 def __init__(self, name):
180 super(Bone_RotateMove, self).__init__(name, 1)
182 return '<ROTATE_MOVE %s>' % (self.name)
186 def __init__(self, name):
187 super(Bone_IK, self).__init__(name, 2)
189 return '<IK %s>' % (self.name)
191 class Bone_IKRotateInfl(Bone):
193 def __init__(self, name):
194 super(Bone_IKRotateInfl, self).__init__(name, 4)
196 return '<IK_ROTATE_INFL %s>' % (self.name)
198 class Bone_RotateInfl(Bone):
200 def __init__(self, name):
201 super(Bone_RotateInfl, self).__init__(name, 5)
203 return '<ROTATE_INFL %s>' % (self.name)
205 class Bone_IKTarget(Bone):
207 def __init__(self, name):
208 super(Bone_IKTarget, self).__init__(name, 6)
210 return '<IK_TARGET %s>' % (self.name)
212 class Bone_Unvisible(Bone):
214 def __init__(self, name):
215 super(Bone_Unvisible, self).__init__(name, 7)
217 return '<UNVISIBLE %s>' % (self.name)
219 class Bone_Rolling(Bone):
221 def __init__(self, name):
222 super(Bone_Rolling, self).__init__(name, 8)
224 return '<ROLLING %s>' % (self.name)
226 class Bone_Tweak(Bone):
228 def __init__(self, name):
229 super(Bone_Tweak, self).__init__(name, 9)
231 return '<TWEAK %s>' % (self.name)
234 def createBone(name, type):
236 return Bone_Rotate(name)
238 return Bone_RotateMove(name)
242 raise Exception("no used bone type: 3(%s)" % name)
244 return Bone_IKRotateInfl(name)
246 return Bone_RotateInfl(name)
248 return Bone_IKTarget(name)
250 return Bone_Unvisible(name)
252 return Bone_Rolling(name)
254 return Bone_Tweak(name)
256 raise Exception("unknown bone type: %d(%s)", type, name)
260 __slots__=['index', 'target', 'iterations', 'weight', 'length', 'children']
261 def __init__(self, index=0, target=0):
269 return "<IK index: %d, target: %d, iterations: %d, weight: %f, children: %s(%d)>" %(self.index, self.target, self.iterations, self.weight, '-'.join([str(i) for i in self.children]), len(self.children))
273 __slots__=['name', 'type', 'indices', 'pos_list', 'english_name',
275 def __init__(self, name='skin'):
283 def append(self, index, x, y, z):
284 self.indices.append(index)
285 self.pos_list.append(Vector3(x, y, z))
288 return '<Skin name: "%s", type: %d, vertex: %d>' % (
289 self.name, self.type, len(self.indices))
292 class BoneGroup(object):
293 __slots__=['_name', '_english_name']
294 def __init__(self, name='group'): self._name=name; self._english_name='center'
301 RIGIDBODY_KINEMATICS=0
303 RIGIDBODY_PHYSICS_WITH_BONE=2
306 class RigidBody(object):
310 'no_collision_group',
322 def __init__(self, name,
338 self.bone_index=bone_index
339 self.collision_group=collision_group
340 self.no_collision_group=no_collision_group
341 self.shape_type=shape_type
342 self.shape_size=shape_size
343 self.shape_position=shape_position
344 self.shape_rotation=shape_rotation
346 self.linear_damping=linear_damping
347 self.angular_damping=angular_damping
348 self.restitution=restitution
349 self.friction=friction
354 __slots__=[ 'name', 'rigidbody_index_a', 'rigidbody_index_b',
355 'position', 'rotation',
356 'translation_limit_max', 'translation_limit_min',
357 'rotation_limit_max', 'rotation_limit_min',
358 'spring_constant_translation', 'spring_constant_rotation',
360 def __init__(self, name,
361 rigidbody_index_a, rigidbody_index_b,
363 translation_limit_max, translation_limit_min,
364 rotation_limit_max, rotation_limit_min,
365 spring_constant_translation, spring_constant_rotation
368 self.rigidbody_index_a=rigidbody_index_a
369 self.rigidbody_index_b=rigidbody_index_b
370 self.position=position
371 self.rotation=rotation
372 self.translation_limit_max=translation_limit_max
373 self.translation_limit_min=translation_limit_min
374 self.rotation_limit_max=rotation_limit_max
375 self.rotation_limit_min=rotation_limit_min
376 self.spring_constant_translation=spring_constant_translation
377 self.spring_constant_rotation=spring_constant_rotation
380 class ToonTextures(object):
381 __slots__=['_toon_textures']
383 self._toon_textures=[]
385 self._toon_textures.append('toon%02d.bmp' % (i+1))
387 def __getitem__(self, key):
388 return from_str(self._toon_textures[key])
390 def __setitem__(self, key, value):
391 self._toon_textures[key]=to_str(value)
394 for toon_texture in self._toon_textures:
395 yield from_str(toon_texture)
406 version: pmd version number
410 'version', 'name', 'comment',
411 'english_name', 'english_comment',
412 'vertices', 'indices', 'materials', 'bones',
414 'morph_indices', 'bone_group_list', 'bone_display_list',
417 'rigidbodies', 'joints',
419 def __init__(self, version):
423 self.english_name=b''
424 self.english_comment=b''
431 self.morph_indices=[]
432 self.bone_group_list=[]
433 self.bone_display_list=[]
435 self.toon_textures=ToonTextures()
439 self.no_parent_bones=[]
441 def each_vertex(self): return self.vertices
442 def getUV(self, i): return self.vertices[i].uv
445 return '<PMDLoader version: %g, model: "%s", vertex: %d, face: %d, material: %d, bone: %d ik: %d, skin: %d>' % (
446 self.version, self.name, len(self.vertices), len(self.indices),
447 len(self.materials), len(self.bones), len(self.ik_list), len(self.morph_list))
454 def read(self, path):
455 warnings.warn("'pymeshio.mqo.IO.read' will be replaced by 'pymeshio.mqo.loader.load'")
456 model=pymeshio.pmd.loader.load(path)