|
| 1 | +"""Geometry type for "point-arrays" w/ colour support""" |
| 2 | +from OpenGL.GL import * |
| 3 | +from vrml.vrml97 import basenodes |
| 4 | +from OpenGLContext.scenegraph import coordinatebounded |
| 5 | +from OpenGLContext.arrays import array |
| 6 | +from OpenGL.extensions import alternate |
| 7 | +from OpenGL.GL.ARB.point_parameters import * |
| 8 | +from OpenGL.GL.EXT.point_parameters import * |
| 9 | +import logging |
| 10 | +log = logging.getLogger( __name__ ) |
| 11 | + |
| 12 | +glPointParameterf = alternate( |
| 13 | + glPointParameterf, glPointParameterfARB,glPointParameterfEXT |
| 14 | +) |
| 15 | +glPointParameterfv = alternate( |
| 16 | + glPointParameterfv, glPointParameterfvARB, glPointParameterfEXT |
| 17 | +) |
| 18 | +RESET_ATTENUATION = array( [1,0,0],'f') |
| 19 | + |
| 20 | +class PointSet( |
| 21 | + coordinatebounded.CoordinateBounded, |
| 22 | + basenodes.PointSet |
| 23 | +): |
| 24 | + """VRML97-style Point-Set object |
| 25 | +
|
| 26 | + http://www.web3d.org/x3d/specifications/vrml/ISO-IEC-14772-IS-VRML97WithAmendment1/part1/nodesRef.html#PointSet |
| 27 | + """ |
| 28 | + def render ( |
| 29 | + self, |
| 30 | + visible = 1, # can skip normals and textures if not |
| 31 | + lit = 1, # can skip normals if not |
| 32 | + textured = 1, # can skip textureCoordinates if not |
| 33 | + transparent = 0, # need to sort triangle geometry... |
| 34 | + mode = None, # the renderpass object |
| 35 | + ): |
| 36 | + """Render the point-set, requires coord attribute be present |
| 37 | +
|
| 38 | + if color is present (and has the same length as coord), will |
| 39 | + render using colors mapped 1:1, otherwise will use the current |
| 40 | + color.color |
| 41 | + """ |
| 42 | + if not self.coord: |
| 43 | + # can't render nothing |
| 44 | + return 1 |
| 45 | + points = self.coord.point |
| 46 | + if not len(points): |
| 47 | + # can't render nothing |
| 48 | + return 1 |
| 49 | + glVertexPointerf(points) |
| 50 | + glEnableClientState( GL_VERTEX_ARRAY ) |
| 51 | + |
| 52 | + if visible and self.color: |
| 53 | + colors = self.color.color |
| 54 | + if len(colors) != len(points): |
| 55 | + # egads, a content error |
| 56 | + if __debug__: |
| 57 | + log.warn( |
| 58 | + """PointSet %s has different number of point (%s) and color (%s) values""", |
| 59 | + str(self), |
| 60 | + len(points), |
| 61 | + len(colors), |
| 62 | + ) |
| 63 | + else: |
| 64 | + glColorMaterial( GL_FRONT_AND_BACK, GL_DIFFUSE) |
| 65 | + glEnable( GL_COLOR_MATERIAL ) |
| 66 | + glColorPointerf ( colors ) |
| 67 | + glEnableClientState( GL_COLOR_ARRAY ) |
| 68 | + glDisable( GL_LIGHTING ) |
| 69 | + if textured: |
| 70 | + # TODO: check for version/extension first! |
| 71 | + # point-sprites instead of regular points... |
| 72 | + glEnable(GL_POINT_SPRITE); |
| 73 | + glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE) |
| 74 | + glPointSize( self.size ) |
| 75 | + if glPointParameterf: |
| 76 | + glPointParameterf( GL_POINT_SIZE_MIN, self.minSize ) |
| 77 | + glPointParameterf( GL_POINT_SIZE_MAX, self.maxSize ) |
| 78 | + glPointParameterfv( GL_POINT_DISTANCE_ATTENUATION, self.attenuation ) |
| 79 | + glDrawArrays( GL_POINTS, 0, len(points)) |
| 80 | + glDisableClientState( GL_VERTEX_ARRAY ) |
| 81 | + glDisable( GL_COLOR_MATERIAL ) |
| 82 | + if textured: |
| 83 | + glDisable( GL_POINT_SPRITE ) |
| 84 | + if glPointParameterf: |
| 85 | + glPointParameterf( GL_POINT_SIZE_MIN, 0.0 ) |
| 86 | + glPointParameterf( GL_POINT_SIZE_MAX, 1.0 ) |
| 87 | + glPointParameterfv( GL_POINT_DISTANCE_ATTENUATION, RESET_ATTENUATION ) |
| 88 | + glPointSize( 1.0 ) |
| 89 | + glDisableClientState( GL_COLOR_ARRAY ) |
| 90 | + return 1 |
| 91 | + def boundingVolume( self, mode=None ): |
| 92 | + """Create a bounding-volume object for this node""" |
| 93 | + from OpenGLContext.scenegraph import boundingvolume |
| 94 | + return boundingvolume.volumeFromCoordinate( |
| 95 | + self.coord, |
| 96 | + ) |
0 commit comments