Exercise: Assemblies#
In this exercise, we will create a new assembly asset called city_blockA
that will reference lrg_bldgF
multiple times to create a city block. We will set the model kind of the new asset to assembly
.
In Visual Studio Code, open the following file:
asset_structure/exercise_10/create_assembly.py
First, let’s set the model kind to assembly. Add the code below into the designated PART 1 section:
1Usd.ModelAPI(world_prim).SetKind(Kind.Tokens.assembly)
Now we will populate the asset by referencing the component assets. Add the code below into the designated PART 2 section:
1for x in range(1,7):
2 ref_path: Sdf.Path = world_prim.GetPath().AppendChild(f"lrg_bldgF_{x:02}")
3 ref_target_prim = UsdGeom.Xform.Define(stage, ref_path).GetPrim()
4 ref_target_prim.GetReferences().AddReference("./lrg_bldgF/lrg_bldgF.usd")
5 position_bldg(ref_target_prim, x)
Assemblies aggregate assets made up of component assets or other assemblies. Here we are referencing lrg_bldgF
six times and positioning them into a city block.
Save the file and then execute the script using the following command:
Windows:
python .\asset_structure\exercise_10\create_assembly.py
Linux:
python ./asset_structure/exercise_10/create_assembly.py
Run the following command in Visual Studio Code to open the file in usdview:
Windows:
.\scripts\usdview.bat .\asset_structure\exercise_10\city_blockA.usd
Linux:
./scripts/usdview.sh ./asset_structure/exercise_10/city_blockA.usd
In usdview, click on the “World” (default) prim in the tree view. Note that the Meta Data tab shows that the
kind
field is set toassembly
. This is an assembly asset.
In usdview, click on “
lrg_bldgF_01
” prim in the tree view. Note that the Meta Data tab shows that thekind
field is set tocomponent
. This is a component asset.
Note that we have created a valid model hierarchy:
World (assembly)
lrg_bldgF_01 (component)
lrg_bldgF_02 (component)
lrg_bldgF_03 (component)
lrg_bldgF_04 (component)
lrg_bldgF_05 (component)
lrg_bldgF_06 (component)