HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
coordSysAPI.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 USDSHADE_GENERATED_COORDSYSAPI_H
8 #define USDSHADE_GENERATED_COORDSYSAPI_H
9 
10 /// \file usdShade/coordSysAPI.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdShade/api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
18 
20 
21 #include "pxr/base/vt/value.h"
22 
23 #include "pxr/base/gf/vec3d.h"
24 #include "pxr/base/gf/vec3f.h"
25 #include "pxr/base/gf/matrix4d.h"
26 
27 #include "pxr/base/tf/token.h"
28 #include "pxr/base/tf/type.h"
29 
31 
32 class SdfAssetPath;
33 
34 // -------------------------------------------------------------------------- //
35 // COORDSYSAPI //
36 // -------------------------------------------------------------------------- //
37 
38 /// \class UsdShadeCoordSysAPI
39 ///
40 /// UsdShadeCoordSysAPI provides a way to designate, name,
41 /// and discover coordinate systems.
42 ///
43 /// Coordinate systems are implicitly established by UsdGeomXformable
44 /// prims, using their local space. That coordinate system may be
45 /// bound (i.e., named) from another prim. The binding is encoded
46 /// as a single-target relationship.
47 /// Coordinate system bindings apply to descendants of the prim
48 /// where the binding is expressed, but names may be re-bound by
49 /// descendant prims.
50 ///
51 /// CoordSysAPI is a multi-apply API schema, where instance names
52 /// signify the named coordinate systems. The instance names are
53 /// used with the "coordSys:" namespace to determine the binding
54 /// to the UsdGeomXformable prim.
55 ///
56 /// Named coordinate systems are useful in shading (and other) workflows.
57 /// An example is projection paint, which projects a texture
58 /// from a certain view (the paint coordinate system), encoded as
59 /// (e.g.) "rel coordSys:paint:binding". Using the paint coordinate frame
60 /// avoids the need to assign a UV set to the object, and can be a
61 /// concise way to project paint across a collection of objects with
62 /// a single shared paint coordinate system.
63 ///
64 ///
66 {
67 public:
68  /// Compile time constant representing what kind of schema this class is.
69  ///
70  /// \sa UsdSchemaKind
72 
73  /// Construct a UsdShadeCoordSysAPI on UsdPrim \p prim with
74  /// name \p name . Equivalent to
75  /// UsdShadeCoordSysAPI::Get(
76  /// prim.GetStage(),
77  /// prim.GetPath().AppendProperty(
78  /// "coordSys:name"));
79  ///
80  /// for a \em valid \p prim, but will not immediately throw an error for
81  /// an invalid \p prim
83  const UsdPrim& prim=UsdPrim(), const TfToken &name=TfToken())
84  : UsdAPISchemaBase(prim, /*instanceName*/ name)
85  { }
86 
87  /// Construct a UsdShadeCoordSysAPI on the prim held by \p schemaObj with
88  /// name \p name. Should be preferred over
89  /// UsdShadeCoordSysAPI(schemaObj.GetPrim(), name), as it preserves
90  /// SchemaBase state.
92  const UsdSchemaBase& schemaObj, const TfToken &name)
93  : UsdAPISchemaBase(schemaObj, /*instanceName*/ name)
94  { }
95 
96  /// Destructor.
98  virtual ~UsdShadeCoordSysAPI();
99 
100  /// Return a vector of names of all pre-declared attributes for this schema
101  /// class and all its ancestor classes. Does not include attributes that
102  /// may be authored by custom/extended methods of the schemas involved.
104  static const TfTokenVector &
105  GetSchemaAttributeNames(bool includeInherited=true);
106 
107  /// Return a vector of names of all pre-declared attributes for this schema
108  /// class and all its ancestor classes for a given instance name. Does not
109  /// include attributes that may be authored by custom/extended methods of
110  /// the schemas involved. The names returned will have the proper namespace
111  /// prefix.
113  static TfTokenVector
114  GetSchemaAttributeNames(bool includeInherited, const TfToken &instanceName);
115 
116  /// Returns the name of this multiple-apply schema instance
117  TfToken GetName() const {
118  return _GetInstanceName();
119  }
120 
121  /// Return a UsdShadeCoordSysAPI holding the prim adhering to this
122  /// schema at \p path on \p stage. If no prim exists at \p path on
123  /// \p stage, or if the prim at that path does not adhere to this schema,
124  /// return an invalid schema object. \p path must be of the format
125  /// <path>.coordSys:name .
126  ///
127  /// This is shorthand for the following:
128  ///
129  /// \code
130  /// TfToken name = SdfPath::StripNamespace(path.GetToken());
131  /// UsdShadeCoordSysAPI(
132  /// stage->GetPrimAtPath(path.GetPrimPath()), name);
133  /// \endcode
134  ///
136  static UsdShadeCoordSysAPI
137  Get(const UsdStagePtr &stage, const SdfPath &path);
138 
139  /// Return a UsdShadeCoordSysAPI with name \p name holding the
140  /// prim \p prim. Shorthand for UsdShadeCoordSysAPI(prim, name);
142  static UsdShadeCoordSysAPI
143  Get(const UsdPrim &prim, const TfToken &name);
144 
145  /// Return a vector of all named instances of UsdShadeCoordSysAPI on the
146  /// given \p prim.
148  static std::vector<UsdShadeCoordSysAPI>
149  GetAll(const UsdPrim &prim);
150 
151  /// Checks if the given name \p baseName is the base name of a property
152  /// of CoordSysAPI.
154  static bool
155  IsSchemaPropertyBaseName(const TfToken &baseName);
156 
157  /// Checks if the given path \p path is of an API schema of type
158  /// CoordSysAPI. If so, it stores the instance name of
159  /// the schema in \p name and returns true. Otherwise, it returns false.
161  static bool
163 
164  /// Returns true if this <b>multiple-apply</b> API schema can be applied,
165  /// with the given instance name, \p name, to the given \p prim. If this
166  /// schema can not be a applied the prim, this returns false and, if
167  /// provided, populates \p whyNot with the reason it can not be applied.
168  ///
169  /// Note that if CanApply returns false, that does not necessarily imply
170  /// that calling Apply will fail. Callers are expected to call CanApply
171  /// before calling Apply if they want to ensure that it is valid to
172  /// apply a schema.
173  ///
174  /// \sa UsdPrim::GetAppliedSchemas()
175  /// \sa UsdPrim::HasAPI()
176  /// \sa UsdPrim::CanApplyAPI()
177  /// \sa UsdPrim::ApplyAPI()
178  /// \sa UsdPrim::RemoveAPI()
179  ///
181  static bool
182  CanApply(const UsdPrim &prim, const TfToken &name,
183  std::string *whyNot=nullptr);
184 
185  /// Applies this <b>multiple-apply</b> API schema to the given \p prim
186  /// along with the given instance name, \p name.
187  ///
188  /// This information is stored by adding "CoordSysAPI:<i>name</i>"
189  /// to the token-valued, listOp metadata \em apiSchemas on the prim.
190  /// For example, if \p name is 'instance1', the token
191  /// 'CoordSysAPI:instance1' is added to 'apiSchemas'.
192  ///
193  /// \return A valid UsdShadeCoordSysAPI object is returned upon success.
194  /// An invalid (or empty) UsdShadeCoordSysAPI object is returned upon
195  /// failure. See \ref UsdPrim::ApplyAPI() for
196  /// conditions resulting in failure.
197  ///
198  /// \sa UsdPrim::GetAppliedSchemas()
199  /// \sa UsdPrim::HasAPI()
200  /// \sa UsdPrim::CanApplyAPI()
201  /// \sa UsdPrim::ApplyAPI()
202  /// \sa UsdPrim::RemoveAPI()
203  ///
205  static UsdShadeCoordSysAPI
206  Apply(const UsdPrim &prim, const TfToken &name);
207 
208 protected:
209  /// Returns the kind of schema this class belongs to.
210  ///
211  /// \sa UsdSchemaKind
213  UsdSchemaKind _GetSchemaKind() const override;
214 
215 private:
216  // needs to invoke _GetStaticTfType.
217  friend class UsdSchemaRegistry;
219  static const TfType &_GetStaticTfType();
220 
221  static bool _IsTypedSchema();
222 
223  // override SchemaBase virtuals.
225  const TfType &_GetTfType() const override;
226 
227 public:
228  // --------------------------------------------------------------------- //
229  // BINDING
230  // --------------------------------------------------------------------- //
231  /// Prim binding expressing the appropriate coordinate systems.
232  ///
235 
236  /// See GetBindingRel(), and also
237  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create
240 
241 public:
242  // ===================================================================== //
243  // Feel free to add custom code below this line, it will be preserved by
244  // the code generator.
245  //
246  // Just remember to:
247  // - Close the class declaration with };
248  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
249  // - Close the include guard with #endif
250  // ===================================================================== //
251  // --(BEGIN CUSTOM CODE)--
252 
253  /// A coordinate system binding.
254  /// Binds a name to a coordSysPrim for the bindingPrim (and its descendants,
255  /// unless overriden).
256  typedef struct {
260  } Binding;
261 
262  /// Returns true if the prim has local coordinate system relationship exists.
263  ///
264  /// \deprecated
265  /// This method is deprecated as it operates on the old non-applied
266  /// UsdShadeCoordSysAPI
267  /// If USD_SHADE_COORD_SYS_IS_MULTI_APPLY is set to True, if prim has
268  /// appropriate API applied, that is conforming to the new behavior.
269  /// If USD_SHADE_COORD_SYS_IS_MULTI_APPLY is set to Warn, try to see if
270  /// multi-apply API compliant local bindings are present for the prim, if
271  /// not fallback to backward compatible deprecated behavior.
272  ///
274  bool HasLocalBindings() const;
275 
276  /// Returns true if the prim has UsdShadeCoordSysAPI applied. Which implies
277  /// it has the appropriate binding relationship(s).
278  ///
280  static bool HasLocalBindingsForPrim(const UsdPrim &prim);
281 
282  /// Get the list of coordinate system bindings local to this prim. This
283  /// does not process inherited bindings. It does not validate that a prim
284  /// exists at the indicated path. If the binding relationship has multiple
285  /// targets, only the first is used.
286  ///
287  /// \deprecated
288  /// This method is deprecated as it operates on the old non-applied
289  /// UsdShadeCoordSysAPI
290  /// If USD_SHADE_COORD_SYS_IS_MULTI_APPLY is set to True, returns
291  /// bindings conforming to the new multi-apply UsdShadeCoordSysAPI schema.
292  /// If USD_SHADE_COORD_SYS_IS_MULTI_APPLY is set to Warn, try to get
293  /// multi-apply API compliant local bindings for the prim, if none
294  /// fallback to backward compatible deprecated behavior.
295  ///
297  std::vector<Binding> GetLocalBindings() const;
298 
299  /// Get the list of coordinate system bindings local to this prim, across
300  /// all multi-apply instanceNames. This does not process inherited bindings.
301  /// It does not validate that a prim exists at the indicated path. If the
302  /// binding relationship has multiple targets, only the first is used.
303  ///
304  /// Note that this will always return empty vector of bindings if the
305  /// \p prim being queried does not have UsdShadeCoordSysAPI applied.
306  ///
308  static std::vector<Binding> GetLocalBindingsForPrim(const UsdPrim &prim);
309 
310  /// Get the coordinate system bindings local to this prim corresponding to
311  /// this instance name. This does not process inherited bindings. It does
312  /// not validate that a prim exists at the indicated path. If the binding
313  /// relationship has multiple targets, only the first is used.
314  ///
316  Binding GetLocalBinding() const;
317 
318  /// Find the list of coordinate system bindings that apply to this prim,
319  /// including inherited bindings.
320  ///
321  /// This computation examines this prim and ancestors for the strongest
322  /// binding for each name. A binding expressed by a child prim supercedes
323  /// bindings on ancestors.
324  ///
325  /// Note that this API does not validate the prims at the target paths;
326  /// they may be of incorrect type, or missing entirely.
327  ///
328  /// Binding relationships with no resolved targets are skipped.
329  ///
330  /// \deprecated
331  /// This method is deprecated as it operates on the old non-applied
332  /// UsdShadeCoordSysAPI
333  /// If USD_SHADE_COORD_SYS_IS_MULTI_APPLY is set to True, returns
334  /// bindings conforming to the new multi-apply UsdShadeCoordSysAPI schema.
335  /// If USD_SHADE_COORD_SYS_IS_MULTI_APPLY is set to Warn, try to get
336  /// multi-apply API compliant local bindings for the prim, if none
337  /// fallback to backward compatible deprecated behavior.
338  ///
340  std::vector<Binding> FindBindingsWithInheritance() const;
341 
342  /// Find the list of coordinate system bindings that apply to this prim,
343  /// including inherited bindings.
344  ///
345  /// This computation examines this prim and ancestors for the strongest
346  /// binding for each name. A binding expressed by a child prim supercedes
347  /// bindings on ancestors. Only prims which have the UsdShadeCoordSysAPI
348  /// applied are considered and queried for a binding.
349  ///
350  /// Note that this API does not validate the prims at the target paths;
351  /// they may be of incorrect type, or missing entirely.
352  ///
353  /// Binding relationships with no resolved targets are skipped.
355  static std::vector<Binding> FindBindingsWithInheritanceForPrim(
356  const UsdPrim &prim);
357 
358  /// Find the coordinate system bindings that apply to this prim, including
359  /// inherited bindings.
360  ///
361  /// This computation examines this prim and ancestors for the strongest
362  /// binding for the specific instanceName. A binding expressed by a child
363  /// prim supercedes bindings on ancestors. Only ancestor prims which have
364  /// the UsdShadeCoordSysAPI:instanceName applied are considered.
365  ///
366  /// Note that this API does not validate the prims at the target paths;
367  /// they may be of incorrect type, or missing entirely.
368  ///
369  /// Binding relationships with no resolved targets are skipped.
372 
373  /// Bind the name to the given path. The prim at the given path is expected
374  /// to be UsdGeomXformable, in order for the binding to be succesfully
375  /// resolved.
376  ///
377  /// \deprecated
378  /// This method is deprecated as it operates on the old non-applied
379  /// UsdShadeCoordSysAPI
380  /// If USD_SHADE_COORD_SYS_IS_MULTI_APPLY is set to True, adds a binding
381  /// conforming to the new multi-apply UsdShadeCoordSysAPI schema.
382  /// If USD_SHADE_COORD_SYS_IS_MULTI_APPLY is set to Warn, try to also
383  /// bind to multi-apply API compliant relationship for the prim, along with
384  /// backward compatible deprecated behavior.
385  ///
387  bool Bind(const TfToken &name, const SdfPath &path) const;
388 
389  /// A convinience API for clients to use to Apply schema in accordance with
390  /// new UsdShadeCoordSysAPI schema constructs and appropriate Bind the
391  /// target. Note that this is only for clients using old behavior.
392  ///
393  /// \deprecated
395  bool ApplyAndBind(const TfToken &name, const SdfPath &path) const;
396 
397  /// Bind the name to the given path. The prim at the given path is expected
398  /// to be UsdGeomXformable, in order for the binding to be succesfully
399  /// resolved.
400  ///
402  bool Bind(const SdfPath &path) const;
403 
404  /// Clear the indicated coordinate system binding on this prim from the
405  /// current edit target.
406  ///
407  /// Only remove the spec if \p removeSpec is true (leave the spec to
408  /// preserve meta-data we may have intentionally authored on the
409  /// relationship)
410  ///
411  /// \deprecated
412  /// This method is deprecated as it operates on the old non-applied
413  /// UsdShadeCoordSysAPI
414  /// If USD_SHADE_COORD_SYS_IS_MULTI_APPLY is set to True, clears a binding
415  /// conforming to the new multi-apply UsdShadeCoordSysAPI schema.
416  /// If USD_SHADE_COORD_SYS_IS_MULTI_APPLY is set to Warn, try to also
417  /// clear binding for multi-apply API compliant relationship for the prim,
418  /// along with backward compatible deprecated behavior.
419  ///
421  bool ClearBinding(const TfToken &name, bool removeSpec) const;
422 
423  /// Clear the coordinate system binding on the prim corresponding to the
424  /// instanceName of this UsdShadeCoordSysAPI, from the current edit target.
425  ///
426  /// Only remove the spec if \p removeSpec is true (leave the spec to
427  /// preserve meta-data we may have intentionally authored on the
428  /// relationship)
429  ///
431  bool ClearBinding(bool removeSpec) const;
432 
433  /// Block the indicated coordinate system binding on this prim by blocking
434  /// targets on the underlying relationship.
435  ///
436  /// \deprecated
437  /// This method is deprecated as it operates on the old non-applied
438  /// UsdShadeCoordSysAPI
439  /// If USD_SHADE_COORD_SYS_IS_MULTI_APPLY is set to True, blocks binding
440  /// conforming to the new multi-apply UsdShadeCoordSysAPI schema.
441  /// If USD_SHADE_COORD_SYS_IS_MULTI_APPLY is set to Warn, try to also
442  /// block binding for multi-apply API compliant relationship for the prim,
443  /// along with backward compatible deprecated behavior.
444  ///
446  bool BlockBinding(const TfToken &name) const;
447 
448  /// Block the indicated coordinate system binding on this prim by blocking
449  /// targets on the underlying relationship.
450  ///
452  bool BlockBinding() const;
453 
454  /// Returns the fully namespaced coordinate system relationship
455  /// name, given the coordinate system name.
456  //
457  /// \deprecated
458  /// This method is deprecated as it operates on the old non-applied
459  /// UsdShadeCoordSysAPI
460  //
462  static TfToken GetCoordSysRelationshipName(const std::string &coordSysName);
463 
464  /// Test whether a given \p name contains the "coordSys:" prefix
466  static bool CanContainPropertyName(const TfToken &name);
467 
468  /// Strips "coordSys:" from the relationship name and returns
469  /// "<instanceName>:binding".
471  static TfToken GetBindingBaseName(const TfToken &name);
472 
473  /// Strips "coordSys:" from the relationship name and returns
474  /// "<instanceName>:binding".
476  TfToken GetBindingBaseName() const;
477 
478 private:
480  static void _GetBindingsForPrim(const UsdPrim &prim,
481  std::vector<Binding> &result, bool checkExistingBindings=false);
482 
483 };
484 
486 
487 #include "pxr/base/tf/envSetting.h"
488 
492 
494 
495 #endif
USDSHADE_API std::vector< Binding > GetLocalBindings() const
#define USDSHADE_API
Definition: api.h:23
USDSHADE_API bool HasLocalBindings() const
USDSHADE_API Binding GetLocalBinding() const
static USDSHADE_API bool HasLocalBindingsForPrim(const UsdPrim &prim)
USDSHADE_API bool ClearBinding(const TfToken &name, bool removeSpec) const
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
static USDSHADE_API std::vector< Binding > FindBindingsWithInheritanceForPrim(const UsdPrim &prim)
static USDSHADE_API UsdShadeCoordSysAPI Get(const UsdStagePtr &stage, const SdfPath &path)
USDSHADE_API std::vector< Binding > FindBindingsWithInheritance() const
UsdShadeCoordSysAPI(const UsdPrim &prim=UsdPrim(), const TfToken &name=TfToken())
Definition: coordSysAPI.h:82
**But if you need a result
Definition: thread.h:622
UsdShadeCoordSysAPI(const UsdSchemaBase &schemaObj, const TfToken &name)
Definition: coordSysAPI.h:91
static USDSHADE_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE USDSHADE_API TfEnvSetting< std::string > USD_SHADE_COORD_SYS_IS_MULTI_APPLY
const TfToken & _GetInstanceName() const
Definition: token.h:70
USDSHADE_API bool ApplyAndBind(const TfToken &name, const SdfPath &path) const
static USDSHADE_API TfToken GetCoordSysRelationshipName(const std::string &coordSysName)
USDSHADE_API UsdRelationship CreateBindingRel() const
Definition: prim.h:116
USDSHADE_API UsdRelationship GetBindingRel() const
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
static USDSHADE_API bool CanApply(const UsdPrim &prim, const TfToken &name, std::string *whyNot=nullptr)
GLuint const GLchar * name
Definition: glcorearb.h:786
static USDSHADE_API bool IsSchemaPropertyBaseName(const TfToken &baseName)
Definition: path.h:273
UsdSchemaKind
Definition: common.h:112
virtual USDSHADE_API ~UsdShadeCoordSysAPI()
Destructor.
USDSHADE_API Binding FindBindingWithInheritance() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static USDSHADE_API std::vector< UsdShadeCoordSysAPI > GetAll(const UsdPrim &prim)
static const UsdSchemaKind schemaKind
Definition: coordSysAPI.h:71
USDSHADE_API bool BlockBinding() const
TfToken GetName() const
Returns the name of this multiple-apply schema instance.
Definition: coordSysAPI.h:117
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static USDSHADE_API std::vector< Binding > GetLocalBindingsForPrim(const UsdPrim &prim)
Definition: type.h:47
USDSHADE_API TfToken GetBindingBaseName() const
static USDSHADE_API bool CanContainPropertyName(const TfToken &name)
Test whether a given name contains the "coordSys:" prefix.
USDSHADE_API bool Bind(const TfToken &name, const SdfPath &path) const
static USDSHADE_API bool IsCoordSysAPIPath(const SdfPath &path, TfToken *name)
static USDSHADE_API UsdShadeCoordSysAPI Apply(const UsdPrim &prim, const TfToken &name)
Multiple Apply API Schema.
USDSHADE_API UsdSchemaKind _GetSchemaKind() const override