USD Utility Functions

Overview

The file usd_utils.py contains set of utility functions for working with the Universal Scene Description (USD) framework. These utilities are designed to facilitate operations such as retrieving prims and their children, handling prim paths, and managing transformation matrices in both JSON and USD formats.

Functions

get_prim_children

get_prim_children(prim) List[Usd.Prim]

Returns all children for the prim.

param prim

A Usd.Prim object representing the parent prim.

returns

A list of Usd.Prim objects representing the children of the specified prim.

get_list_of_prim_paths

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

Returns list of all children of prim on ‘prim_str_path’. Works with collections as well.

param stage

A Usd.Stage object where the prim is located.

param prim_str_path

A string representing the SDF path to the prim.

returns

A list of Sdf.Path objects representing the paths to all children of the specified prim, including those within USD collections.

serialize_matrix_to_json

serialize_matrix_to_json(matrix: Gf.Matrix4d) str

Creates json string out of matrix.

param matrix

A Gf.Matrix4d object representing the transformation matrix.

returns

A JSON string representation of the matrix.

deserialize_matrix_from_json

deserialize_matrix_from_json(json_string: str) Optional[Gf.Matrix4d]

Creates matrix out of json string. Returns None in case of failure.

param json_string

A JSON string representation of a matrix.

returns

A Gf.Matrix4d object representing the matrix, or None if deserialization fails.

get_prim_matrix

get_prim_matrix(stage, prim_path: str, time_code: Usd.TimeCode = None) Optional[Gf.Matrix4d]

Returns world transformation of a prim on ‘prim_path’ or None in case of failure.

param stage

A Usd.Stage object where the prim is located.

param prim_path

A string representing the SDF path to the prim.

param time_code

(Optional) A Usd.TimeCode object specifying the time for which to retrieve the transformation. Defaults to Usd.TimeCode.Default() if not provided.

returns

A Gf.Matrix4d object representing the world transformation matrix of the specified prim, or None if the operation fails.