.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/02-basic-usd-examples/usd_to_html_export.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_02-basic-usd-examples_usd_to_html_export.py: .. _ref_usd_to_html_export: ========================== Export a USD file to HTML ========================== This example shows how to convert a USD file (or an in-memory :class:`pxr.Usd.Stage`) into a self-contained HTML viewer page. The page embeds all geometry as a base64-encoded GLB file and renders it with `Three.js `_ — only a CDN connection is required to open it in any modern browser. .. note:: This feature requires the ``[usd]`` optional dependencies:: pip install ansys-tools-visualization-interface[usd] .. GENERATED FROM PYTHON SOURCE LINES 45-49 Create a sample USD file ======================== Build a minimal USD stage with one triangular mesh and save it to disk so the file-path examples below have something to read. .. GENERATED FROM PYTHON SOURCE LINES 49-62 .. code-block:: Python from pxr import Gf, Usd, UsdGeom stage = Usd.Stage.CreateNew("my_model.usd") mesh = UsdGeom.Mesh.Define(stage, "/Triangle") stage.SetDefaultPrim(mesh.GetPrim()) mesh.GetPointsAttr().Set( [Gf.Vec3f(0, 0, 0), Gf.Vec3f(1, 0, 0), Gf.Vec3f(0, 1, 0)] ) mesh.GetFaceVertexCountsAttr().Set([3]) mesh.GetFaceVertexIndicesAttr().Set([0, 1, 2]) stage.Save() .. GENERATED FROM PYTHON SOURCE LINES 63-68 Export from a USD file on disk ============================== Pass a file path string or :class:`pathlib.Path` to :func:`~ansys.tools.visualization_interface.export_usd_to_html`. The function returns the :class:`pathlib.Path` to the generated HTML file. .. GENERATED FROM PYTHON SOURCE LINES 68-75 .. code-block:: Python from ansys.tools.visualization_interface import export_usd_to_html html_path = export_usd_to_html("my_model.usd", "my_model_viewer.html") print(f"Viewer written to: {html_path}") .. rst-class:: sphx-glr-script-out .. code-block:: none Viewer written to: /home/runner/work/ansys-tools-visualization-interface/ansys-tools-visualization-interface/examples/02-basic-usd-examples/my_model_viewer.html .. GENERATED FROM PYTHON SOURCE LINES 76-81 Export from an in-memory stage ============================== You can pass a :class:`pxr.Usd.Stage` directly — no ``.usd`` file on disk is required. A temporary file is created automatically, used to generate the GLB, and removed when the function returns. .. GENERATED FROM PYTHON SOURCE LINES 81-86 .. code-block:: Python html_path = export_usd_to_html(stage, "triangle_viewer.html") print(f"Viewer written to: {html_path}") .. rst-class:: sphx-glr-script-out .. code-block:: none Viewer written to: /home/runner/work/ansys-tools-visualization-interface/ansys-tools-visualization-interface/examples/02-basic-usd-examples/triangle_viewer.html .. GENERATED FROM PYTHON SOURCE LINES 87-92 Add a wireframe overlay ======================= Set ``show_mesh_lines=True`` to inject a Three.js ``LineSegments`` overlay that traces every polygon edge. Use ``line_color`` (CSS hex) and ``line_opacity`` (0–1) to style it. .. GENERATED FROM PYTHON SOURCE LINES 92-101 .. code-block:: Python html_path = export_usd_to_html( "my_model.usd", "my_model_viewer.html", show_mesh_lines=True, line_color="#00ffcc", line_opacity=0.7, ) print(f"Viewer with wireframe written to: {html_path}") .. rst-class:: sphx-glr-script-out .. code-block:: none Viewer with wireframe written to: /home/runner/work/ansys-tools-visualization-interface/ansys-tools-visualization-interface/examples/02-basic-usd-examples/my_model_viewer.html .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.306 seconds) .. _sphx_glr_download_examples_02-basic-usd-examples_usd_to_html_export.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: usd_to_html_export.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: usd_to_html_export.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: usd_to_html_export.zip `