Commit 9578a913 authored by sumpfralle's avatar sumpfralle

greatly improved OpenGL visualization (contributed by Mattes - thanks a lot!)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1122 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent f7a52e52
Version 0.6 - UNRELEASED
* greatly improved OpenGL visualization (contributed by Mattes)
Version 0.5.1 - 2011-06-13 Version 0.5.1 - 2011-06-13
* added extrusion for 2D models * added extrusion for 2D models
* 2D projection of multi-layered 2D models * 2D projection of multi-layered 2D models
......
...@@ -147,10 +147,38 @@ class BaseModel(TransformableContainer): ...@@ -147,10 +147,38 @@ class BaseModel(TransformableContainer):
self._opengl_display_cache[cache_index] = list_index self._opengl_display_cache[cache_index] = list_index
# somehow "GL_COMPILE_AND_EXECUTE" fails - we render it later # somehow "GL_COMPILE_AND_EXECUTE" fails - we render it later
GL.glNewList(list_index, GL.GL_COMPILE) GL.glNewList(list_index, GL.GL_COMPILE)
for item in self.next(): if isinstance(self, Model):
# ignore invisible things like the normal of a ContourModel get_coords = lambda p: (p.x, p.y, p.z)
if hasattr(item, "to_OpenGL"): def calc_normal(main, normals):
item.to_OpenGL(show_directions=show_directions) suitable = Vector(0, 0, 0)
for normal, weight in normals:
dot = main.dot(normal)
if dot > 0:
suitable = suitable.add(normal.mul(weight * dot))
return suitable.normalized()
vertices = {}
for t in self.triangles():
for p in (t.p1, t.p2, t.p3):
coords = get_coords(p)
if not coords in vertices:
vertices[coords] = []
vertices[coords].append((t.normal.normalized(), t.get_area()))
print "Triangles: %d / Vertices: %d" % (len(self.triangles()), len(vertices))
GL.glBegin(GL.GL_TRIANGLES)
for t in self.triangles():
# The triangle's points are in clockwise order, but GL expects
# counter-clockwise sorting.
for p in (t.p1, t.p3, t.p2):
coords = get_coords(p)
normal = calc_normal(t.normal.normalized(), vertices[coords])
GL.glNormal3f(normal.x, normal.y, normal.z)
GL.glVertex3f(p.x, p.y, p.z)
GL.glEnd()
else:
for item in self.next():
# ignore invisble things like the normal of a ContourModel
if hasattr(item, "to_OpenGL"):
item.to_OpenGL(show_directions=show_directions)
if list_index > 0: if list_index > 0:
GL.glEndList() GL.glEndList()
GL.glCallList(list_index) GL.glCallList(list_index)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment