1212
1313class Effect :
1414 """
15- Effect base class.
15+ Effect base class that should be extended when making an effect
1616
17- The following attributes are injected by demosys before initialization :
17+ Example: :
1818
19- * ``window`` (demosys.context.Context): Window
20- * ``ctx`` (moderngl.Context): The moderngl context
21- * ``sys_camera`` (demosys.scene.camera.Camera): The system camera responding to inputs
19+ from demosys.effects import Effect
20+
21+ class MyEffect(Effect):
22+ def __init__(self):
23+ # Initalization
24+
25+ def draw(self, time, frametime, target):
26+ # Draw stuff
2227 """
23- # By default effects are runnable with ``runeffect``
28+ #: The runnable status of the effect instance.
29+ #: A runnable effect should be able to run with the ``runeffect`` command
30+ #: or run in a project
2431 runnable = True
2532
2633 # Full python path to the effect (set per instance)
@@ -34,9 +41,35 @@ class Effect:
3441 _ctx = None # type: moderngl.Context
3542 _sys_camera = None # type: camera.SystemCamera
3643
44+ def __init__ (self , * args , ** kwargs ):
45+ """
46+ Implement the initialize when extending the class.
47+ This method is responsible for fetching resources
48+ and doing genereal initalization of the effect.
49+
50+ The effect initializer is called when all resources are loaded
51+ with the exception of resources loaded by other effects in
52+ the initializer.
53+
54+ The siganture of this method is entirely up to you.
55+
56+ You do not have to call the superclass initializer though ``super()``
57+
58+ Example::
59+
60+ def __init__(self):
61+ # Fetch reference to resource by their label
62+ self.program = self.get_program('simple_textured')
63+ self.texture = self.get_texture('bricks')
64+ # .. create a cube etc ..
65+ """
66+ pass
67+
3768 def post_load (self ):
3869 """
39- Called when all effects are initialized before effects start running.
70+ Called after all effects are initialized before drawing starts.
71+ Some initialization may be neccessary to do here such as
72+ interaction with other effects.
4073 """
4174 pass
4275
@@ -52,11 +85,12 @@ def label(self) -> str:
5285
5386 @property
5487 def window (self ) -> BaseWindow :
88+ """The :py:class:`Window`"""
5589 return self ._window
5690
5791 @property
5892 def ctx (self ) -> moderngl .Context :
59- """ModernGL context"""
93+ """The ModernGL context"""
6094 return self ._ctx
6195
6296 @property
@@ -70,9 +104,10 @@ def draw(self, time, frametime, target):
70104 Draw function called by the system every frame when the effect is active.
71105 You are supposed to override this method.
72106
73- :param time: The current time in seconds (float)
74- :param frametime: The time the previous frame used to render in seconds (float)
75- :param target: The target FBO for the effect
107+ Args:
108+ time (float): The current time in seconds.
109+ frametime (float): The time the previous frame used to render in seconds.
110+ target (``moderngl.Framebuffer``): The target FBO for the effect.
76111 """
77112 raise NotImplementedError ("draw() is not implemented" )
78113
@@ -82,89 +117,127 @@ def get_program(self, label) -> moderngl.Program:
82117 """
83118 Get a program by its label
84119
85- :param label: The label for the program
86- :return: moderngl.Program instance
120+ Args:
121+ label (str): The label for the program
122+
123+ Returns: py:class:`moderngl.Program` instance
87124 """
88125 return self ._project .get_program (label )
89126
90127 def get_texture (self , label ) -> moderngl .Texture :
91128 """
92129 Get a texture by its label
93130
94- :param label: Label for the texture
95- :return: The moderngl texture instance
131+ Args:
132+ label (str): The Label for the texture
133+
134+ Returns:
135+ The py:class:`moderngl.Texture` instance
96136 """
97137 return self ._project .get_texture (label )
98138
99139 def get_track (self , name ) -> Track :
100140 """
141+ This is only avaiable when using a Rocket timer.
142+
101143 Get or create a rocket track. This only makes sense when using rocket timers.
102144 If the resource is not loaded yet, an empty track object
103145 is returned that will be populated later.
104146
105- :param name: The rocket track name
106- :param local: Auto-prepend the effect package name to the path
107- :return: Track object
147+ Args:
148+ name (str): The rocket track name
149+
150+ Returns:
151+ The :py:class:`rocket.Track` instance
108152 """
109153 return resources .tracks .get (name )
110154
111155 def get_scene (self , label ) -> Scene :
112156 """
113157 Get a scene by its label
114158
115- :param label: The label for the scene
116- :return: Scene object
159+ Args:
160+ label (str): The label for the scene
161+
162+ Returns: The :py:class:`Scene` instance
117163 """
118164 return self ._project .get_scene (label )
119165
120166 def get_data (self , label ) -> Any :
121167 """
122- Get a data file by its label
168+ Get a data instance by its label
123169
124- :param label: Label for the data file
125- :return: Contents of the data file
170+ Args:
171+ label (str): Label for the data instance
172+
173+ Returns:
174+ Contents of the data file
126175 """
127176 return self ._project .get_data (label )
128177
129178 def get_effect (self , label ) -> 'Effect' :
130179 """
131- Get an effect instance by label
180+ Get an effect instance by label.
181+ This is only possible when you have your own Project
182+
183+ Args:
184+ label (str): Label for the data file
132185
133- :param label: Label for the data file
134- :return: The requested effect instance
186+ Returns: The :py:class:`Effect` instance
135187 """
136188 return self ._project .get_effect (label )
137189
138190 def get_effect_class (self , effect_name , package_name = None ) -> Type ['Effect' ]:
139191 """
140192 Get an effect class.
141193
142- :param effect_name: Name of the effect class
143- :param package_name: (optional) The package this effect belongs to
194+ Args:
195+ effect_name (str): Name of the effect class
196+
197+ Keyword Args:
198+ package_name (str): The package the effect belongs to
199+
200+ Returns:
201+ :py:class:`Effect` class
144202 """
145203 return self ._project .get_effect_class (effect_name , package_name = package_name )
146204
147205 # Utility methods for matrices
148206
149- def create_projection (self , fov = 75.0 , near = 1.0 , far = 100.0 , ratio = None ):
207+ def create_projection (self , fov = 75.0 , near = 1.0 , far = 100.0 , aspect_ratio = None ):
150208 """
151209 Create a projection matrix with the following parameters.
210+ When ``aspect_ratio`` is not provided the configured aspect
211+ ratio for the window will be used.
212+
213+ Args:
214+ :param float fov: Field of view (float)
215+ :param float near: Camera near value
216+ :param float far: Camrea far value
152217
153- :param fov: Field of view (float)
154- :param near: Camera near value
155- :param far: Camrea far value
156- :param ratio: Aspect ratio of the window
157- :return: The projection matrix
218+ :param float ratio: Aspect ratio of the window
219+
220+ Returns: The projection matrix as a float32 :py:class:`numpy.array`
158221 """
159222 return matrix44 .create_perspective_projection_matrix (
160223 fov ,
161- ratio or self .window .aspect_ratio ,
224+ aspect_ratio or self .window .aspect_ratio ,
162225 near ,
163226 far ,
227+ dtype = 'f4' ,
164228 )
165229
166230 def create_transformation (self , rotation = None , translation = None ):
167- """Convenient transformation method doing rotations and translation"""
231+ """
232+ Creates a transformation matrix woth rotations and translation.
233+
234+ Args:
235+ rotation: 3 component vector as a list, tuple, or :py:class:`pyrr.Vector3`
236+ translation: 3 component vector as a list, tuple, or :py:class:`pyrr.Vector3`
237+
238+ Returns:
239+ A 4x4 matrix as a :py:class:`numpy.array`
240+ """
168241 mat = None
169242 if rotation is not None :
170243 mat = Matrix44 .from_eulers (Vector3 (rotation ))
@@ -180,11 +253,13 @@ def create_transformation(self, rotation=None, translation=None):
180253
181254 def create_normal_matrix (self , modelview ):
182255 """
183- Convert to mat3 and return inverse transpose.
184- These are normally needed when dealing with normals in shaders.
256+ Creates a normal matrix from modelview matrix
257+
258+ Args:
259+ modelview: The modelview matrix
185260
186- :param modelview: The modelview matrix
187- :return: Normal matrix
261+ :return:
262+ A 3x3 Normal matrix as a :py:class:`numpy.array`
188263 """
189264 normal_m = Matrix33 .from_matrix44 (modelview )
190265 normal_m = normal_m .inverse
0 commit comments