def compile(self, mode=None): """Compile material information into readily-rendered format""" holder = mode.cache.holder(self, None) for field in protofunctions.getFields(self): # change to any field requires a recompile holder.depend(self, field) # def dl(): dl = displaylist.DisplayList() dl.start() try: alpha = 1.0 - self.transparency renderingData = zeros((4, 4), 'f') renderingData[:, 3] = alpha diffuseColor = self.diffuseColor.astype('f') renderingData[0, :3] = diffuseColor renderingData[1, :3] = self.emissiveColor.astype('f') renderingData[2, :3] = self.specularColor.astype('f') renderingData[3, :3] = (diffuseColor * self.ambientIntensity).astype('f') map(glMaterialfv, self.faces, self.datamap, renderingData) glMaterialf(self.faces[0], GL_SHININESS, self.shininess * 128) finally: dl.end() holder.data = dl return holder.data
def fromConfig(cls, cfg, section='contextdefinition'): """Generate a ContextDefinition from a ConfigParser instance""" from vrml import protofunctions instance = cls() for field in protofunctions.getFields(cls): if cfg.has_option(section, field.name): setattr(instance, field.name, cfg.get(section, field.name)) return instance
def fromConfig( cls, cfg, section='contextdefinition' ): """Generate a ContextDefinition from a ConfigParser instance""" from vrml import protofunctions instance = cls() for field in protofunctions.getFields( cls ): if cfg.has_option( section, field.name ): setattr( instance, field.name, cfg.get( section, field.name )) return instance
def compile(self, mode=None): """Build the cached display list for this background object Note: we store 2 display lists in the cache, but only return one from the compile method. The second list is the final rendering list, while the first is just the low-level rendering code. """ colorSet = self.colorSet() if len(colorSet): vertices, colors = self.buildSphere(colorSet) glMultMatrixf(mode.matrix) first = displaylist.DisplayList() first.start() try: glVertexPointerf(vertices) glColorPointerf(colors) glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_COLOR_ARRAY) glDrawArrays(GL_TRIANGLE_STRIP, 0, len(vertices)) finally: first.end() second = displaylist.DisplayList() second.start() try: glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) glDisable( GL_DEPTH_TEST ) # we don't want to do anything with the depth buffer... glDisable(GL_LIGHTING) glEnable(GL_COLOR_MATERIAL) glDisable(GL_CULL_FACE) for index in range(int(SEGMENTS)): first() glRotated(360.0 / SEGMENTS, 0, 1, 0) glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_COLOR_ARRAY) # now, completely wipe out the depth buffer, so this appears as a "background"... no idea how expensive this is glClear(GL_DEPTH_BUFFER_BIT) glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glColor(0.0, 0.0, 0.0) glDisable(GL_COLOR_MATERIAL) glEnable(GL_CULL_FACE) glFrontFace(GL_CCW) holder = mode.cache.holder(self, (first, second)) for field in protofunctions.getFields(self): # change to any field requires a recompile if field.name != 'bound': holder.depend(self, field) return second finally: second.end() holder = mode.cache.holder(self, (None, ())) return None
def compile(self, mode=None): """Build the cached display list for this background object Note: we store 2 display lists in the cache, but only return one from the compile method. The second list is the final rendering list, while the first is just the low-level rendering code. """ colorSet = self.colorSet() if len(colorSet): vertices, colors = self.buildSphere( colorSet ) glMultMatrixf( mode.matrix ) first = displaylist.DisplayList() first.start() try: glVertexPointerf(vertices) glColorPointerf ( colors ) glEnableClientState( GL_VERTEX_ARRAY ) glEnableClientState( GL_COLOR_ARRAY ) glDrawArrays( GL_TRIANGLE_STRIP, 0, len(vertices)) finally: first.end() second = displaylist.DisplayList() second.start() try: glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) glDisable( GL_DEPTH_TEST ) # we don't want to do anything with the depth buffer... glDisable( GL_LIGHTING ) glEnable( GL_COLOR_MATERIAL ) glDisable( GL_CULL_FACE ) for index in range( int(SEGMENTS) ): first() glRotated( 360.0/SEGMENTS, 0,1,0) glDisableClientState( GL_VERTEX_ARRAY ) glDisableClientState( GL_COLOR_ARRAY ) # now, completely wipe out the depth buffer, so this appears as a "background"... no idea how expensive this is glClear( GL_DEPTH_BUFFER_BIT ) glEnable( GL_DEPTH_TEST ) glEnable( GL_LIGHTING ) glColor( 0.0,0.0,0.0) glDisable( GL_COLOR_MATERIAL ) glEnable( GL_CULL_FACE ) glFrontFace( GL_CCW ) holder = mode.cache.holder(self, (first, second)) for field in protofunctions.getFields( self ): # change to any field requires a recompile if field.name != 'bound': holder.depend( self, field ) return second finally: second.end() holder = mode.cache.holder(self, (None, ())) return None
def buildCacheHolder(self, key="", mode=None): """Get a cache holder with all dependencies set""" holder = mode.cache.holder(self.target, None, key=key) for field in protofunctions.getFields(self.target): # change to any field requires a recompile holder.depend(self.target, field) for (n, attr) in [ (self.target.coord, 'point'), (self.target.color, 'color'), (self.target.texCoord, 'point'), (self.target.normal, 'vector'), ]: if n: holder.depend(n, protofunctions.getField(n, attr)) return holder
def buildCacheHolder( self, key="", mode=None ): """Get a cache holder with all dependencies set""" holder = mode.cache.holder(self.target, None, key=key) for field in protofunctions.getFields( self.target ): # change to any field requires a recompile holder.depend( self.target, field ) for (n, attr) in [ (self.target.coord, 'point'), (self.target.color, 'color'), (self.target.texCoord, 'point'), (self.target.normal, 'vector'), ]: if n: holder.depend( n, protofunctions.getField(n,attr) ) return holder
def compile( self, mode=None ): """Compile the VPCurve into a display-list """ # This code is not OpenGL 3.1 compatible if self.pos.any(): dl = displaylist.DisplayList() #XXX should do sanity checks here... dl.start() try: pos = self.pos color = self.color colorLen = len(color) killThickness = 0 if self.radius: glLineWidth( self.radius*2 ) killThickness = 1 try: glEnable( GL_COLOR_MATERIAL ) try: glBegin( GL_LINE_STRIP ) try: lastColor = None for index in range(len(pos)): point = pos[index] if index < colorLen: col = tuple(color[index]) if col != lastColor: glColor3dv( col ) lastColor = col glVertex3dv(point) finally: glEnd() finally: glDisable( GL_COLOR_MATERIAL ) finally: if killThickness: glLineWidth( 1 ) finally: dl.end() holder = mode.cache.holder(self, dl) for field in protofunctions.getFields( self ): # change to any field requires a recompile holder.depend( self, field ) return dl return None
def compile(self, mode=None): """Compile the VPCurve into a display-list """ # This code is not OpenGL 3.1 compatible if self.pos.any(): dl = displaylist.DisplayList() #XXX should do sanity checks here... dl.start() try: pos = self.pos color = self.color colorLen = len(color) killThickness = 0 if self.radius: glLineWidth(self.radius * 2) killThickness = 1 try: glEnable(GL_COLOR_MATERIAL) try: glBegin(GL_LINE_STRIP) try: lastColor = None for index in range(len(pos)): point = pos[index] if index < colorLen: col = tuple(color[index]) if col != lastColor: glColor3dv(col) lastColor = col glVertex3dv(point) finally: glEnd() finally: glDisable(GL_COLOR_MATERIAL) finally: if killThickness: glLineWidth(1) finally: dl.end() holder = mode.cache.holder(self, dl) for field in protofunctions.getFields(self): # change to any field requires a recompile holder.depend(self, field) return dl return None
def compile( self, mode=None ): """Compile material information into readily-rendered format""" holder = mode.cache.holder(self, None) for field in protofunctions.getFields( self ): # change to any field requires a recompile holder.depend( self, field ) # def dl(): dl = displaylist.DisplayList( ) dl.start() try: alpha = 1.0 - self.transparency renderingData = zeros( (4,4),'f') renderingData[:,3] = alpha diffuseColor = self.diffuseColor.astype( 'f' ) renderingData[0,:3] = diffuseColor renderingData[1,:3] = self.emissiveColor.astype( 'f' ) renderingData[2,:3] = self.specularColor.astype( 'f' ) renderingData[3,:3] = (diffuseColor*self.ambientIntensity).astype('f') map ( glMaterialfv, self.faces, self.datamap, renderingData ) glMaterialf( self.faces[0], GL_SHININESS, self.shininess*128 ) finally: dl.end() holder.data = dl return holder.data
def compile(self, mode=None): """Compile the IndexedLineSet into a display-list """ if self.coord and len(self.coord.point) and len(self.coordIndex): dl = displaylist.DisplayList() holder = mode.cache.holder(self, dl) for field in protofunctions.getFields(self): # change to any field requires a recompile holder.depend(self, field) for (n, attr) in [ (self.coord, 'point'), (self.color, 'color'), ]: if n: holder.depend(n, protofunctions.getField(n, attr)) points = self.coord.point indices = expandIndices(self.coordIndex) #XXX should do sanity checks here... if self.color and len(self.color.color): colors = self.color.color if self.colorPerVertex: if len(self.colorIndex): colorIndices = expandIndices(self.colorIndex) else: colorIndices = indices else: if len(self.colorIndex): # each item represents a single polyline colour colorIndices = self.colorIndex else: # each item in color used in turn by each polyline colorIndices = range(len(indices)) # compile the color-friendly ILS dl.start() try: glEnable(GL_COLOR_MATERIAL) for index in range(len(indices)): polyline = indices[index] color = colorIndices[index] try: color = int(color) except (TypeError, ValueError), err: glBegin(GL_LINE_STRIP) try: for i, c in map(None, polyline, color): if c is not None: # numpy treats None as retrieve all??? why? currentColor = colors[c] if currentColor is not None: glColor3d(*currentColor) glVertex3f(*points[i]) finally: glEnd() else: glColor3d(*colors[color]) glBegin(GL_LINE_STRIP) try: for i in polyline: glVertex3f(*points[i]) finally: glEnd() glDisable(GL_COLOR_MATERIAL) finally: dl.end()
def compile( self, mode=None ): """Compile the IndexedLineSet into a display-list """ if self.coord and len(self.coord.point) and len(self.coordIndex): dl = displaylist.DisplayList() holder = mode.cache.holder(self, dl) for field in protofunctions.getFields( self ): # change to any field requires a recompile holder.depend( self, field ) for (n, attr) in [ (self.coord, 'point'), (self.color, 'color'), ]: if n: holder.depend( n, protofunctions.getField(n,attr) ) points = self.coord.point indices = expandIndices( self.coordIndex ) #XXX should do sanity checks here... if self.color and len(self.color.color): colors = self.color.color if self.colorPerVertex: if len(self.colorIndex): colorIndices = expandIndices( self.colorIndex ) else: colorIndices = indices else: if len(self.colorIndex): # each item represents a single polyline colour colorIndices = self.colorIndex else: # each item in color used in turn by each polyline colorIndices = range(len(indices)) # compile the color-friendly ILS dl.start() try: glEnable( GL_COLOR_MATERIAL ) for index in range(len(indices)): polyline = indices[index] color = colorIndices[index] try: color = int(color) except (TypeError,ValueError), err: glBegin( GL_LINE_STRIP ) try: for i,c in map(None, polyline, color): if c is not None: # numpy treats None as retrieve all??? why? currentColor = colors[c] if currentColor is not None: glColor3d( *currentColor ) glVertex3f(*points[i]) finally: glEnd() else: glColor3d( *colors[color] ) glBegin( GL_LINE_STRIP ) try: for i in polyline: glVertex3f(*points[i]) finally: glEnd() glDisable( GL_COLOR_MATERIAL ) finally: dl.end()