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
360 RIGIDBODY_KINEMATICS=0
362 RIGIDBODY_PHYSICS_WITH_BONE=2
365 class RigidBody(object):
369 'no_collision_group',
381 def __init__(self, name,
392 shape_size=common.Vector3(),
393 shape_position=common.Vector3(),
394 shape_rotation=common.Vector3()
397 self.bone_index=bone_index
398 self.collision_group=collision_group
399 self.no_collision_group=no_collision_group
400 self.shape_type=shape_type
401 self.shape_size=shape_size
402 self.shape_position=shape_position
403 self.shape_rotation=shape_rotation
405 self.linear_damping=linear_damping
406 self.angular_damping=angular_damping
407 self.restitution=restitution
408 self.friction=friction
411 def __eq__(self, rhs):
414 and self.bone_index==rhs.bone_index
415 and self.collision_group==rhs.collision_group
416 and self.no_collision_group==rhs.no_collision_group
417 and self.shape_type==rhs.shape_type
418 and self.shape_size==rhs.shape_size
419 and self.shape_position==rhs.shape_position
420 and self.shape_rotation==rhs.shape_rotation
421 and self.mass==rhs.mass
422 and self.linear_damping==rhs.linear_damping
423 and self.angular_damping==rhs.angular_damping
424 and self.restitution==rhs.restitution
425 and self.friction==rhs.friction
426 and self.mode==rhs.mode
431 __slots__=[ 'name', 'rigidbody_index_a', 'rigidbody_index_b',
432 'position', 'rotation',
433 'translation_limit_max', 'translation_limit_min',
434 'rotation_limit_max', 'rotation_limit_min',
435 'spring_constant_translation', 'spring_constant_rotation',
437 def __init__(self, name,
438 rigidbody_index_a, rigidbody_index_b,
440 translation_limit_max, translation_limit_min,
441 rotation_limit_max, rotation_limit_min,
442 spring_constant_translation, spring_constant_rotation
445 self.rigidbody_index_a=rigidbody_index_a
446 self.rigidbody_index_b=rigidbody_index_b
447 self.position=position
448 self.rotation=rotation
449 self.translation_limit_max=translation_limit_max
450 self.translation_limit_min=translation_limit_min
451 self.rotation_limit_max=rotation_limit_max
452 self.rotation_limit_min=rotation_limit_min
453 self.spring_constant_translation=spring_constant_translation
454 self.spring_constant_rotation=spring_constant_rotation
456 def __eq__(self, rhs):
459 and self.rigidbody_index_a==rhs.rigidbody_index_a
460 and self.rigidbody_index_b==rhs.rigidbody_index_b
461 and self.position==rhs.position
462 and self.rotation==rhs.rotation
463 and self.translation_limit_max==rhs.translation_limit_max
464 and self.translation_limit_min==rhs.translation_limit_min
465 and self.rotation_limit_max==rhs.rotation_limit_max
466 and self.rotation_limit_min==rhs.rotation_limit_min
467 and self.spring_constant_translation==rhs.spring_constant_translation
468 and self.spring_constant_rotation==rhs.spring_constant_rotation
480 version: pmd version number
484 'version', 'name', 'comment',
485 'english_name', 'english_comment',
486 'vertices', 'indices', 'materials', 'bones',
488 'morph_indices', 'bone_group_list', 'bone_display_list',
490 'rigidbodies', 'joints',
494 def __init__(self, version):
498 self.english_name=b''
499 self.english_comment=b''
506 self.morph_indices=[]
507 self.bone_group_list=[]
508 self.bone_display_list=[]
510 self.toon_textures=[b'']*10
514 self.no_parent_bones=[]
516 def each_vertex(self): return self.vertices
517 def getUV(self, i): return self.vertices[i].uv
520 return '<pmd-%g, "%s" vertex: %d, face: %d, material: %d, bone: %d ik: %d, skin: %d>' % (
521 self.version, self.name, len(self.vertices), len(self.indices),
522 len(self.materials), len(self.bones), len(self.ik_list), len(self.morph_list))
524 def __eq__(self, rhs):
527 and self.comment==rhs.comment
528 and self.english_name==rhs.english_name
529 and self.english_comment==rhs.english_comment
530 and self.vertices==rhs.vertices
531 and self.indices==rhs.indices
532 and self.materials==rhs.materials
533 and self.bones==rhs.bones
534 and self.ik_list==rhs.ik_list
535 and self.morphs==rhs.morphs
536 and self.morph_indices==rhs.morph_indices
537 and self.bone_group_list==rhs.bone_group_list
538 and self.bone_display_list==rhs.bone_display_list
539 and self.toon_textures==rhs.toon_textures
540 and self.rigidbodies==rhs.rigidbodies
541 and self.joints==rhs.joints