.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/gallery/14_openusd_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_gallery_examples_gallery_14_openusd_export.py: .. _ref_openusd_export: ==================================================== Export a bracket scaffold mesh as OpenUSD HTML ==================================================== **Summary**: This example imports the bracket scaffold geometry, scaffolds and surface meshes it, and exports the resulting mesh as a self-contained HTML viewer using OpenUSD. Procedure ~~~~~~~~~~ #. Launch an Ansys Prime Server instance. #. Import the bracket scaffold geometry. #. Scaffold the topofaces and surface mesh them with quad elements. #. Display the resulting mesh. #. Export the mesh as a USD file and a self-contained Three.js HTML viewer. #. Exit the PyPrimeMesh session. .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python # sphinx_gallery_tags = ["USD"] .. GENERATED FROM PYTHON SOURCE LINES 47-51 Launch Ansys Prime Server ~~~~~~~~~~~~~~~~~~~~~~~~~ Import all necessary modules, launch an instance of Ansys Prime Server, and connect the PyPrimeMesh client. .. GENERATED FROM PYTHON SOURCE LINES 51-81 .. code-block:: Python from pathlib import Path import ansys.meshing.prime as prime from ansys.meshing.prime.core.mesh_usd_io import export_usd_viewer_html from ansys.meshing.prime.graphics import PrimePlotter prime_client = prime.launch_prime() model = prime_client.model ################# # Import geometry # ~~~~~~~~~~~~~~~ # Download the bracket scaffold geometry (FMD) file and import it into the # model, creating a part per the CAD model for the topology-based connection. bracket_file = prime.examples.download_bracket_fmd(force=True) file_io = prime.FileIO(model) file_io.import_cad( file_name=bracket_file, params=prime.ImportCadParams( model=model, length_unit=prime.LengthUnit.MM, part_creation_type=prime.PartCreationType.MODEL, ), ) part = model.get_part_by_name('bracket_mid_surface-3') .. rst-class:: sphx-glr-script-out .. code-block:: none Warning (Client): Modification of these configurations is not recommended. Refer the documentation for your installed product for additional information. /home/runner/work/pyprimemesh/pyprimemesh/.venv/lib/python3.14/site-packages/ansys/meshing/prime/internals/cyberchannel.py:183: UserWarning: Starting gRPC client without TLS on 127.0.0.1:42731. This is INSECURE. Consider using a secure connection. warn( .. GENERATED FROM PYTHON SOURCE LINES 82-86 Scaffold and surface mesh ~~~~~~~~~~~~~~~~~~~~~~~~~ Scaffold the topofaces to connect all the surface bodies, then surface mesh the topofaces with a constant size to generate quad elements. .. GENERATED FROM PYTHON SOURCE LINES 86-121 .. code-block:: Python element_size = 0.5 scaffolder_params = prime.ScaffolderParams( model, absolute_dist_tol=0.1 * element_size, intersection_control_mask=prime.IntersectionMask.FACEFACEANDEDGEEDGE, constant_mesh_size=element_size, ) faces = part.get_topo_faces() scaffold_res = prime.Scaffolder(model, part.id).scaffold_topo_faces_and_beams( topo_faces=faces, topo_beams=[], params=scaffolder_params ) print(scaffold_res) surfer_params = prime.SurferParams( model=model, size_field_type=prime.SizeFieldType.CONSTANT, constant_size=element_size, generate_quads=True, ) surfer_result = prime.Surfer(model).mesh_topo_faces(part.id, topo_faces=faces, params=surfer_params) ################## # Display the mesh # ~~~~~~~~~~~~~~~~ # Show the resulting surface mesh. display = PrimePlotter() display.plot(model, update=True) display.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/gallery/images/sphx_glr_14_openusd_export_001.png :alt: 14 openusd export :srcset: /examples/gallery_examples/gallery/images/sphx_glr_14_openusd_export_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/pyprimemesh/pyprimemesh/doc/source/examples/gallery_examples/gallery/images/sphx_glr_14_openusd_export_001.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none n_incomplete_topo_faces : 0 error_code : 0 .. GENERATED FROM PYTHON SOURCE LINES 122-126 Export to OpenUSD and HTML ~~~~~~~~~~~~~~~~~~~~~~~~~~ Build the USD geometry representation from the surface mesh and export it as both a ``.usd`` file and a self-contained Three.js HTML viewer. .. GENERATED FROM PYTHON SOURCE LINES 126-147 .. code-block:: Python usd_geom = model.as_usd(update=True) out_dir = Path.cwd() / "examples" / "gallery" / "_generated" out_dir.mkdir(parents=True, exist_ok=True) usd_path = out_dir / "bracket_scaffold_mesh.usd" html_path = export_usd_viewer_html( usd_geom, usd_path, out_dir / "bracket_scaffold_mesh_viewer.html" ) print(f"USD file: {usd_path}") print(f"HTML viewer: {html_path}") print("Controls: left-drag orbit, right-drag pan, scroll zoom.") ###### # Exit # ~~~~ # Exit the PyPrimeMesh session. prime_client.exit() .. rst-class:: sphx-glr-script-out .. code-block:: none USD file: /home/runner/work/pyprimemesh/pyprimemesh/examples/gallery/examples/gallery/_generated/bracket_scaffold_mesh.usd HTML viewer: /home/runner/work/pyprimemesh/pyprimemesh/examples/gallery/examples/gallery/_generated/bracket_scaffold_mesh_viewer.html Controls: left-drag orbit, right-drag pan, scroll zoom. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 17.543 seconds) .. rst-class:: sphx-glr-example-tags 🏷 Tags: USD .. _sphx_glr_download_examples_gallery_examples_gallery_14_openusd_export.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 14_openusd_export.ipynb <14_openusd_export.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 14_openusd_export.py <14_openusd_export.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 14_openusd_export.zip <14_openusd_export.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_