The html_export.py module#
Summary#
Convert a USD asset to a self-contained Three.js HTML viewer. |
Description#
Self-contained USD → Three.js HTML export.
Converts a USD asset (file or in-memory pxr.Usd.Stage) into a
self-contained HTML viewer page. The generated page embeds the geometry as a
base64 GLB and requires only a CDN connection for Three.js at runtime.
Module detail#
- html_export.export_usd_to_html(source: str | Path | object, output_path: str | Path | None = None, *, show_mesh_lines: bool = True, line_color: str = '#ffffff', line_opacity: float = 0.9, template_path: str | Path | None = None) pathlib.Path#
Convert a USD asset to a self-contained Three.js HTML viewer.
- Parameters:
- source
str|Path|pxr.Usd.Stage USD file path (.usd / .usda / .usdc / .usdz) or an in-memory USD stage.
- output_path
str|Path|None, default:None Destination for the HTML file. When None, placed alongside the source as
{stem}_viewer.html.- show_mesh_linesbool, default:
True When True, injects Three.js LineSegments derived from polygon edges of all UsdGeomMesh prims in the stage for a wireframe overlay.
- line_color
str, default: “#ffffff” CSS hex color for the mesh-edge overlay.
- line_opacity
float, default: 0.9 Opacity of the mesh-edge overlay (0.0 - 1.0).
- template_path
str|Path|None, default:None Path to a custom HTML template. The template must contain
__GLB_B64_JSON__and__MODEL_NAME_JSON__as literal placeholders that will be replaced with JSON-encoded values at render time. Whenshow_mesh_lines=True, the template must also include the wireframe injection anchors (const binary = atob(glbBase64);andscene.add(gltf.scene);). WhenNone, the built-inglb_template.htmlis used.
- source
- Returns:
pathlib.PathAbsolute path to the written HTML file.
- Raises:
ImportErrorIf
usd-coreis not installed.FileNotFoundErrorIf a file path is given but does not exist on disk, or if
template_pathpoints to a missing file.ValueErrorIf
line_opacityis outside [0.0, 1.0],line_coloris not a valid CSS hex color, or the template is missing required placeholders or wireframe injection anchors.