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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef USDMEDIA_GENERATED_ASSETPREVIEWSAPI_H
25 #define USDMEDIA_GENERATED_ASSETPREVIEWSAPI_H
26 
27 /// \file usdMedia/assetPreviewsAPI.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/usdMedia/api.h"
32 #include "pxr/usd/usd/prim.h"
33 #include "pxr/usd/usd/stage.h"
35 
36 #include "pxr/usd/sdf/types.h"
37 
38 
39 #include "pxr/base/vt/value.h"
40 
41 #include "pxr/base/gf/vec3d.h"
42 #include "pxr/base/gf/vec3f.h"
43 #include "pxr/base/gf/matrix4d.h"
44 
45 #include "pxr/base/tf/token.h"
46 #include "pxr/base/tf/type.h"
47 
49 
50 class SdfAssetPath;
51 
52 // -------------------------------------------------------------------------- //
53 // ASSETPREVIEWSAPI //
54 // -------------------------------------------------------------------------- //
55 
56 /// \class UsdMediaAssetPreviewsAPI
57 ///
58 /// AssetPreviewsAPI is the interface for authoring and accessing
59 /// precomputed, lightweight previews of assets. It is an applied schema,
60 /// which means that an arbitrary number of prims on a stage can have the schema
61 /// applied and therefore can contain previews; however, to access a stage's
62 /// "default" previews, one consults
63 /// the stage's `defaultPrim`.
64 ///
65 /// AssetPreviewsAPI supports the following kinds of previews:
66 /// - **thumbnails** : a set of pre-rendered images of the asset. There is no
67 /// prescribed size for thumbnail images, but care should be taken to ensure
68 /// their inclusion does not substantially increase the overall size of an
69 /// asset, as, for example, when packaged into USDZ.
70 ///
71 /// Although the UsdMediaAssetPreviewsAPI class can be used to interrogate any
72 /// prim, no query in the API will succeed unless the schema has been applied
73 /// to the prim. This schema deals only with asset paths, and clients wishing
74 /// to directly consume the returned data must do so by retrieving an ArAsset
75 /// from the session's ArAssetResolver.
76 ///
77 /// The schema defines no properties or metadata fallback values. Rather,
78 /// Asset Previews are encoded as part of a prim's `assetInfo` metadata. A
79 /// default thumbnail image would look like:
80 /// ```
81 /// 1. assetInfo = {
82 /// 2. dictionary previews = {
83 /// 3. dictionary thumbnails = {
84 /// 4. dictionary default = {
85 /// 5. asset defaultImage = @chair_thumb.jpg@
86 /// 6. }
87 /// 7. }
88 /// 8. }
89 /// 9. }
90 /// ```
91 ///
92 ///
93 ///
95 {
96 public:
97  /// Compile time constant representing what kind of schema this class is.
98  ///
99  /// \sa UsdSchemaKind
101 
102  /// Construct a UsdMediaAssetPreviewsAPI on UsdPrim \p prim .
103  /// Equivalent to UsdMediaAssetPreviewsAPI::Get(prim.GetStage(), prim.GetPath())
104  /// for a \em valid \p prim, but will not immediately throw an error for
105  /// an invalid \p prim
106  explicit UsdMediaAssetPreviewsAPI(const UsdPrim& prim=UsdPrim())
107  : UsdAPISchemaBase(prim)
108  {
109  }
110 
111  /// Construct a UsdMediaAssetPreviewsAPI on the prim held by \p schemaObj .
112  /// Should be preferred over UsdMediaAssetPreviewsAPI(schemaObj.GetPrim()),
113  /// as it preserves SchemaBase state.
114  explicit UsdMediaAssetPreviewsAPI(const UsdSchemaBase& schemaObj)
115  : UsdAPISchemaBase(schemaObj)
116  {
117  }
118 
119  /// Destructor.
121  virtual ~UsdMediaAssetPreviewsAPI();
122 
123  /// Return a vector of names of all pre-declared attributes for this schema
124  /// class and all its ancestor classes. Does not include attributes that
125  /// may be authored by custom/extended methods of the schemas involved.
127  static const TfTokenVector &
128  GetSchemaAttributeNames(bool includeInherited=true);
129 
130  /// Return a UsdMediaAssetPreviewsAPI holding the prim adhering to this
131  /// schema at \p path on \p stage. If no prim exists at \p path on
132  /// \p stage, or if the prim at that path does not adhere to this schema,
133  /// return an invalid schema object. This is shorthand for the following:
134  ///
135  /// \code
136  /// UsdMediaAssetPreviewsAPI(stage->GetPrimAtPath(path));
137  /// \endcode
138  ///
141  Get(const UsdStagePtr &stage, const SdfPath &path);
142 
143 
144  /// Returns true if this <b>single-apply</b> API schema can be applied to
145  /// the given \p prim. If this schema can not be a applied to the prim,
146  /// this returns false and, if provided, populates \p whyNot with the
147  /// reason it can not be applied.
148  ///
149  /// Note that if CanApply returns false, that does not necessarily imply
150  /// that calling Apply will fail. Callers are expected to call CanApply
151  /// before calling Apply if they want to ensure that it is valid to
152  /// apply a schema.
153  ///
154  /// \sa UsdPrim::GetAppliedSchemas()
155  /// \sa UsdPrim::HasAPI()
156  /// \sa UsdPrim::CanApplyAPI()
157  /// \sa UsdPrim::ApplyAPI()
158  /// \sa UsdPrim::RemoveAPI()
159  ///
161  static bool
162  CanApply(const UsdPrim &prim, std::string *whyNot=nullptr);
163 
164  /// Applies this <b>single-apply</b> API schema to the given \p prim.
165  /// This information is stored by adding "AssetPreviewsAPI" to the
166  /// token-valued, listOp metadata \em apiSchemas on the prim.
167  ///
168  /// \return A valid UsdMediaAssetPreviewsAPI object is returned upon success.
169  /// An invalid (or empty) UsdMediaAssetPreviewsAPI object is returned upon
170  /// failure. See \ref UsdPrim::ApplyAPI() for conditions
171  /// resulting in failure.
172  ///
173  /// \sa UsdPrim::GetAppliedSchemas()
174  /// \sa UsdPrim::HasAPI()
175  /// \sa UsdPrim::CanApplyAPI()
176  /// \sa UsdPrim::ApplyAPI()
177  /// \sa UsdPrim::RemoveAPI()
178  ///
181  Apply(const UsdPrim &prim);
182 
183 protected:
184  /// Returns the kind of schema this class belongs to.
185  ///
186  /// \sa UsdSchemaKind
188  UsdSchemaKind _GetSchemaKind() const override;
189 
190 private:
191  // needs to invoke _GetStaticTfType.
192  friend class UsdSchemaRegistry;
194  static const TfType &_GetStaticTfType();
195 
196  static bool _IsTypedSchema();
197 
198  // override SchemaBase virtuals.
200  const TfType &_GetTfType() const override;
201 
202 public:
203  // ===================================================================== //
204  // Feel free to add custom code below this line, it will be preserved by
205  // the code generator.
206  //
207  // Just remember to:
208  // - Close the class declaration with };
209  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
210  // - Close the include guard with #endif
211  // ===================================================================== //
212  // --(BEGIN CUSTOM CODE)--
213 
214  /// \struct Thumbnails
215  ///
216  /// Thumbnails is a value type that serves as schema to aid in serialization
217  /// and deserialization of thumbnail images in the assetInfo["thumbnails"]
218  /// dictionary
219  struct Thumbnails
220  {
223 
225  };
226 
227  /// Fetch the default Thumbnails data, returning `true` if data was
228  /// successfully fetched.
230  bool GetDefaultThumbnails(Thumbnails *defaultThumbnails) const;
231 
232  /// Author the default thumbnails dictionary from the provided Thumbnails
233  /// data
235  void SetDefaultThumbnails(const Thumbnails &defaultThumbnails) const;
236 
237  /// Remove the entire entry for default Thumbnails in the current
238  /// UsdEditTarget
240  void ClearDefaultThumbnails() const;
241 
242  /// Return a schema object that can be used to interrogate previews
243  /// for the default prim of the stage constructed from `layerPath`.
244  ///
245  /// The schema object will create and retain a minimal stage required for
246  /// interrogation. This is equivalent to:
247  /// `GetAssetDefaultPreviews(SdfLayer::FindOrOpen(layerPath))`
250  GetAssetDefaultPreviews(const std::string &layerPath);
251 
252  /// \overload
255  GetAssetDefaultPreviews(const SdfLayerHandle &layer);
256 
257 private:
258  UsdStageRefPtr _defaultMaskedStage;
259 };
260 
262 
263 #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.
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
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:135
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
#define USDMEDIA_API
Definition: api.h:40
Definition: path.h:291
USDMEDIA_API Thumbnails(const SdfAssetPath &defaultImage=SdfAssetPath())
UsdSchemaKind
Definition: common.h:127
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
virtual USDMEDIA_API ~UsdMediaAssetPreviewsAPI()
Destructor.
UsdMediaAssetPreviewsAPI(const UsdSchemaBase &schemaObj)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Definition: type.h:64
static USDMEDIA_API UsdMediaAssetPreviewsAPI Apply(const UsdPrim &prim)
static USDMEDIA_API bool CanApply(const UsdPrim &prim, std::string *whyNot=nullptr)