USD Traversal

A USD Asset is a node that uses virtual nodes to represent its content in the Rumba universe. To access these virtual nodes, we use node delegates.

See also

The node delegate documentation

Traversal of a USD asset

  • python
import rumba

# Retrieve the USD node delegate root
def usd_root(usd_asset):
        return usd_asset.node_delegate().find("display.output/")

# How to traverse the USD nodes
def traverse_usd_nodes(parent):
        for child in parent.children():
                print (child.path())
                traverse_usd_nodes(child)

# Get the USDAsset node
usd_asset = rumba.active_document().child("asset_name")
traverse_use_nodes(usd_root(usd_asset))

Listing all attributes of selected USD object

  • python
selected_nds = rumba.delegate_selection()
for nd in selected_nds:
        for attr in nd.attributes():
                # True if this attribute is overridden
                is_overridden = attr.is_overridden()
                type_name = attr.type_name()
                if type_name == "Int":
                        print(f"{attr.name()} {attr.value().as_int()}")
                if type_name == "Bool":
                        print(f"{attr.name()} {attr.value().as_bool()}")
                if type_name == "Float":
                        print(f"{attr.name()} {attr.value().as_float()}")

Listing all overridden attributes

When an attribute of an USD object inside an USD Asset is modified, it creates an override in Rumba that can later be exported as an USD Layer. Here is a snippet of code to access all the created overrides :

  • python
import rumba

# How to get USD overrides

# Retrieve the USD node delegate root
def usd_root(usd_asset):
        return usd_asset.node_delegate().find("display.output/")

class Override:
        """ A single override on the USD content

        path: the USD path of USD Node
        attribute: the name of the overidden attribute
        value: the new value
        """
        def __init__(self, path, attribute, value):
                self.path = path
                self.attribute = attribute
                self.value = value

def usd_overrides(usd_asset):
        """ Return all the overrides done on the USD content """
        override = usd_asset.child("override")
        override_output = override.plug("output")
        override_paths = override.plug("paths")
        value_index = 2
        result = []
        for dep_plug in override_paths.valued_dependencies():
                attribute_path = dep_plug.as_string()
                path = attribute_path.split(".")
                attribute = ".".join(path[1:])
                value = override_output.valued_dependencies()[value_index].value()
                result.append(Override(path[0], attribute, value))
                value_index += 1
        return result

def usd_attribute(usd_asset, override):
        """ Return the node delegate of an overridden object and its atribute delegate """
        nd = usd_root(usd_asset).find(override.path)
        return (nd, nd.attribute(override.attribute))

# Get the USDAsset node
usd_asset = rumba.active_document().child("Kitchen_set")

# Traverse the USD overrides
overrides = usd_overrides(usd_asset)
for o in overrides:
        value = o.value
        (nd, nd_attr) = usd_attribute(usd_asset, o)
        if value.type_name() == "M44f":
                # The overriden matrix
                override_matrix = value.as_M44d()

                # The new local matrix
                matrix = nd.matrix()

                # The new world matrix
                world_matrix = nd.world_matrix()
        elif value.type_name() == "Int":
                override_value = value.as_int()