102. opengl.drawable
— OpenGL rendering objects for the new OpenGL2 engine.¶
102.1. Classes defined in module opengl.drawable¶
-
class
opengl.drawable.
Drawable
(parent, **kargs)[source]¶ Base class for objects that can be rendered by the OpenGL engine.
This is the basic drawable object in the pyFormex OpenGL rendering engine. It collects all the data that are needed to properly described any object to be rendered by the OpenGL shader programs. It has a multitude of optional attributes allowing it to describe many very different objects and rendering situations.
This class is however not intended to be directly used to construct an object for rendering. The
Actor
class and its multiple subclasses should be used for that purpose. The Actor classes provide an easier and more logical interface, and more powerful at the same time, since they can be compound: one Actor can hold multiple Drawables.The elementary objects that can be directly drawn by the shader programs are more simple, yet very diverse. The Drawable class collects all the data that are needed by the OpenGL engine to do a proper rendering of the object. It this represents a single, versatile interface of the Actor classes with the GPU shader programs.
The versatility comes from the
Attributes
base class, with an unlimited set of attributes. Any undefined attribute just returns None. Some of the most important attributes are described hereafter:rendertype: int: the type of rendering process that will be applied by the rendering engine to the Drawable:
- 0: A full 3D Actor. The Drawable will be rendered in full 3D with
all active capabilities, such as camera rotation, projection, rendermode, lighting. The full object undergoes the camera transformations, and thus will appear as a 3D object in space. The object’s vertices are defined in 3D world coordinates. Used in:
Actor
.- 1: A 2D object (often a text or an image) inserted at a 3D position.
The 2D object always keeps its orientation towards the camera. When the camera changes, the object can change its position on the viewport, but the oject itself looks the same. This can be used to add annotations to (parts of) a 3D object. The object is defined in viewport coordinates, the insertion points are in 3D world coordinates. Used in:
textext.Text
.- 2: A 2D object inserted at a 2D position. Both object and position
are defined in viewport coordinates. The object will take a fixed position on the viewport. This can be use to add decorations to the viewport (like color legends and background images). Used in:
decors.ColorLegend
.- 3: Like 2, but with special purpose. These Drawables are not part of
the user scene, but used for system purposes (like setting the background color, or adding an elastic rectangle during mouse picking). Used in:
Canvas.createBackground()
.- -1: Like 1, but with different insertion points for the multiple items
in the object. Used to place a list of marks at a list of points. Used in:
textext.Text
.- -2: A 3D object inserted at a 2D position. The 3D object will rotate
when the camera changes directions, but it will always be located on the same position of the viewport. This is normally used to display a helper object showing the global axis directions. Used in:
decors.Triade
.
The initialization of a Drawable takes a single parameter: parent, which is the Actor that created the Drawable. All other parameters should be keyword arguments, and are stored as attributes in the Drawable.
Methods:
prepare…: creates sanitized and derived attributes/data. Its action depends on current canvas settings: mode, transparent, avgnormals
render: push values to shader and render the object: depends on canvas and renderer.
pick: fake render to be used during pick operations
str: format the full data set of the Drawable
-
class
opengl.drawable.
BaseActor
(**kargs)[source]¶ Base class for all drawn objects (Actors) in pyFormex.
This defines the interface for all drawn objects, but does not implement any drawn objects. Drawable objects should be instantiated from the derived classes. Currently, we have the following derived classes:
- Actor: a 3-D object positioned and oriented in the 3D scene. Defined
in actors.py.
- Mark: an object positioned in 3D scene but not undergoing the camera
axis rotations and translations. It will always appear the same to the viewer, but will move over the screen according to its 3D position. Defined in marks.py.
- Decor: an object drawn in 2D viewport coordinates. It will unchangeably
stick on the viewport until removed. Defined in decors.py.
The BaseActor class is just an Attributes dict storing all the rendering parameters, and providing defaults from the current canvas drawoptions for the essential parameters that are not specified.
Additional parameters can be set at init time or later using the update method. The specified parameters are sanitized before being stored.
Arguments processed by the base class:
marksize: force to float and also copied as pointsize
-
class
opengl.drawable.
Actor
(obj, **kargs)[source]¶ Proposal for drawn objects
__init__: store all static values: attributes, geometry, vbo’s prepare: creates sanitized and derived attributes/data render: push values to shader and render the object
__init__ is only dependent on input attributes and geometry
- prepare may depend on current canvas settings:
mode, transparent, avgnormals
render depends on canvas and renderer
If the actor does not have a name, it will be given a default one.
The actor has the following attributes, initialized or computed on demand