OSDN Git Service

implement pmdbuilder
[meshio/pymeshio.git] / examples / opengl / vertexarray.py
index 749b6e0..5b1a0c4 100644 (file)
@@ -68,49 +68,52 @@ class VertexArrayWithUV(object):
 属性\r
 ====\r
 * 位置\r
+* UV\r
 '''\r
 class IndexedVertexArray(object):\r
-    def __init__(self, vertices, indices):\r
-        self.vertices=vertices\r
-        self.indices=indices\r
+    def __init__(self):\r
+        # vertices\r
+        self.vertices=[]\r
+        self.normal=[]\r
+        self.colors=[]\r
+        self.uvlist=[]\r
+        self.b0=[]\r
+        self.b1=[]\r
+        self.w0=[]\r
+        # indices\r
+        self.materials=[]\r
+        self.indicesMap={}\r
+\r
+    def addVertex(self, pos, normal, color, uv, b0, b1, w0):\r
+        self.vertices+=pos\r
+        self.normal+=normal\r
+        self.colors+=color\r
+        self.uvlist+=uv\r
+        self.b0.append(b0)\r
+        self.b1.append(b1)\r
+        self.w0.append(w0)\r
+\r
+    def addMaterial(self, material):\r
+        self.materials.append(material)\r
+        indices=[]\r
+        self.indicesMap[material]=indices\r
+        return indices\r
 \r
     def draw(self):\r
         # 位置属性\r
         glEnableClientState(GL_VERTEX_ARRAY)\r
-        glVertexPointer(3, GL_FLOAT, 0, self.vertices)\r
-        # indexによる描画\r
-        glDrawElements(GL_TRIANGLES, len(self.indices),\r
-                GL_UNSIGNED_INT, self.indices)\r
+        glVertexPointer(4, GL_FLOAT, 0, self.vertices)\r
+        # マテリアル毎の描画\r
+        for m in self.materials:\r
+            # 順序維持\r
+            indices=self.indicesMap[m]\r
+            # indexによる描画\r
+            glDrawElements(GL_TRIANGLES, len(indices), GL_UNSIGNED_INT, indices)\r
         # 後始末\r
         glDisableClientState(GL_VERTEX_ARRAY)\r
 \r
-\r
-'''\r
-インデックス参照頂点配列\r
-\r
-====\r
-属性\r
-====\r
-* 位置\r
-* 色\r
-'''\r
-class IndexedVertexArrayWithColor(object):\r
-    def __init__(self, vertices, colors, indices):\r
-        self.vertices=vertices\r
-        self.colors=colors\r
-        self.indices=indices\r
-\r
-    def draw(self):\r
-        # 位置属性\r
-        glEnableClientState(GL_VERTEX_ARRAY)\r
-        glVertexPointer(3, GL_FLOAT, 0, self.vertices)\r
-        # 色属性\r
-        glEnableClientState(GL_COLOR_ARRAY)\r
-        glColorPointer(3, GL_FLOAT, 0, self.colors)\r
-        # indexによる描画\r
-        glDrawElements(GL_TRIANGLES, len(self.indices),\r
-                GL_UNSIGNED_INT, self.indices)\r
-        # 後始末\r
-        glDisableClientState(GL_COLOR_ARRAY)\r
-        glDisableClientState(GL_VERTEX_ARRAY)\r
+    def optimize(self):\r
+        pass\r
+        #for v in self.vertexArrayMap.values():\r
+        #    v.vertices=numpy.array(v.vertices, 'f') \r
 \r