def extrude(self):
        """Virtual Method to do the extrusion along a 3D path with a 2D shape
        using the gle extrusion. We then get the geometry information
        using the extrusion method in Feedback mode. This will then be
        used to build a triangle strip."""
        
        from gle import glec
        gle.gleSetJoinStyle ( self.joinStyle | self.normalStyle )
        glec.gleFeedBack()

        #DisplayFunction of the old GlePolyCylinder
        GL.glColorMaterial (GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT)
        GL.glEnable (GL.GL_COLOR_MATERIAL)
        #glEnable(GL_LIGHTING)
        if self.viewer is not None:
            self.viewer.enableOpenglLighting()
        colors = self.materials[GL.GL_FRONT].prop[0][:,:3]
        gle.glePolyCylinder(self.trace3D, colors, self.radius)
        GL.glDisable (GL.GL_COLOR_MATERIAL)
        
        glec.gleTextureMode(0)
        v,n,s = glec.gleGetTriangleMesh()

        return v,n,s
    def extrude(self):
        """Extrude a cone with radii specified at each point
        of the extrusion"""

        assert len(self.radii)==len(self.trace3D)
        from gle import glec
        gle.gleSetJoinStyle ( self.joinStyle | self.normalStyle )
        glec.gleFeedBack()

        #DisplayFunction of the old GlePolyCylinder
        GL.glColorMaterial (GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT)
        GL.glEnable (GL.GL_COLOR_MATERIAL)

        if self.viewer is not None:
            self.viewer.enableOpenglLighting()

        colors = self.materials[GL.GL_FRONT].prop[0][:,:3]
        gle.glePolyCone(self.trace3D, colors, self.radii)
        GL.glDisable (GL.GL_COLOR_MATERIAL)
        
        glec.gleTextureMode(0)
        v,n,s = glec.gleGetTriangleMesh()

        return v,n,s
    def drawVertexArray(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        """ drawVertexArray
"""
        #print "drawVertexArray", self.name
        if hasattr(self, 'faceSet') and len(self.faceSet.faces.array) > 0:
            # vertices
            GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
            
            # normals
            if len(self.vertexSet.normals.array) > 0:
                GL.glEnableClientState(GL.GL_NORMAL_ARRAY)
        
            # colors
            if hasattr(self, 'colorPointerIsOn') and self.colorPointerIsOn is True:
                GL.glEnableClientState(GL.GL_COLOR_ARRAY)
                from DejaVu import preventIntelBug_WhiteTriangles
                if preventIntelBug_WhiteTriangles:
                    GL.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE)
                else:
                    GL.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE)
                GL.glEnable( GL.GL_COLOR_MATERIAL )
                
            if DejaVu.enableVBO is True:
                from opengltk.extent import _glextlib
                # vertices
                _glextlib.glBindBufferARB(_glextlib.GL_ARRAY_BUFFER_ARB,
                                 int(self.vertexArrayFlagBufferList[0]))
                _gllib.glVertexPointer(len(self.vertexSet.vertices.array[0]),
                                              GL.GL_FLOAT, 0, 0)
                # normals
                if len(self.vertexSet.normals.array) > 0:
                    _glextlib.glBindBufferARB(_glextlib.GL_ARRAY_BUFFER_ARB,
                                              int(self.vertexArrayFlagBufferList[1]))
                    _gllib.glNormalPointer(GL.GL_FLOAT, 0, 0)
                # colors
                if hasattr(self, 'colorPointerIsOn') and self.colorPointerIsOn is True:
                    _glextlib.glBindBufferARB(_glextlib.GL_ARRAY_BUFFER_ARB,
                                              int(self.vertexArrayFlagBufferList[3]))
                    _gllib.glColorPointer(4, GL.GL_FLOAT, 0, 0)
            else:
                # vertices
                _gllib.glVertexPointer(len(self.vertexSet.vertices.array[0]),
                                   GL.GL_FLOAT, 0, self.vertexSet.vertices.array)
                # normals
                if len(self.vertexSet.normals.array) > 0:
                    _gllib.glNormalPointer(GL.GL_FLOAT, 0, self.vertexSet.normals.array)
                # colors
                if hasattr(self, 'colorPointerIsOn') and self.colorPointerIsOn is True:
                    _gllib.glColorPointer(4, GL.GL_FLOAT, 0, self.colorArray)

            # Draw faces
            if self.primitiveType == GL.GL_LINE_STRIP:
                lPrimitiveType = GL.GL_LINES
            elif self.primitiveType == GL.GL_TRIANGLES:
                #print "triangles' length:", len(self.faceSet.faces.array[0])
                lPrimitiveType = GL.GL_TRIANGLES
            elif self.primitiveType == GL.GL_QUADS:
                #print "quads' length:", len(self.faceSet.faces.array[0])
                lPrimitiveType = GL.GL_QUADS
            else:
                #print "what's that ?" , self.primitiveType
                lPrimitiveType = self.primitiveType

            lNumOfNonHighlightedIndices = len(self.faceSet.faces.array) - self.numOfHighlightedIndex
            if DejaVu.enableVBO is True:
                _glextlib.glBindBufferARB(_glextlib.GL_ELEMENT_ARRAY_BUFFER, 
                                      int(self.vertexArrayFlagBufferList[2])) #this protect from unexplained segfault
                if self.disableStencil is False and self.numOfHighlightedIndex > 0:
                    # highlighted
                    GL.glStencilFunc(GL.GL_ALWAYS, 1, 1)
                    _gllib.glDrawElements(lPrimitiveType,
                                  self.numOfHighlightedIndex*len(self.faceSet.faces.array[0]),
                                  GL.GL_UNSIGNED_INT,
                                  0 
                                 )
                    GL.glStencilFunc(GL.GL_ALWAYS, 0, 1)

                    # non highlighted
                    _gllib.glDrawElements(lPrimitiveType,
                                  lNumOfNonHighlightedIndices * len(self.faceSet.faces.array[0]),
                                  GL.GL_UNSIGNED_INT,
                                  self.numOfHighlightedIndex * len(self.faceSet.faces.array[0]) * 4
                                 )
                else:
                    _gllib.glDrawElements(lPrimitiveType,
                                  len(self.faceSet.faces.array)*len(self.faceSet.faces.array[0]),
                                  GL.GL_UNSIGNED_INT,
                                  0 
                                 )
                _glextlib.glBindBufferARB(_glextlib.GL_ELEMENT_ARRAY_BUFFER, 0 ) #this protect from unexplained segfault
            else:
                if self.disableStencil is False and self.numOfHighlightedIndex > 0:
                    # highlighted
                    GL.glStencilFunc(GL.GL_ALWAYS, 1, 1)
                    _gllib.glDrawElements(lPrimitiveType,
                                  self.numOfHighlightedIndex*len(self.faceSet.faces.array[0]),
                                  GL.GL_UNSIGNED_INT,
                                  self.faceSet.faces.array 
                                 )
                    GL.glStencilFunc(GL.GL_ALWAYS, 0, 1)

                    # non highlighted
                    _gllib.glDrawElements(lPrimitiveType,
                                  lNumOfNonHighlightedIndices * len(self.faceSet.faces.array[0]),
                                  GL.GL_UNSIGNED_INT,
                                  self.faceSet.faces.array[self.numOfHighlightedIndex: ]
                                 )
                else:
                    _gllib.glDrawElements(lPrimitiveType,
                                  len(self.faceSet.faces.array)*len(self.faceSet.faces.array[0]),
                                  GL.GL_UNSIGNED_INT,
                                  self.faceSet.faces.array
                                 )
            if hasattr(self, 'colorPointerIsOn') and self.colorPointerIsOn is True:
                GL.glDisable( GL.GL_COLOR_MATERIAL )
                GL.glDisableClientState(GL.GL_COLOR_ARRAY)
            if len(self.vertexSet.normals.array) > 0:
                GL.glDisableClientState(GL.GL_NORMAL_ARRAY)
            GL.glDisableClientState(GL.GL_VERTEX_ARRAY)

        return 1
