HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bindingAPI.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 USDSKEL_GENERATED_BINDINGAPI_H
25 #define USDSKEL_GENERATED_BINDINGAPI_H
26 
27 /// \file usdSkel/bindingAPI.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/usdSkel/api.h"
32 #include "pxr/usd/usd/prim.h"
33 #include "pxr/usd/usd/stage.h"
34 #include "pxr/usd/usdSkel/tokens.h"
35 
36 #include "pxr/base/tf/span.h"
39 
40 #include "pxr/base/vt/value.h"
41 
42 #include "pxr/base/gf/vec3d.h"
43 #include "pxr/base/gf/vec3f.h"
44 #include "pxr/base/gf/matrix4d.h"
45 
46 #include "pxr/base/tf/token.h"
47 #include "pxr/base/tf/type.h"
48 
50 
51 class SdfAssetPath;
52 
53 // -------------------------------------------------------------------------- //
54 // SKELBINDINGAPI //
55 // -------------------------------------------------------------------------- //
56 
57 /// \class UsdSkelBindingAPI
58 ///
59 /// Provides API for authoring and extracting all the skinning-related
60 /// data that lives in the "geometry hierarchy" of prims and models that want
61 /// to be skeletally deformed.
62 ///
63 /// See the extended \ref UsdSkel_BindingAPI "UsdSkelBindingAPI schema"
64 /// documentation for more about bindings and how they apply in a scene graph.
65 ///
66 ///
67 /// For any described attribute \em Fallback \em Value or \em Allowed \em Values below
68 /// that are text/tokens, the actual token is published and defined in \ref UsdSkelTokens.
69 /// So to set an attribute to the value "rightHanded", use UsdSkelTokens->rightHanded
70 /// as the value.
71 ///
73 {
74 public:
75  /// Compile time constant representing what kind of schema this class is.
76  ///
77  /// \sa UsdSchemaKind
79 
80  /// Construct a UsdSkelBindingAPI on UsdPrim \p prim .
81  /// Equivalent to UsdSkelBindingAPI::Get(prim.GetStage(), prim.GetPath())
82  /// for a \em valid \p prim, but will not immediately throw an error for
83  /// an invalid \p prim
84  explicit UsdSkelBindingAPI(const UsdPrim& prim=UsdPrim())
85  : UsdAPISchemaBase(prim)
86  {
87  }
88 
89  /// Construct a UsdSkelBindingAPI on the prim held by \p schemaObj .
90  /// Should be preferred over UsdSkelBindingAPI(schemaObj.GetPrim()),
91  /// as it preserves SchemaBase state.
92  explicit UsdSkelBindingAPI(const UsdSchemaBase& schemaObj)
93  : UsdAPISchemaBase(schemaObj)
94  {
95  }
96 
97  /// Destructor.
99  virtual ~UsdSkelBindingAPI();
100 
101  /// Return a vector of names of all pre-declared attributes for this schema
102  /// class and all its ancestor classes. Does not include attributes that
103  /// may be authored by custom/extended methods of the schemas involved.
105  static const TfTokenVector &
106  GetSchemaAttributeNames(bool includeInherited=true);
107 
108  /// Return a UsdSkelBindingAPI holding the prim adhering to this
109  /// schema at \p path on \p stage. If no prim exists at \p path on
110  /// \p stage, or if the prim at that path does not adhere to this schema,
111  /// return an invalid schema object. This is shorthand for the following:
112  ///
113  /// \code
114  /// UsdSkelBindingAPI(stage->GetPrimAtPath(path));
115  /// \endcode
116  ///
118  static UsdSkelBindingAPI
119  Get(const UsdStagePtr &stage, const SdfPath &path);
120 
121 
122  /// Returns true if this <b>single-apply</b> API schema can be applied to
123  /// the given \p prim. If this schema can not be a applied to the prim,
124  /// this returns false and, if provided, populates \p whyNot with the
125  /// reason it can not be applied.
126  ///
127  /// Note that if CanApply returns false, that does not necessarily imply
128  /// that calling Apply will fail. Callers are expected to call CanApply
129  /// before calling Apply if they want to ensure that it is valid to
130  /// apply a schema.
131  ///
132  /// \sa UsdPrim::GetAppliedSchemas()
133  /// \sa UsdPrim::HasAPI()
134  /// \sa UsdPrim::CanApplyAPI()
135  /// \sa UsdPrim::ApplyAPI()
136  /// \sa UsdPrim::RemoveAPI()
137  ///
139  static bool
140  CanApply(const UsdPrim &prim, std::string *whyNot=nullptr);
141 
142  /// Applies this <b>single-apply</b> API schema to the given \p prim.
143  /// This information is stored by adding "SkelBindingAPI" to the
144  /// token-valued, listOp metadata \em apiSchemas on the prim.
145  ///
146  /// \return A valid UsdSkelBindingAPI object is returned upon success.
147  /// An invalid (or empty) UsdSkelBindingAPI object is returned upon
148  /// failure. See \ref UsdPrim::ApplyAPI() for conditions
149  /// resulting in failure.
150  ///
151  /// \sa UsdPrim::GetAppliedSchemas()
152  /// \sa UsdPrim::HasAPI()
153  /// \sa UsdPrim::CanApplyAPI()
154  /// \sa UsdPrim::ApplyAPI()
155  /// \sa UsdPrim::RemoveAPI()
156  ///
158  static UsdSkelBindingAPI
159  Apply(const UsdPrim &prim);
160 
161 protected:
162  /// Returns the kind of schema this class belongs to.
163  ///
164  /// \sa UsdSchemaKind
166  UsdSchemaKind _GetSchemaKind() const override;
167 
168 private:
169  // needs to invoke _GetStaticTfType.
170  friend class UsdSchemaRegistry;
172  static const TfType &_GetStaticTfType();
173 
174  static bool _IsTypedSchema();
175 
176  // override SchemaBase virtuals.
178  const TfType &_GetTfType() const override;
179 
180 public:
181  // --------------------------------------------------------------------- //
182  // SKINNINGMETHOD
183  // --------------------------------------------------------------------- //
184  /// The skinningMethod specifies the skinning method for the prim.
185  ///
186  /// | ||
187  /// | -- | -- |
188  /// | Declaration | `uniform token primvars:skel:skinningMethod = "classicLinear"` |
189  /// | C++ Type | TfToken |
190  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
191  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
192  /// | \ref UsdSkelTokens "Allowed Values" | classicLinear, dualQuaternion |
195 
196  /// See GetSkinningMethodAttr(), and also
197  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
198  /// If specified, author \p defaultValue as the attribute's default,
199  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
200  /// the default for \p writeSparsely is \c false.
202  UsdAttribute CreateSkinningMethodAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
203 
204 public:
205  // --------------------------------------------------------------------- //
206  // GEOMBINDTRANSFORM
207  // --------------------------------------------------------------------- //
208  /// Encodes the bind-time world space transforms of the prim.
209  /// If the transform is identical for a group of gprims that share a common
210  /// ancestor, the transform may be authored on the ancestor, to "inherit"
211  /// down to all the leaf gprims. If this transform is unset, an identity
212  /// transform is used instead.
213  ///
214  /// | ||
215  /// | -- | -- |
216  /// | Declaration | `matrix4d primvars:skel:geomBindTransform` |
217  /// | C++ Type | GfMatrix4d |
218  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Matrix4d |
221 
222  /// See GetGeomBindTransformAttr(), and also
223  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
224  /// If specified, author \p defaultValue as the attribute's default,
225  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
226  /// the default for \p writeSparsely is \c false.
228  UsdAttribute CreateGeomBindTransformAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
229 
230 public:
231  // --------------------------------------------------------------------- //
232  // JOINTS
233  // --------------------------------------------------------------------- //
234  /// An (optional) array of tokens defining the list of
235  /// joints to which jointIndices apply. If not defined, jointIndices applies
236  /// to the ordered list of joints defined in the bound Skeleton's *joints*
237  /// attribute. If undefined on a primitive, the primitive inherits the
238  /// value of the nearest ancestor prim, if any.
239  ///
240  /// | ||
241  /// | -- | -- |
242  /// | Declaration | `uniform token[] skel:joints` |
243  /// | C++ Type | VtArray<TfToken> |
244  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->TokenArray |
245  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
247  UsdAttribute GetJointsAttr() const;
248 
249  /// See GetJointsAttr(), and also
250  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
251  /// If specified, author \p defaultValue as the attribute's default,
252  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
253  /// the default for \p writeSparsely is \c false.
255  UsdAttribute CreateJointsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
256 
257 public:
258  // --------------------------------------------------------------------- //
259  // JOINTINDICES
260  // --------------------------------------------------------------------- //
261  /// Indices into the *joints* attribute of the closest
262  /// (in namespace) bound Skeleton that affect each point of a PointBased
263  /// gprim. The primvar can have either *constant* or *vertex* interpolation.
264  /// This primvar's *elementSize* will determine how many joint influences
265  /// apply to each point. Indices must point be valid. Null influences should
266  /// be defined by setting values in jointWeights to zero.
267  /// See UsdGeomPrimvar for more information on interpolation and
268  /// elementSize.
269  ///
270  /// | ||
271  /// | -- | -- |
272  /// | Declaration | `int[] primvars:skel:jointIndices` |
273  /// | C++ Type | VtArray<int> |
274  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->IntArray |
277 
278  /// See GetJointIndicesAttr(), and also
279  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
280  /// If specified, author \p defaultValue as the attribute's default,
281  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
282  /// the default for \p writeSparsely is \c false.
284  UsdAttribute CreateJointIndicesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
285 
286 public:
287  // --------------------------------------------------------------------- //
288  // JOINTWEIGHTS
289  // --------------------------------------------------------------------- //
290  /// Weights for the joints that affect each point of a PointBased
291  /// gprim. The primvar can have either *constant* or *vertex* interpolation.
292  /// This primvar's *elementSize* will determine how many joints influences
293  /// apply to each point. The length, interpolation, and elementSize of
294  /// *jointWeights* must match that of *jointIndices*. See UsdGeomPrimvar
295  /// for more information on interpolation and elementSize.
296  ///
297  /// | ||
298  /// | -- | -- |
299  /// | Declaration | `float[] primvars:skel:jointWeights` |
300  /// | C++ Type | VtArray<float> |
301  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->FloatArray |
304 
305  /// See GetJointWeightsAttr(), and also
306  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
307  /// If specified, author \p defaultValue as the attribute's default,
308  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
309  /// the default for \p writeSparsely is \c false.
311  UsdAttribute CreateJointWeightsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
312 
313 public:
314  // --------------------------------------------------------------------- //
315  // BLENDSHAPES
316  // --------------------------------------------------------------------- //
317  /// An array of tokens defining the order onto which blend shape
318  /// weights from an animation source map onto the *skel:blendShapeTargets*
319  /// rel of a binding site. If authored, the number of elements must be equal
320  /// to the number of targets in the _blendShapeTargets_ rel. This property
321  /// is not inherited hierarchically, and is expected to be authored directly
322  /// on the skinnable primitive to which the blend shapes apply.
323  ///
324  /// | ||
325  /// | -- | -- |
326  /// | Declaration | `uniform token[] skel:blendShapes` |
327  /// | C++ Type | VtArray<TfToken> |
328  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->TokenArray |
329  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
332 
333  /// See GetBlendShapesAttr(), and also
334  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
335  /// If specified, author \p defaultValue as the attribute's default,
336  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
337  /// the default for \p writeSparsely is \c false.
339  UsdAttribute CreateBlendShapesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
340 
341 public:
342  // --------------------------------------------------------------------- //
343  // ANIMATIONSOURCE
344  // --------------------------------------------------------------------- //
345  /// Animation source to be bound to Skeleton primitives at or
346  /// beneath the location at which this property is defined.
347  ///
348  ///
351 
352  /// See GetAnimationSourceRel(), and also
353  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create
356 
357 public:
358  // --------------------------------------------------------------------- //
359  // SKELETON
360  // --------------------------------------------------------------------- //
361  /// Skeleton to be bound to this prim and its descendents that
362  /// possess a mapping and weighting to the joints of the identified
363  /// Skeleton.
364  ///
367 
368  /// See GetSkeletonRel(), and also
369  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create
372 
373 public:
374  // --------------------------------------------------------------------- //
375  // BLENDSHAPETARGETS
376  // --------------------------------------------------------------------- //
377  /// Ordered list of all target blend shapes. This property is not
378  /// inherited hierarchically, and is expected to be authored directly on
379  /// the skinnable primitive to which the the blend shapes apply.
380  ///
383 
384  /// See GetBlendShapeTargetsRel(), and also
385  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create
388 
389 public:
390  // ===================================================================== //
391  // Feel free to add custom code below this line, it will be preserved by
392  // the code generator.
393  //
394  // Just remember to:
395  // - Close the class declaration with };
396  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
397  // - Close the include guard with #endif
398  // ===================================================================== //
399  // --(BEGIN CUSTOM CODE)--
400 
401  /// Convenience function to get the jointIndices attribute as a primvar.
402  ///
403  /// \sa GetJointIndicesAttr, GetInheritedJointWeightsPrimvar
406 
407  /// Convenience function to create the jointIndices primvar, optionally
408  /// specifying elementSize.
409  /// If \p constant is true, the resulting primvar is configured
410  /// with 'constant' interpolation, and describes a rigid deformation.
411  /// Otherwise, the primvar is configured with 'vertex' interpolation,
412  /// and describes joint influences that vary per point.
413  ///
414  /// \sa CreateJointIndicesAttr(), GetJointIndicesPrimvar()
417  int elementSize=-1) const;
418 
419  /// Convenience function to get the jointWeights attribute as a primvar.
420  ///
421  /// \sa GetJointWeightsAttr, GetInheritedJointWeightsPrimvar
424 
425  /// Convenience function to create the jointWeights primvar, optionally
426  /// specifying elementSize.
427  /// If \p constant is true, the resulting primvar is configured
428  /// with 'constant' interpolation, and describes a rigid deformation.
429  /// Otherwise, the primvar is configured with 'vertex' interpolation,
430  /// and describes joint influences that vary per point.
431  ///
432  /// \sa CreateJointWeightsAttr(), GetJointWeightsPrimvar()
435  int elementSize=-1) const;
436 
437  /// Convenience method for defining joints influences that
438  /// make a primitive rigidly deformed by a single joint.
440  bool SetRigidJointInfluence(int jointIndex, float weight=1) const;
441 
442  /// Convenience method to query the Skeleton bound on this prim.
443  /// Returns true if a Skeleton binding is defined, and sets \p skel to
444  /// the target skel. The resulting Skeleton may still be invalid,
445  /// if the Skeleton has been explicitly *unbound*.
446  ///
447  /// This does not resolved inherited skeleton bindings.
449  bool GetSkeleton(UsdSkelSkeleton* skel) const;
450 
451  /// Convenience method to query the animation source bound on this prim.
452  /// Returns true if an animation source binding is defined, and sets
453  /// \p prim to the target prim. The resulting primitive may still be
454  /// invalid, if the prim has been explicitly *unbound*.
455  ///
456  /// This does not resolved inherited animation source bindings.
458  bool GetAnimationSource(UsdPrim* prim) const;
459 
460  /// Returns the skeleton bound at this prim, or one of its ancestors.
463 
464  /// Returns the animation source bound at this prim, or one of
465  /// its ancestors.
468 
469  /// Validate an array of joint indices.
470  /// This ensures that all indices are the in the range [0, numJoints).
471  /// Returns true if the indices are valid, or false otherwise.
472  /// If invalid and \p reason is non-null, an error message describing
473  /// the first validation error will be set.
476  size_t numJoints,
477  std::string* reason=nullptr);
478 };
479 
481 
482 #endif
USDSKEL_API bool SetRigidJointInfluence(int jointIndex, float weight=1) const
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
USDSKEL_API UsdAttribute CreateJointIndicesAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDSKEL_API UsdGeomPrimvar GetJointIndicesPrimvar() const
USDSKEL_API UsdRelationship GetSkeletonRel() const
USDSKEL_API UsdSkelSkeleton GetInheritedSkeleton() const
Returns the skeleton bound at this prim, or one of its ancestors.
static const UsdSchemaKind schemaKind
Definition: bindingAPI.h:78
USDSKEL_API UsdAttribute GetBlendShapesAttr() const
USDSKEL_API UsdGeomPrimvar GetJointWeightsPrimvar() const
Single Apply API schema.
virtual USDSKEL_API ~UsdSkelBindingAPI()
Destructor.
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
USDSKEL_API UsdRelationship GetAnimationSourceRel() const
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USDSKEL_API UsdSchemaKind _GetSchemaKind() const override
static USDSKEL_API UsdSkelBindingAPI Apply(const UsdPrim &prim)
USDSKEL_API UsdAttribute CreateJointsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDSKEL_API UsdPrim GetInheritedAnimationSource() const
USDSKEL_API bool GetSkeleton(UsdSkelSkeleton *skel) const
static USDSKEL_API UsdSkelBindingAPI Get(const UsdStagePtr &stage, const SdfPath &path)
USDSKEL_API UsdAttribute CreateGeomBindTransformAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDSKEL_API UsdAttribute CreateSkinningMethodAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
UsdSkelBindingAPI(const UsdPrim &prim=UsdPrim())
Definition: bindingAPI.h:84
USDSKEL_API UsdRelationship CreateBlendShapeTargetsRel() const
USDSKEL_API UsdAttribute GetGeomBindTransformAttr() const
static USDSKEL_API bool ValidateJointIndices(TfSpan< const int > indices, size_t numJoints, std::string *reason=nullptr)
USDSKEL_API UsdAttribute CreateBlendShapesAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Definition: span.h:87
static USDSKEL_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
USDSKEL_API UsdRelationship GetBlendShapeTargetsRel() const
USDSKEL_API UsdGeomPrimvar CreateJointIndicesPrimvar(bool constant, int elementSize=-1) const
USDSKEL_API bool GetAnimationSource(UsdPrim *prim) const
USDSKEL_API UsdRelationship CreateAnimationSourceRel() const
USDSKEL_API UsdRelationship CreateSkeletonRel() const
Definition: prim.h:135
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
USDSKEL_API UsdAttribute GetJointsAttr() const
#define USDSKEL_API
Definition: api.h:40
Definition: path.h:291
USDSKEL_API UsdGeomPrimvar CreateJointWeightsPrimvar(bool constant, int elementSize=-1) const
UsdSchemaKind
Definition: common.h:127
USDSKEL_API UsdAttribute CreateJointWeightsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDSKEL_API UsdAttribute GetJointIndicesAttr() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
UsdSkelBindingAPI(const UsdSchemaBase &schemaObj)
Definition: bindingAPI.h:92
USDSKEL_API UsdAttribute GetJointWeightsAttr() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Definition: type.h:64
static USDSKEL_API bool CanApply(const UsdPrim &prim, std::string *whyNot=nullptr)
USDSKEL_API UsdAttribute GetSkinningMethodAttr() const
Definition: value.h:167