4 http://blog.goo.ne.jp/torisu_tetosuki/e/209ad341d3ece2b1b4df24abf619d6e4
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 __eq__(self, rhs):
46 and self.normal==rhs.normal
48 and self.bone0==rhs.bone0
49 and self.bone1==rhs.bone1
50 and self.weight0==rhs.weight0
51 and self.edge_flag==rhs.edge_flag
54 def __getitem__(self, key):
65 class Material(object):
66 """pmd material struct.
71 specular_factor: float
76 vertex_count: indices length
77 texture_file: texture file path
80 'diffuse_color', 'alpha',
81 'specular_factor', 'specular_color', 'ambient_color',
82 'toon_index', 'edge_flag',
83 'vertex_count', 'texture_file',
85 def __init__(self, diffuse_color, alpha,
86 specular_factor, specular_color, ambient_color,
87 toon_index, edge_flag, vertex_count, texture_file):
88 self.diffuse_color=diffuse_color
90 self.specular_factor=specular_factor
91 self.specular_color=specular_color
92 self.ambient_color=ambient_color
93 self.toon_index=toon_index
94 self.edge_flag=edge_flag
95 self.vertex_count=vertex_count
96 self.texture_file=texture_file
99 return "<Material [%f, %f, %f, %f]>" % (
100 self.diffuse[0], self.diffuse[1],
101 self.diffuse[2], self.diffuse[3],
104 def __eq__(self, rhs):
106 self.diffuse_color==rhs.diffuse_color
107 and self.alpha==rhs.alpha
108 and self.specular_factor==rhs.specular_factor
109 and self.specular_color==rhs.specular_color
110 and self.ambient_color==rhs.ambient_color
111 and self.toon_index==rhs.toon_index
112 and self.edge_flag==rhs.edge_flag
113 and self.vertex_count==rhs.vertex_count
114 and self.texture_file==rhs.texture_file
119 """pmd material struct.
147 __slots__=['name', 'index', 'type', 'parent', 'ik', 'pos',
148 'children', 'english_name', 'ik_index',
149 'parent_index', 'tail_index', 'tail',
151 def __init__(self, name=b'bone', type=0):
155 self.parent_index=0xFFFF
157 self.tail=common.Vector3(0, 0, 0)
160 self.pos=common.Vector3(0, 0, 0)
164 def __eq__(self, rhs):
167 and self.index==rhs.index
168 and self.type==rhs.type
169 and self.parent_index==rhs.parent_index
170 and self.tail_index==rhs.tail_index
171 and self.tail==rhs.tail
172 and self.ik_index==rhs.ik_index
173 and self.pos==rhs.pos
174 and self.children==rhs.children
175 and self.english_name==rhs.english_name
179 return self.parent_index!=0xFFFF
182 return self.tail_index!=0
184 def display(self, indent=[]):
187 for i, is_end in enumerate(indent):
191 prefix+=' ' if is_end else ' |'
192 uni='%s +%s(%s)' % (prefix, unicode(self), self.english_name)
193 print(uni.encode(ENCODING))
195 uni='%s(%s)' % (unicode(self), self.english_name)
196 print(uni.encode(ENCODING))
198 child_count=len(self.children)
199 for i in range(child_count):
200 child=self.children[i]
202 child.display(indent+[False])
205 child.display(indent+[True])
208 class Bone_Rotate(Bone):
210 def __init__(self, name):
211 super(Bone_Rotate, self).__init__(name, 0)
213 return '<ROTATE %s>' % (self.name)
215 class Bone_RotateMove(Bone):
217 def __init__(self, name):
218 super(Bone_RotateMove, self).__init__(name, 1)
220 return '<ROTATE_MOVE %s>' % (self.name)
224 def __init__(self, name):
225 super(Bone_IK, self).__init__(name, 2)
227 return '<IK %s>' % (self.name)
229 class Bone_IKRotateInfl(Bone):
231 def __init__(self, name):
232 super(Bone_IKRotateInfl, self).__init__(name, 4)
234 return '<IK_ROTATE_INFL %s>' % (self.name)
236 class Bone_RotateInfl(Bone):
238 def __init__(self, name):
239 super(Bone_RotateInfl, self).__init__(name, 5)
241 return '<ROTATE_INFL %s>' % (self.name)
243 class Bone_IKTarget(Bone):
245 def __init__(self, name):
246 super(Bone_IKTarget, self).__init__(name, 6)
248 return '<IK_TARGET %s>' % (self.name)
250 class Bone_Unvisible(Bone):
252 def __init__(self, name):
253 super(Bone_Unvisible, self).__init__(name, 7)
255 return '<UNVISIBLE %s>' % (self.name)
257 class Bone_Rolling(Bone):
259 def __init__(self, name):
260 super(Bone_Rolling, self).__init__(name, 8)
262 return '<ROLLING %s>' % (self.name)
264 class Bone_Tweak(Bone):
266 def __init__(self, name):
267 super(Bone_Tweak, self).__init__(name, 9)
269 return '<TWEAK %s>' % (self.name)
272 def createBone(name, type):
274 return Bone_Rotate(name)
276 return Bone_RotateMove(name)
280 raise Exception("no used bone type: 3(%s)" % name)
282 return Bone_IKRotateInfl(name)
284 return Bone_RotateInfl(name)
286 return Bone_IKTarget(name)
288 return Bone_Unvisible(name)
290 return Bone_Rolling(name)
292 return Bone_Tweak(name)
294 raise Exception("unknown bone type: %d(%s)", type, name)
298 __slots__=['index', 'target', 'iterations', 'weight', 'length', 'children']
299 def __init__(self, index=0, target=0):
307 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))
309 def __eq__(self, rhs):
311 self.index==rhs.index
312 and self.target==rhs.target
313 and self.iterations==rhs.iterations
314 and self.weight==rhs.weight
315 and self.children==rhs.children
320 __slots__=['name', 'type', 'indices', 'pos_list', 'english_name',
322 def __init__(self, name):
330 def append(self, index, x, y, z):
331 self.indices.append(index)
332 self.pos_list.append(common.Vector3(x, y, z))
335 return '<Skin name: "%s", type: %d, vertex: %d>' % (
336 self.name, self.type, len(self.indices))
338 def __eq__(self, rhs):
341 and self.type==rhs.type
342 and self.indices==rhs.indices
343 and self.pos_list==rhs.pos_list
344 and self.english_name==rhs.english_name
345 and self.vertex_count==rhs.vertex_count
349 class BoneGroup(object):
350 __slots__=['name', 'english_name']
351 def __init__(self, name=b'group', english_name=b'center'):
353 self.english_name=english_name
355 def __eq__(self, rhs):
356 return self.name==rhs.name and self.english_name==rhs.english_name
363 RIGIDBODY_KINEMATICS=0
365 RIGIDBODY_PHYSICS_WITH_BONE=2
368 class RigidBody(object):
372 'no_collision_group',
384 def __init__(self, name,
395 shape_size=common.Vector3(),
396 shape_position=common.Vector3(),
397 shape_rotation=common.Vector3()
400 self.bone_index=bone_index
401 self.collision_group=collision_group
402 self.no_collision_group=no_collision_group
403 self.shape_type=shape_type
404 self.shape_size=shape_size
405 self.shape_position=shape_position
406 self.shape_rotation=shape_rotation
408 self.linear_damping=linear_damping
409 self.angular_damping=angular_damping
410 self.restitution=restitution
411 self.friction=friction
414 def __eq__(self, rhs):
417 and self.bone_index==rhs.bone_index
418 and self.collision_group==rhs.collision_group
419 and self.no_collision_group==rhs.no_collision_group
420 and self.shape_type==rhs.shape_type
421 and self.shape_size==rhs.shape_size
422 and self.shape_position==rhs.shape_position
423 and self.shape_rotation==rhs.shape_rotation
424 and self.mass==rhs.mass
425 and self.linear_damping==rhs.linear_damping
426 and self.angular_damping==rhs.angular_damping
427 and self.restitution==rhs.restitution
428 and self.friction==rhs.friction
429 and self.mode==rhs.mode
434 __slots__=[ 'name', 'rigidbody_index_a', 'rigidbody_index_b',
435 'position', 'rotation',
436 'translation_limit_max', 'translation_limit_min',
437 'rotation_limit_max', 'rotation_limit_min',
438 'spring_constant_translation', 'spring_constant_rotation',
440 def __init__(self, name,
441 rigidbody_index_a, rigidbody_index_b,
443 translation_limit_max, translation_limit_min,
444 rotation_limit_max, rotation_limit_min,
445 spring_constant_translation, spring_constant_rotation
448 self.rigidbody_index_a=rigidbody_index_a
449 self.rigidbody_index_b=rigidbody_index_b
450 self.position=position
451 self.rotation=rotation
452 self.translation_limit_max=translation_limit_max
453 self.translation_limit_min=translation_limit_min
454 self.rotation_limit_max=rotation_limit_max
455 self.rotation_limit_min=rotation_limit_min
456 self.spring_constant_translation=spring_constant_translation
457 self.spring_constant_rotation=spring_constant_rotation
459 def __eq__(self, rhs):
462 and self.rigidbody_index_a==rhs.rigidbody_index_a
463 and self.rigidbody_index_b==rhs.rigidbody_index_b
464 and self.position==rhs.position
465 and self.rotation==rhs.rotation
466 and self.translation_limit_max==rhs.translation_limit_max
467 and self.translation_limit_min==rhs.translation_limit_min
468 and self.rotation_limit_max==rhs.rotation_limit_max
469 and self.rotation_limit_min==rhs.rotation_limit_min
470 and self.spring_constant_translation==rhs.spring_constant_translation
471 and self.spring_constant_rotation==rhs.spring_constant_rotation
483 version: pmd version number
487 'version', 'name', 'comment',
488 'english_name', 'english_comment',
489 'vertices', 'indices', 'materials', 'bones',
491 'morph_indices', 'bone_group_list', 'bone_display_list',
493 'rigidbodies', 'joints',
497 def __init__(self, version):
501 self.english_name=b''
502 self.english_comment=b''
509 self.morph_indices=[]
510 self.bone_group_list=[]
511 self.bone_display_list=[]
513 self.toon_textures=[b'']*10
517 self.no_parent_bones=[]
519 def each_vertex(self): return self.vertices
520 def getUV(self, i): return self.vertices[i].uv
523 return '<pmd-%g, "%s" vertex: %d, face: %d, material: %d, bone: %d ik: %d, skin: %d>' % (
524 self.version, self.name, len(self.vertices), len(self.indices),
525 len(self.materials), len(self.bones), len(self.ik_list), len(self.morph_list))
527 def __eq__(self, rhs):
530 and self.comment==rhs.comment
531 and self.english_name==rhs.english_name
532 and self.english_comment==rhs.english_comment
533 and self.vertices==rhs.vertices
534 and self.indices==rhs.indices
535 and self.materials==rhs.materials
536 and self.bones==rhs.bones
537 and self.ik_list==rhs.ik_list
538 and self.morphs==rhs.morphs
539 and self.morph_indices==rhs.morph_indices
540 and self.bone_group_list==rhs.bone_group_list
541 and self.bone_display_list==rhs.bone_display_list
542 and self.toon_textures==rhs.toon_textures
543 and self.rigidbodies==rhs.rigidbodies
544 and self.joints==rhs.joints
548 if self.name!=rhs.name:
549 print(self.name, rhs.name)
551 if self.comment!=rhs.comment:
552 print(self.comment, rhs.comment)
554 if self.english_name!=rhs.english_name:
555 print(self.english_name, rhs.english_name)
557 if self.english_comment!=rhs.english_comment:
558 print(self.english_comment, rhs.english_comment)
560 if self.vertices!=rhs.vertices:
561 print(self.vertices, rhs.vertices)
563 if self.indices!=rhs.indices:
564 print(self.indices, rhs.indices)
566 if self.materials!=rhs.materials:
567 print(self.materials, rhs.materials)
569 if self.bones!=rhs.bones:
570 print(self.bones, rhs.bones)
572 if self.ik_list!=rhs.ik_list:
573 print(self.ik_list, rhs.ik_list)
575 if self.morphs!=rhs.morphs:
576 print(self.morphs, rhs.morphs)
578 if self.morph_indices!=rhs.morph_indices:
579 print(self.morph_indices, rhs.morph_indices)
581 if self.bone_group_list!=rhs.bone_group_list:
582 print(self.bone_group_list, rhs.bone_group_list)
584 if self.bone_display_list!=rhs.bone_display_list:
585 print(self.bone_display_list, rhs.bone_display_list)
587 if self.toon_textures!=rhs.toon_textures:
588 print(self.toon_textures, rhs.toon_textures)
590 if self.rigidbodies!=rhs.rigidbodies:
591 print(self.rigidbodies, rhs.rigidbodies)
593 if self.joints!=rhs.joints:
594 print(self.joints, rhs.joints)