pygfx.geometries

Containers for geometry data.

A geometry object contains the data that defines (the shape of) the object, such as positions, plus data associated with these positions (normals, texcoords, colors, etc.).

Its attributes are Buffer and Texture(View) objects. The data can be provided as keyword arguments, which are converted to numpy arrays and wrapped in a Buffer if necessary.

The names for these attributes are standardized so that the renderers know what to expect. Each material requires certain attributes to be present, and may support optional attributes. Optional attributes must always be “turned on” on the material; their presence on the geometry does not mean that they’re used.

The standardized names are:

  • indices: An index into per-vertex data. Typically Nx3 for mesh geometry.

  • positions: Nx3 positions (xyz), defining the location of e.g. vertices or points.

  • normals: Nx3 normal vectors. These may or may not be unit.

  • texcoords: Texture coordinates used to lookup the color for a vertex.

    Can be Nx1, Nx2 or Nx3, corresponding to a 1D, 2D and 3D texture map.

  • colors: Per-vertex colors. Must be NxM, with M 1-4 for gray,

    gray+alpha, rgb, rgba, respectively.

  • sizes: Scalar size per-vertex.

  • grid: A 2D or 3D Texture that contains a regular grid of data, i.e. for images and volumes.

Basic Geometry

box_geometry([width, height, depth, ...])

Generate a box (rectangular cuboid).

cylinder_geometry([radius_bottom, ...])

Generate a cylinder or a cylinder segment.

cone_geometry([radius, height, ...])

Generate a cone or a cone segment.

sphere_geometry([radius, width_segments, ...])

Generate a sphere.

plane_geometry([width, height, ...])

Generate a plane.

Geometry(**kwargs)

Generic container for Geometry data.

Text Geometry

TextGeometry([text, markdown, screen_space, ...])

Geometry specific for representing text.

TextItem(text[, font_props, ws_before, ...])

A formatted piece of text.

Other/Special Geometry

geometry_from_trimesh(mesh)

Convert a Trimesh geometry object to pygfx geometry.

octahedron_geometry([radius, subdivisions])

Generate a octahedron.

icosahedron_geometry([radius, subdivisions])

Generate a icosahedron.

dodecahedron_geometry([radius, subdivisions])

Generate a dodecahedron.

tetrahedron_geometry([radius, subdivisions])

Generate a tetrahedron.

torus_knot_geometry([scale, tube, ...])

Generate a torus knot.

klein_bottle_geometry([scale, stitch])

Generate a Klein bottle.