pygfx.helpers.BoxHelper

class pygfx.helpers.BoxHelper(size=1.0, thickness=1, color='white')

Bases: Line

A WorldObject that shows a box-shaped wireframe.

Commonly used to visualize bounding boxes.

Parameters:
  • size (float) – The length of the box’ edges in local space.

  • thickness (float) – The thickness of the lines in (onscreen) pixels.

  • color (Color) – The color of the box.

set_transform_by_aabb(aabb, scale=1.0)

Align with axis aligned bounding box.

The position and scale attributes will be configured such that the helper will match the given bounding box.

Parameters:
  • aabb (ndarray, [2, 3]) – The bounding box to align with. The two vectors represent the minimum and maximum coordinates of the axis-aligned bounding box.

  • scale (float) – Scale multiplier of the final wireframe. Useful for adding margin to the box.

set_transform_by_object(object: WorldObject, space='world', scale=1.0)

Align with WorldObject.

Set the position and scale attributes based on the bounding box of another object.

Parameters:
  • object (WorldObject) – The object to wrap inside this wireframe.

  • space (str) – If “world”, the wire will be aligned to the world’s axes. If “local”, the wire will be aligned to the local axes.

  • scale (float) – Scale multiplier of the final wireframe. Useful for adding margin to the box.

Examples

World-space bounding box visualization:

box = gfx.BoxHelper()
box.set_transform_by_object(mesh)
scene.add(box)

Local-space bounding box visualization:

box = gfx.BoxHelper()
box.set_transform_by_object(mesh, space="local")
mesh.add(box)
get_world_bounding_box()

Axis aligned bounding box in world space.

Returns:

aabb – The transformed axis-aligned bounding box, or None when the object does not take up a particular space.

Return type:

ndarray, [2, 3] or None

get_world_bounding_sphere()

Bounding Sphere in world space.

Returns:

bounding_shere – A sphere (x, y, z, radius), or None when the object does not take up a particular space.

Return type:

ndarray, [4] or None

Examples

Boundary Boxes

Boundary Boxes

Multi-Object Selection

Multi-Object Selection

Axis Helper 2

Axis Helper 2