pmdとmqoの入出力ライブラリと、それを使ったBlender2.5向けのaddon。
Revision | 5e1fa9276d1c5d19038bd400de3250ac3ead8a52 (tree) |
---|---|
Time | 2011-10-12 11:35:52 |
Author | ousttrue <ousttrue@gmai...> |
Commiter | ousttrue |
fix relative import
@@ -26,7 +26,7 @@ __versioon__="1.0.0" | ||
26 | 26 | import io |
27 | 27 | import os |
28 | 28 | import struct |
29 | -from pymeshio import common | |
29 | +from .. import common | |
30 | 30 | |
31 | 31 | |
32 | 32 |
@@ -3,11 +3,11 @@ | ||
3 | 3 | pmx reader |
4 | 4 | """ |
5 | 5 | import io |
6 | -import pymeshio.common | |
7 | -import pymeshio.pmx | |
6 | +from .. import common | |
7 | +from .. import pmx | |
8 | 8 | |
9 | 9 | |
10 | -class Reader(pymeshio.common.BinaryReader): | |
10 | +class Reader(common.BinaryReader): | |
11 | 11 | """pmx reader |
12 | 12 | """ |
13 | 13 | def __init__(self, ios, |
@@ -23,7 +23,7 @@ class Reader(pymeshio.common.BinaryReader): | ||
23 | 23 | super(Reader, self).__init__(ios) |
24 | 24 | self.read_text=self.get_read_text(text_encoding) |
25 | 25 | if extended_uv>0: |
26 | - raise pymeshio.common.ParseException( | |
26 | + raise common.ParseException( | |
27 | 27 | "extended uv is not supported", extended_uv) |
28 | 28 | self.read_vertex_index=lambda : self.read_int(vertex_index_size) |
29 | 29 | self.read_texture_index=lambda : self.read_int(texture_index_size) |
@@ -33,7 +33,7 @@ class Reader(pymeshio.common.BinaryReader): | ||
33 | 33 | self.read_rigidbody_index=lambda : self.read_int(rigidbody_index_size) |
34 | 34 | |
35 | 35 | def __str__(self): |
36 | - return '<pymeshio.pmx.Reader>' | |
36 | + return '<pmx.Reader>' | |
37 | 37 | |
38 | 38 | def get_read_text(self, text_encoding): |
39 | 39 | if text_encoding==0: |
@@ -50,7 +50,7 @@ class Reader(pymeshio.common.BinaryReader): | ||
50 | 50 | print("unknown text encoding", text_encoding) |
51 | 51 | |
52 | 52 | def read_vertex(self): |
53 | - return pymeshio.pmx.Vertex( | |
53 | + return pmx.Vertex( | |
54 | 54 | self.read_vector3(), # pos |
55 | 55 | self.read_vector3(), # normal |
56 | 56 | self.read_vector2(), # uv |
@@ -61,23 +61,23 @@ class Reader(pymeshio.common.BinaryReader): | ||
61 | 61 | def read_deform(self): |
62 | 62 | deform_type=self.read_int(1) |
63 | 63 | if deform_type==0: |
64 | - return pymeshio.pmx.Bdef1(self.read_bone_index()) | |
64 | + return pmx.Bdef1(self.read_bone_index()) | |
65 | 65 | elif deform_type==1: |
66 | - return pymeshio.pmx.Bdef2( | |
66 | + return pmx.Bdef2( | |
67 | 67 | self.read_bone_index(), |
68 | 68 | self.read_bone_index(), |
69 | 69 | self.read_float() |
70 | 70 | ) |
71 | 71 | elif deform_type==2: |
72 | 72 | # todo |
73 | - raise pymeshio.common.ParseException( | |
73 | + raise common.ParseException( | |
74 | 74 | "not implemented Bdef4") |
75 | 75 | else: |
76 | - raise pymeshio.common.ParseException( | |
76 | + raise common.ParseException( | |
77 | 77 | "unknown deform type: {0}".format(deform_type)) |
78 | 78 | |
79 | 79 | def read_material(self): |
80 | - material=pymeshio.pmx.Material( | |
80 | + material=pmx.Material( | |
81 | 81 | name=self.read_text(), |
82 | 82 | english_name=self.read_text(), |
83 | 83 | diffuse_color=self.read_rgb(), |
@@ -98,7 +98,7 @@ class Reader(pymeshio.common.BinaryReader): | ||
98 | 98 | elif material.toon_sharing_flag==1: |
99 | 99 | material.toon_texture_index=self.read_int(1) |
100 | 100 | else: |
101 | - raise pymeshio.common.ParseException( | |
101 | + raise common.ParseException( | |
102 | 102 | "unknown toon_sharing_flag {0}".format( |
103 | 103 | material.toon_sharing_flag)) |
104 | 104 | material.comment=self.read_text() |
@@ -106,7 +106,7 @@ class Reader(pymeshio.common.BinaryReader): | ||
106 | 106 | return material |
107 | 107 | |
108 | 108 | def read_bone(self): |
109 | - bone=pymeshio.pmx.Bone( | |
109 | + bone=pmx.Bone( | |
110 | 110 | name=self.read_text(), |
111 | 111 | english_name=self.read_text(), |
112 | 112 | position=self.read_vector3(), |
@@ -119,7 +119,7 @@ class Reader(pymeshio.common.BinaryReader): | ||
119 | 119 | elif bone.getConnectionFlag()==1: |
120 | 120 | bone.tail_index=self.read_bone_index() |
121 | 121 | else: |
122 | - raise pymeshio.common.ParseException( | |
122 | + raise common.ParseException( | |
123 | 123 | "unknown bone conenction flag: {0}".format( |
124 | 124 | bone.getConnectionFlag())) |
125 | 125 |
@@ -143,7 +143,7 @@ class Reader(pymeshio.common.BinaryReader): | ||
143 | 143 | return bone |
144 | 144 | |
145 | 145 | def read_ik(self): |
146 | - ik=pymeshio.pmx.Ik( | |
146 | + ik=pmx.Ik( | |
147 | 147 | target_index=self.read_bone_index(), |
148 | 148 | loop=self.read_int(4), |
149 | 149 | limit_radian=self.read_float()) |
@@ -153,7 +153,7 @@ class Reader(pymeshio.common.BinaryReader): | ||
153 | 153 | return ik |
154 | 154 | |
155 | 155 | def read_ik_link(self): |
156 | - link=pymeshio.pmx.IkLink( | |
156 | + link=pmx.IkLink( | |
157 | 157 | self.read_bone_index(), |
158 | 158 | self.read_int(1)) |
159 | 159 | if link.limit_angle==0: |
@@ -162,7 +162,7 @@ class Reader(pymeshio.common.BinaryReader): | ||
162 | 162 | link.limit_min=self.read_vector3() |
163 | 163 | link.limit_max=self.read_vector3() |
164 | 164 | else: |
165 | - raise pymeshio.common.ParseException( | |
165 | + raise common.ParseException( | |
166 | 166 | "invalid ik link limit_angle: {0}".format( |
167 | 167 | link.limit_angle)) |
168 | 168 | return link |
@@ -175,52 +175,52 @@ class Reader(pymeshio.common.BinaryReader): | ||
175 | 175 | offset_size=self.read_int(4) |
176 | 176 | if morph_type==0: |
177 | 177 | # todo |
178 | - raise pymeshio.common.ParseException( | |
178 | + raise common.ParseException( | |
179 | 179 | "not implemented GroupMorph") |
180 | 180 | elif morph_type==1: |
181 | - morph=pymeshio.pmx.Morph(name, english_name, | |
181 | + morph=pmx.Morph(name, english_name, | |
182 | 182 | panel, morph_type) |
183 | 183 | morph.offsets=[self.read_vertex_morph_offset() |
184 | 184 | for _ in range(offset_size)] |
185 | 185 | return morph |
186 | 186 | elif morph_type==2: |
187 | 187 | # todo |
188 | - raise pymeshio.common.ParseException( | |
188 | + raise common.ParseException( | |
189 | 189 | "not implemented BoneMorph") |
190 | 190 | elif morph_type==3: |
191 | 191 | # todo |
192 | - raise pymeshio.common.ParseException( | |
192 | + raise common.ParseException( | |
193 | 193 | "not implemented UvMorph") |
194 | 194 | elif morph_type==4: |
195 | 195 | # todo |
196 | - raise pymeshio.common.ParseException( | |
196 | + raise common.ParseException( | |
197 | 197 | "not implemented extended UvMorph1") |
198 | 198 | elif morph_type==5: |
199 | 199 | # todo |
200 | - raise pymeshio.common.ParseException( | |
200 | + raise common.ParseException( | |
201 | 201 | "not implemented extended UvMorph2") |
202 | 202 | elif morph_type==6: |
203 | 203 | # todo |
204 | - raise pymeshio.common.ParseException( | |
204 | + raise common.ParseException( | |
205 | 205 | "not implemented extended UvMorph3") |
206 | 206 | elif morph_type==7: |
207 | 207 | # todo |
208 | - raise pymeshio.common.ParseException( | |
208 | + raise common.ParseException( | |
209 | 209 | "not implemented extended UvMorph4") |
210 | 210 | elif morph_type==8: |
211 | 211 | # todo |
212 | - raise pymeshio.common.ParseException( | |
212 | + raise common.ParseException( | |
213 | 213 | "not implemented extended MaterialMorph") |
214 | 214 | else: |
215 | - raise pymeshio.common.ParseException( | |
215 | + raise common.ParseException( | |
216 | 216 | "unknown morph type: {0}".format(morph_type)) |
217 | 217 | |
218 | 218 | def read_vertex_morph_offset(self): |
219 | - return pymeshio.pmx.VerexMorphOffset( | |
219 | + return pmx.VerexMorphOffset( | |
220 | 220 | self.read_vertex_index(), self.read_vector3()) |
221 | 221 | |
222 | 222 | def read_display_slot(self): |
223 | - display_slot=pymeshio.pmx.DisplaySlot(self.read_text(), self.read_text(), | |
223 | + display_slot=pmx.DisplaySlot(self.read_text(), self.read_text(), | |
224 | 224 | self.read_int(1)) |
225 | 225 | display_count=self.read_int(4) |
226 | 226 | for _ in range(display_count): |
@@ -232,12 +232,12 @@ class Reader(pymeshio.common.BinaryReader): | ||
232 | 232 | display_slot.refrences.append( |
233 | 233 | (display_type, self.read_morph_index())) |
234 | 234 | else: |
235 | - raise pymeshio.common.ParseException( | |
235 | + raise common.ParseException( | |
236 | 236 | "unknown display_type: {0}".format(display_type)) |
237 | 237 | return display_slot |
238 | 238 | |
239 | 239 | def read_rigidbody(self): |
240 | - return pymeshio.pmx.RigidBody( | |
240 | + return pmx.RigidBody( | |
241 | 241 | name=self.read_text(), |
242 | 242 | english_name=self.read_text(), |
243 | 243 | bone_index=self.read_bone_index(), |
@@ -256,7 +256,7 @@ class Reader(pymeshio.common.BinaryReader): | ||
256 | 256 | ) |
257 | 257 | |
258 | 258 | def read_joint(self): |
259 | - return pymeshio.pmx.Joint( | |
259 | + return pmx.Joint( | |
260 | 260 | name=self.read_text(), |
261 | 261 | english_name=self.read_text(), |
262 | 262 | joint_type=self.read_int(1), |
@@ -274,55 +274,55 @@ class Reader(pymeshio.common.BinaryReader): | ||
274 | 274 | |
275 | 275 | def read_from_file(path): |
276 | 276 | """ |
277 | - read from file path, then return the pymeshio.pmx.Model. | |
277 | + read from file path, then return the pmx.Model. | |
278 | 278 | |
279 | 279 | :Parameters: |
280 | 280 | path |
281 | 281 | file path |
282 | 282 | |
283 | - >>> import pymeshio.pmx.reader | |
284 | - >>> m=pymeshio.pmx.reader.read_from_file('resources/初音ミクVer2.pmx') | |
283 | + >>> import pmx.reader | |
284 | + >>> m=pmx.reader.read_from_file('resources/初音ミクVer2.pmx') | |
285 | 285 | >>> print(m) |
286 | 286 | <pmx-2.0 "Miku Hatsune" 12354vertices> |
287 | 287 | |
288 | 288 | """ |
289 | - pmx=read(io.BytesIO(pymeshio.common.readall(path))) | |
289 | + pmx=read(io.BytesIO(common.readall(path))) | |
290 | 290 | pmx.path=path |
291 | 291 | return pmx |
292 | 292 | |
293 | 293 | |
294 | 294 | def read(ios): |
295 | 295 | """ |
296 | - read from ios, then return the pmx pymeshio.pmx.Model. | |
296 | + read from ios, then return the pmx pmx.Model. | |
297 | 297 | |
298 | 298 | :Parameters: |
299 | 299 | ios |
300 | 300 | input stream (in io.IOBase) |
301 | 301 | |
302 | - >>> import pymeshio.pmx.reader | |
303 | - >>> m=pymeshio.pmx.reader.read(io.open('resources/初音ミクVer2.pmx', 'rb')) | |
302 | + >>> import pmx.reader | |
303 | + >>> m=pmx.reader.read(io.open('resources/初音ミクVer2.pmx', 'rb')) | |
304 | 304 | >>> print(m) |
305 | 305 | <pmx-2.0 "Miku Hatsune" 12354vertices> |
306 | 306 | |
307 | 307 | """ |
308 | 308 | assert(isinstance(ios, io.IOBase)) |
309 | - reader=pymeshio.common.BinaryReader(ios) | |
309 | + reader=common.BinaryReader(ios) | |
310 | 310 | |
311 | 311 | # header |
312 | 312 | signature=reader.unpack("4s", 4) |
313 | 313 | if signature!=b"PMX ": |
314 | - raise pymeshio.common.ParseException( | |
314 | + raise common.ParseException( | |
315 | 315 | "invalid signature", signature) |
316 | 316 | |
317 | 317 | version=reader.read_float() |
318 | 318 | if version!=2.0: |
319 | 319 | print("unknown version", version) |
320 | - model=pymeshio.pmx.Model(version) | |
320 | + model=pmx.Model(version) | |
321 | 321 | |
322 | 322 | # flags |
323 | 323 | flag_bytes=reader.read_int(1) |
324 | 324 | if flag_bytes!=8: |
325 | - raise pymeshio.common.ParseException( | |
325 | + raise common.ParseException( | |
326 | 326 | "invalid flag length", reader.flag_bytes) |
327 | 327 | text_encoding=reader.read_int(1) |
328 | 328 | extended_uv=reader.read_int(1) |