Material Binding#

Materials in USD are assigned to geometry prims via the material:binding relationship. ovrtx lets you change these bindings at runtime, so you can swap materials on prims without reloading the scene.

To bind a material, write the material:binding attribute on the target geometry prim with the absolute path of the material prim as a path string.

Note

The material prim must already exist in the stage (loaded from USD). This operation changes which existing material is assigned to a prim – it does not create new materials.

Binding a Material#

Use write_array_attribute() with the prim path, the material:binding attribute name, and the material path as a list[list[str]]. The string list format is automatically detected as path/relationship data.

# Bind /World/Looks/srf_glass to /World/logo
renderer.write_array_attribute(
    prim_paths=["/World/logo/logo/logo"],
    attribute_name="material:binding",
    tensors=[["/World/Looks/srf_glass"]],
)

Use the ovrtx_set_path_attributes() convenience helper from <ovrtx/ovrtx_attributes.h>. It wraps the path value into the single-element relationship array that USD requires.

// Bind /World/Looks/srf_glass to /World/logo
ovx_string_t prim_path = ovx_str("/World/logo/logo/logo");
ovx_string_t material_path = ovx_str("/World/Looks/srf_glass");
enqueue_result = ovrtx_set_path_attributes(
    renderer_, &prim_path, 1,
    ovx_str("material:binding"), &material_path);
ASSERT_API_SUCCESS(enqueue_result.status);
result = ovrtx_wait_op(renderer_, enqueue_result.op_index, ovrtx_timeout_infinite, &wait_result);
ASSERT_API_SUCCESS(result.status);
ASSERT_NO_OP_ERRORS(wait_result);