Scope#
Understanding Scopes is important as they help in organizing and managing complexity in large-scale 3D scenes.
What is a Scope?#
In OpenUSD, a Scope is a special type of prim that is used primarily as a grouping mechanism in the scenegraph. It does not represent any geometry or renderable content itself but acts as a container for organizing other prims. Think of Scope as an empty folder on your computer where you organize files; similarly, Scope helps in structuring and organizing prims within a USD scene.
How Does It Work?#
Scope prims are used to create a logical grouping of related prims, which can be particularly useful in complex scenes with numerous elements. For example, a Scope might be used to group all prims related to materials, animation, or geometry. A key feature of Scopes is that they cannot be transformed, which promotes their usage as lightweight organizational containers. All transformable child prims (such as geometry prims or Xforms) will be evaluated correctly from within the Scope prim and down the hierarchy. This organization aids in simplifying scene management, making it easier for teams to navigate, modify, and render scenes.
Working With Python#
When working with Scope in USD using Python, a couple functions are particularly useful:
1# Used to define a new Scope at a specified path on a given stage
2UsdGeom.Scope.Define(stage, path)
3
4# This command is generic, but it's useful to confirm that a prim's type is a Scope, ensuring correct usage in scripts
5prim.IsA(UsdGeom.Scope)
Examples#
Example 1: Define a Scope#
Scope
is a grouping primitive and does NOT have transformability. It can be used to organize libraries with large numbers of entry points. It also is best to group actors and environments under partitioning Scopes. Besides navigating, it’s easy for a user to deactivate all actors or environments by deactivating the root scope.
We can define Scope
using UsdGeom.Scope.Define()
.
1from pxr import Usd, UsdGeom
2
3file_path = "_assets/scope.usda"
4stage = Usd.Stage.CreateNew(file_path)
5
6world: UsdGeom.Xform = UsdGeom.Xform.Define(stage, "/World")
7stage.SetDefaultPrim(world.GetPrim())
8
9# Define a new Scope primitive at the path "/World/Geometry" on the current stage:
10geo_scope: UsdGeom.Scope = UsdGeom.Scope.Define(stage, world.GetPath().AppendPath("Geometry"))
11
12# Define a new Cube primitive at the path "/World/Geometry/Cube" on the current stage:
13box_geo: UsdGeom.Cube = UsdGeom.Cube.Define(stage, geo_scope.GetPath().AppendPath("Cube"))
14
15stage.Save()
Key Takeaways#
Scope prims in OpenUSD play a crucial role in the organization and management of complex 3D scenes. Its primary function is to serve as a container for other prims, helping maintain clarity and structure in large projects.