Note
Go to the end to download the full example code.
Bounding Box Coordinates
Render two volumes using different world transforms. Prints the world bounding box of the scene which used to trigger an Exception.

World bounding box:
[[ -0.5 -0.5 -0.5]
[277.5 127.5 255.5]]
import imageio.v3 as iio
import numpy as np
from rendercanvas.auto import RenderCanvas, loop
import pygfx as gfx
canvas = RenderCanvas()
renderer = gfx.renderers.WgpuRenderer(canvas)
scene = gfx.Scene()
voldata = iio.imread("imageio:stent.npz").astype(np.float32)
geometry = gfx.Geometry(grid=voldata)
geometry_with_texture = gfx.Geometry(grid=gfx.Texture(data=voldata, dim=3))
material = gfx.VolumeMipMaterial(clim=(0, 2000))
vol1 = gfx.Volume(geometry, material)
vol2 = gfx.Volume(geometry_with_texture, material)
scene.add(vol1, vol2)
vol2.local.x = 150
camera = gfx.PerspectiveCamera(70, 16 / 9)
camera.show_object(scene, view_dir=(-1, -1, -1), up=(0, 0, 1))
controller = gfx.OrbitController(camera, register_events=renderer)
print("World bounding box:\n", scene.get_world_bounding_box())
def animate():
renderer.render(scene, camera)
canvas.request_draw()
if __name__ == "__main__":
canvas.request_draw(animate)
loop.run()
Total running time of the script: (0 minutes 0.842 seconds)
Gallery generated by Sphinx-Gallery
Interactive example
Try this example in your browser using Pyodide. Might not work with all examples and all devices. Check the output and your browser’s console for details.