Is there any way to specify that variants are in a given order within a variant set?
For example, I have the following Planet usda file, but when reading it in, the SDF data model seems to change it to alphabetically ordered. I assume that’s because they exist in the variant map, so order is implementation defined.
However is there any metadata that would preserve a given order?
#usda 1.0
(
defaultPrim = "Planets"
metersPerUnit = 1
upAxis = "Y"
)
def Xform "Planets" (
kind = "component"
prepend variantSets = ["Planet"]
variants = {
string Planet = "Earth"
}
) {
variantSet "Planet" = {
"Mercury" {
def Mesh "Resource" (
prepend payload = @Mercury.usdz@
)
{}
}
"Venus" {
def Mesh "Resource" (
prepend payload = @Venus.usdz@
)
{}
}
"Earth" {
def Mesh "Resource" (
prepend payload = @Earth.usdz@
)
{}
}
}
Hmm, looking at the API and document model, there doesn’t seem to be anything to order Variants within a variant sets. Hopefully I’m mistaken but I’ve filed an issue accordingly because I believe it would be useful
opened 05:51PM - 09 May 24 UTC
### Description of Issue
For pipeline purposes, it would be very useful to be… able to preserve variant ordering within a USD file. This is especially important when presenting the variants to artists etc in a UI.
Currently (USD 24.5), if you author variants in a given order, they will be stored in an implementation defined way. This appears to be alphabetical, but I do not see this as an expressly determined logic, so it may be non-deterministic depending on the underlying data structures behaviour.
This can be worked around somewhat by use of custom pipeline metadata but requires every application to specify the same logic. This also doesn't scale to third party vendors or creators easily.
It would be great if there was a way to specify variant ordering in a way such that USD's methods to query the Variant names just return them in a pre-determined order. It might also be useful to store them in authoring order by default.
### Steps to Reproduce
Run this code and open the file
```
from pxr import Usd, UsdGeom
stage = Usd.Stage.CreateNew('planets.usda')
xform = UsdGeom.Xform.Define(stage, '/planets')
prim = xform.GetPrim()
vset = prim.GetVariantSets().AddVariantSet("Planets")
for planet in ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus"]:
vset.AddVariant(planet)
vset.SetVariantSelection(planet)
stage.Save()
```