HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
flattenLayerStack.h
Go to the documentation of this file.
1 //
2 // Copyright 2017 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_USD_UTILS_FLATTEN_LAYER_STACK_H
8 #define PXR_USD_USD_UTILS_FLATTEN_LAYER_STACK_H
9 
10 /// \file usdUtils/flattenLayerStack.h
11 ///
12 /// Utilities for flattening layer stacks into a single layer.
13 
14 #include "pxr/pxr.h"
15 #include "pxr/usd/usd/stage.h"
16 #include "pxr/usd/usdUtils/api.h"
19 
21 
23 
24 /// Flatten the root layer stack of the given \p stage into a single layer
25 /// with the given optional \p tag.
26 ///
27 /// The result layer can be substituted for the original layer stack
28 /// while producing the same composed UsdStage.
29 ///
30 /// Unlike UsdStage::Export(), this function does not flatten
31 /// composition arcs, such as references, payloads, inherits,
32 /// specializes, or variants.
33 ///
34 /// Sublayer time offsets on the sublayers will be applied to remap
35 /// any time-keyed scene description, such as timeSamples and clips.
36 ///
37 /// Asset paths will be resolved to absolute form, to ensure that
38 /// they continue to identify the same asset from the output layer.
39 /// \sa UsdUtilsFlattenLayerStackResolveAssetPath
40 ///
41 /// A few historical scene description features cannot be flattened
42 /// into a single opinion because they unfortunately encode
43 /// operations that are not closed under composition. Specifically,
44 /// the SdfListOp operations "add" and "reorder" cannot be flattened.
45 /// Instead, "add" will be converted to "append", and "reorder"
46 /// will be discarded.
47 ///
50 UsdUtilsFlattenLayerStack(const UsdStagePtr &stage,
51  const std::string& tag = std::string());
52 
53 /// Callback function for overloaded version of \c UsdUtilsFlattenLayerStack.
54 ///
55 /// The callback is given the \c sourceLayer and the \c assetPath authored in
56 /// that layer. It should return the \c std::string that should be authored in
57 /// the flattened layer.
58 ///
59 /// \sa UsdUtilsFlattenLayerStackResolveAssetPath
60 using UsdUtilsResolveAssetPathFn = std::function<std::string(
61  const SdfLayerHandle& sourceLayer,
62  const std::string& assetPath)>;
63 
64 /// Flatten the root layer stack of the given \p stage into a single layer with
65 /// the given optional \p tag and using the \p resolveAssetPathFn to resolve
66 /// asset paths that are encountered.
67 ///
68 /// This is an advanced version of the above function.
69 ///
70 ///
71 /// One use case for this version of the function is to flatten a layer stack
72 /// that contains relative asset paths that we want to preserve as relative
73 /// paths. For example:
74 ///
75 /// \code
76 /// /source/root.usd # sublayers a.usd and b.usd
77 /// /source/a.usd # contains reference to ./subdir/layer.usd
78 /// /source/b.usd
79 /// /source/subdir/layer.usd
80 /// \endcode
81 ///
82 /// We may want to generate \c "/dest/root.flat.usd" knowing that we will
83 /// (by some other means) also be copying \c "/source/subdir" into \c
84 /// "/dest/subdir". It's useful then to preserve the relative paths.
85 ///
86 /// Note, only the caller knows the ultimate destination of the flattened layer.
87 /// So to accomplish this, we can provide a \c resolveAssetPathFn callback that
88 /// captures the outputDir, tests if the authored path is relative, and if so,
89 /// computes a new relative path (based on where it will eventually be
90 /// exported).
93 UsdUtilsFlattenLayerStack(const UsdStagePtr &stage,
94  const UsdUtilsResolveAssetPathFn& resolveAssetPathFn,
95  const std::string& tag = std::string());
96 
97 /// The default \c UsdUtilsResolvePathFn used by \c UsdUtilsFlattenLayerStack.
98 /// For paths that the current ArResolver identifies as searchpaths or absolute
99 /// paths, we return the unmodified path. However, any "Layer relative path"
100 /// (see SdfComputeAssetPathRelativeToLayer) will be absolutized, because we do
101 /// not know if the flattened layer's containing directory will be the same as
102 /// any given source layer's in the incoming layerStack.
104 std::string
106  const SdfLayerHandle& sourceLayer,
107  const std::string& assetPath);
108 
109 
111 
112 #endif /* PXR_USD_USD_UTILS_FLATTEN_LAYER_STACK_H */
Definition: layer.h:81
USDUTILS_API SdfLayerRefPtr UsdUtilsFlattenLayerStack(const UsdStagePtr &stage, const std::string &tag=std::string())
USDUTILS_API std::string UsdUtilsFlattenLayerStackResolveAssetPath(const SdfLayerHandle &sourceLayer, const std::string &assetPath)
PXR_NAMESPACE_OPEN_SCOPE SDF_DECLARE_HANDLES(SdfLayer)
std::function< std::string(const SdfLayerHandle &sourceLayer, const std::string &assetPath)> UsdUtilsResolveAssetPathFn
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
#define USDUTILS_API
Definition: api.h:23