Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USD Stage Traversal For Reference/Instance/Proxies #10

Open
cadop opened this issue Aug 18, 2023 · 2 comments
Open

USD Stage Traversal For Reference/Instance/Proxies #10

cadop opened this issue Aug 18, 2023 · 2 comments
Labels
new request Request a new code sample

Comments

@cadop
Copy link
Contributor

cadop commented Aug 18, 2023

The typical methods for traversing a stage don't work in some cases, like an external stage being referenced in the current stage.

I would be happy to open a PR with a few examples, if told where to put them (I guess in https://github.com/NVIDIA-Omniverse/OpenUSD-Code-Samples/tree/main/source/hierarchy-traversal)

A few examples would be nice:

  • How to traverse the entire stage, including everything referenced in it.
  • How to traverse everything below a specific prim
@cadop
Copy link
Contributor Author

cadop commented Aug 18, 2023

For the first bullet, I made a script that does the traversal on the entire scene, and appends all the prims that are a mesh type:

def get_all_stage_mesh(stage):

    found_meshes = []

    # Traverse the scene graph and print the paths of prims, including instance proxies
    for x in Usd.PrimRange(stage.GetPseudoRoot(), Usd.TraverseInstanceProxies()):
        if x.IsA(UsdGeom.Mesh):
            found_meshes.append(x)
    return found_meshes

@cadop
Copy link
Contributor Author

cadop commented Aug 18, 2023

On the second bullet, there is a nice script from https://github.com/ColinKennedy/USD-Cookbook/blob/master/tricks/traverse_instanced_prims/README.md

def traverse_instanced_children(prim):
    """Get every Prim child beneath `prim`, even if `prim` is instanced.

    Important:
        If `prim` is instanced, any child that this function yields will
        be an instance proxy.

    Args:
        prim (`pxr.Usd.Prim`): Some Prim to check for children.

    Yields:
        `pxr.Usd.Prim`: The children of `prim`.

    """
    for child in prim.GetFilteredChildren(Usd.TraverseInstanceProxies()):
        yield child

        for subchild in traverse_instanced_children(child):
            yield subchild

@mati-nvidia mati-nvidia added the new request Request a new code sample label Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new request Request a new code sample
Projects
None yet
Development

No branches or pull requests

2 participants