opynsim.graphics#
Classes
|
Represents a virtual camera at position in world space, looking along a direction vector. |
|
Represents an RGBA color in an sRGB color space with normalized 32-bit floating-point components. |
|
Represents a renderable mesh. |
|
Caches slow-to-load assets (shaders, meshes). |
Represents a two-dimensional image. |
- class opynsim.graphics.Camera(*args, **kwargs)#
Bases:
objectRepresents a virtual camera at position in world space, looking along a direction vector. The up vector specifies which direction corresponds to the ‘top’ of the rendered image.
- __init__(self) None#
- property direction#
Get/set the normalized direction the camera is looking toward.
- property position#
Get/set the position of the camera in world space.
- property up#
Get/set the normalized direction vector that corresponds to the ‘top’ of the rendered image
- class opynsim.graphics.Color(*args, **kwargs)#
Bases:
objectRepresents an RGBA color in an sRGB color space with normalized 32-bit floating-point components.
- __init__(self) None#
- __init__(self, r: float, g: float, b: float, a: float = 1.0) None
- property a#
(self) -> float
- property b#
(self) -> float
- black = Color(0, 0, 0, 1)#
- blue = Color(0, 0, 1, 1)#
- clear = Color(0, 0, 0, 0)#
- property g#
(self) -> float
- green = Color(0, 1, 0, 1)#
- property r#
(self) -> float
- red = Color(1, 0, 0, 1)#
- white = Color(1, 1, 1, 1)#
- class opynsim.graphics.Mesh(*args, **kwargs)#
Bases:
objectRepresents a renderable mesh.
- __init__(self) None#
- property faces#
Gets/sets the faces (indices) of the mesh as an 1-dimensional ndarray.
- property vertices#
Gets/sets the vertices of the mesh as an Nx3 ndarray.
- class opynsim.graphics.SceneCache(*args, **kwargs)#
Bases:
objectCaches slow-to-load assets (shaders, meshes).
- __init__(self) None#
- class opynsim.graphics.Texture2D#
Bases:
objectRepresents a two-dimensional image.
- __init__(*args, **kwargs)#
- pixels_rgb24(self) numpy.ndarray[dtype=uint8, shape=(*, *, 3), writable=False]#
Returns an ndarray with the shape
(height, width, 3), where each element of the 3rd dimension is a raw uint8 (0-255) pixel value for the red (R), green (G), and blue (B) components of the texture respectively.The layout of the pixels is such that the first pixel in the first row (
rv[0, 0]) starts in the top-left of the image. Subsequent pixels within that row are then encoded left-to-right. The following row (rv[1]) is then below that row, and so on, until the final pixel, which is in the bottom-right of the image.The encoding of the components of a pixel is such that the lowest value for each component is zero, representing zero intensity of that component. The highest value for each component is 255, representing the maximum intensity of that component. All components are in an sRGB color space.
- pixels_rgba32(self) numpy.ndarray[dtype=uint8, shape=(*, *, 4), writable=False]#
Returns an ndarray with the shape
(height, width, 4), where each element of the 3rd dimension is a raw uint8 (0-255) pixel value for the red (R), green (G), blue (B), and alpha (A) components of the texture respectively.The layout of the pixels is such that the first pixel in the first row (
rv[0, 0]) starts in the top-left of the image. Subsequent pixels within that row are then encoded left-to-right. The following row (rv[1]) is then below that row, and so on, until the final pixel, which is in the bottom-right of the image.The encoding of the components of a pixel is such that the lowest value for each component is zero, representing zero intensity of that component. The highest value for each component is 255, representing the maximum intensity of that component. The color components (R, G, and B) are in an sRGB color space, while the alpha component (A) is linear.
- opynsim.graphics.render_model_in_state(model: Model, model_state: ModelState, *, dimensions: tuple[int, int] = (640, 480), background_color: graphics.Color = Color(0, 0, 0, 0), draw_floor: bool = False, scene_cache: graphics.SceneCache | None = None, camera: graphics.Camera | None = None) graphics.Texture2D#
Renders the given
opynsim.Model+opynsim.ModelStateto aopynsim.graphics.Texture2D.- Parameters:
model (opynsim.Model) – The model to render.
model_state (opynsim.ModelState) – The state of the model to render. Should be realized to at least
opynsim.ModelStateStage.REPORT.dimensions (tuple[int, int]) – The desired output resolution (width, height) of the rendered image in pixels.
background_color (opynsim.graphics.Color) – The desired background color of the rendered scene.
draw_floor (bool) – Toggles drawing a chequered floor at Y=0 in the scene.
scene_cache (opynsim.graphics.SceneCache) – A scene cache from which the implementation pulls cached scene elements (shaders, meshes, etc.). Otherwise, the implementation loads all assets every time this function is called (slow).
camera (opynsim.graphics.Camera) – The camera to use when rendering (default: looks down -Z and pulls back from the origin until the entire model fits in-frame).
- Returns:
The rendered image, which will have the specified
dimensions.- Return type: