Displayable#

Provides a mixin class for local 3D display (Babylon.js HTML, or the GLB viewer).

class volmdlr.displayable.Displayable3D#

Bases: object

Mixin class for local 3D display using Babylon.js.

display_3d(selector: str | None = None, page_name: str | None = None, use_cdn: bool = True, dark_mode: bool = False, **kwargs: Any) str#

Display the 3D model locally in a web browser using Babylon.js.

Parameters:
  • selector – The selector of the @cad_view method to use. If None, uses the first one.

  • page_name – The name of the HTML file to generate. If None, a temp file is created.

  • use_cdn – Flag to use CDN for loading Babylon.js resources.

  • dark_mode – Enable dark mode for the visualization.

  • kwargs – Additional arguments passed to the @cad_view method.

Returns:

The file path of the generated HTML file.

save_display_3d_to_file(filename: str, selector: str | None = None, use_cdn: bool = True, dark_mode: bool = False, **kwargs: Any) str#

Save the 3D model display to an HTML file without opening the browser.

Parameters:
  • filename – The name of the HTML file to generate.

  • selector – The selector of the @cad_view method to use. If None, uses the first one.

  • use_cdn – Flag to use CDN for loading Babylon.js resources.

  • dark_mode – Enable dark mode for the visualization.

  • kwargs – Additional arguments passed to the @cad_view method.

Returns:

The file path of the generated HTML file.

save_display_3d_to_stream(stream, selector: str | None = None, use_cdn: bool = True, dark_mode: bool = False, **kwargs: Any) None#

Save the 3D display HTML content to a stream.

Parameters:
  • stream – The stream to write the HTML content to (StringFile or file-like).

  • selector – The selector of the @cad_view method to use. If None, uses the first one.

  • use_cdn – Flag to use CDN for loading Babylon.js resources.

  • dark_mode – Enable dark mode for the visualization.

  • kwargs – Additional arguments passed to the @cad_view method.

view(selector: str | None = None, *, open_browser: bool = True) str#

Open, in the local GLB viewer, the model.json produced by this object’s @volmdlr_view method.

Local counterpart of the platform display: it runs the same @volmdlr_view method (which exports model.json + GLBs to the viewer’s export directory) and serves the result through the shared volmdlr_viewer daemon. Requires pip install ‘volmdlr[viewer]’.

Parameters:
  • selector – Selector of the @volmdlr_view method to use. If None, uses the first one.

  • open_browser – Open the URL in the default browser.

Returns:

The viewer URL serving this object.