Refinement through Variants#

Exercise: Variant Set Refinement#

We will use variant sets to add a shipping label decal to a box. This is a standard part of our shipping and receiving workflow so our asset already has a variant set to handle that.

  1. Run in the terminal:

.\scripts\usdview.bat .\instancing_exercises\ex_sg_varset_refine\Scenario.usd  --camera ExCam_01

Tip

Click Camera > Select Camera > ExCam_01 if you ever lose your place in the scene or want to get back to this camera position.

  1. Click on the top left box in the Viewport.

  1. On the Metadata tab, set the “statusVariant” to “allocated”.

This adds a shipping label to the top of the box and sets the custom “status” attribute on that prim to “ALLOCATED”. We can use these variants to track the status of packages within our facility.

  1. Click on the box to the right of your current selection in the Viewport.

  1. On the Metadata tab, set the “statusVariant” to “allocated”.

  1. Click Window > Interpreter to open the Interpreter window.

  2. Run the following code in the Interpreter window:

1from pprint import pprint
2stats = UsdUtils.ComputeUsdStageStats(usdviewApi.stage)
3pprint(stats)

This prints a breakdown of the prim and instancing stats. Here’s a summarized comparison to other scenarios:

Scenario

Prims

Instances

Prototypes

Instancing

1711

1450

3

1 De-instanced Box

1741

1449

3

2 De-instanced Boxes

1771

1448

3

2 Allocated Variant Boxes

1737

1450

4

Before we were only using one box variant so we had one box prototype. Using a second box variant now, “allocated,” introduces a new prototype based on the box asset. Note how this uses less prims than the de-instancing approach. It also scales well. We can switch more boxes to use the “allocated” variant without incrementing the total prim count.

You can see how with a little foresight and planning you can keep the instance refinement experience as simple as de-instancing, but without losing as much optimization.

  1. Close usdview.