Deinstancing Refinement#
Exercise: Deinstance Refinement#
If we wanted to hide the decal on a box, a simple approach is to use de-instancing. We will lose some optimization in the process, but get back full editability for that copy of the box.
Run in the terminal:
.\scripts\usdview.bat .\instancing_exercises\ex_sg_deinstance_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.
Click on the top left box in the Viewport.
Click Window > Interpreter to open the Interpreter window.
Run the following code in the Interpreter window:
1box = usdviewApi.prim
2box.SetInstanceable(False)
3decal = box.GetChild("SM_CubeBox_A04_Decal_01")
4decal_vis = decal.GetAttribute("visibility")
5decal_vis.Set(UsdGeom.Tokens.invisible)
This code de-instanced the cube box asset we selected by setting the instanceable metadata to false. We were then able to edit the child decal prim to hide it without any problems. You box should look like this now with the hidden decal:
Run the following code in the Interpreter window:
1from pprint import pprint
2stats = UsdUtils.ComputeUsdStageStats(usdviewApi.stage)
3pprint(stats)
The downside is that we are introducing more total prims by using less instancing. Here’s a summarized comparison:
Scenario |
Prims |
Instances |
Prototypes |
---|---|---|---|
Instancing |
1711 |
1450 |
3 |
1 De-instanced Box |
1741 |
1449 |
3 |
Let’s say we needed to make changes to more boxes. Let’s apply the same decal visibility change to another box.
Click on the box to the right of your current selection in the Viewport.
Run the following code in the Interpreter window:
1box = usdviewApi.prim
2box.SetInstanceable(False)
3decal = box.GetChild("SM_CubeBox_A04_Decal_01")
4decal_vis = decal.GetAttribute("visibility")
5decal_vis.Set(UsdGeom.Tokens.invisible)
The decal on that box should now be hidden too.
Run the following code in the Interpreter window:
1from pprint import pprint
2stats = UsdUtils.ComputeUsdStageStats(usdviewApi.stage)
3pprint(stats)
The more we de-instance, the more optimizations we lose. Here’s a summarized comparison:
Scenario |
Prims |
Instances |
Prototypes |
---|---|---|---|
Instancing |
1711 |
1450 |
3 |
1 De-instanced Box |
1741 |
1449 |
3 |
2 De-instanced Boxes |
1771 |
1448 |
3 |
While simple and convenient, this refinement approach is significantly more unoptimized than others if you are making identical refinements to more than one asset. The next refinement examples will show more optimal approaches to achieve the same.
Close usdview.