OSDN Git Service

fix
[meshio/pymeshio.git] / pymeshio / mqo / __init__.py
index e00d9ae..a21794c 100644 (file)
@@ -1,15 +1,28 @@
 # coding: utf-8\r
 """ \r
-MQOの読み込み\r
-http://www.metaseq.net/metaseq/format.html\r
+======================\r
+Metasequioa MQO format\r
+======================\r
+\r
+file format\r
+~~~~~~~~~~~\r
+* http://www.metaseq.net/metaseq/format.html\r
+\r
+specs\r
+~~~~~\r
+* textencoding: bytes(cp932)\r
+* coordinate: right handed y-up\r
+* uv origin: \r
+* face: edge(2), triangle(3), quadrangle(4)\r
+* backculling: enable\r
+\r
 """\r
 \r
 import os\r
 import sys\r
 import math\r
-import pymeshio.common\r
-import pymeshio.mqo.loader\r
 import warnings\r
+from .. import common\r
 \r
 \r
 """\r
@@ -37,13 +50,13 @@ class Material(object):
     def __init__(self, name):\r
         self.name=name\r
         self.shader=3\r
-        self.color=pymeshio.common.RGBA(0.5, 0.5, 0.5, 1.0)\r
+        self.color=common.RGBA(0.5, 0.5, 0.5, 1.0)\r
         self.diffuse=1.0\r
         self.ambient=0.0\r
         self.emit=0.0\r
         self.specular=0.0\r
         self.power=5.0\r
-        self.tex=""\r
+        self.tex=b""\r
 \r
     def getName(self): return self.name\r
     def getTexture(self): return self.tex\r
@@ -51,30 +64,30 @@ class Material(object):
     def parse(self, line):\r
         offset=0\r
         while True:\r
-            leftParenthesis=line.find("(", offset)\r
+            leftParenthesis=line.find(b"(", offset)\r
             if leftParenthesis==-1:\r
                 break\r
             key=line[offset:leftParenthesis]\r
-            rightParenthesis=line.find(")", leftParenthesis+1)\r
+            rightParenthesis=line.find(b")", leftParenthesis+1)\r
             if rightParenthesis==-1:\r
                 raise ValueError("assert")\r
 \r
             param=line[leftParenthesis+1:rightParenthesis]\r
-            if key=="shader":\r
+            if key==b"shader":\r
                 self.shader=int(param)\r
-            elif key=="col":\r
-                self.color=pymeshio.common.RGBA(*[float(e) for e in param.split()])\r
-            elif key=="dif":\r
+            elif key==b"col":\r
+                self.color=common.RGBA(*[float(e) for e in param.split()])\r
+            elif key==b"dif":\r
                 self.diffuse=float(param)\r
-            elif key=="amb":\r
+            elif key==b"amb":\r
                 self.ambient=float(param)\r
-            elif key=="emi":\r
+            elif key==b"emi":\r
                 self.emit=float(param)\r
-            elif key=="spc":\r
+            elif key==b"spc":\r
                 self.specular=float(param)\r
-            elif key=="power":\r
+            elif key==b"power":\r
                 self.power=float(param)\r
-            elif key=="tex":\r
+            elif key==b"tex":\r
                 self.tex=param[1:-1]\r
             else:\r
                 print(\r
@@ -143,7 +156,7 @@ class Obj(object):
     def getName(self): return self.name\r
 \r
     def addVertex(self, x, y, z):\r
-        self.vertices.append(pymeshio.common.Vector3(x, y, z))\r
+        self.vertices.append(common.Vector3(x, y, z))\r
 \r
     def addFace(self, face):\r
         if face.index_count==2:\r
@@ -175,28 +188,28 @@ class Face(object):
             raise ValueError("invalid vertex count: %d" % index_count)\r
         self.material_index=0\r
         self.col=[]\r
-        self.uv=[pymeshio.common.Vector2(0, 0)]*4\r
+        self.uv=[common.Vector2(0, 0)]*4\r
         self.index_count=index_count\r
         offset=0\r
         while True:\r
-            leftParenthesis=line.find("(", offset)\r
+            leftParenthesis=line.find(b"(", offset)\r
             if leftParenthesis==-1:\r
                 break\r
             key=line[offset:leftParenthesis]\r
-            rightParenthesis=line.find(")", leftParenthesis+1)\r
+            rightParenthesis=line.find(b")", leftParenthesis+1)\r
             if rightParenthesis==-1:\r
                 raise ValueError("assert")\r
             params=line[leftParenthesis+1:rightParenthesis].split()\r
-            if key=="V":\r
+            if key==b"V":\r
                 self.indices=[int(e) for e in params]\r
-            elif key=="M":\r
+            elif key==b"M":\r
                 self.material_index=int(params[0])\r
-            elif key=="UV":\r
+            elif key==b"UV":\r
                 uv_list=[float(e) for e in params]\r
                 self.uv=[]\r
                 for i in range(0, len(uv_list), 2):\r
-                    self.uv.append(pymeshio.common.Vector2(uv_list[i], uv_list[i+1]))\r
-            elif key=="COL":\r
+                    self.uv.append(common.Vector2(uv_list[i], uv_list[i+1]))\r
+            elif key==b"COL":\r
                 for n in params:\r
                     d=int(n)\r
                     # R\r
@@ -217,7 +230,7 @@ class Face(object):
             offset=rightParenthesis+2\r
 \r
     def getIndex(self, i): return self.indices[i]\r
-    def getUV(self, i): return self.uv[i] if i<len(self.uv) else pymeshio.common.Vector2(0, 0)\r
+    def getUV(self, i): return self.uv[i] if i<len(self.uv) else common.Vector2(0, 0)\r
 \r
 \r
 class Model(object):\r
@@ -227,16 +240,3 @@ class Model(object):
         self.objects=[]\r
 \r
 \r
-class IO(object):\r
-    def __init__(self):\r
-        pass\r
-\r
-    def read(self, path):\r
-        warnings.warn("'pymeshio.mqo.IO.read' will be replaced by 'pymeshio.mqo.loader.load'")\r
-        model=pymeshio.mqo.loader.load(path)\r
-        if model:\r
-            self.has_mikoto=model.has_mikoto\r
-            self.materials=model.materials\r
-            self.objects=model.objects\r
-            return True\r
-\r