• R/O
  • HTTP
  • SSH
  • HTTPS

pymeshio: Commit

pmdとmqoの入出力ライブラリと、それを使ったBlender2.5向けのaddon。


Commit MetaInfo

Revision5e1fa9276d1c5d19038bd400de3250ac3ead8a52 (tree)
Time2011-10-12 11:35:52
Authorousttrue <ousttrue@gmai...>
Commiterousttrue

Log Message

fix relative import

Change Summary

Incremental Difference

--- a/pymeshio/pmx/__init__.py
+++ b/pymeshio/pmx/__init__.py
@@ -26,7 +26,7 @@ __versioon__="1.0.0"
2626 import io
2727 import os
2828 import struct
29-from pymeshio import common
29+from .. import common
3030
3131
3232
--- a/pymeshio/pmx/reader.py
+++ b/pymeshio/pmx/reader.py
@@ -3,11 +3,11 @@
33 pmx reader
44 """
55 import io
6-import pymeshio.common
7-import pymeshio.pmx
6+from .. import common
7+from .. import pmx
88
99
10-class Reader(pymeshio.common.BinaryReader):
10+class Reader(common.BinaryReader):
1111 """pmx reader
1212 """
1313 def __init__(self, ios,
@@ -23,7 +23,7 @@ class Reader(pymeshio.common.BinaryReader):
2323 super(Reader, self).__init__(ios)
2424 self.read_text=self.get_read_text(text_encoding)
2525 if extended_uv>0:
26- raise pymeshio.common.ParseException(
26+ raise common.ParseException(
2727 "extended uv is not supported", extended_uv)
2828 self.read_vertex_index=lambda : self.read_int(vertex_index_size)
2929 self.read_texture_index=lambda : self.read_int(texture_index_size)
@@ -33,7 +33,7 @@ class Reader(pymeshio.common.BinaryReader):
3333 self.read_rigidbody_index=lambda : self.read_int(rigidbody_index_size)
3434
3535 def __str__(self):
36- return '<pymeshio.pmx.Reader>'
36+ return '<pmx.Reader>'
3737
3838 def get_read_text(self, text_encoding):
3939 if text_encoding==0:
@@ -50,7 +50,7 @@ class Reader(pymeshio.common.BinaryReader):
5050 print("unknown text encoding", text_encoding)
5151
5252 def read_vertex(self):
53- return pymeshio.pmx.Vertex(
53+ return pmx.Vertex(
5454 self.read_vector3(), # pos
5555 self.read_vector3(), # normal
5656 self.read_vector2(), # uv
@@ -61,23 +61,23 @@ class Reader(pymeshio.common.BinaryReader):
6161 def read_deform(self):
6262 deform_type=self.read_int(1)
6363 if deform_type==0:
64- return pymeshio.pmx.Bdef1(self.read_bone_index())
64+ return pmx.Bdef1(self.read_bone_index())
6565 elif deform_type==1:
66- return pymeshio.pmx.Bdef2(
66+ return pmx.Bdef2(
6767 self.read_bone_index(),
6868 self.read_bone_index(),
6969 self.read_float()
7070 )
7171 elif deform_type==2:
7272 # todo
73- raise pymeshio.common.ParseException(
73+ raise common.ParseException(
7474 "not implemented Bdef4")
7575 else:
76- raise pymeshio.common.ParseException(
76+ raise common.ParseException(
7777 "unknown deform type: {0}".format(deform_type))
7878
7979 def read_material(self):
80- material=pymeshio.pmx.Material(
80+ material=pmx.Material(
8181 name=self.read_text(),
8282 english_name=self.read_text(),
8383 diffuse_color=self.read_rgb(),
@@ -98,7 +98,7 @@ class Reader(pymeshio.common.BinaryReader):
9898 elif material.toon_sharing_flag==1:
9999 material.toon_texture_index=self.read_int(1)
100100 else:
101- raise pymeshio.common.ParseException(
101+ raise common.ParseException(
102102 "unknown toon_sharing_flag {0}".format(
103103 material.toon_sharing_flag))
104104 material.comment=self.read_text()
@@ -106,7 +106,7 @@ class Reader(pymeshio.common.BinaryReader):
106106 return material
107107
108108 def read_bone(self):
109- bone=pymeshio.pmx.Bone(
109+ bone=pmx.Bone(
110110 name=self.read_text(),
111111 english_name=self.read_text(),
112112 position=self.read_vector3(),
@@ -119,7 +119,7 @@ class Reader(pymeshio.common.BinaryReader):
119119 elif bone.getConnectionFlag()==1:
120120 bone.tail_index=self.read_bone_index()
121121 else:
122- raise pymeshio.common.ParseException(
122+ raise common.ParseException(
123123 "unknown bone conenction flag: {0}".format(
124124 bone.getConnectionFlag()))
125125
@@ -143,7 +143,7 @@ class Reader(pymeshio.common.BinaryReader):
143143 return bone
144144
145145 def read_ik(self):
146- ik=pymeshio.pmx.Ik(
146+ ik=pmx.Ik(
147147 target_index=self.read_bone_index(),
148148 loop=self.read_int(4),
149149 limit_radian=self.read_float())
@@ -153,7 +153,7 @@ class Reader(pymeshio.common.BinaryReader):
153153 return ik
154154
155155 def read_ik_link(self):
156- link=pymeshio.pmx.IkLink(
156+ link=pmx.IkLink(
157157 self.read_bone_index(),
158158 self.read_int(1))
159159 if link.limit_angle==0:
@@ -162,7 +162,7 @@ class Reader(pymeshio.common.BinaryReader):
162162 link.limit_min=self.read_vector3()
163163 link.limit_max=self.read_vector3()
164164 else:
165- raise pymeshio.common.ParseException(
165+ raise common.ParseException(
166166 "invalid ik link limit_angle: {0}".format(
167167 link.limit_angle))
168168 return link
@@ -175,52 +175,52 @@ class Reader(pymeshio.common.BinaryReader):
175175 offset_size=self.read_int(4)
176176 if morph_type==0:
177177 # todo
178- raise pymeshio.common.ParseException(
178+ raise common.ParseException(
179179 "not implemented GroupMorph")
180180 elif morph_type==1:
181- morph=pymeshio.pmx.Morph(name, english_name,
181+ morph=pmx.Morph(name, english_name,
182182 panel, morph_type)
183183 morph.offsets=[self.read_vertex_morph_offset()
184184 for _ in range(offset_size)]
185185 return morph
186186 elif morph_type==2:
187187 # todo
188- raise pymeshio.common.ParseException(
188+ raise common.ParseException(
189189 "not implemented BoneMorph")
190190 elif morph_type==3:
191191 # todo
192- raise pymeshio.common.ParseException(
192+ raise common.ParseException(
193193 "not implemented UvMorph")
194194 elif morph_type==4:
195195 # todo
196- raise pymeshio.common.ParseException(
196+ raise common.ParseException(
197197 "not implemented extended UvMorph1")
198198 elif morph_type==5:
199199 # todo
200- raise pymeshio.common.ParseException(
200+ raise common.ParseException(
201201 "not implemented extended UvMorph2")
202202 elif morph_type==6:
203203 # todo
204- raise pymeshio.common.ParseException(
204+ raise common.ParseException(
205205 "not implemented extended UvMorph3")
206206 elif morph_type==7:
207207 # todo
208- raise pymeshio.common.ParseException(
208+ raise common.ParseException(
209209 "not implemented extended UvMorph4")
210210 elif morph_type==8:
211211 # todo
212- raise pymeshio.common.ParseException(
212+ raise common.ParseException(
213213 "not implemented extended MaterialMorph")
214214 else:
215- raise pymeshio.common.ParseException(
215+ raise common.ParseException(
216216 "unknown morph type: {0}".format(morph_type))
217217
218218 def read_vertex_morph_offset(self):
219- return pymeshio.pmx.VerexMorphOffset(
219+ return pmx.VerexMorphOffset(
220220 self.read_vertex_index(), self.read_vector3())
221221
222222 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(),
224224 self.read_int(1))
225225 display_count=self.read_int(4)
226226 for _ in range(display_count):
@@ -232,12 +232,12 @@ class Reader(pymeshio.common.BinaryReader):
232232 display_slot.refrences.append(
233233 (display_type, self.read_morph_index()))
234234 else:
235- raise pymeshio.common.ParseException(
235+ raise common.ParseException(
236236 "unknown display_type: {0}".format(display_type))
237237 return display_slot
238238
239239 def read_rigidbody(self):
240- return pymeshio.pmx.RigidBody(
240+ return pmx.RigidBody(
241241 name=self.read_text(),
242242 english_name=self.read_text(),
243243 bone_index=self.read_bone_index(),
@@ -256,7 +256,7 @@ class Reader(pymeshio.common.BinaryReader):
256256 )
257257
258258 def read_joint(self):
259- return pymeshio.pmx.Joint(
259+ return pmx.Joint(
260260 name=self.read_text(),
261261 english_name=self.read_text(),
262262 joint_type=self.read_int(1),
@@ -274,55 +274,55 @@ class Reader(pymeshio.common.BinaryReader):
274274
275275 def read_from_file(path):
276276 """
277- read from file path, then return the pymeshio.pmx.Model.
277+ read from file path, then return the pmx.Model.
278278
279279 :Parameters:
280280 path
281281 file path
282282
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')
285285 >>> print(m)
286286 <pmx-2.0 "Miku Hatsune" 12354vertices>
287287
288288 """
289- pmx=read(io.BytesIO(pymeshio.common.readall(path)))
289+ pmx=read(io.BytesIO(common.readall(path)))
290290 pmx.path=path
291291 return pmx
292292
293293
294294 def read(ios):
295295 """
296- read from ios, then return the pmx pymeshio.pmx.Model.
296+ read from ios, then return the pmx pmx.Model.
297297
298298 :Parameters:
299299 ios
300300 input stream (in io.IOBase)
301301
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'))
304304 >>> print(m)
305305 <pmx-2.0 "Miku Hatsune" 12354vertices>
306306
307307 """
308308 assert(isinstance(ios, io.IOBase))
309- reader=pymeshio.common.BinaryReader(ios)
309+ reader=common.BinaryReader(ios)
310310
311311 # header
312312 signature=reader.unpack("4s", 4)
313313 if signature!=b"PMX ":
314- raise pymeshio.common.ParseException(
314+ raise common.ParseException(
315315 "invalid signature", signature)
316316
317317 version=reader.read_float()
318318 if version!=2.0:
319319 print("unknown version", version)
320- model=pymeshio.pmx.Model(version)
320+ model=pmx.Model(version)
321321
322322 # flags
323323 flag_bytes=reader.read_int(1)
324324 if flag_bytes!=8:
325- raise pymeshio.common.ParseException(
325+ raise common.ParseException(
326326 "invalid flag length", reader.flag_bytes)
327327 text_encoding=reader.read_int(1)
328328 extended_uv=reader.read_int(1)
Show on old repository browser