X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=examples%2Fopengl%2Fvertexarray.py;h=5b1a0c43af203f1f5da545f9df434f2587323d71;hb=65211f29fc6e1e540cc3e1c515753f860653382b;hp=749b6e0896b63144824205c5f076e6fc3a2fd0f0;hpb=6fcd334d6c80537283ab6afb30603d243178c768;p=meshio%2Fpymeshio.git diff --git a/examples/opengl/vertexarray.py b/examples/opengl/vertexarray.py index 749b6e0..5b1a0c4 100644 --- a/examples/opengl/vertexarray.py +++ b/examples/opengl/vertexarray.py @@ -68,49 +68,52 @@ class VertexArrayWithUV(object): 属性 ==== * 位置 +* UV ''' class IndexedVertexArray(object): - def __init__(self, vertices, indices): - self.vertices=vertices - self.indices=indices + def __init__(self): + # vertices + self.vertices=[] + self.normal=[] + self.colors=[] + self.uvlist=[] + self.b0=[] + self.b1=[] + self.w0=[] + # indices + self.materials=[] + self.indicesMap={} + + def addVertex(self, pos, normal, color, uv, b0, b1, w0): + self.vertices+=pos + self.normal+=normal + self.colors+=color + self.uvlist+=uv + self.b0.append(b0) + self.b1.append(b1) + self.w0.append(w0) + + def addMaterial(self, material): + self.materials.append(material) + indices=[] + self.indicesMap[material]=indices + return indices def draw(self): # 位置属性 glEnableClientState(GL_VERTEX_ARRAY) - glVertexPointer(3, GL_FLOAT, 0, self.vertices) - # indexによる描画 - glDrawElements(GL_TRIANGLES, len(self.indices), - GL_UNSIGNED_INT, self.indices) + glVertexPointer(4, GL_FLOAT, 0, self.vertices) + # マテリアル毎の描画 + for m in self.materials: + # 順序維持 + indices=self.indicesMap[m] + # indexによる描画 + glDrawElements(GL_TRIANGLES, len(indices), GL_UNSIGNED_INT, indices) # 後始末 glDisableClientState(GL_VERTEX_ARRAY) - -''' -インデックス参照頂点配列 - -==== -属性 -==== -* 位置 -* 色 -''' -class IndexedVertexArrayWithColor(object): - def __init__(self, vertices, colors, indices): - self.vertices=vertices - self.colors=colors - self.indices=indices - - def draw(self): - # 位置属性 - glEnableClientState(GL_VERTEX_ARRAY) - glVertexPointer(3, GL_FLOAT, 0, self.vertices) - # 色属性 - glEnableClientState(GL_COLOR_ARRAY) - glColorPointer(3, GL_FLOAT, 0, self.colors) - # indexによる描画 - glDrawElements(GL_TRIANGLES, len(self.indices), - GL_UNSIGNED_INT, self.indices) - # 後始末 - glDisableClientState(GL_COLOR_ARRAY) - glDisableClientState(GL_VERTEX_ARRAY) + def optimize(self): + pass + #for v in self.vertexArrayMap.values(): + # v.vertices=numpy.array(v.vertices, 'f')