HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
assetPreviewsAPI.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 USDMEDIA_GENERATED_ASSETPREVIEWSAPI_H
8 #define USDMEDIA_GENERATED_ASSETPREVIEWSAPI_H
9 
10 /// \file usdMedia/assetPreviewsAPI.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdMedia/api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
18 
19 #include "pxr/usd/sdf/types.h"
20 
21 
22 #include "pxr/base/vt/value.h"
23 
24 #include "pxr/base/gf/vec3d.h"
25 #include "pxr/base/gf/vec3f.h"
26 #include "pxr/base/gf/matrix4d.h"
27 
28 #include "pxr/base/tf/token.h"
29 #include "pxr/base/tf/type.h"
30 
32 
33 class SdfAssetPath;
34 
35 // -------------------------------------------------------------------------- //
36 // ASSETPREVIEWSAPI //
37 // -------------------------------------------------------------------------- //
38 
39 /// \class UsdMediaAssetPreviewsAPI
40 ///
41 /// AssetPreviewsAPI is the interface for authoring and accessing
42 /// precomputed, lightweight previews of assets. It is an applied schema,
43 /// which means that an arbitrary number of prims on a stage can have the schema
44 /// applied and therefore can contain previews; however, to access a stage's
45 /// "default" previews, one consults
46 /// the stage's `defaultPrim`.
47 ///
48 /// AssetPreviewsAPI supports the following kinds of previews:
49 /// - **thumbnails** : a set of pre-rendered images of the asset. There is no
50 /// prescribed size for thumbnail images, but care should be taken to ensure
51 /// their inclusion does not substantially increase the overall size of an
52 /// asset, as, for example, when packaged into USDZ.
53 ///
54 /// Although the UsdMediaAssetPreviewsAPI class can be used to interrogate any
55 /// prim, no query in the API will succeed unless the schema has been applied
56 /// to the prim. This schema deals only with asset paths, and clients wishing
57 /// to directly consume the returned data must do so by retrieving an ArAsset
58 /// from the session's ArAssetResolver.
59 ///
60 /// The schema defines no properties or metadata fallback values. Rather,
61 /// Asset Previews are encoded as part of a prim's `assetInfo` metadata. A
62 /// default thumbnail image would look like:
63 /// ```
64 /// 1. assetInfo = {
65 /// 2. dictionary previews = {
66 /// 3. dictionary thumbnails = {
67 /// 4. dictionary default = {
68 /// 5. asset defaultImage = @chair_thumb.jpg@
69 /// 6. }
70 /// 7. }
71 /// 8. }
72 /// 9. }
73 /// ```
74 ///
75 ///
76 ///
78 {
79 public:
80  /// Compile time constant representing what kind of schema this class is.
81  ///
82  /// \sa UsdSchemaKind
84 
85  /// Construct a UsdMediaAssetPreviewsAPI on UsdPrim \p prim .
86  /// Equivalent to UsdMediaAssetPreviewsAPI::Get(prim.GetStage(), prim.GetPath())
87  /// for a \em valid \p prim, but will not immediately throw an error for
88  /// an invalid \p prim
89  explicit UsdMediaAssetPreviewsAPI(const UsdPrim& prim=UsdPrim())
90  : UsdAPISchemaBase(prim)
91  {
92  }
93 
94  /// Construct a UsdMediaAssetPreviewsAPI on the prim held by \p schemaObj .
95  /// Should be preferred over UsdMediaAssetPreviewsAPI(schemaObj.GetPrim()),
96  /// as it preserves SchemaBase state.
97  explicit UsdMediaAssetPreviewsAPI(const UsdSchemaBase& schemaObj)
98  : UsdAPISchemaBase(schemaObj)
99  {
100  }
101 
102  /// Destructor.
104  virtual ~UsdMediaAssetPreviewsAPI();
105 
106  /// Return a vector of names of all pre-declared attributes for this schema
107  /// class and all its ancestor classes. Does not include attributes that
108  /// may be authored by custom/extended methods of the schemas involved.
110  static const TfTokenVector &
111  GetSchemaAttributeNames(bool includeInherited=true);
112 
113  /// Return a UsdMediaAssetPreviewsAPI holding the prim adhering to this
114  /// schema at \p path on \p stage. If no prim exists at \p path on
115  /// \p stage, or if the prim at that path does not adhere to this schema,
116  /// return an invalid schema object. This is shorthand for the following:
117  ///
118  /// \code
119  /// UsdMediaAssetPreviewsAPI(stage->GetPrimAtPath(path));
120  /// \endcode
121  ///
124  Get(const UsdStagePtr &stage, const SdfPath &path);
125 
126 
127  /// Returns true if this <b>single-apply</b> API schema can be applied to
128  /// the given \p prim. If this schema can not be a applied to the prim,
129  /// this returns false and, if provided, populates \p whyNot with the
130  /// reason it can not be applied.
131  ///
132  /// Note that if CanApply returns false, that does not necessarily imply
133  /// that calling Apply will fail. Callers are expected to call CanApply
134  /// before calling Apply if they want to ensure that it is valid to
135  /// apply a schema.
136  ///
137  /// \sa UsdPrim::GetAppliedSchemas()
138  /// \sa UsdPrim::HasAPI()
139  /// \sa UsdPrim::CanApplyAPI()
140  /// \sa UsdPrim::ApplyAPI()
141  /// \sa UsdPrim::RemoveAPI()
142  ///
144  static bool
145  CanApply(const UsdPrim &prim, std::string *whyNot=nullptr);
146 
147  /// Applies this <b>single-apply</b> API schema to the given \p prim.
148  /// This information is stored by adding "AssetPreviewsAPI" to the
149  /// token-valued, listOp metadata \em apiSchemas on the prim.
150  ///
151  /// \return A valid UsdMediaAssetPreviewsAPI object is returned upon success.
152  /// An invalid (or empty) UsdMediaAssetPreviewsAPI object is returned upon
153  /// failure. See \ref UsdPrim::ApplyAPI() for conditions
154  /// resulting in failure.
155  ///
156  /// \sa UsdPrim::GetAppliedSchemas()
157  /// \sa UsdPrim::HasAPI()
158  /// \sa UsdPrim::CanApplyAPI()
159  /// \sa UsdPrim::ApplyAPI()
160  /// \sa UsdPrim::RemoveAPI()
161  ///
164  Apply(const UsdPrim &prim);
165 
166 protected:
167  /// Returns the kind of schema this class belongs to.
168  ///
169  /// \sa UsdSchemaKind
171  UsdSchemaKind _GetSchemaKind() const override;
172 
173 private:
174  // needs to invoke _GetStaticTfType.
175  friend class UsdSchemaRegistry;
177  static const TfType &_GetStaticTfType();
178 
179  static bool _IsTypedSchema();
180 
181  // override SchemaBase virtuals.
183  const TfType &_GetTfType() const override;
184 
185 public:
186  // ===================================================================== //
187  // Feel free to add custom code below this line, it will be preserved by
188  // the code generator.
189  //
190  // Just remember to:
191  // - Close the class declaration with };
192  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
193  // - Close the include guard with #endif
194  // ===================================================================== //
195  // --(BEGIN CUSTOM CODE)--
196 
197  /// \struct Thumbnails
198  ///
199  /// Thumbnails is a value type that serves as schema to aid in serialization
200  /// and deserialization of thumbnail images in the assetInfo["thumbnails"]
201  /// dictionary
202  struct Thumbnails
203  {
206 
208  };
209 
210  /// Fetch the default Thumbnails data, returning `true` if data was
211  /// successfully fetched.
213  bool GetDefaultThumbnails(Thumbnails *defaultThumbnails) const;
214 
215  /// Author the default thumbnails dictionary from the provided Thumbnails
216  /// data
218  void SetDefaultThumbnails(const Thumbnails &defaultThumbnails) const;
219 
220  /// Remove the entire entry for default Thumbnails in the current
221  /// UsdEditTarget
223  void ClearDefaultThumbnails() const;
224 
225  /// Return a schema object that can be used to interrogate previews
226  /// for the default prim of the stage constructed from `layerPath`.
227  ///
228  /// The schema object will create and retain a minimal stage required for
229  /// interrogation. This is equivalent to:
230  /// `GetAssetDefaultPreviews(SdfLayer::FindOrOpen(layerPath))`
233  GetAssetDefaultPreviews(const std::string &layerPath);
234 
235  /// \overload
238  GetAssetDefaultPreviews(const SdfLayerHandle &layer);
239 
240 private:
241  UsdStageRefPtr _defaultMaskedStage;
242 };
243 
245 
246 #endif
static USDMEDIA_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
static USDMEDIA_API UsdMediaAssetPreviewsAPI Get(const UsdStagePtr &stage, const SdfPath &path)
USDMEDIA_API bool GetDefaultThumbnails(Thumbnails *defaultThumbnails) const
USDMEDIA_API void SetDefaultThumbnails(const Thumbnails &defaultThumbnails) const
Single Apply API schema.
UsdMediaAssetPreviewsAPI(const UsdPrim &prim=UsdPrim())
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USDMEDIA_API UsdSchemaKind _GetSchemaKind() const override
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
USDMEDIA_API void ClearDefaultThumbnails() const
static USDMEDIA_API UsdMediaAssetPreviewsAPI GetAssetDefaultPreviews(const std::string &layerPath)
static const UsdSchemaKind schemaKind
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
#define USDMEDIA_API
Definition: api.h:23
Definition: path.h:273
USDMEDIA_API Thumbnails(const SdfAssetPath &defaultImage=SdfAssetPath())
UsdSchemaKind
Definition: common.h:112
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
virtual USDMEDIA_API ~UsdMediaAssetPreviewsAPI()
Destructor.
UsdMediaAssetPreviewsAPI(const UsdSchemaBase &schemaObj)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: type.h:47
static USDMEDIA_API UsdMediaAssetPreviewsAPI Apply(const UsdPrim &prim)
static USDMEDIA_API bool CanApply(const UsdPrim &prim, std::string *whyNot=nullptr)