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