Effect¶
-
demosys.effects.
Effect
¶ Effect base class that should be extended when making an effect
Example:
from demosys.effects import Effect class MyEffect(Effect): def __init__(self): # Initalization def draw(self, time, frametime, target): # Draw stuff
Initialization¶
-
Effect.
__init__
(*args, **kwargs)¶ Implement the initialize when extending the class. This method is responsible for fetching resources and doing genereal initalization of the effect.
The effect initializer is called when all resources are loaded with the exception of resources loaded by other effects in the initializer.
The siganture of this method is entirely up to you.
You do not have to call the superclass initializer though
super()
Example:
def __init__(self): # Fetch reference to resource by their label self.program = self.get_program('simple_textured') self.texture = self.get_texture('bricks') # .. create a cube etc ..
-
Effect.
post_load
()¶ Override this method if needed when creating an effect.
Called after all effects are initialized before drawing starts. Some initialization may be neccessary to do here such as interaction with other effects.
Draw Methods¶
-
Effect.
draw
(time, frametime, target)¶ Draw function called by the system every frame when the effect is active. You are supposed to override this method.
Parameters: - time (float) – The current time in seconds.
- frametime (float) – The time the previous frame used to render in seconds.
- target (
moderngl.Framebuffer
) – The target FBO for the effect.
Resource Methods¶
-
Effect.
get_texture
(label) → moderngl.texture.Texture¶ Get a texture by its label
Parameters: label (str) – The Label for the texture Returns: The py:class:moderngl.Texture instance
-
Effect.
get_program
(label) → moderngl.program.Program¶ Get a program by its label
Parameters: label (str) – The label for the program Returns: py:class:moderngl.Program instance
-
Effect.
get_scene
(label) → demosys.scene.scene.Scene¶ Get a scene by its label
Parameters: label (str) – The label for the scene Returns: The
Scene
instance
-
Effect.
get_data
(label) → Any¶ Get a data instance by its label
Parameters: label (str) – Label for the data instance Returns: Contents of the data file
-
Effect.
get_effect
(label) → demosys.effects.effect.Effect¶ Get an effect instance by label. This is only possible when you have your own Project
Parameters: label (str) – Label for the data file Returns: The
Effect
instance
-
Effect.
get_effect_class
(effect_name, package_name=None) → Type[Effect]¶ Get an effect class.
Parameters: effect_name (str) – Name of the effect class Keyword Arguments: package_name (str) – The package the effect belongs to Returns: Effect
class
-
Effect.
get_track
(name) → rocket.tracks.Track¶ This is only avaiable when using a Rocket timer.
Get or create a rocket track. This only makes sense when using rocket timers. If the resource is not loaded yet, an empty track object is returned that will be populated later.
Parameters: name (str) – The rocket track name Returns: The rocket.Track
instance
Utility Methods¶
-
Effect.
create_projection
(fov=75.0, near=1.0, far=100.0, aspect_ratio=None)¶ Create a projection matrix with the following parameters. When
aspect_ratio
is not provided the configured aspect ratio for the window will be used.:param : param float fov: Field of view (float) :param : param float near: Camera near value :param : param float far: Camrea far value
Parameters: ratio (float) – Aspect ratio of the window Returns: The projection matrix as a float32
numpy.array
-
Effect.
create_transformation
(rotation=None, translation=None)¶ Creates a transformation matrix woth rotations and translation.
Parameters: - rotation – 3 component vector as a list, tuple, or
pyrr.Vector3
- translation – 3 component vector as a list, tuple, or
pyrr.Vector3
Returns: A 4x4 matrix as a
numpy.array
- rotation – 3 component vector as a list, tuple, or
-
Effect.
create_normal_matrix
(modelview)¶ Creates a normal matrix from modelview matrix
Parameters: modelview – The modelview matrix Returns: A 3x3 Normal matrix as a numpy.array
Attributes¶
-
Effect.
runnable
= True¶ The runnable status of the effect instance. A runnable effect should be able to run with the
runeffect
command or run in a project
-
Effect.
ctx
¶ The ModernGL context
-
Effect.
window
¶ The
Window
-
Effect.
sys_camera
¶ The system camera responding to input
-
Effect.
name
¶ Full python path to the effect
-
Effect.
label
¶ Full python path to the effect