Plain usage of the USD backend#

This example shows how to use the Python USD viewer backend in the Visualization Interface Tool to display meshes using the OpenUSD-based viewer from the python-usd-viewer package.

Plot a single mesh#

This code shows how to plot a single PyVista mesh with the USD backend.

import pyvista as pv

from ansys.tools.visualization_interface import Plotter
from ansys.tools.visualization_interface.backends.usd.usd_interface import USDInterface

mesh = pv.Sphere()

# Create a plotter with the USD backend
pl = Plotter(backend=USDInterface())

# Add the mesh to the plotter
pl.plot(mesh)

# Show the plotter — opens a Qt window and blocks until it is closed
pl.show()

Plot multiple meshes#

Use plot_iter() to add several meshes at once before showing the viewer.

import pyvista as pv

from ansys.tools.visualization_interface import Plotter
from ansys.tools.visualization_interface.backends.usd.usd_interface import USDInterface

meshes = [
    pv.Sphere(center=(0, 0, 0)),
    pv.Cube(center=(2, 0, 0)),
    pv.Cylinder(center=(-2, 0, 0)),
]

pl = Plotter(backend=USDInterface())
pl.plot_iter(meshes)
pl.show()

Load and display a USD file#

If you already have a .usd / .usda / .usdc file on disk, pass its path directly to plot(). The file is opened as a pxr.Usd.Stage and displayed in the viewer.

import pyvista as pv
import tempfile, os

from ansys.tools.visualization_interface import Plotter
from ansys.tools.visualization_interface.backends.usd.usd_interface import USDInterface

# Write a simple USD file to a temporary location for demonstration purposes
usd_content = """\
#usda 1.0

def Sphere "Ball"
{
    double radius = 1
}
"""
tmp = tempfile.NamedTemporaryFile(suffix=".usda", mode="w", delete=False)
tmp.write(usd_content)
tmp.close()

pl = Plotter(backend=USDInterface())
pl.plot(tmp.name)
pl.show()

os.unlink(tmp.name)

Total running time of the script: (0 minutes 0.000 seconds)