Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyopengl example: avoid quadratic loop #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions examples/pyopengl.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,27 @@ def __init__(self, operation):
except RuntimeError as e:
raise RuntimeError(e)
sys.setrecursionlimit(recursionlimit)


pos_index = {}

for polygon in polygons:
n = polygon.plane.normal
indices = []
for v in polygon.vertices:
pos = [v.pos.x, v.pos.y, v.pos.z]
if not pos in self.vertices:
pos = (v.pos.x, v.pos.y, v.pos.z)
try:
index = pos_index[pos]
except KeyError:
index = len(pos_index)
pos_index[pos] = index
self.vertices.append(pos)
self.vnormals.append([])
index = self.vertices.index(pos)
indices.append(index)
self.vnormals[index].append(v.normal)
self.faces.append(indices)
self.normals.append([n.x, n.y, n.z])
self.colors.append(polygon.shared)

# setup vertex-normals
ns = []
for vns in self.vnormals:
Expand Down Expand Up @@ -124,7 +129,7 @@ def display():
glTranslatef(0.0, 0.0, -1.0);
glRotatef(rot, 1.0, 0.0, 0.0);
glRotatef(rot, 0.0, 0.0, 1.0);
rot += 0.1
rot += 0.02

renderable.render()

Expand Down