usdrt::UsdLuxLightListAPI

Defined in usdrt/scenegraph/usd/usdLux/lightListAPI.h

Functions

Variables

class UsdLuxLightListAPI : public usdrt::UsdAPISchemaBase

API schema to support discovery and publishing of lights in a scene.

Discovering Lights via Traversal

To motivate this API, consider what is required to discover all lights in a scene. We must load all payloads and traverse all prims:

01  // Load everything on the stage so we can find all lights,
02  // including those inside payloads
03  stage->Load();
04
05  // Traverse all prims, checking if they have an applied UsdLuxLightAPI
06  // (Note: ignoring instancing and a few other things for simplicity)
07  SdfPathVector lights;
08  for (UsdPrim prim: stage->Traverse()) {
09      if (prim.HasAPI<UsdLuxLightAPI>()) {
10          lights.push_back(i->GetPath());
11      }
12  }

This traversal &#8212; suitably elaborated to handle certain details &#8212; is the first and simplest thing UsdLuxLightListAPI provides. UsdLuxLightListAPI::ComputeLightList() performs this traversal and returns all lights in the scene:

01  UsdLuxLightListAPI listAPI(stage->GetPseudoRoot());
02  SdfPathVector lights = listAPI.ComputeLightList();

Publishing a Cached Light List

Consider a USD client that needs to quickly discover lights but wants to defer loading payloads and traversing the entire scene where possible, and is willing to do up-front computation and caching to achieve that.

UsdLuxLightListAPI provides a way to cache the computed light list, by publishing the list of lights onto prims in the model hierarchy. Consider a big set that contains lights:

01  def Xform "BigSetWithLights" (
02      kind = "assembly"
03      payload = @BigSetWithLights.usd@   // Heavy payload
04  ) {
05      // Pre-computed, cached list of lights inside payload
06      rel lightList = [
07          <./Lights/light_1>,
08          <./Lights/light_2>,
09          ...
10      ]
11      token lightList:cacheBehavior = "consumeAndContinue";
12  }

The lightList relationship encodes a set of lights, and the lightList:cacheBehavior property provides fine-grained control over how to use that cache. (See details below.)

The cache can be created by first invoking ComputeLightList(ComputeModeIgnoreCache) to pre-compute the list and then storing the result with UsdLuxLightListAPI::StoreLightList().

To enable efficient retrieval of the cache, it should be stored on a model hierarchy prim. Furthermore, note that while you can use a UsdLuxLightListAPI bound to the pseudo-root prim to query the lights (as in the example above) because it will perform a traversal over descendants, you cannot store the cache back to the pseduo-root prim.

To consult the cached list, we invoke ComputeLightList(ComputeModeConsultModelHierarchyCache):

01  // Find and load all lights, using lightList cache where available
02  UsdLuxLightListAPI list(stage->GetPseudoRoot());
03  SdfPathSet lights = list.ComputeLightList(
04      UsdLuxLightListAPI::ComputeModeConsultModelHierarchyCache);
05  stage.LoadAndUnload(lights, SdfPathSet());

In this mode, ComputeLightList() will traverse the model hierarchy, accumulating cached light lists.

Controlling Cache Behavior

The lightList:cacheBehavior property gives additional fine-grained control over cache behavior:

  • The fallback value, “ignore”, indicates that the lightList should be disregarded. This provides a way to invalidate cache entries. Note that unless “ignore” is specified, a lightList with an empty list of targets is considered a cache indicating that no lights are present.

  • The value “consumeAndContinue” indicates that the cache should be consulted to contribute lights to the scene, and that recursion should continue down the model hierarchy in case additional lights are added as descedants. This is the default value established when StoreLightList() is invoked. This behavior allows the lights within a large model, such as the BigSetWithLights example above, to be published outside the payload, while also allowing referencing and layering to add additional lights over that set.

  • The value “consumeAndHalt” provides a way to terminate recursive traversal of the scene for light discovery. The cache will be consulted but no descendant prims will be examined.

Instancing

Where instances are present, UsdLuxLightListAPI::ComputeLightList() will return the instance-unique paths to any lights discovered within those instances. Lights within a UsdGeomPointInstancer will not be returned, however, since they cannot be referred to solely via paths.

For any described attribute Fallback Value or Allowed Values below that are text/tokens, the actual token is published and defined in UsdLuxTokens. So to set an attribute to the value “rightHanded”, use UsdLuxTokens->rightHanded as the value.

Public Functions

inline explicit UsdLuxLightListAPI(const UsdPrim &prim = UsdPrim())

Construct a UsdLuxLightListAPI on UsdPrim prim. Equivalent to UsdLuxLightListAPI::Get(prim.GetStage(), prim.GetPath()) for a valid prim , but will not immediately throw an error for an invalid prim.

inline explicit UsdLuxLightListAPI(const UsdSchemaBase &schemaObj)

Construct a UsdLuxLightListAPI on the prim held by schemaObj . Should be preferred over UsdLuxLightListAPI(schemaObj.GetPrim()), as it preserves SchemaBase state.

inline virtual ~UsdLuxLightListAPI()

Destructor.

inline operator bool() const

Boolean operator.

Returns

Return true if the contained prim is has this api schema applied using HasAPI, and false otherwise.

inline UsdAttribute GetLightListCacheBehaviorAttr() const

Controls how the lightList should be interpreted. Valid values are:

  • consumeAndHalt: The lightList should be consulted, and if it exists, treated as a final authoritative statement of any lights that exist at or below this prim, halting recursive discovery of lights.

  • consumeAndContinue: The lightList should be consulted, but recursive traversal over nameChildren should continue in case additional lights are added by descendants.

  • ignore: The lightList should be entirely ignored. This provides a simple way to temporarily invalidate an existing cache. This is the fallback behavior.

Declaration

token lightList:cacheBehavior

C++ Type

TfToken

Usd Type

SdfValueTypeNames->Token

Allowed Values

consumeAndHalt, consumeAndContinue, ignore

inline UsdAttribute CreateLightListCacheBehaviorAttr() const

See GetLightListCacheBehaviorAttr(), and also Create vs Get Property Methods for when to use Get vs Create. If specified, author defaultValue as the attribute’s default, sparsely (when it makes sense to do so) if writeSparsely is true - the default for writeSparsely is false.

inline UsdRelationship GetLightListRel() const

Relationship to lights in the scene.

inline UsdRelationship CreateLightListRel() const

See GetLightListRel(), and also Create vs Get Property Methods for when to use Get vs Create.

UsdPrim GetPrim() const

Return this schema object’s held prim.

SdfPath GetPath() const

Return the SdfPath to this schema object’s held prim.

Public Static Functions

static inline UsdLuxLightListAPI Apply(const UsdPrim &prim)

Applies this single-apply API schema to the given prim. This information is stored by adding “LightListAPI” to the token-valued, listOp metadata apiSchemas on the prim.

See also

UsdPrim::GetAppliedSchemas()

See also

UsdPrim::HasAPI()

See also

UsdPrim::ApplyAPI()

See also

UsdPrim::RemoveAPI()

Returns

A valid UsdLuxLightListAPI object is returned upon success. An invalid (or empty) UsdLuxLightListAPI object is returned upon failure. See UsdPrim::ApplyAPI() for conditions resulting in failure.

Public Static Attributes

static const UsdSchemaType schemaType = UsdSchemaType::SingleApplyAPI

Compile time constant representing what kind of schema this class is.

See also

UsdSchemaType

Protected Functions

inline const TfToken &_GetInstanceName() const

Returns the instance name of the API schema object belonging to a multiple-apply API schema.

The returned instance name will be empty for non-applied and single-apply API schemas.