示例#4
0
#    initialize GL 
GL.glClearDepth (1.0)
GL.glEnable (GL.GL_DEPTH_TEST)
GL.glClearColor (0.0, 0.0, 0.0, 0.0)
GL.glShadeModel (GL.GL_SMOOTH)

GL.glMatrixMode (GL.GL_PROJECTION)
# roughly, measured in centimeters 
GL.glFrustum (-9.0, 9.0, -9.0, 9.0, 50.0, 150.0)
GL.glMatrixMode(GL.GL_MODELVIEW)

# initialize lighting 
GL.glLightfv (GL.GL_LIGHT0, GL.GL_POSITION, lightOnePosition)
GL.glLightfv (GL.GL_LIGHT0, GL.GL_DIFFUSE, lightOneColor)
GL.glEnable (GL.GL_LIGHT0)
GL.glLightfv (GL.GL_LIGHT1, GL.GL_POSITION, lightTwoPosition)
GL.glLightfv (GL.GL_LIGHT1, GL.GL_DIFFUSE, lightTwoColor)
GL.glEnable (GL.GL_LIGHT1)
GL.glEnable (GL.GL_LIGHTING)
GL.glEnable (GL.GL_NORMALIZE)
GL.glColorMaterial (GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE)
GL.glEnable (GL.GL_COLOR_MATERIAL)

InitStuff ()
GLUT.glutKeyboardFunc(keyboard)
print "Type 'q' in the demo window to quit"
GLUT.glutMainLoop ()