All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
18 #ifndef __XUSD_Utils_h__
19 #define __XUSD_Utils_h__
21 #include "HUSD_API.h"
22 #include "HUSD_DataHandle.h"
23 #include "HUSD_Utils.h"
24 #include <OP/OP_ItemId.h>
25 #include <UT/UT_StringHolder.h>
26 #include <UT/UT_StringArray.h>
27 #include <UT/UT_StringMMPattern.h>
28 #include <UT/UT_Map.h>
29 #include <pxr/usd/sdf/fileFormat.h>
30 #include <pxr/usd/sdf/layer.h>
32 #include <pxr/usd/sdf/path.h>
33 #include <pxr/usd/usd/prim.h>
34 #include <pxr/usd/usd/stage.h>
35 #include <pxr/usd/usd/timeCode.h>
38 class HUSD_LayerOffset;
39 class HUSD_LoadMasks;
40 class HUSD_TimeCode;
44 class UsdGeomPrimvar;
45 class UsdGeomXformCache;
48 {
49 public:
51  { }
53  { }
55  virtual int getPriority() const = 0;
56  virtual UsdStageRefPtr createStage(UsdStage::InitialLoadSet loadset,
57  int nodeid) const = 0;
58 };
60 extern "C" {
63 };
66 {
67 public:
68  explicit XUSD_SavePathInfo()
69  : myNodeBasedPath(false)
70  { }
71  explicit XUSD_SavePathInfo(const UT_StringHolder &finalpath)
72  : myFinalPath(finalpath),
73  myOriginalPath(finalpath),
74  myNodeBasedPath(false)
75  { }
76  explicit XUSD_SavePathInfo(const UT_StringHolder &finalpath,
77  const UT_StringHolder &originalpath,
78  bool node_based_path)
79  : myFinalPath(finalpath),
80  myOriginalPath(originalpath),
81  myNodeBasedPath(node_based_path)
82  { }
87 };
94 // Helper function to convert a node id directly to a node path, and return
95 // true if the conversion was successful.
96 HUSD_API bool HUSDgetNodePath(int nodeid, UT_StringHolder &nodepath);
97 // Similar to the above method, but for the dedicated purpose of returning a
98 // std::string to pass to HUSDcreateAnonymousLayer.
113 HUSD_API const TfType &HUSDfindType(const UT_StringRef &type_name);
114 HUSD_API bool HUSDisDerivedType(const UsdPrim &prim,
115  const TfType &base_type);
117 // Path conversion functions.
122 // Timecode conversion functions.
126  const HUSD_TimeCode &timecode);
128  const HUSD_TimeCode &timecode,
129  const UsdAttribute &attr);
131  const HUSD_TimeCode &timecode,
132  const UsdAttribute &attr);
135 // Layer offset conversion.
137 HUSDgetSdfLayerOffset(const HUSD_LayerOffset &layeroffset);
139 HUSDgetLayerOffset(const SdfLayerOffset &layeroffset);
141 // Other functions to convert from HUSD classes to USD equivalents.
145 HUSDgetUsdListPosition(const UT_StringRef &editopstr);
151 // Determine if a layer comes from a SOP or not.
152 HUSD_API bool
153 HUSDisSopLayer(const std::string &identifier);
154 HUSD_API bool
155 HUSDisSopLayer(const SdfLayerHandle &layer);
157 // Determine if the specified layer should be saved to disk when saving a
158 // LOP network which sublayers or references this layer.
159 HUSD_API bool
160 HUSDshouldSaveLayerToDisk(const SdfLayerHandle &layer);
162 // Figures out from the layer metadata where the layer should be saved. This
163 // method only works on layers that return true from HUSDshouldSaveLayerToDisk.
165 HUSDgetLayerSaveLocation(const SdfLayerHandle &layer,
166  bool *using_node_path = nullptr);
168 // Get (creating if requested) the special prim that gets put on LOP layers
169 // to hold special layer information (save path, creator node, editor nodes,
170 // etc.) We store this on the custom data of a dedicated prim instead of on
171 // the layer root because custom data on the layer root can cause a whole lot
172 // of recomposition.
173 HUSD_API SdfPrimSpecHandle
174 HUSDgetLayerInfoPrim(const SdfLayerHandle &layer, bool create);
176 // Get or set the save path custom data on a layer. Used by the above
177 // HUSDgetLayerSaveLocation as one of the methods to determine where a layer
178 // should be saved.
179 HUSD_API void
180 HUSDsetSavePath(const SdfLayerHandle &layer,
181  const UT_StringRef &savepath);
182 HUSD_API bool
183 HUSDgetSavePath(const SdfLayerHandle &layer,
184  std::string &savepath);
186 // Get or set the save control token which modified how the USD ROP treats
187 // this layer when it is being saved with various options.
188 HUSD_API void
189 HUSDsetSaveControl(const SdfLayerHandle &layer,
190  const UT_StringRef &savecontrol);
191 HUSD_API bool
192 HUSDgetSaveControl(const SdfLayerHandle &layer,
193  std::string &savecontrol);
195 HUSD_API void
196 HUSDsetCreatorNode(const SdfLayerHandle &layer, int node_id);
197 HUSD_API void
198 HUSDsetCreatorNode(const SdfLayerHandle &layer, const std::string &nodepath);
199 HUSD_API bool
200 HUSDgetCreatorNode(const SdfLayerHandle &layer, std::string &nodepath);
202 HUSD_API void
203 HUSDsetSourceNode(const UsdPrim &prim, int node_id);
204 HUSD_API bool
205 HUSDgetSourceNode(const UsdPrim &prim, std::string &nodepath);
207 HUSD_API void
208 HUSDclearEditorNodes(const SdfLayerHandle &layer);
209 HUSD_API void
210 HUSDaddEditorNode(const SdfLayerHandle &layer, int node_id);
211 HUSD_API bool
212 HUSDgetEditorNodes(const SdfLayerHandle &layer,
213  std::vector<std::string> &nodepaths);
215 // Set the list of SdfPaths of all solo'ed lights. This information is stored
216 // as custom data on the HoudiniLayerInfo prim. These methods should only be
217 // used by HUSD_Overrides.
218 HUSD_API void
219 HUSDsetSoloLightPaths(const SdfLayerHandle &layer,
220  const std::vector<std::string> &paths);
221 HUSD_API bool
222 HUSDgetSoloLightPaths(const SdfLayerHandle &layer,
223  std::vector<std::string> &paths);
225 // Set the list of SdfPaths of all solo'ed geometry. This information is stored
226 // as custom data on the HoudiniLayerInfo prim. These methods should only be
227 // used by HUSD_Overrides.
228 HUSD_API void
229 HUSDsetSoloGeometryPaths(const SdfLayerHandle &layer,
230  const std::vector<std::string> &paths);
231 HUSD_API bool
232 HUSDgetSoloGeometryPaths(const SdfLayerHandle &layer,
233  std::vector<std::string> &paths);
235 // Set the Editor node for a specific USD primitive. This is stored as custom
236 // data on the primitive, and indicates the node that last modified this
237 // primitive, and so the node that we should use for any future requests to
238 // edit the prim.
239 HUSD_API void
240 HUSDsetPrimEditorNodeId(const UsdPrim &prim, int node_id);
241 HUSD_API void
242 HUSDsetPrimEditorNodeId(const SdfPrimSpecHandle &prim, int node_id);
244 HUSD_API void
245 HUSDclearDataId(const UsdAttribute &attr);
248 HUSDgetParentKind(const TfToken &kind);
250 // Create a new primitive in the specified layer. The stage parameter may or
251 // may not include the layer. It is used only to look up any existing prims
252 // so we know which ancestors of the new prim should be defined and which
253 // should simply be over prims. If the requested prim already exists on the
254 // stage, this function does nothing.
255 HUSD_API SdfPrimSpecHandle
257  const SdfLayerHandle &layer,
258  const SdfPath &path,
259  const TfToken &kind,
260  bool parent_prims_define,
261  const std::string &parent_prims_type);
263 HUSD_API bool
264 HUSDcopySpec(const SdfLayerHandle &srclayer,
265  const SdfPath &srcpath,
266  const SdfLayerHandle &destlayer,
267  const SdfPath &destath,
268  const SdfPath &srcroot = SdfPath(),
269  const SdfPath &destroot = SdfPath());
271 // This function duplicates the functionality of
272 // SdfLayer::UpdateExternalRefernce, but can retarget a bunch of references
273 // with a single method call, and thus a single traversal.
274 HUSD_API bool
275 HUSDupdateExternalReferences(const SdfLayerHandle &layer,
276  const std::map<std::string, std::string> &pathmap);
278 HUSD_API bool
279 HUSDcopyLayerMetadata(const SdfLayerHandle &srclayer,
280  const SdfLayerHandle &destlayer);
282 HUSD_API bool
283 HUSDclearLayerMetadata(const SdfLayerHandle &destlayer);
285 // Utility function used for stitching stages together and saving them.
286 HUSD_API void
288  XUSD_IdentifierToLayerMap &layermap,
289  bool recursive);
291 // Calls the USD stitch function but with a callback that looks for SOP data
292 // ids on the attributes to avoid creating duplicate time samples.
293 HUSD_API void
294 HUSDstitchLayers(const SdfLayerHandle &strongLayer,
295  const SdfLayerHandle &weakLayer);
296 // Stitch two stages together by stitching together their "corresponding"
297 // layers, as determined by the requested save paths for each layer.
298 HUSD_API bool
300  const UsdStageRefPtr &dest,
301  SdfLayerRefPtrVector &hold_layers);
303 // Create a new in-memory stage. Use this method instead of calling
304 // UsdStage::CreateInMemory directly, as we want to configure the stage
305 // with a reasonable identifier, and a path resolver context. The first
306 // version only sets the payload loading option, which must be set when
307 // the stage is constructed. The second version sets the payload loading
308 // option, the stage population maks, and the layer muting based on the
309 // values set in the provided load masks object.
310 HUSD_API UsdStageRefPtr
312  int resolver_context_nodeid = OP_INVALID_ITEM_ID,
313  const UsdStageWeakPtr &resolver_context_state = UsdStageWeakPtr(),
314  const ArResolverContext *resolver_context = nullptr);
315 HUSD_API UsdStageRefPtr
316 HUSDcreateStageInMemory(const HUSD_LoadMasks *load_masks,
317  int resolver_context_nodeid = OP_INVALID_ITEM_ID,
318  const UsdStageWeakPtr &resolver_context_state = UsdStageWeakPtr(),
319  const ArResolverContext *resolver_context = nullptr);
321 // Create a new anonymous layer. Usd this method instead of calling
322 // SdfLayer::CreateAnonymous directly, as we want to configure the layer
323 // with some common default data.
326  bool set_up_axis = false);
333 };
335 // Combine layers together based on some options and custom data set on each
336 // layer in the stack (or referenced by a layer in the stack).
339  int flatten_flags,
340  SdfLayerRefPtrVector &explicit_layers);
342 // Combine all layers in the stack by calling the USD flatten layers method.
344 HUSDflattenLayers(const UsdStageWeakPtr &stage);
346 // Check if the supplied layer is completely devoid of any useful information.
347 // This includes both primitives and layer level metadata. However the presence
348 // of only a HoudiniLayerInfo prim may still indicate an "empty" layer if it
349 // only contains creator node information.
350 HUSD_API bool
351 HUSDisLayerEmpty(const SdfLayerHandle &layer);
352 // Check if the supplied layer is a placeholder layer.
353 HUSD_API bool
354 HUSDisLayerPlaceholder(const SdfLayerHandle &layer);
355 // As above, but takes an identifier, which is used to find the layer handle.
356 HUSD_API bool
357 HUSDisLayerPlaceholder(const std::string &identifier);
359 // Return the SdfPath that should be passed to create a reference to the
360 // specified layer. This gives priority to any passed in ref prim path
361 // string, then the layer's default prim (if one is set), then looks at
362 // the layer root prims and picks the first geometry primitive, or the
363 // first primitive if there are no geometry primitives. Raises an warning
364 // if it picks a primitive, but there are other primitives.
366 HUSDgetBestRefPrimPath(const UT_StringRef &reffilepath,
368  const UT_StringRef &refprimpath,
369  UsdStageRefPtr &stage);
370 HUSD_API void
371 HUSDclearBestRefPathCache(const std::string &layeridentifier = std::string());
373 // Functions for checking the amount of time sampling of an attribute/xfrom:
380 // Conveninece methods for updating the given time sampling.
382  HUSD_TimeSampling new_sampling );
384  const UsdAttribute &attrib);
386  const UsdGeomPrimvar &primvar);
388  const UsdPrim &prim);
390  const UsdPrim &prim);
392 // Returns ture if an attribute (or any aspect of a local transform)
393 // has more than 1 time sample.
399 #endif
HUSD_API UsdTimeCode HUSDgetNonDefaultUsdTimeCode(const HUSD_TimeCode &timecode)
HUSD_API const SdfPath & HUSDgetHoudiniLayerInfoSdfPath()
HUSD_API bool HUSDgetSoloGeometryPaths(const SdfLayerHandle &layer, std::vector< std::string > &paths)
HUSD_API void HUSDaddEditorNode(const SdfLayerHandle &layer, int node_id)
HUSD_API const TfToken & HUSDgetSoloLightPathsToken()
GLenum src
Definition: glew.h:2410
HUSD_API void HUSDupdateValueTimeSampling(HUSD_TimeSampling &sampling, const UsdAttribute &attrib)
HUSD_API bool HUSDisLayerEmpty(const SdfLayerHandle &layer)
HUSD_API const TfToken & HUSDgetPrimEditorNodeIdToken()
Definition: common.h:110
Unsorted map container.
Definition: UT_Map.h:83
virtual UsdStageRefPtr createStage(UsdStage::InitialLoadSet loadset, int nodeid) const =0
HUSD_API void HUSDsetSaveControl(const SdfLayerHandle &layer, const UT_StringRef &savecontrol)
HUSD_API bool HUSDvalueMightBeTimeVarying(const UsdAttribute &attrib)
HUSD_API SdfLayerRefPtr HUSDcreateAnonymousLayer(const std::string &tag=std::string(), bool set_up_axis=false)
const Args & args
Definition: printf.h:628
HUSD_API void HUSDupdateTimeSampling(HUSD_TimeSampling &sampling, HUSD_TimeSampling new_sampling)
Definition: OP_ItemId.h:23
HUSD_API HUSD_LayerOffset HUSDgetLayerOffset(const SdfLayerOffset &layeroffset)
UT_Map< std::string, SdfLayerRefPtr > XUSD_IdentifierToLayerMap
Definition: XUSD_Utils.h:90
HUSD_API std::string HUSDgetLayerSaveLocation(const SdfLayerHandle &layer, bool *using_node_path=nullptr)
HUSD_API Usd_PrimFlagsPredicate HUSDgetUsdPrimPredicate(HUSD_PrimTraversalDemands demands)
HUSD_API bool HUSDgetNodePath(int nodeid, UT_StringHolder &nodepath)
HUSD_API SdfPath HUSDgetBestRefPrimPath(const UT_StringRef &reffilepath, const SdfFileFormat::FileFormatArguments &args, const UT_StringRef &refprimpath, UsdStageRefPtr &stage)
HUSD_API SdfLayerOffset HUSDgetSdfLayerOffset(const HUSD_LayerOffset &layeroffset)
#define HUSD_API
Definition: HUSD_API.h:32
HUSD_API SdfVariability HUSDgetSdfVariability(HUSD_Variability variability)
HUSD_API void HUSDclearEditorNodes(const SdfLayerHandle &layer)
HUSD_API const TfToken & HUSDgetMaterialBindingIdToken()
HUSD_API bool HUSDgetSoloLightPaths(const SdfLayerHandle &layer, std::vector< std::string > &paths)
HUSD_API HUSD_TimeCode HUSDgetEffectiveTimeCode(const HUSD_TimeCode &timecode, const UsdAttribute &attr)
HUSD_API void HUSDclearBestRefPathCache(const std::string &layeridentifier=std::string())
Definition: stage.h:155
HUSD_API bool HUSDisSopLayer(const std::string &identifier)
HUSD_API HUSD_TimeSampling HUSDgetWorldTransformTimeSampling(const UsdPrim &pr)
Definition: HUSD_Utils.h:28
HUSD_API UsdListPosition HUSDgetUsdListPosition(const UT_StringRef &editopstr)
HUSD_API bool HUSDupdateExternalReferences(const SdfLayerHandle &layer, const std::map< std::string, std::string > &pathmap)
HUSD_API bool HUSDgetSaveControl(const SdfLayerHandle &layer, std::string &savecontrol)
HUSD_API UsdStagePopulationMask HUSDgetUsdStagePopulationMask(const HUSD_LoadMasks &load_masks)
HUSD_API bool HUSDgetSourceNode(const UsdPrim &prim, std::string &nodepath)
HUSD_API bool HUSDcopyLayerMetadata(const SdfLayerHandle &srclayer, const SdfLayerHandle &destlayer)
HUSD_API bool HUSDgetSavePath(const SdfLayerHandle &layer, std::string &savepath)
HUSD_API SdfPrimSpecHandle HUSDgetLayerInfoPrim(const SdfLayerHandle &layer, bool create)
HUSD_API void HUSDsetSoloGeometryPaths(const SdfLayerHandle &layer, const std::vector< std::string > &paths)
HUSD_API bool HUSDaddStageTimeSample(const UsdStageWeakPtr &src, const UsdStageRefPtr &dest, SdfLayerRefPtrVector &hold_layers)
Definition: HUSD_Utils.h:66
HUSD_API UsdStageRefPtr HUSDcreateStageInMemory(UsdStage::InitialLoadSet load, int resolver_context_nodeid=OP_INVALID_ITEM_ID, const UsdStageWeakPtr &resolver_context_state=UsdStageWeakPtr(), const ArResolverContext *resolver_context=nullptr)
Definition: token.h:89
UT_Map< std::string, XUSD_SavePathInfo > XUSD_IdentifierToSavePathMap
Definition: XUSD_Utils.h:92
HUSD_API void HUSDaddExternalReferencesToLayerMap(const SdfLayerRefPtr &layer, XUSD_IdentifierToLayerMap &layermap, bool recursive)
HUSD_API const TfToken & HUSDgetSavePathToken()
UT_StringHolder myFinalPath
Definition: XUSD_Utils.h:84
HUSD_API bool HUSDgetCreatorNode(const SdfLayerHandle &layer, std::string &nodepath)
std::vector< TfRefPtr< SdfLayer > > SdfLayerRefPtrVector
HUSD_API bool HUSDclearLayerMetadata(const SdfLayerHandle &destlayer)
HUSD_API HUSD_TimeSampling HUSDgetValueTimeSampling(const UsdAttribute &attrib)
Definition: HUSD_Utils.h:81
HUSD_API void HUSDsetPrimEditorNodeId(const UsdPrim &prim, int node_id)
HUSD_API void HUSDupdateWorldTransformTimeSampling(HUSD_TimeSampling &samplig, const UsdPrim &prim)
HUSD_API const TfToken & HUSDgetEditorNodesToken()
HUSD_API void HUSDsetCreatorNode(const SdfLayerHandle &layer, int node_id)
Definition: prim.h:131
HUSD_API bool HUSDisLayerPlaceholder(const SdfLayerHandle &layer)
HUSD_API const TfType & HUSDfindType(const UT_StringRef &type_name)
virtual ~XUSD_StageFactory()
Definition: XUSD_Utils.h:52
HUSD_API SdfLayerRefPtr HUSDflattenLayers(const UsdStageWeakPtr &stage)
HUSD_API void HUSDsetSavePath(const SdfLayerHandle &layer, const UT_StringRef &savepath)
HUSD_API UsdTimeCode HUSDgetEffectiveUsdTimeCode(const HUSD_TimeCode &timecode, const UsdAttribute &attr)
Definition: path.h:287
HUSD_API HUSD_TimeSampling HUSDgetLocalTransformTimeSampling(const UsdPrim &pr)
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:208
HUSD_API const TfToken & HUSDgetSaveControlToken()
Definition: types.h:182
GLsizei const GLchar *const * path
Definition: glew.h:6461
UsdStagePtr UsdStageWeakPtr
Definition: common.h:55
HUSD_API const TfToken & HUSDgetSourceNodeToken()
GLsizei const GLchar *const * string
Definition: glew.h:1844
HUSD_API void HUSDsetSourceNode(const UsdPrim &prim, int node_id)
SYS_VISIBILITY_EXPORT void newStageFactory(UT_Array< XUSD_StageFactory * > *factories)
HUSD_API bool HUSDcopySpec(const SdfLayerHandle &srclayer, const SdfPath &srcpath, const SdfLayerHandle &destlayer, const SdfPath &destath, const SdfPath &srcroot=SdfPath(), const SdfPath &destroot=SdfPath())
HUSD_API UsdTimeCode HUSDgetCurrentUsdTimeCode()
Definition: path.h:1245
HUSD_API const TfToken & HUSDgetCreatorNodeToken()
HUSD_API bool HUSDlocalTransformMightBeTimeVarying(const UsdPrim &prim)
HUSD_API const TfToken & HUSDgetSoloGeometryPathsToken()
virtual int getPriority() const =0
HUSD_API UsdTimeCode HUSDgetUsdTimeCode(const HUSD_TimeCode &timecode)
HUSD_API SdfPath HUSDgetSdfPath(const UT_StringRef &path)
Definition: XUSD_Utils.h:328
XUSD_SavePathInfo(const UT_StringHolder &finalpath, const UT_StringHolder &originalpath, bool node_based_path)
Definition: XUSD_Utils.h:76
HUSD_API SdfPrimSpecHandle HUSDcreatePrimInLayer(const UsdStageWeakPtr &stage, const SdfLayerHandle &layer, const SdfPath &path, const TfToken &kind, bool parent_prims_define, const std::string &parent_prims_type)
GLint GLboolean GLint layer
Definition: glew.h:3601
Definition: pxr.h:83
HUSD_API void HUSDstitchLayers(const SdfLayerHandle &strongLayer, const SdfLayerHandle &weakLayer)
HUSD_API void HUSDsetSoloLightPaths(const SdfLayerHandle &layer, const std::vector< std::string > &paths)
HUSD_API bool HUSDshouldSaveLayerToDisk(const SdfLayerHandle &layer)
Definition: type.h:70
HUSD_API const TfToken & HUSDgetDataIdToken()
HUSD_API bool HUSDgetEditorNodes(const SdfLayerHandle &layer, std::vector< std::string > &nodepaths)
HUSD_API const TfToken & HUSDgetMaterialIdToken()
XUSD_SavePathInfo(const UT_StringHolder &finalpath)
Definition: XUSD_Utils.h:71
HUSD_API void HUSDclearDataId(const UsdAttribute &attr)
HUSD_API void HUSDupdateLocalTransformTimeSampling(HUSD_TimeSampling &samplig, const UsdPrim &prim)
std::map< std::string, std::string > FileFormatArguments
Definition: fileFormat.h:113
HUSD_API std::string HUSDgetTag(const XUSD_DataLockPtr &datalock)
HUSD_API SdfLayerRefPtr HUSDflattenLayerPartitions(const UsdStageWeakPtr &stage, int flatten_flags, SdfLayerRefPtrVector &explicit_layers)
UT_StringHolder myOriginalPath
Definition: XUSD_Utils.h:85
HUSD_API TfToken HUSDgetParentKind(const TfToken &kind)
GLenum const void * paths
Definition: glew.h:13589
HUSD_API bool HUSDisDerivedType(const UsdPrim &prim, const TfType &base_type)
HUSD_API SdfPathVector HUSDgetSdfPaths(const UT_StringArray &paths)