From: ousttrue Date: Sun, 2 Oct 2011 14:07:06 +0000 (+0900) Subject: fix refactoring X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=9605a347880a8ad2809383c6851661550fc23c6b;p=meshio%2Fpymeshio.git fix refactoring --- diff --git a/blender25-meshio/__init__.pyc b/blender25-meshio/__init__.pyc deleted file mode 100644 index 24c4690..0000000 Binary files a/blender25-meshio/__init__.pyc and /dev/null differ diff --git a/examples/mqobuilder.py b/examples/mqobuilder.py index b0dcd88..abfc9c5 100644 --- a/examples/mqobuilder.py +++ b/examples/mqobuilder.py @@ -10,16 +10,15 @@ import opengl.vertexarraymap def build(path): - # load scenee t=time.time() - io=pymeshio.mqo.IO() - if not io.read(path): + model=pymeshio.mqo.reader.read_from_file(path) + if not model: return print(time.time()-t, "sec") # build basedir=os.path.dirname(path) vertexArrayMap=opengl.vertexarraymap.VertexArrayMapWithUV() - for m in io.materials: + for m in model.materials: material=opengl.material.MQOMaterial() material.rgba=(m.color.r, m.color.g, m.color.b, m.color.a) if m.tex: @@ -27,7 +26,7 @@ def build(path): material.texture=opengl.texture.Texture(texturepath) vertexArrayMap.addMaterial(material) - for o in io.objects: + for o in model.objects: # skip mikoto objects if o.name.startswith("anchor"): continue diff --git a/examples/pmdbuilder.py b/examples/pmdbuilder.py index 846c7b2..ee5361f 100644 --- a/examples/pmdbuilder.py +++ b/examples/pmdbuilder.py @@ -3,7 +3,7 @@ import time import os -import pymeshio.pmd +import pymeshio.pmd.reader import opengl.material import opengl.texture import opengl.vertexarray @@ -12,14 +12,14 @@ import opengl.vertexarray def build(path): # load scenee t=time.time() - io=pymeshio.pmd.IO() - if not io.read(path): + model=pymeshio.pmd.reader.read_from_file(path) + if not model: return print(time.time()-t, "sec") # build basedir=os.path.dirname(path) indexedVertexArray=opengl.vertexarray.IndexedVertexArray() - for v in io.vertices: + for v in model.vertices: # left-handed y-up to right-handed y-up indexedVertexArray.addVertex( (v.pos[0], v.pos[1], -v.pos[2], 1), @@ -32,18 +32,18 @@ def build(path): textureMap={} faceIndex=0 def indices(): - for i in io.indices: + for i in model.indices: yield i indexGen=indices() - for i, m in enumerate(io.materials): + for i, m in enumerate(model.materials): material=opengl.material.MQOMaterial() material.vcol=True material.rgba=( - m.diffuse[0], - m.diffuse[1], - m.diffuse[2], - m.diffuse[3]) - texturefile=m.texture.decode('cp932') + m.diffuse_color[0], + m.diffuse_color[1], + m.diffuse_color[2], + m.alpha) + texturefile=m.texture_file.decode('cp932') texturepath=os.path.join(basedir, texturefile) if os.path.isfile(texturepath): if not texturepath in textureMap: diff --git a/examples/pmxbuilder.py b/examples/pmxbuilder.py index 76f39f4..44a6907 100644 --- a/examples/pmxbuilder.py +++ b/examples/pmxbuilder.py @@ -3,16 +3,15 @@ import time import os -import pymeshio.pmx.loader +import pymeshio.pmx.reader import opengl.material import opengl.texture import opengl.vertexarray def build(path): - # load scenee t=time.time() - model=pymeshio.pmx.loader.load(path) + model=pymeshio.pmx.reader.read_from_file(path) if not model: return print(time.time()-t, "sec") diff --git a/pymeshio/mqo/__init__.py b/pymeshio/mqo/__init__.py index 45aca2e..6eeda67 100644 --- a/pymeshio/mqo/__init__.py +++ b/pymeshio/mqo/__init__.py @@ -8,7 +8,7 @@ import os import sys import math import pymeshio.common -import pymeshio.mqo.loader +import pymeshio.mqo.reader import warnings @@ -227,16 +227,3 @@ class Model(object): self.objects=[] -class IO(object): - def __init__(self): - pass - - def read(self, path): - warnings.warn("'pymeshio.mqo.IO.read' will be replaced by 'pymeshio.mqo.loader.load'") - model=pymeshio.mqo.loader.load_from_file(path) - if model: - self.has_mikoto=model.has_mikoto - self.materials=model.materials - self.objects=model.objects - return True - diff --git a/pymeshio/mqo/reader.py b/pymeshio/mqo/reader.py index b3e0919..1b7e365 100644 --- a/pymeshio/mqo/reader.py +++ b/pymeshio/mqo/reader.py @@ -20,7 +20,7 @@ class Reader(object): """ __slots__=[ "has_mikoto", - "eof", "io", "lines", + "eof", "ios", "lines", "materials", "objects", ] def __init__(self, ios): @@ -169,11 +169,12 @@ class Reader(object): def read_from_file(path): - with open(path, 'rb') as ios: - read(ios) + with io.open(path, 'rb') as ios: + return read(ios) def read(ios): + print(type(ios), ios) assert(isinstance(ios, io.IOBase)) reader=Reader(ios) model=pymeshio.mqo.Model() diff --git a/pymeshio/pmd/__init__.py b/pymeshio/pmd/__init__.py index df77c79..f6c9bb3 100644 --- a/pymeshio/pmd/__init__.py +++ b/pymeshio/pmd/__init__.py @@ -561,13 +561,3 @@ class Model(object): ) -class IO(object): - def __init__(self): - pass - - def read(self, path): - warnings.warn("'pymeshio.mqo.IO.read' will be replaced by 'pymeshio.mqo.loader.load'") - model=pymeshio.pmd.reader.read_from_file(path) - if model: - return True - diff --git a/pymeshio/pmx/reader.py b/pymeshio/pmx/reader.py index cfb228e..40358bb 100644 --- a/pymeshio/pmx/reader.py +++ b/pymeshio/pmx/reader.py @@ -301,7 +301,7 @@ def read(ios): rigidbody_index_size=reader.read_uint(1) # pmx custom reader - reader=Reader(reader.io, + reader=Reader(reader.ios, text_encoding, extended_uv, vertex_index_size, diff --git a/test/mqo_test.py b/test/mqo_test.py index cb68799..b2bbd1b 100644 --- a/test/mqo_test.py +++ b/test/mqo_test.py @@ -5,13 +5,9 @@ import sys MQO_FILE="resources/cube.mqo" -def test_old_mqo_load(): - io=pymeshio.mqo.IO() - assert io.read(MQO_FILE) def test_mqo_read(): model=pymeshio.mqo.reader.read_from_file(MQO_FILE) - print(model.materials) assert pymeshio.mqo.Model==model.__class__ assert 6==len(model.materials) assert 1==len(model.objects) diff --git a/test/mqo_test.pyc b/test/mqo_test.pyc index c489dfc..6179dfd 100644 Binary files a/test/mqo_test.pyc and b/test/mqo_test.pyc differ diff --git a/test/pmd_test.py b/test/pmd_test.py index e394045..64eea9d 100644 --- a/test/pmd_test.py +++ b/test/pmd_test.py @@ -10,11 +10,6 @@ import pymeshio.pmd.writer PMD_FILE=u'resources/初音ミクVer2.pmd' -def test_old_pmd_load(): - loader=pymeshio.pmd.IO() - assert loader.read(PMD_FILE) - - class TestPmd(unittest.TestCase): def setUp(self): diff --git a/test/pmd_test.pyc b/test/pmd_test.pyc index bc73751..237a34b 100644 Binary files a/test/pmd_test.pyc and b/test/pmd_test.pyc differ