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