2012-03-09 17:38:15 +00:00
|
|
|
from OpenGL.GL import *
|
|
|
|
from .. GLGraphicsItem import GLGraphicsItem
|
2012-03-24 16:17:48 +00:00
|
|
|
from .. MeshData import MeshData
|
2012-03-09 17:38:15 +00:00
|
|
|
from pyqtgraph.Qt import QtGui
|
|
|
|
import pyqtgraph as pg
|
|
|
|
from .. import shaders
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = ['GLMeshItem']
|
|
|
|
|
|
|
|
class GLMeshItem(GLGraphicsItem):
|
2012-03-24 16:17:48 +00:00
|
|
|
"""
|
|
|
|
Displays a 3D triangle mesh.
|
|
|
|
|
|
|
|
"""
|
|
|
|
def __init__(self, faces, vertexes=None):
|
2012-03-09 17:38:15 +00:00
|
|
|
|
2012-03-24 16:17:48 +00:00
|
|
|
"""
|
|
|
|
See MeshData for initialization arguments.
|
|
|
|
"""
|
2012-04-15 14:21:31 +00:00
|
|
|
if isinstance(faces, MeshData):
|
|
|
|
self.data = faces
|
|
|
|
else:
|
|
|
|
self.data = MeshData()
|
|
|
|
self.data.setFaces(faces, vertexes)
|
2012-03-09 17:38:15 +00:00
|
|
|
GLGraphicsItem.__init__(self)
|
|
|
|
|
|
|
|
def initializeGL(self):
|
|
|
|
self.shader = shaders.getShader('balloon')
|
|
|
|
|
|
|
|
l = glGenLists(1)
|
|
|
|
self.triList = l
|
|
|
|
glNewList(l, GL_COMPILE)
|
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
|
|
|
glEnable( GL_BLEND )
|
|
|
|
glEnable( GL_ALPHA_TEST )
|
|
|
|
#glAlphaFunc( GL_ALWAYS,0.5 )
|
|
|
|
glEnable( GL_POINT_SMOOTH )
|
|
|
|
glDisable( GL_DEPTH_TEST )
|
|
|
|
glColor4f(1, 1, 1, .1)
|
|
|
|
glBegin( GL_TRIANGLES )
|
2012-03-24 16:17:48 +00:00
|
|
|
for face in self.data:
|
|
|
|
for (pos, norm, color) in face:
|
|
|
|
glColor4f(*color)
|
2012-03-09 17:38:15 +00:00
|
|
|
glNormal3f(norm.x(), norm.y(), norm.z())
|
2012-03-24 16:17:48 +00:00
|
|
|
glVertex3f(pos.x(), pos.y(), pos.z())
|
2012-03-09 17:38:15 +00:00
|
|
|
glEnd()
|
|
|
|
glEndList()
|
|
|
|
|
|
|
|
|
2012-03-24 16:17:48 +00:00
|
|
|
#l = glGenLists(1)
|
|
|
|
#self.meshList = l
|
|
|
|
#glNewList(l, GL_COMPILE)
|
|
|
|
#glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
|
|
|
#glEnable( GL_BLEND )
|
|
|
|
#glEnable( GL_ALPHA_TEST )
|
|
|
|
##glAlphaFunc( GL_ALWAYS,0.5 )
|
|
|
|
#glEnable( GL_POINT_SMOOTH )
|
|
|
|
#glEnable( GL_DEPTH_TEST )
|
|
|
|
#glColor4f(1, 1, 1, .3)
|
|
|
|
#glBegin( GL_LINES )
|
|
|
|
#for f in self.faces:
|
|
|
|
#for i in [0,1,2]:
|
|
|
|
#j = (i+1) % 3
|
|
|
|
#glVertex3f(*f[i])
|
|
|
|
#glVertex3f(*f[j])
|
|
|
|
#glEnd()
|
|
|
|
#glEndList()
|
2012-03-09 17:38:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
def paint(self):
|
|
|
|
shaders.glUseProgram(self.shader)
|
|
|
|
glCallList(self.triList)
|
|
|
|
shaders.glUseProgram(0)
|
|
|
|
#glCallList(self.meshList)
|