How to retrieve nested VariantSets inside not-selected Variants

Hi wizards of USD,

I am working on some tool working with VariantSets and Variants to choose or modify them and for that I want to show some kind of tree view of the nested VariantSets. My current approach is to iterate over the SdfVariantSetsProxy, from the SdfPrimSpecHandle, get the list of variants for each and try to get the nested variants from the SdfVariantSetSpecHandle by calling the GetVariantSets() function for each variant.

However, when the specified variant is not selected - this function returns an empty proxy, regardless of if there are nested variants or not.

I understand that from a compositional approach this makes sense as the variant is not chosen, so it also doesn’t have any children… but from a point of an UI tool trying to paint a tree, I still want to show this data to the user - as they are part of the layer - even if they are not currently actively selected.

So my question, is there a way to retrieve this information somehow? Basically getting a complete nested VariantSet hierarchy without taking in account the current selection?

Thanks in advance,
Ulrich

Hi @haberlu , unfortunately there isn’t, and it’s difficult to imagine how there could be. It may be the case for the particular assets you are working with that all of the nested variants are laid out straightforwardly in child specs of the top-most variant specs, but because of the combinatorial nature of USD composition, that is not a requirement.

For example, each of your top-level variants might add a reference to a prim in another asset/layer, and that prim has an inherits to another prim that defines a variantSet with variants. Composition will make that all “work” so that the inner variantSet becomes a nested variantSet of your top-level variant. But without actually composing the variant in-question, you’d need to recreate the composition logic to find the inner variantSet and its variants.

This is a pipeline issue we’ve run up against ourselves when using nested variants. Our “solution” was not entirely satisfying or general… in our case the nested variantSet tended to be pretty uniform for each variant (it was LOD, nested inside a modelingVariant). So, as part of the “publish” step for each asset, we loaded it and iterated over each variant of the outer variantsets, discovering nested variantSets and their variants, unioning everything we found. Then, on a newly created spec for the asset (in an “interface” usda layer that simply payloads in the entirety of the asset) we added specs for each variantSet, and empty variant children for each.

The nested variantSets are no longer nested on this top-level spec, but that’s not harmful, as the nesting across the payload arc will still take place. You just are always able to see all the variants and select among them, however, some selections for the inner variantSet may not be valid, and you won’t know until you select and get a warning during composition. And that’s a big reason this scheme is unsatisfying.

I don’t think there’s any likely solution that doesn’t involve iterating through the composed variants… we could try to work out a standardized (likely dictionary) scheme for describing the variant nesting, as metadata available for GUI’s - and a utility for computing it for you, such that you can add it to the prims that contain variantSets. However, that’s a “baking” step, and if the asset contains live references, it could go stale due to upstream changes.

But if that sounds useful/appealing to folks, please file an Issue, and it’s also something that could be a nice external PR.