All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
flattenLayerStack.h File Reference

Utilities for flattening layer stacks into a single layer. More...

+ Include dependency graph for flattenLayerStack.h:

Go to the source code of this file.

Typedefs

using UsdUtilsResolveAssetPathFn = std::function< std::string(const SdfLayerHandle &sourceLayer, const std::string &assetPath)>
 Callback function for overloaded version of UsdUtilsFlattenLayerStack. More...
 

Functions

 SDF_DECLARE_HANDLES (SdfLayer)
 
USDUTILS_API SdfLayerRefPtr UsdUtilsFlattenLayerStack (const UsdStagePtr &stage, const std::string &tag=std::string())
 Flatten the root layer stack of the given stage into a single layer with the given optional tag. More...
 
USDUTILS_API SdfLayerRefPtr UsdUtilsFlattenLayerStack (const UsdStagePtr &stage, const UsdUtilsResolveAssetPathFn &resolveAssetPathFn, const std::string &tag=std::string())
 Flatten the root layer stack of the given stage into a single layer with the given optional tag and using the resolveAssetPathFn to resolve asset paths that are encountered. More...
 
USDUTILS_API std::string UsdUtilsFlattenLayerStackResolveAssetPath (const SdfLayerHandle &sourceLayer, const std::string &assetPath)
 The default UsdUtilsResolvePathFn used by UsdUtilsFlattenLayerStack. More...
 

Detailed Description

Utilities for flattening layer stacks into a single layer.

Definition in file flattenLayerStack.h.

Typedef Documentation

using UsdUtilsResolveAssetPathFn = std::function<std::string( const SdfLayerHandle& sourceLayer, const std::string& assetPath)>

Callback function for overloaded version of UsdUtilsFlattenLayerStack.

The callback is given the sourceLayer and the assetPath authored in that layer. It should return the std::string that should be authored in the flattened layer.

See Also
UsdUtilsFlattenLayerStackResolveAssetPath

Definition at line 79 of file flattenLayerStack.h.

Function Documentation

USDUTILS_API SdfLayerRefPtr UsdUtilsFlattenLayerStack ( const UsdStagePtr &  stage,
const std::string &  tag = std::string() 
)

Flatten the root layer stack of the given stage into a single layer with the given optional tag.

The result layer can be substituted for the original layer stack while producing the same composed UsdStage.

Unlike UsdStage::Export(), this function does not flatten composition arcs, such as references, payloads, inherits, specializes, or variants.

Sublayer time offsets on the sublayers will be applied to remap any time-keyed scene description, such as timeSamples and clips.

Asset paths will be resolved to absolute form, to ensure that they continue to identify the same asset from the output layer.

See Also
UsdUtilsFlattenLayerStackResolveAssetPath

A few historical scene description features cannot be flattened into a single opinion because they unfortunately encode operations that are not closed under composition. Specifically, the SdfListOp operations "add" and "reorder" cannot be flattened. Instead, "add" will be converted to "append", and "reorder" will be discarded.

USDUTILS_API SdfLayerRefPtr UsdUtilsFlattenLayerStack ( const UsdStagePtr &  stage,
const UsdUtilsResolveAssetPathFn resolveAssetPathFn,
const std::string &  tag = std::string() 
)

Flatten the root layer stack of the given stage into a single layer with the given optional tag and using the resolveAssetPathFn to resolve asset paths that are encountered.

This is an advanced version of the above function.

One use case for this version of the function is to flatten a layer stack that contains relative asset paths that we want to preserve as relative paths. For example:

* /source/root.usd # sublayers a.usd and b.usd
* /source/a.usd # contains reference to ./subdir/layer.usd
* /source/b.usd
* /source/subdir/layer.usd
*

We may want to generate "/dest/root.flat.usd" knowing that we will (by some other means) also be copying "/source/subdir" into "/dest/subdir". It's useful then to preserve the relative paths.

Note, only the caller knows the ultimate destination of the flattened layer. So to accomplish this, we can provide a resolveAssetPathFn callback that captures the outputDir, tests if the authored path is relative, and if so, computes a new relative path (based on where it will eventually be exported).

USDUTILS_API std::string UsdUtilsFlattenLayerStackResolveAssetPath ( const SdfLayerHandle &  sourceLayer,
const std::string &  assetPath 
)

The default UsdUtilsResolvePathFn used by UsdUtilsFlattenLayerStack.

For paths that the current ArResolver identifies as searchpaths or absolute paths, we return the unmodified path. However, any "Layer relative path" (see SdfComputeAssetPathRelativeToLayer) will be absolutized, because we do not know if the flattened layer's containing directory will be the same as any given source layer's in the incoming layerStack.