Home | Trees | Indices | Help |
---|
|
1 # coding: utf-8 2 """ 3 pmd writer 4 """ 5 import io 6 import struct 7 from .. import common 8 from .. import pmd 9 10119 12013 self.write_uint(len(vertices), 4) 14 for v in vertices: 15 self.write_vector3(v.pos) 16 self.write_vector3(v.normal) 17 self.write_vector2(v.uv) 18 self.write_uint(v.bone0, 2) 19 self.write_uint(v.bone1, 2) 20 self.write_uint(v.weight0, 1) 21 self.write_uint(v.edge_flag, 1)22 2628 self.write_uint(len(materials), 4) 29 for m in materials: 30 self.write_rgb(m.diffuse_color) 31 self.write_float(m.alpha) 32 self.write_float(m.specular_factor) 33 self.write_rgb(m.specular_color) 34 self.write_rgb(m.ambient_color) 35 self.write_uint(m.toon_index, 1) 36 self.write_uint(m.edge_flag, 1) 37 self.write_uint(m.vertex_count, 4) 38 self.write_bytes(m.texture_file, 20)3941 self.write_uint(len(bones), 2) 42 sBone=struct.Struct("=20sHHBH3f") 43 assert(sBone.size==39) 44 for b in bones: 45 self.write_bytes(b.name, 20) 46 self.write_uint(b.parent_index, 2) 47 self.write_uint(b.tail_index, 2) 48 self.write_uint(b.type, 1) 49 self.write_uint(b.ik_index, 2) 50 self.write_vector3(b.pos)5153 self.write_uint(len(ik_list), 2) 54 for ik in ik_list: 55 self.write_uint(ik.index, 2) 56 self.write_uint(ik.target, 2) 57 self.write_uint(len(ik.children), 1) 58 self.write_uint(ik.iterations, 2) 59 self.write_float(ik.weight) 60 self.ios.write(struct.pack("=%dH" % len(ik.children), *ik.children))6163 self.write_uint(len(morphs), 2) 64 for morph in morphs: 65 self.write_bytes(morph.name, 20) 66 self.write_uint(len(morph.indices), 4) 67 self.write_uint(morph.type, 1) 68 for i, v in zip(morph.indices, morph.pos_list): 69 self.write_uint(i, 4) 70 self.write_vector3(v)7173 self.write_uint(len(morph_indices), 1) 74 self.ios.write(struct.pack("=%dH" % len(morph_indices), *morph_indices))7577 self.write_uint(len(bone_group_list), 1) 78 for g in bone_group_list: 79 self.write_bytes(g.name, 50)8082 self.write_uint(len(bone_display_list), 4) 83 for l in bone_display_list: 84 self.write_uint(l[0], 2) 85 self.write_uint(l[1], 1)8688 self.write_uint(len(rigidbodies), 4) 89 for r in rigidbodies: 90 self.write_bytes(r.name, 20) 91 self.write_int(r.bone_index, 2) 92 self.write_uint(r.collision_group, 1) 93 self.write_int(r.no_collision_group, 2) 94 self.write_uint(r.shape_type, 1) 95 self.write_vector3(r.shape_size) 96 self.write_vector3(r.shape_position) 97 self.write_vector3(r.shape_rotation) 98 self.write_float(r.mass) 99 self.write_float(r.linear_damping) 100 self.write_float(r.angular_damping) 101 self.write_float(r.restitution) 102 self.write_float(r.friction) 103 self.write_uint(r.mode, 1)104106 self.write_uint(len(joints), 4) 107 for j in joints: 108 self.write_bytes(j.name, 20) 109 self.write_uint(j.rigidbody_index_a, 4) 110 self.write_uint(j.rigidbody_index_b, 4) 111 self.write_vector3(j.position) 112 self.write_vector3(j.rotation) 113 self.write_vector3(j.translation_limit_min) 114 self.write_vector3(j.translation_limit_max) 115 self.write_vector3(j.rotation_limit_min) 116 self.write_vector3(j.rotation_limit_max) 117 self.write_vector3(j.spring_constant_translation) 118 self.write_vector3(j.spring_constant_rotation)122 """ 123 write model to ios. 124 125 :Parameters: 126 ios 127 output stream (in io.IOBase) 128 model 129 pmd model 130 131 >>> import pymeshio.pmd.writer 132 >>> pymeshio.pmd.writer.write(io.open('out.pmd', 'wb'), pmd_model) 133 134 """ 135 assert(isinstance(ios, io.IOBase)) 136 assert(isinstance(model, pmd.Model)) 137 writer=Writer(ios) 138 writer.write_bytes(b"Pmd") 139 writer.write_float(model.version) 140 writer.write_bytes(model.name, 20) 141 writer.write_bytes(model.comment, 256) 142 writer.write_veritices(model.vertices) 143 writer.write_indices(model.indices) 144 writer.write_materials(model.materials) 145 writer.write_bones(model.bones) 146 writer.write_ik_list(model.ik_list) 147 writer.write_morphs(model.morphs) 148 writer.write_morph_indices(model.morph_indices) 149 writer.write_bone_group_list(model.bone_group_list) 150 writer.write_bone_display_list(model.bone_display_list) 151 # extend data 152 writer.write_uint(1, 1) 153 writer.write_bytes(model.english_name, 20) 154 writer.write_bytes(model.english_comment, 256) 155 for bone in model.bones: 156 writer.write_bytes(bone.english_name, 20) 157 for skin in model.morphs: 158 if skin.name==b'base': 159 continue 160 writer.write_bytes(skin.english_name, 20) 161 for g in model.bone_group_list: 162 writer.write_bytes(g.english_name, 50) 163 for toon_texture in model.toon_textures: 164 writer.write_bytes(toon_texture, 100) 165 writer.write_rigidbodies(model.rigidbodies) 166 writer.write_joints(model.joints) 167 return True168
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Dec 2 06:05:54 2011 | http://epydoc.sourceforge.net |