svg3d

Three-dimensional vector rendering software in Python. This primary package contains object primitives (Mesh) and the rendering engine Engine itself.

class svg3d.svg3d.Engine(views, precision=14)[source]

Bases: object

Parameters:

precision (int)

__init__(views, precision=14)[source]

The engine used to render a scene into an image.

Example

> import svg3d > scene = [svg3d.Mesh.example_mesh()] > view = svg3d.View.isometric(scene) > svg3d.Engine([view]).render(“example.svg”) Wrote file “example.svg”

Parameters:
  • views (list[View]) – List of View objects to render. Each is rendered into the same image, allowing for composite graphics from multiple viewpoints. For simplicity, a single View object is often best.

  • precision (int) – Number of decimal places of precision for numeric quantities in the mesh. Smaller values will reduce file sizes but may result in minor inconsistencies in very small geometries. Default value: 14

property precision

Get or set the rounding precision for vertices of rendered polygons.

Type:

int

render(filename, size=(512, 512), viewbox='-0.5 -0.5 1.0 1.0', **extra)[source]

Render the current view or views to a file.

Parameters:
  • filename (str) – The name of the file to save the render to. Should be postfixed with .svg

  • size (tuple of int, optional) – Size of the render in pixels. Default is (512, 512).

  • viewbox (str, optional) – viewBox attribute for the SVG. Default is “-0.5 -0.5 1.0 1.0”.

  • **extra – Additional keyword arguments to be passed into svgwrite.

Raises:
property views

Get or set the list of views to render.

Type:

list[View]

class svg3d.svg3d.Mesh(faces, shader=None, circle_radius=0.0)[source]

Bases: object

Parameters:
__init__(faces, shader=None, circle_radius=0.0)[source]
Parameters:
property circle_radius
property faces

Get or set the faces of the Mesh

Type:

np.ndarray

classmethod from_coxeter(poly, shader=None)[source]

Create a Mesh object from a coxeter ConvexPolyhedron.

Parameters:
classmethod from_vertices_and_faces(vertices, faces, shader=None)[source]
Parameters:
property normals

Get the normals for the faces of the Mesh.

Type:

np.ndarray

property shader

Get or set the Shader for the Mesh

Type:

Callable