USD Utilities#

Overview#

File Name: usd_utils.py

This file provides utility functions for working with USD (Universal Scene Description) files. It includes functions to retrieve child prims, list prim paths, serialize and deserialize matrices, and compute transformation matrices for prims.

Functions#

get_prim_children#

get_prim_children(prim: Usd.Prim) List[Usd.Prim]#

Returns all children for the given prim.

Parameters:

prim (Usd.Prim) – The prim whose children are to be retrieved.

Returns:

List of child prims.

Return type:

List[Usd.Prim]

get_list_of_prim_paths#

get_list_of_prim_paths(
stage: Usd.Stage,
prim_str_path: str,
) List[Sdf.Path]#

Returns a list of all children of a prim located at ‘prim_str_path’. This function also works with collections.

Parameters:
  • stage (Usd.Stage) – The stage containing the prims.

  • prim_str_path (str) – The path to the prim or collection.

Returns:

List of child prim paths.

Return type:

List[Sdf.Path]

serialize_matrix_to_json#

serialize_matrix_to_json(matrix: Gf.Matrix4d) str#

Creates a JSON string representation of a matrix.

Parameters:

matrix (Gf.Matrix4d) – The matrix to serialize into a JSON string.

Returns:

The JSON string representation of the matrix.

Return type:

str

deserialize_matrix_from_json#

deserialize_matrix_from_json(
json_string: str,
) Gf.Matrix4d | None#

Creates a matrix from a JSON string. Returns None in case of failure.

Parameters:

json_string (str) – The JSON string to deserialize into a matrix.

Returns:

The deserialized matrix or None if failed.

Return type:

Optional[Gf.Matrix4d]

get_prim_matrix#

get_prim_matrix(
stage: Usd.Stage,
prim_path: str,
time: float = None,
) Optional[Gf.Matrix4d]:#

Returns the world transformation of a prim on ‘prim_path’ or None in case of failure. If ‘time’ is None, then Usd.TimeCode.Default() is used.

Parameters:
  • stage (Usd.Stage) – The stage containing the prim.

  • prim_path (str) – The path to the prim.

  • time (float, optional) – The time of the transformation in seconds. Defaults to Usd.TimeCode.Default().

Returns:

The world transformation matrix or None if failed.

Return type:

Optional[Gf.Matrix4d]