svg3d.view¶
Overview
Define OpenGL-style views and viewports for scene rendering.
- class svg3d.view.View(look_at, projection, scene, viewport=None)[source]¶
Bases:
object- DEFAULT_OBJECT_POSITION = array([0., 0., 0.])¶
Classmethods for this object center their view on the origin by default.
- ISOMETRIC_VIEW_MATRIX = array([[ 0.70710678, -0.40824829, 0.57735027, 0. ], [ 0. , 0.81649658, 0.57735027, 0. ], [ -0.70710678, -0.40824829, 0.57735027, 0. ], [ 0. , 0. , -100. , 1. ]])¶
- classmethod dimetric(scene, fov=1.0, distance=100.0)[source]¶
Create a
Viewbased on a dimetric projection.In a dimetric projection, the scale along two out of three axes is identical. This strikes a balance between the simplicity and interpretability of isometric projections and the improved sense of realism afforded by trimetric projections.
This is a parallel projection method, meaning that objects remain the same size regardless of their position from the camera. This is useful in diagrams and technical renderings but may be undesirable for realistic scenes.
- classmethod from_look_at_and_projection(look_at, projection, scene)[source]¶
Create a new
Viewfrom a lookAt and projection matrix.
- classmethod isometric(scene, fov=1.0, distance=100.0)[source]¶
Create a
Viewbased on an isometric projection.In an isometric projection, the scale along each coordinate axis is identical. This is a parallel projection method, meaning that objects remain the same size regardless of their position from the camera. This is useful in diagrams and technical renderings but may be undesirable for realistic scenes.
- property look_at¶
The openGL-style lookAt matrix.
- Type:
\((4,4)\)
numpy.ndarray
- property projection¶
The openGL-style projection matrix.
- Type:
\((4,4)\)
numpy.ndarray
- classmethod trimetric(scene, fov=1.0, distance=100.0)[source]¶
Create a
Viewbased on a trimetric projection.In a trimetric projection, each axis is scaled independently. This results in a more “natural” scene than isometric and trimetric views, as the foreshortening of each axis provides a sense of depth to the scene.
This is a parallel projection method, meaning that objects remain the same size regardless of their position from the camera. This is useful in diagrams and technical renderings but may be undesirable for realistic scenes.
- class svg3d.view.Viewport(minx=-0.5, miny=-0.5, width=1.0, height=1.0)[source]¶
Bases:
NamedTupleA
Viewportcontrols the visible area in a rendered SVG.This is a convience wrapper around the svgwrite
Viewboxclasses with a simplified interface.- classmethod from_aspect(aspect_ratio)[source]¶
Create a
Viewportwith the given aspect ratio.- Parameters:
aspect_ratio (float)
- svg3d.view.get_lookat_matrix(pos_object, pos_camera, vec_up=(0.0, 1.0, 0.0))[source]¶
Get the “look at” or view matrix for our system.
This matrix moves the world such that the camera is at the origin and rotates the world such that the z-axis of the camera is the mathematical z axis.
- Parameters:
pos_object (\((3,)\)
numpy.ndarray) – Position of the object we are looking at. “at” in openGL vernacular.pos_camera (\((3,)\)
numpy.ndarray) – Position of the camera. “eye” in openGL vernacular.vec_up (\((3,)\)
numpy.ndarray: | tuple, optional) – Vector describing the height of the camera. “up” in openGL vernacular. Default value: (0.0, 1.0, 0.0)
See also
Calculating a Lookat Matrix:
https://stackoverflow.com/questions/349050/calculating-a-lookat-matrix/6802424#6802424
See also
Understanding Lookat Matrices:
https://medium.com/@carmencincotti/lets-look-at-magic-lookat-matrices-c77e53ebdf78
- svg3d.view.get_projection_matrix(z_near, z_far, fov_y, aspect=1.0)[source]¶
Get a projection matrix from parameters of the provided view frustum.
z_near and z_far are the distances to the tip and base of the frustum, respectively. fov_y describes the opening angle of the base, and aspect describes the relationship between the y opening angle and the x. Objects that lie outside the view frustum are culled and wil not be rendered into the scene.
- Parameters:
z_near (float) – Distance to the near clipping plane. Must be greater than zero.
z_far (float) – Distance to the far clipping plane. Must be greater than z_near.
fov_y (float) – Field of view angle along the y direction, in degrees.
aspect (float, optional) – Ratio of field of view angle in the y direction to field of view angle in x. Default value: 1.0
See also
OpenGL Reference:
https://registry.khronos.org/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml