BigRoy / usd-qtpy

Python Qt components for building custom USD tools.
MIT License
57 stars 8 forks source link

Visualize the current edit target - breadcrumbs #33

Open BigRoy opened 7 months ago

BigRoy commented 7 months ago

Issue

It can be tricky to visualize exactly what the current edit target is when dealing with variants and e.g. editing nested variants.

Idea

I was thinking of maybe displaying these in a "breadcrumb" like way where one could also click to go up and pop off a variant of the edit target.

image

Like that image it can also have little drop down entries to "pick" from the current stage what additional targets could be appended to the current mapping, e.g. another variant set.

Here's some quick pseudocode:

from pxr import Usd, Sdf

def get_edit_target_breadcrumbs(edit_target):
    layer = edit_target.GetLayer()
    if not edit_target.IsValid():
        return []

    layer_str = layer.GetDisplayName()

    mapping = edit_target.GetMapFunction()
    if mapping.isIdentityPathMapping:
        return [layer_str]

    crumbs = [layer_str]
    for source, target in mapping.sourceToTargetMap.items():
        if source == target:
            # Nothing special here?
            continue

        crumbs.append(source.pathString)

    return crumbs

edit_target = stage.GetEditTarget()
crumbs = get_edit_target_breadcrumbs(edit_target)
print(f"Edit Target: {' > '.join(crumbs)}")

# Targeting e.g. root layer this shows:
# Edit Target: look.usda
# Targeting the variant set `model` variant `main` on `/root` prim
# Edit Target: look.usda > /asset/geo{model=main}
# Then appending subtarget look = main
# Edit Target: look.usda > /asset/geo{model=main}{look=main}

Which in breadcrumbds could be clickable blocks like:

look.usda  >  /asset/geo  >  {model=main}  >  {look=main}