Nested Instancing#

Instances can contain other instances.

Common patterns:

  • Instanced assemblies with instanced components.

  • Instanced components with instanced material networks.

Enables large-scale scene aggregation. Scenegraph instances can include Point Instancers too and vice versa. Be cautious about too much complexity

Exercise: Nested Scenegraph Instancing#

In this exercise, we will start with the instanced component assets and introduce nested instancing by enabling instancing for the entire rack assemblies. We will see how that impacts performance as well as authoring flexibility.

  1. Run in the terminal:

.\scripts\usdview.bat .\instancing_exercises\ex_sg_nested_inst\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.

  2. Hover your mouse over the Tree View panel and press the “F” key to frame the selected prim in the Tree View.

You should see “CubeBox_A04_26cm_18” selected in the Tree View panel. Note the light blue text indicating that we have instancing enabled for our component assets. In the next steps, we are going to utilize nested instancing and see how that impacts the stage.

Note also the decals on the boxes. The boxes with decals showing form a T-shape on the left pallet and the boxes on the right pallet have no decals showing.

  1. Close usdview.

  2. Open instancing_exercises/ex_sg_nest/toggle_nested_inst.py in VSCode to inspect its code.

  3. Run in the terminal:

python .\instancing_exercises\ex_sg_nested_inst\toggle_nested_inst.py 1
  1. Run in the terminal:

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

Note that the Rack_BoxPallet prims are now instances.

  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)

Scenario

Prims

Instances

Prototypes

No Instancing

44408

0

0

Instancing

1711

1450

3

Nested Instancing

1482

25

1

  1. Close the Interpreter window.

Note that every pallet now has the same T-shape formation for box decals. The stage has lost a significant amount of diversity. A creator painstakingly authored local opinions in Warehouse.usd to give unique positions and rotations to each box for added realism. These opinions within the rack instances are now being ignored. We’ll look at this more closely in the next exercises.

  1. Close usdview.

  2. Run in the terminal:

Measure-Command { .\scripts\usdview.bat .\instancing_exercises\ex_sg_nested_inst\Scenario.usd --quitAfterStartup }

This will measure how long it takes to execute usdview. usdview is an interactive app, but with the --quitAfterStartup flag we can just time the startup and time to first frame with the Storm renderer. You can run the command a few times and take an average for a more reliable result. My average was 5.31 seconds on a mid-end laptop. Let’s compare my performance results of the different instancing strategies:

Scenario

Execution Time (sec)

Improvement (%)

No Instancing

27.77

0% (Baseline)

Instancing

18.98

+46.3%

Nested Instancing

5.31

+423.0%