HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
modelAPI.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 USD_GENERATED_MODELAPI_H
8 #define USD_GENERATED_MODELAPI_H
9 
10 /// \file usd/modelAPI.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usd/api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
17 
18 #include "pxr/base/vt/value.h"
19 
20 #include "pxr/base/gf/vec3d.h"
21 #include "pxr/base/gf/vec3f.h"
22 #include "pxr/base/gf/matrix4d.h"
23 
24 #include "pxr/base/tf/token.h"
25 #include "pxr/base/tf/type.h"
26 
28 
29 class SdfAssetPath;
30 
31 // -------------------------------------------------------------------------- //
32 // MODELAPI //
33 // -------------------------------------------------------------------------- //
34 
35 /// \class UsdModelAPI
36 ///
37 /// UsdModelAPI is an API schema that provides an interface to a prim's
38 /// model qualities, if it does, in fact, represent the root prim of a model.
39 ///
40 /// The first and foremost model quality is its \em kind, i.e. the metadata
41 /// that establishes it as a model (See KindRegistry). UsdModelAPI provides
42 /// various methods for setting and querying the prim's kind, as well as
43 /// queries (also available on UsdPrim) for asking what category of model
44 /// the prim is. See \ref Usd_ModelKind "Kind and Model-ness".
45 ///
46 /// UsdModelAPI also provides access to a prim's \ref Usd_Model_AssetInfo "assetInfo"
47 /// data. While any prim \em can host assetInfo, it is common that published
48 /// (referenced) assets are packaged as models, therefore it is convenient
49 /// to provide access to the one from the other.
50 ///
51 /// \todo establish an _IsCompatible() override that returns IsModel()
52 /// \todo GetModelInstanceName()
53 ///
54 ///
56 {
57 public:
58  /// Compile time constant representing what kind of schema this class is.
59  ///
60  /// \sa UsdSchemaKind
62 
63  /// Construct a UsdModelAPI on UsdPrim \p prim .
64  /// Equivalent to UsdModelAPI::Get(prim.GetStage(), prim.GetPath())
65  /// for a \em valid \p prim, but will not immediately throw an error for
66  /// an invalid \p prim
67  explicit UsdModelAPI(const UsdPrim& prim=UsdPrim())
68  : UsdAPISchemaBase(prim)
69  {
70  }
71 
72  /// Construct a UsdModelAPI on the prim held by \p schemaObj .
73  /// Should be preferred over UsdModelAPI(schemaObj.GetPrim()),
74  /// as it preserves SchemaBase state.
75  explicit UsdModelAPI(const UsdSchemaBase& schemaObj)
76  : UsdAPISchemaBase(schemaObj)
77  {
78  }
79 
80  /// Destructor.
81  USD_API
82  virtual ~UsdModelAPI();
83 
84  /// Return a vector of names of all pre-declared attributes for this schema
85  /// class and all its ancestor classes. Does not include attributes that
86  /// may be authored by custom/extended methods of the schemas involved.
87  USD_API
88  static const TfTokenVector &
89  GetSchemaAttributeNames(bool includeInherited=true);
90 
91  /// Return a UsdModelAPI holding the prim adhering to this
92  /// schema at \p path on \p stage. If no prim exists at \p path on
93  /// \p stage, or if the prim at that path does not adhere to this schema,
94  /// return an invalid schema object. This is shorthand for the following:
95  ///
96  /// \code
97  /// UsdModelAPI(stage->GetPrimAtPath(path));
98  /// \endcode
99  ///
100  USD_API
101  static UsdModelAPI
102  Get(const UsdStagePtr &stage, const SdfPath &path);
103 
104 
105 protected:
106  /// Returns the kind of schema this class belongs to.
107  ///
108  /// \sa UsdSchemaKind
109  USD_API
110  UsdSchemaKind _GetSchemaKind() const override;
111 
112 private:
113  // needs to invoke _GetStaticTfType.
114  friend class UsdSchemaRegistry;
115  USD_API
116  static const TfType &_GetStaticTfType();
117 
118  static bool _IsTypedSchema();
119 
120  // override SchemaBase virtuals.
121  USD_API
122  const TfType &_GetTfType() const override;
123 
124 public:
125  // ===================================================================== //
126  // Feel free to add custom code below this line, it will be preserved by
127  // the code generator.
128  //
129  // Just remember to:
130  // - Close the class declaration with };
131  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
132  // - Close the include guard with #endif
133  // ===================================================================== //
134  // --(BEGIN CUSTOM CODE)--
135 
136  /// \anchor Usd_ModelKind
137  /// \name Kind and Model-ness
138  /// @{
139 
140  /// \enum KindValidation
141  ///
142  /// Option for validating queries to a prim's kind metadata.
143  /// \sa IsKind()
147  };
148 
149  /// Retrieve the authored \p kind for this prim.
150  ///
151  /// \return true if there was an authored kind that was successfully read,
152  /// otherwise false.
153  ///
154  /// \sa UsdPrim::GetKind
155  USD_API
156  bool GetKind(TfToken* kind) const;
157 
158  /// Author a \p kind for this prim, at the current UsdEditTarget.
159  /// \return true if \p kind was successully authored, otherwise false.
160  ///
161  /// \sa UsdPrim::SetKind
162  USD_API
163  bool SetKind(const TfToken& kind) const;
164 
165  /// Return true if the prim's kind metadata is or inherits from
166  /// \p baseKind as defined by the Kind Registry.
167  ///
168  /// If \p validation is KindValidationModelHierarchy (the default), then
169  /// this also ensures that if baseKind is a model, the prim conforms to
170  /// the rules of model hierarchy, as defined by IsModel. If set to
171  /// KindValidationNone, no additional validation is done.
172  ///
173  /// IsModel and IsGroup are preferrable to IsKind("model") as they are
174  /// optimized for fast traversal.
175  ///
176  /// \note If a prim's model hierarchy is not valid, it is possible that
177  /// that prim.IsModel() and
178  /// prim.IsKind("model", Usd.ModelAPI.KindValidationNone) return different
179  /// answers. (As a corallary, this is also true for for prim.IsGroup())
180  USD_API
181  bool IsKind(const TfToken& baseKind,
183 
184  /// Return true if this prim represents a model, based on its kind
185  /// metadata.
186  USD_API
187  bool IsModel() const;
188 
189  /// Return true if this prim represents a model group, based on its kind
190  /// metadata.
191  USD_API
192  bool IsGroup() const;
193 
194  /// @}
195 
196  /// \anchor Usd_Model_AssetInfo
197  /// \name Model Asset Info API
198  /// @{
199 
200  /// Returns the model's asset identifier as authored in the composed
201  /// assetInfo dictionary.
202  ///
203  /// The asset identifier can be used to resolve the model's root layer via
204  /// the asset resolver plugin.
205  ///
206  USD_API
207  bool GetAssetIdentifier(SdfAssetPath *identifier) const;
208 
209  /// Sets the model's asset identifier to the given asset path, \p identifier.
210  ///
211  /// \sa GetAssetIdentifier()
212  ///
213  USD_API
214  void SetAssetIdentifier(const SdfAssetPath &identifier) const;
215 
216  /// Returns the model's asset name from the composed assetInfo dictionary.
217  ///
218  /// The asset name is the name of the asset, as would be used in a database
219  /// query.
220  ///
221  USD_API
222  bool GetAssetName(std::string *assetName) const;
223 
224  /// Sets the model's asset name to \p assetName.
225  ///
226  /// \sa GetAssetName()
227  ///
228  USD_API
229  void SetAssetName(const std::string &assetName) const;
230 
231  /// Returns the model's resolved asset version.
232  ///
233  /// If you publish assets with an embedded version, then you may receive
234  /// that version string. You may, however, cause your authoring tools to
235  /// record the resolved version <em>at the time at which a reference to the
236  /// asset was added to an aggregate</em>, at the referencing site. In
237  /// such a pipeline, this API will always return that stronger opinion,
238  /// even if the asset is republished with a newer version, and even though
239  /// that newer version may be the one that is resolved when the UsdStage is
240  /// opened.
241  ///
242  USD_API
243  bool GetAssetVersion(std::string *version) const;
244 
245  /// Sets the model's asset version string.
246  ///
247  /// \sa GetAssetVersion()
248  ///
249  USD_API
250  void SetAssetVersion(const std::string &version) const;
251 
252  /// Returns the list of asset dependencies referenced inside the
253  /// payload of the model.
254  ///
255  /// This typically contains identifiers of external assets that are
256  /// referenced inside the model's payload. When the model is created, this
257  /// list is compiled and set at the root of the model. This enables
258  /// efficient dependency analysis without the need to include the model's
259  /// payload.
260  ///
261  USD_API
263  const;
264 
265  /// Sets the list of external asset dependencies referenced inside the
266  /// payload of a model.
267  ///
268  /// \sa GetPayloadAssetDependencies()
269  ///
270  USD_API
271  void SetPayloadAssetDependencies(const VtArray<SdfAssetPath> &assetDeps)
272  const;
273 
274  /// Returns the model's composed assetInfo dictionary.
275  ///
276  /// The asset info dictionary is used to annotate models with various
277  /// data related to asset management. For example, asset name,
278  /// identifier, version etc.
279  ///
280  /// The elements of this dictionary are composed element-wise, and are
281  /// nestable.
282  ///
283  USD_API
284  bool GetAssetInfo(VtDictionary *info) const;
285 
286  /// Sets the model's assetInfo dictionary to \p info in the current edit
287  /// target.
288  ///
289  USD_API
290  void SetAssetInfo(const VtDictionary &info) const;
291 
292  /// @}
293 
294 protected:
295 
296  template<typename T>
297  bool _GetAssetInfoByKey(const TfToken &key, T *val) const {
298  VtValue vtVal = GetPrim().GetAssetInfoByKey(key);
299  if (!vtVal.IsEmpty() && vtVal.IsHolding<T>()) {
300  *val = vtVal.UncheckedGet<T>();
301  return true;
302  }
303  return false;
304  }
305 };
306 
307 /// \anchor UsdModelAPIAssetInfoKeys
308 ///
309 /// <b>UsdModelAPIAssetInfoKeys</b> provides tokens for the various core
310 /// entries into the assetInfo dictionary.
311 ///
312 /// The keys provided here are:
313 /// \li <b> identifier</b>
314 /// \li <b> name</b>
315 /// \li <b> version</b>
316 ///
317 /// \sa UsdModelAPI::GetAssetIdentifier()
318 /// \sa UsdModelAPI::GetAssetName()
319 /// \sa UsdModelAPI::GetAssetVersion()
320 ///
321 #define USDMODEL_ASSET_INFO_KEYS \
322  (identifier) \
323  (name) \
324  (version) \
325  (payloadAssetDependencies)
326 
327 TF_DECLARE_PUBLIC_TOKENS(UsdModelAPIAssetInfoKeys, USD_API, USDMODEL_ASSET_INFO_KEYS);
328 
330 
331 #endif
USD_API bool SetKind(const TfToken &kind) const
Non-applied API schema.
USD_API bool GetAssetInfo(VtDictionary *info) const
USD_API void SetAssetName(const std::string &assetName) const
#define USD_API
Definition: api.h:23
T const & UncheckedGet() const &
Definition: value.h:1104
static const UsdSchemaKind schemaKind
Definition: modelAPI.h:61
static USD_API UsdModelAPI Get(const UsdStagePtr &stage, const SdfPath &path)
USD_API UsdSchemaKind _GetSchemaKind() const override
#define USDMODEL_ASSET_INFO_KEYS
Definition: modelAPI.h:321
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USD_API bool GetKind(TfToken *kind) const
USD_API bool GetAssetVersion(std::string *version) const
USD_API void SetAssetIdentifier(const SdfAssetPath &identifier) const
bool IsEmpty() const
Returns true iff this value is empty.
Definition: value.h:1285
USD_API bool IsGroup() const
USD_API void SetAssetVersion(const std::string &version) const
USD_API void SetAssetInfo(const VtDictionary &info) const
USD_API bool IsKind(const TfToken &baseKind, KindValidation validation=KindValidationModelHierarchy) const
Definition: token.h:70
UsdModelAPI(const UsdPrim &prim=UsdPrim())
Definition: modelAPI.h:67
bool _GetAssetInfoByKey(const TfToken &key, T *val) const
Definition: modelAPI.h:297
USD_API VtValue GetAssetInfoByKey(const TfToken &keyPath) const
USD_API bool GetAssetIdentifier(SdfAssetPath *identifier) const
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: types.h:153
Definition: path.h:273
USD_API bool IsModel() const
GT_API const UT_StringHolder version
USD_API bool GetAssetName(std::string *assetName) const
UsdSchemaKind
Definition: common.h:112
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static USD_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
bool IsHolding() const
Definition: value.h:1064
GLuint GLfloat * val
Definition: glcorearb.h:1608
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USD_API void SetPayloadAssetDependencies(const VtArray< SdfAssetPath > &assetDeps) const
Definition: type.h:47
TF_DECLARE_PUBLIC_TOKENS(UsdModelAPIAssetInfoKeys, USD_API, USDMODEL_ASSET_INFO_KEYS)
USD_API bool GetPayloadAssetDependencies(VtArray< SdfAssetPath > *assetDeps) const
virtual USD_API ~UsdModelAPI()
Destructor.
UsdPrim GetPrim() const
Return this schema object's held prim.
Definition: schemaBase.h:103
Definition: value.h:146
UsdModelAPI(const UsdSchemaBase &schemaObj)
Definition: modelAPI.h:75