Miscellaneous Classes
Auto-generated API reference. For a guided introduction to the vector array classes see the Vector Arrays tutorial.
Random
Static class for generating random numbers and vectors.
Source code in ncca/ngl/random.py
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
add_float_generator(name, generator)
staticmethod
Add a generator to the float generators.
| Parameters: |
|
|---|
Source code in ncca/ngl/random.py
74 75 76 77 78 79 80 81 82 | |
add_int_generator(name, generator)
staticmethod
Add a generator to the int generators.
| Parameters: |
|
|---|
Source code in ncca/ngl/random.py
64 65 66 67 68 69 70 71 72 | |
get_float_from_generator_name(name)
staticmethod
Gets a pre-generated float value for a genetator.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/random.py
36 37 38 39 40 41 42 43 44 45 46 47 48 | |
get_int_from_generator_name(name)
staticmethod
Gets a pre-generated int value for a genetator.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/random.py
50 51 52 53 54 55 56 57 58 59 60 61 62 | |
get_random_colour3()
staticmethod
Get a random colour with components ranged from 0-1.
Source code in ncca/ngl/random.py
96 97 98 99 100 | |
get_random_colour4()
staticmethod
Get a random colour with components ranged from 0-1.
Source code in ncca/ngl/random.py
90 91 92 93 94 | |
get_random_normalized_vec2()
staticmethod
Get a random vector with componets ranged from +/- 1 and Normalized.
Source code in ncca/ngl/random.py
130 131 132 133 134 135 136 | |
get_random_normalized_vec3()
staticmethod
Get a random vector with componets ranged from +/- 1 and Normalized.
Source code in ncca/ngl/random.py
116 117 118 119 120 121 122 | |
get_random_normalized_vec4()
staticmethod
Get a random vector with componets ranged from +/- 1 and Normalized.
Source code in ncca/ngl/random.py
102 103 104 105 106 107 108 | |
get_random_point(x_range=1.0, y_range=1.0, z_range=1.0)
staticmethod
Get a random point in 3D space defaults to +/- 1 else user defined range.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/random.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
get_random_vec2()
staticmethod
Get a random vector with componets ranged from +/- 1.
Source code in ncca/ngl/random.py
124 125 126 127 128 | |
get_random_vec3()
staticmethod
Get a random vector with componets ranged from +/- 1.
Source code in ncca/ngl/random.py
110 111 112 113 114 | |
get_random_vec4()
staticmethod
Get a random vector with componets ranged from +/- 1.
Source code in ncca/ngl/random.py
84 85 86 87 88 | |
random_number(mult=1.0)
staticmethod
A replacement for the old RandomNumber func, a convinience function.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/random.py
155 156 157 158 159 160 161 162 163 164 165 166 | |
random_positive_number(mult=1.0)
staticmethod
A replacement for the old ReandomPosNum, a convinience function.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/random.py
168 169 170 171 172 173 174 175 176 177 178 179 | |
set_seed()
staticmethod
Set the seed using std::time(NULL).
Source code in ncca/ngl/random.py
22 23 24 25 | |
set_seed_value(value)
staticmethod
Set the seed using a param value.
| Parameters: |
|
|---|
Source code in ncca/ngl/random.py
27 28 29 30 31 32 33 34 | |
PySideEventHandlingMixin
Mixin class providing standard event handling for PyNGL applications.
This mixin provides common functionality for: - Mouse-based camera control (rotation with left button, translation with right button) - Keyboard shortcuts (wireframe/solid mode, reset, escape) - Mouse wheel zooming
Classes using this mixin should call setup_event_handling() in their init method.
Source code in ncca/ngl/opengl/pyside_event_handling_mixin.py
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
close_target()
The thing the Escape shortcut should close.
The mixin is used two ways round. Most applications mix it into a QOpenGLWindow, which is a QWindow and is already the top level thing, so closing it is closing the application. A few mix it into a QOpenGLWidget sitting inside a QMainWindow alongside a control panel, and there closing the widget only hides the viewport and leaves the rest of the window behind, which is never what Escape is meant to do.
QWidget has window() to walk up to the top level; QWindow has no such method at all, so this cannot simply be self.window().
| Returns: |
|
|---|
Source code in ncca/ngl/opengl/pyside_event_handling_mixin.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
keyPressEvent(event)
Handle keyboard press events with common shortcuts.
Shortcuts: - Escape: Close the window this is in - W: Switch to wireframe mode - S: Switch to solid fill mode - Space: Reset camera rotation and position
All of these are off when setup_event_handling was given handle_key_shortcuts=False, in which case every key is passed on untouched for the parent to deal with.
| Parameters: |
|
|---|
Source code in ncca/ngl/opengl/pyside_event_handling_mixin.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
mouseMoveEvent(event)
Handle mouse movement for camera control.
- Left button: Rotate the scene
- Right button: Translate (pan) the scene
| Parameters: |
|
|---|
Source code in ncca/ngl/opengl/pyside_event_handling_mixin.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
mousePressEvent(event)
Handle mouse button press events to initiate rotation or translation.
- Left button: Start rotation mode
- Right button: Start translation mode
| Parameters: |
|
|---|
Source code in ncca/ngl/opengl/pyside_event_handling_mixin.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
mouseReleaseEvent(event)
Handle mouse button release events to stop rotation or translation.
| Parameters: |
|
|---|
Source code in ncca/ngl/opengl/pyside_event_handling_mixin.py
214 215 216 217 218 219 220 221 222 223 | |
reset_camera()
Reset camera rotation and model position to defaults.
Source code in ncca/ngl/opengl/pyside_event_handling_mixin.py
92 93 94 95 96 | |
setup_event_handling(rotation_sensitivity=DEFAULT_ROTATION_SENSITIVITY, translation_sensitivity=DEFAULT_TRANSLATION_SENSITIVITY, zoom_sensitivity=DEFAULT_ZOOM_SENSITIVITY, initial_position=None, handle_key_shortcuts=True)
Initialize event handling attributes.
| Parameters: |
|
|---|
Source code in ncca/ngl/opengl/pyside_event_handling_mixin.py
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 | |
wheelEvent(event)
Handle mouse wheel events for zooming.
Zooming is performed by adjusting the Z coordinate of the model position.
| Parameters: |
|
|---|
Source code in ncca/ngl/opengl/pyside_event_handling_mixin.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
Vec2Array
A class to hold Vec2 data in contiguous memory for efficient GPU transfer.
Internally uses a numpy array of shape (N, 2) for optimal performance. Mutable container — intentionally not hashable.
Source code in ncca/ngl/vec2_array.py
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
__eq__(other)
Compare two Vec2Array instances for equality.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec2_array.py
85 86 87 88 89 90 91 92 93 94 95 96 | |
__getitem__(index)
Get the Vec2 at the specified index.
| Parameters: |
|
|---|
| Returns: |
|---|
Source code in ncca/ngl/vec2_array.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
__init__(values=None)
Initializes the Vec2Array.
| Parameters: |
|
|---|
Source code in ncca/ngl/vec2_array.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
__iter__()
Return an iterator that yields Vec2 objects.
Source code in ncca/ngl/vec2_array.py
79 80 81 82 83 | |
__len__()
Return the number of elements in the array.
Source code in ncca/ngl/vec2_array.py
75 76 77 | |
__repr__()
Eval-able representation, e.g. Vec2Array([Vec2(0.0, 0.0)]).
Source code in ncca/ngl/vec2_array.py
146 147 148 149 | |
__setitem__(index, value)
Set the Vec2 at the specified index.
| Parameters: |
|
|---|
Source code in ncca/ngl/vec2_array.py
64 65 66 67 68 69 70 71 72 73 | |
__str__()
Pretty representation as a list of Vec2 values.
Source code in ncca/ngl/vec2_array.py
151 152 153 154 | |
append(value)
Append a Vec2 object to the array.
| Parameters: |
|
|---|
Source code in ncca/ngl/vec2_array.py
98 99 100 101 102 103 104 105 106 107 | |
extend(values)
Extend the array with a list of Vec2 objects.
| Parameters: |
|
|---|
Source code in ncca/ngl/vec2_array.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
sizeof()
Return the size of the array in bytes.
| Returns: |
|
|---|
Source code in ncca/ngl/vec2_array.py
156 157 158 159 160 161 162 | |
to_list()
Convert the array of Vec2 objects to a single flat list of floats.
| Returns: |
|
|---|
Source code in ncca/ngl/vec2_array.py
124 125 126 127 128 129 130 | |
to_numpy()
Convert the array of Vec2 objects to a numpy array.
This is the primary method for GPU data transfer.
| Returns: |
|
|---|
Source code in ncca/ngl/vec2_array.py
132 133 134 135 136 137 138 139 140 | |
to_tuple()
Return all components as one flat tuple of floats.
Source code in ncca/ngl/vec2_array.py
142 143 144 | |
Vec3Array
A class to hold Vec3 data in contiguous memory for efficient GPU transfer.
Internally uses a numpy array of shape (N, 3) for optimal performance. Mutable container — intentionally not hashable.
Source code in ncca/ngl/vec3_array.py
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
__eq__(other)
Compare two Vec3Array instances for equality.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec3_array.py
85 86 87 88 89 90 91 92 93 94 95 96 | |
__getitem__(index)
Get the Vec3 at the specified index.
| Parameters: |
|
|---|
| Returns: |
|---|
Source code in ncca/ngl/vec3_array.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
__init__(values=None)
Initializes the Vec3Array.
| Parameters: |
|
|---|
Source code in ncca/ngl/vec3_array.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
__iter__()
Return an iterator that yields Vec3 objects.
Source code in ncca/ngl/vec3_array.py
79 80 81 82 83 | |
__len__()
Return the number of elements in the array.
Source code in ncca/ngl/vec3_array.py
75 76 77 | |
__repr__()
Eval-able representation, e.g. Vec3Array([Vec3(0.0, 0.0, 0.0)]).
Source code in ncca/ngl/vec3_array.py
152 153 154 155 | |
__setitem__(index, value)
Set the Vec3 at the specified index.
| Parameters: |
|
|---|
Source code in ncca/ngl/vec3_array.py
64 65 66 67 68 69 70 71 72 73 | |
__str__()
Pretty representation as a list of Vec3 values.
Source code in ncca/ngl/vec3_array.py
157 158 159 160 | |
append(value)
Append a Vec3 object to the array.
| Parameters: |
|
|---|
Source code in ncca/ngl/vec3_array.py
98 99 100 101 102 103 104 105 106 107 | |
extend(values)
Extend the array by appending elements from the iterable.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Source code in ncca/ngl/vec3_array.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
sizeof()
Return the size of the array in bytes.
| Returns: |
|
|---|
Source code in ncca/ngl/vec3_array.py
162 163 164 165 166 167 168 | |
to_list()
Convert the array of Vec3 objects to a single flat list of floats.
| Returns: |
|
|---|
Source code in ncca/ngl/vec3_array.py
130 131 132 133 134 135 136 | |
to_numpy()
Convert the array of Vec3 objects to a numpy array.
This is the primary method for GPU data transfer.
| Returns: |
|
|---|
Source code in ncca/ngl/vec3_array.py
138 139 140 141 142 143 144 145 146 | |
to_tuple()
Return all components as one flat tuple of floats.
Source code in ncca/ngl/vec3_array.py
148 149 150 | |
Vec4Array
A class to hold Vec4 data in contiguous memory for efficient GPU transfer.
Internally uses a numpy array of shape (N, 4) for optimal performance. Mutable container — intentionally not hashable.
Source code in ncca/ngl/vec4_array.py
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
__eq__(other)
Compare two Vec4Array instances for equality.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec4_array.py
86 87 88 89 90 91 92 93 94 95 96 97 | |
__getitem__(index)
Get the Vec4 at the specified index.
| Parameters: |
|
|---|
| Returns: |
|---|
Source code in ncca/ngl/vec4_array.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
__init__(values=None)
Initializes the Vec4Array.
| Parameters: |
|
|---|
Source code in ncca/ngl/vec4_array.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
__iter__()
Return an iterator that yields Vec4 objects.
Source code in ncca/ngl/vec4_array.py
80 81 82 83 84 | |
__len__()
Return the number of elements in the array.
Source code in ncca/ngl/vec4_array.py
76 77 78 | |
__repr__()
Eval-able representation, e.g. Vec4Array([Vec4(0.0, 0.0, 0.0, 1.0)]).
Source code in ncca/ngl/vec4_array.py
147 148 149 150 | |
__setitem__(index, value)
Set the Vec4 at the specified index.
| Parameters: |
|
|---|
Source code in ncca/ngl/vec4_array.py
65 66 67 68 69 70 71 72 73 74 | |
__str__()
Pretty representation as a list of Vec4 values.
Source code in ncca/ngl/vec4_array.py
152 153 154 155 | |
append(value)
Append a Vec4 object to the array.
| Parameters: |
|
|---|
Source code in ncca/ngl/vec4_array.py
99 100 101 102 103 104 105 106 107 108 | |
extend(values)
Extend the array with a list of Vec4 objects.
| Parameters: |
|
|---|
Source code in ncca/ngl/vec4_array.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
sizeof()
Return the size of the array in bytes.
| Returns: |
|
|---|
Source code in ncca/ngl/vec4_array.py
157 158 159 160 161 162 163 | |
to_list()
Convert the array of Vec4 objects to a single flat list of floats.
| Returns: |
|
|---|
Source code in ncca/ngl/vec4_array.py
125 126 127 128 129 130 131 | |
to_numpy()
Convert the array of Vec4 objects to a numpy array.
This is the primary method for GPU data transfer.
| Returns: |
|
|---|
Source code in ncca/ngl/vec4_array.py
133 134 135 136 137 138 139 140 141 | |
to_tuple()
Return all components as one flat tuple of floats.
Source code in ncca/ngl/vec4_array.py
143 144 145 | |
Logging
ncca.ngl.logger is a ready-made logging.Logger shared by the whole
library — it writes coloured output to the console and plain text to
NGLDebug.log. Import it and use it directly:
from ncca.ngl import logger
logger.info("shader compiled")
setup_logger builds it, and is only worth calling yourself if you want
a second, separately configured logger.
setup_logger
Create (or return) the "ngl" logger with file and coloured console handlers.
Source code in ncca/ngl/log.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |