Exercise: Lofting Variant Sets#

For this exercise, we added a variant set called exteriorType to control the main exterior color. This is defined on the “Looks” Scope. We will loft the variant set so that it will be accessible as a new asset parameter and make sure it’s available even with the payload unloaded.

  1. Open the output lrg_bldgF in usdview by running the following command in Visual Studio Code:

Windows:

.\scripts\usdview.bat .\asset_structure\exercise_08\lrg_bldgF.usd

Linux:

./scripts/usdview.sh ./asset_structure/exercise_08/lrg_bldgF.usd
  1. In usdview, click on the “Looks” Scope in the tree view. Note that the Meta Data tab shows a new variant set, exteriorType.

  1. In the Meta Data tab, click on the exteriorType variant set dropdown and change the variant selection to “brick”. Note the building color change in the viewport.

  1. In Visual Studio Code, open the following file: asset_structure/exercise_08/loft_variant_set.py

  2. Let’s add the code to loft the exteriorType variant set from the “Looks” Scope to the asset entry point. Add the code below into the block:

 1# Create the same variant set on the default_prim.
 2lofted_vset: Usd.VariantSet = default_prim.GetVariantSets().AddVariantSet(vset_name)
 3for variant in variants:
 4    lofted_vset.AddVariant(variant)
 5    lofted_vset.SetVariantSelection(variant)
 6    # The lofted variant set just selects the
 7    # same variant from the nested variant set.
 8    with lofted_vset.GetVariantEditContext():
 9        vset.SetVariantSelection(variant)
10lofted_vset.SetVariantSelection(default)

Here, we’re lofting the exteriorType variant set by creating a matching variant set on the asset entry point. Each variant on the new variant set has just one opinion, it selects its matching variant from the exteriorType variant set on the “Looks” prim.

  1. Save the file and then execute the script using the following command:

Windows:

python .\asset_structure\exercise_08\loft_variant_set.py

Linux:

python ./asset_structure/exercise_08/loft_variant_set.py
  1. Open the output lrg_bldgF in usdview by running the following command:

Windows:

.\scripts\usdview.bat .\asset_structure\exercise_08\lrg_bldgF.usd

Linux:

./scripts/usdview.sh ./asset_structure/exercise_08/lrg_bldgF.usd
  1. In usdview, click on the “Looks” Scope in the tree view. Note that the Meta Data tab shows that the exteriorType variant set is set to “stucco”.

  1. In usdview, click on the “World” (default) prim in the tree view.

  1. In the Meta Data tab, click on the exteriorType variant set dropdown and change the variant selection to “brick”. Note the building color change in the viewport.

  1. In usdview, click on the “Looks” Scope in the tree view. Note that the Meta Data tab shows that the exteriorType variant set has also been set to “brick”.