HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dependencies.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_DEPENDENCIES_H
8 #define PXR_USD_USD_UTILS_DEPENDENCIES_H
9 
10 /// \file usdUtils/dependencies.h
11 ///
12 /// Utilities for the following tasks that require consideration of a USD
13 /// asset's external dependencies:
14 /// * extracting asset dependencies from a USD file.
15 /// * creating a USDZ package containing a given asset and all of its external
16 /// dependencies.
17 /// * some time in the future, localize a given asset and all of its
18 /// dependencies into a specified directory.
19 ///
20 
21 #include "pxr/pxr.h"
22 #include "pxr/usd/usdUtils/api.h"
25 
26 #include <string>
27 #include <vector>
28 
30 
31 /// Structure which controls aspects of the
32 /// \ref UsdUtilsExtractExternalReferences function.
34 public:
35  /// Specifies whether UDIM template paths should be resolved when extracting
36  /// references. If true, the resolved paths for all discovered UDIM tiles
37  /// will be included in the references bucket and the template path will be
38  /// discarded. If false, no resolution will take place and the template path
39  /// will appear in the references bucket.
40  inline void SetResolveUdimPaths(bool resolveUdimPaths) {
41  _resolveUdimPaths = resolveUdimPaths;
42  }
43 
44 
45  inline bool GetResolveUdimPaths() const { return _resolveUdimPaths; }
46 
47 private:
48  bool _resolveUdimPaths = false;
49 };
50 
51 /// Parses the file at \p filePath, identifying external references, and
52 /// sorting them into separate type-based buckets. Sublayers are returned in
53 /// the \p sublayers vector, references, whether prim references, value clip
54 /// references or values from asset path attributes, are returned in the
55 /// \p references vector. Payload paths are returned in \p payloads.
56 /// The \p params parameter controls various settings that affect the
57 /// extraction process. See \ref UsdUtilsExtractExternalReferencesParams for
58 /// additional details.
59 ///
60 /// \note No recursive chasing of dependencies is performed; that is the
61 /// client's responsibility, if desired.
62 ///
63 /// \note Not all returned references are actually authored explicitly in the
64 /// layer. For example, templated clip asset paths are resolved and expanded
65 /// to include all available clip files that match the specified pattern.
68  const std::string& filePath,
69  std::vector<std::string>* subLayers,
70  std::vector<std::string>* references,
71  std::vector<std::string>* payloads,
73 
74 /// Recursively computes all the dependencies of the given asset and populates
75 /// \p layers with all the dependencies that can be opened as an SdfLayer.
76 /// All of the resolved non-layer dependencies are populated in \p assets.
77 /// Any unresolved (layer and non-layer) asset paths are populated in
78 /// \p unresolvedPaths.
79 ///
80 /// If a function is provided for the \p processingFunc parameter, it will be
81 /// invoked on every asset path that is discovered during localization.
82 /// Refer to \ref UsdUtilsDependencyInfo for general information on User
83 /// processing functions. Any changes made to the paths during the
84 /// invocation of this function will not be written to processed layers.
85 ///
86 /// The input vectors to be populated with the results are *cleared* before
87 /// any results are added to them.
88 ///
89 /// Returns true if the given asset was resolved correctly.
91 bool
93  const SdfAssetPath &assetPath,
94  std::vector<SdfLayerRefPtr> *layers,
95  std::vector<std::string> *assets,
96  std::vector<std::string> *unresolvedPaths,
97  const std::function<UsdUtilsProcessingFunc> &processingFunc =
98  std::function<UsdUtilsProcessingFunc>());
99 
100 /// Callback that is used to modify asset paths in a layer. The \c assetPath
101 /// will contain the string value that's authored. The returned value is the
102 /// new value that should be authored in the layer. If the function returns
103 /// an empty string, that value will be removed from the layer.
104 using UsdUtilsModifyAssetPathFn = std::function<std::string(
105  const std::string& assetPath)>;
106 
107 /// Helper function that visits every asset path in \c layer, calls \c modifyFn
108 /// and replaces the value with the return value of \c modifyFn. This modifies
109 /// \c layer in place. If the \c keepEmptyPathsInArrays parameter is true, empty
110 /// asset paths will be written in into arrays even if \c modifyFn returns an
111 /// empty string. This functionality is useful in cases where arrays are
112 /// expected to have a specific length or such values may be meaningful.
113 ///
114 /// This can be useful in preparing a layer for consumption in contexts that do
115 /// not have access to the ArResolver for which the layer's asset paths were
116 /// authored: we can replace all paths with their fully resolved equivalents,
117 /// for example.
120  const SdfLayerHandle& layer,
121  const UsdUtilsModifyAssetPathFn& modifyFn,
122  bool keepEmptyPathsInArrays = false);
123 
125 
126 #endif // PXR_USD_USD_UTILS_DEPENDENCIES_H
USDUTILS_API void UsdUtilsModifyAssetPaths(const SdfLayerHandle &layer, const UsdUtilsModifyAssetPathFn &modifyFn, bool keepEmptyPathsInArrays=false)
void SetResolveUdimPaths(bool resolveUdimPaths)
Definition: dependencies.h:40
Attempt to access an object that no longer exists in Houdini Invalid output Invalid type The attempted operation failed Node initialization script failed Failed to modify node or parameter because of a permission error Possible causes include locked assets
Definition: HOM_Errors.h:191
GLenum const GLfloat * params
Definition: glcorearb.h:105
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
USDUTILS_API void UsdUtilsExtractExternalReferences(const std::string &filePath, std::vector< std::string > *subLayers, std::vector< std::string > *references, std::vector< std::string > *payloads, const UsdUtilsExtractExternalReferencesParams &params={})
std::function< std::string(const std::string &assetPath)> UsdUtilsModifyAssetPathFn
Definition: dependencies.h:105
USDUTILS_API bool UsdUtilsComputeAllDependencies(const SdfAssetPath &assetPath, std::vector< SdfLayerRefPtr > *layers, std::vector< std::string > *assets, std::vector< std::string > *unresolvedPaths, const std::function< UsdUtilsProcessingFunc > &processingFunc=std::function< UsdUtilsProcessingFunc >())
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