Mitsuba Bridge

Convert WiTwin scenes to Mitsuba renderer format

Overview#

WiTwin Core provides a bridge between WiTwin scenes and the Mitsuba renderer. This is used internally by witwin.channel and witwin.maxwell to power their ray tracing backends. It can also be used directly when you need to render or validate a scene in Mitsuba.

from witwin.core import build_mitsuba_scene, create_mitsuba_mesh

build_mitsuba_scene()#

Convert a WiTwin scene to a Mitsuba scene object.

from witwin.core import build_mitsuba_scene, Box, Material, Structure, SceneBase
 
scene = SceneBase(
    structures=[
        Structure(
            name="wall",
            geometry=Box(position=(0.0, 0.0, 1.5), size=(0.25, 4.0, 3.0)),
            material=Material(eps_r=4.0),
        )
    ]
)
 
mi_scene = build_mitsuba_scene(scene)

Returns a MitsubaSceneHandle wrapping the compiled Mitsuba scene.


create_mitsuba_mesh()#

Convert a single geometry object to a Mitsuba mesh primitive.

from witwin.core import create_mitsuba_mesh, Box
 
mi_mesh = create_mitsuba_mesh(Box(position=(0.0, 0.0, 0.0), size=(1.0, 1.0, 1.0)))

update_mitsuba_scene_vertices()#

Update vertex positions in an existing compiled Mitsuba scene without a full rebuild. Used for differentiable geometry optimization where mesh topology stays fixed but vertex positions change.

from witwin.core import update_mitsuba_scene_vertices
 
update_mitsuba_scene_vertices(mi_scene_handle, new_vertices)

MitsubaSceneHandle#

A handle to a compiled Mitsuba scene. Returned by build_mitsuba_scene(). Holds the internal Mitsuba scene state and exposes it to WiTwin solver backends.


MitsubaRenderable#

A protocol that geometry objects can implement to provide custom Mitsuba rendering behavior. Most users do not need to implement this directly.


When to Use#

The Mitsuba bridge is used automatically when you call a WiTwin solver. You only need to use it directly when:

  • Debugging scene geometry in the Mitsuba renderer
  • Building a custom solver on top of WiTwin Core
  • Updating mesh vertices during a differentiable optimization loop without rebuilding the full scene

Note

The Mitsuba bridge requires Mitsuba to be installed. It is not included in the base witwin package. Install Mitsuba separately if you need direct access to these functions.

Next Steps#