HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stitch.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_STITCH_H
8 #define PXR_USD_USD_UTILS_STITCH_H
9 
10 /// \file usdUtils/stitch.h
11 ///
12 /// Collection of module-scoped utilities for combining layers.
13 /// These utilize the convention of a strong and a weak layer. The strong
14 /// layer will be the first parameter to the function and will always have
15 /// precedence in conflicts during the merge.
16 
17 #include "pxr/pxr.h"
18 #include "pxr/usd/usdUtils/api.h"
20 #include "pxr/usd/sdf/spec.h"
21 
22 #include <functional>
23 
25 
27 
28 /// Merge all scene description in \p weakLayer into \p strongLayer.
29 ///
30 /// Prims and properties in \p weakLayer that do not exist in \p strongLayer
31 /// will be copied into \p strongLayer. Prims and properties that do
32 /// exist in \p strongLayer will be merged with the existing scene
33 /// description.
34 ///
35 /// Merging prims and properties is done on a field-by-field basis.
36 /// In general, if a field has a value in \p strongLayer, the value from
37 /// \p weakLayer will be ignored. However, certain fields have special
38 /// rules for merging values together:
39 ///
40 /// - For map and dictionary-valued fields (including time samples),
41 /// a dictionary merge is performed; values in the weaker dictionary
42 /// are copied into the stronger dictionary only if the key does not
43 /// already exist.
44 ///
45 /// - For listOp-valued fields, the listOps will be combined into a
46 /// single listOp. The historical "add" and "reorder" list op operations
47 /// cannot be combined in this way; "add" will be converted to "append",
48 /// and "reorder" will be discarded.
49 ///
50 /// - The minimum startTimeCode value and maximum endTimeCode value will
51 /// be used.
54  const SdfLayerHandle& strongLayer,
55  const SdfLayerHandle& weakLayer);
56 
57 /// Merge the scene description for \p weakObj into \p strongObj.
58 ///
59 /// See documentation on UsdUtilsStitchLayers for a description of
60 /// the merging behavior.
63  const SdfSpecHandle& strongObj,
64  const SdfSpecHandle& weakObj);
65 
66 /// \name Advanced Stitching API
67 /// @{
68 
69 /// Status enum returned by UsdUtilsStitchValueFn describing the
70 /// desired value stitching behavior.
72 {
73  NoStitchedValue, ///< Don't stitch values for this field.
74  UseDefaultValue, ///< Use the default stitching behavior for this field.
75  UseSuppliedValue ///< Use the value supplied in stitchedValue.
76 };
77 
78 /// Callback for customizing how values are stitched together.
79 ///
80 /// This callback will be invoked for each field being stitched from the
81 /// source spec at \p path in \p weakLayer to the destination spec at
82 /// \p path in \p strongLayer. \p fieldInStrongLayer and \p fieldInWeakLayer
83 /// indicates whether the field has values in either layer.
84 ///
85 /// The callback should return a UsdUtilsStitchValueStatus to indicate the
86 /// desired behavior. Note that if the callback returns UseSuppliedValue and
87 /// supplies an empty VtValue in \p stitchedValue, the field will be removed
88 /// from the destination spec.
89 using UsdUtilsStitchValueFn = std::function<
91  const TfToken& field, const SdfPath& path,
92  const SdfLayerHandle& strongLayer, bool fieldInStrongLayer,
93  const SdfLayerHandle& weakLayer, bool fieldInWeakLayer,
94  VtValue* stitchedValue)>;
95 
96 /// Advanced version of UsdUtilsStitchLayers that accepts a \p stitchValueFn
97 /// callback to customize how fields in \p strongLayer and \p weakLayer are
98 /// stitched together. See documentation on UsdUtilsStitchValueFn for more
99 /// details.
102  const SdfLayerHandle& strongLayer,
103  const SdfLayerHandle& weakLayer,
104  const UsdUtilsStitchValueFn& stitchValueFn);
105 
106 /// Advanced version of UsdUtilsStitchInfo that accepts a \p stitchValueFn
107 /// callback to customize how fields in \p strongObj and \p weakObj are
108 /// stitched together. See documentation on UsdUtilsStitchValueFn for more
109 /// details.
111 void UsdUtilsStitchInfo(
112  const SdfSpecHandle& strongObj,
113  const SdfSpecHandle& weakObj,
114  const UsdUtilsStitchValueFn& stitchValueFn);
115 
116 /// @}
117 
119 
120 #endif /* PXR_USD_USD_UTILS_STITCH_H */
Definition: layer.h:81
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
Definition: token.h:70
Definition: path.h:273
Use the default stitching behavior for this field.
std::function< UsdUtilsStitchValueStatus(const TfToken &field, const SdfPath &path, const SdfLayerHandle &strongLayer, bool fieldInStrongLayer, const SdfLayerHandle &weakLayer, bool fieldInWeakLayer, VtValue *stitchedValue)> UsdUtilsStitchValueFn
Definition: stitch.h:94
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
Use the value supplied in stitchedValue.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USDUTILS_API void UsdUtilsStitchLayers(const SdfLayerHandle &strongLayer, const SdfLayerHandle &weakLayer)
PXR_NAMESPACE_OPEN_SCOPE SDF_DECLARE_HANDLES(SdfLayer)
Don't stitch values for this field.
#define USDUTILS_API
Definition: api.h:23
USDUTILS_API void UsdUtilsStitchInfo(const SdfSpecHandle &strongObj, const SdfSpecHandle &weakObj)
Definition: value.h:146
UsdUtilsStitchValueStatus
Definition: stitch.h:71