Skip to content

USD API

dcc_mcp_core (usd module)

USD (Universal Scene Description) support for DCC-MCP-Core.

Overview

Provides:

  • Core USD types: SdfPath, VtValue, UsdPrim, UsdStage
  • USDA serialization: Export stages as human-readable .usda text
  • JSON transport: Serialize/deserialize stages for MCP IPC
  • DCC bridge: Convert between SceneInfo JSON and UsdStage
  • Pure Rust: No dependency on OpenUSD C++ library

WARNING

This crate provides a compatible data model and serialization format for lightweight scene description exchange. It does not link against the OpenUSD C++ library.

SdfPath

USD scene graph path (e.g. /World/Cube).

Constructor

python
from dcc_mcp_core import SdfPath

path = SdfPath("/World/Cube")

Methods

MethodReturnsDescription
child(name)SdfPathAppend child segment
parent()SdfPath | NoneParent path
__eq__(other)boolEquality comparison
__hash__()intHash value (usable as dict key)
__str__()strString representation

Properties

PropertyTypeDescription
is_absoluteboolTrue if path starts with /
namestrLast path element

Example

python
path = SdfPath("/World/Cube")
print(path.is_absolute)  # True
print(path.name)         # Cube
child = path.child("Material")  # SdfPath("/World/Cube/Material")
parent = path.parent()   # SdfPath("/World")

VtValue

USD variant value container.

Factory Methods

MethodReturnsDescription
from_bool(v)VtValueCreate bool value
from_int(v)VtValueCreate int value
from_float(v)VtValueCreate float value
from_string(v)VtValueCreate string value
from_token(v)VtValueCreate token value
from_asset(v)VtValueCreate asset value
from_vec3f(x, y, z)VtValueCreate vec3 from floats

Properties

PropertyTypeDescription
type_namestrUSD type name (e.g. float3)

Methods

MethodReturnsDescription
to_python()bool | int | float | str | tuple | list | NoneConvert to Python primitive

Example

python
v_bool = VtValue.from_bool(True)
v_int = VtValue.from_int(42)
v_float = VtValue.from_float(3.14)
v_vec3 = VtValue.from_vec3f(1.0, 2.0, 3.0)

print(v_vec3.to_python())   # (1.0, 2.0, 3.0)
print(v_vec3.type_name)    # float3

UsdPrim

A prim (primitive) within a USD stage.

Properties

PropertyTypeDescription
pathSdfPathPrim path
type_namestrPrim type (e.g. Mesh)
activeboolWhether prim is active
namestrPrim name

Methods

MethodReturnsDescription
set_attribute(name, value)NoneSet attribute value
get_attribute(name)VtValue | NoneGet attribute value
attribute_names()list[str]List attribute names
attributes_summary()dict[str, str]Attribute names to type names
has_api(schema)boolCheck if prim has API

UsdStage

Main stage container for USD scene data.

Constructor

python
from dcc_mcp_core import UsdStage

stage = UsdStage("my_scene")

Properties

PropertyTypeDescription
namestrStage name
idstrStage UUID
default_primstr | NoneDefault prim name
up_axisstrUp axis (X, Y, or Z)
meters_per_unitfloatMeters per unit
fpsfloat | NoneFrames per second
start_time_codefloat | NoneStart time code
end_time_codefloat | NoneEnd time code

Methods

MethodReturnsDescription
define_prim(path, type_name)UsdPrimDefine a prim
get_prim(path)UsdPrim | NoneGet a prim
has_prim(path)boolCheck if prim exists
remove_prim(path)boolRemove a prim
traverse()list[UsdPrim]Get all prims
prims_of_type(type_name)list[UsdPrim]Get prims of type
set_attribute(prim_path, attr_name, value)NoneSet attribute
get_attribute(prim_path, attr_name)VtValue | NoneGet attribute
metrics()dict[str, int]Get stage metrics
to_json()strExport as JSON
from_json(json) (staticmethod)UsdStageImport from JSON
export_usda()strExport as USDA text

Example

python
stage = UsdStage("my_scene")
stage.default_prim = "World"

stage.define_prim("/World", "Xform")
stage.define_prim("/World/Cube", "Mesh")
stage.set_attribute("/World/Cube", "extent", VtValue.from_vec3f(1, 1, 1))

# Serialize
json_str = stage.to_json()
usda = stage.export_usda()

# Query
for prim in stage.traverse():
    print(f"{prim.path} ({prim.type_name})")

DCC Bridge Functions

scene_info_json_to_stage()

python
from dcc_mcp_core import scene_info_json_to_stage

scene_info_json = '{"name": "my_scene", "prim_count": 100}'
usd_stage = scene_info_json_to_stage(scene_info_json, "maya")

stage_to_scene_info_json()

python
from dcc_mcp_core import stage_to_scene_info_json

scene_info_json = stage_to_scene_info_json(stage)

units_to_mpu()

python
from dcc_mcp_core import units_to_mpu

print(units_to_mpu("cm"))   # 0.01
print(units_to_mpu("m"))    # 1.0

mpu_to_units()

python
from dcc_mcp_core import mpu_to_units

print(mpu_to_units(0.01))   # cm
print(mpu_to_units(1.0))    # m

Performance Notes

  • USDA export is human-readable but slower than JSON
  • JSON serialization is compact and fast, ideal for IPC
  • Path validation is performed on construction, not lazily

Released under the MIT License.