openusd-build
openusd-build generates Rust code from OpenUSD schema.usda files. It serves
the same purpose as usdGenSchema for C++: generating typed schema views,
property accessors, and the schema definitions used by a stage's registry.
The generator uses
openusd
to open schema libraries as stages and resolve their sublayers and inheritance.
It is written in Rust and requires no C++ or Python dependencies.
Add it as a build dependency, configure your schema libraries in build.rs,
and include the generated code with openusd::include_schema!.
openusd-schemas
uses this workflow to build its eleven standard schema families.
Each library produces a single Rust file containing:
- A
tokensmodule with constants for schema names, property names, and token values. - A
SCHEMASconstant with schema declarations, including property fallbacks, allowed tokens, and inheritance, plus the metadata fields and kinds the library'splugInfo.jsondeclares. The registry accepts these declarations directly, without parsing schema files at runtime. - Typed schema views with accessors for declared and inherited properties.
- Optional Rust enums generated from token properties'
allowedTokens.
Usage
[]
= "0.8"
[]
= "0.8"
// build.rs
Use the libraryName declared in schema.usda to include the generated code:
// src/lib.rs
Register the generated schema definitions so the stage can recognize schema types and supply fallback values for properties without authored values:
use ;
let registry = builder.register.build?;
let stage = builder.schema_registry.open?;
let mesh = get?.expect;
let points = mesh.points_attr.?;
To generate several libraries, call .schema(..) once for each library. If a
schema inherits from a library generated elsewhere, use .extern_library(..)
to specify the Rust module containing that library's views.
The generated output
fixtures/tiny/expected.rs
shows the complete output for a small test library. For a larger example, see
the generated core usd schemas in
core_schemas.rs.
Generated property methods use names and documentation from the source schema. For example, an attribute accessor includes the declared type, fallback value, and Rust type used to read it:
/// The bounds, in the shape's own space.
///
/// Declared `double3 extent = (1.0, 1.0, 1.0)`. Read it with
/// `get::<::openusd::gf::Vec3d>()`.
License
Licensed under the MIT License.