HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
skeletonQuery.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 PXR_USD_USD_SKEL_SKELETON_QUERY_H
8 #define PXR_USD_USD_SKEL_SKELETON_QUERY_H
9 
10 /// \file usdSkel/skeletonQuery.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdSkel/api.h"
14 
16 #include "pxr/base/vt/types.h"
17 
18 #include "pxr/usd/usd/prim.h"
19 
22 
23 
25 
26 class UsdGeomXformCache;
27 class UsdSkelSkeleton;
28 class UsdSkelTopology;
29 
30 TF_DECLARE_REF_PTRS(UsdSkel_SkelDefinition);
31 
32 
33 /// \class UsdSkelSkeletonQuery
34 ///
35 /// Primary interface to reading *bound* skeleton data.
36 /// This is used to query properties such as resolved transforms and animation
37 /// bindings, as bound through the UsdSkelBindingAPI.
38 ///
39 /// A UsdSkelSkeletonQuery can not be constructed directly, and instead must be
40 /// constructed through a UsdSkelCache instance. This is done as follows:
41 ///
42 /// \code
43 /// // Global cache, intended to persist.
44 /// UsdSkelCache skelCache;
45 /// // Populate the cache for a skel root.
46 /// skelCache.Populate(UsdSkelRoot(skelRootPrim));
47 ///
48 /// if (UsdSkelSkeletonQuery skelQuery = skelCache.GetSkelQuery(skelPrim)) {
49 /// ...
50 /// }
51 /// \endcode
52 ///
54 {
55 public:
57 
58  /// Return true if this query is valid.
59  bool IsValid() const { return _definition; }
60 
61  /// Boolean conversion operator. Equivalent to IsValid().
62  explicit operator bool() const { return IsValid(); }
63 
64  /// Equality comparison. Return true if \a lhs and \a rhs represent the
65  /// same UsdSkelSkeletonQuery, false otherwise.
66  friend bool operator==(const UsdSkelSkeletonQuery& lhs,
67  const UsdSkelSkeletonQuery& rhs) {
68  return lhs._definition == rhs._definition &&
69  lhs._animQuery == rhs._animQuery;
70  }
71 
72  /// Inequality comparison. Return false if \a lhs and \a rhs represent the
73  /// same UsdSkelSkeletonQuery, true otherwise.
74  friend bool operator!=(const UsdSkelSkeletonQuery& lhs,
75  const UsdSkelSkeletonQuery& rhs) {
76  return !(lhs == rhs);
77  }
78 
79  /// Returns \c true if the size of the array returned by
80  /// skeleton::GetBindTransformsAttr() matches the number of joints in the skeleton.
82  bool HasBindPose() const;
83 
84  /// Returns \c true if the size of the array returned by
85  /// skeleton::GetRestTransformsAttr() matches the number of joints in the skeleton.
87  bool HasRestPose() const;
88 
89  // hash_value overload for std/boost hash.
91  friend size_t hash_value(const UsdSkelSkeletonQuery& query);
92 
93  /// Returns the underlying Skeleton primitive corresponding to the
94  /// bound skeleton instance, if any.
96  UsdPrim GetPrim() const;
97 
98  /// Returns the bound skeleton instance, if any.
100  const UsdSkelSkeleton& GetSkeleton() const;
101 
102  /// Returns the animation query that provides animation for the
103  /// bound skeleton instance, if any.
105  const UsdSkelAnimQuery& GetAnimQuery() const;
106 
107  /// Returns the topology of the bound skeleton instance, if any.
109  const UsdSkelTopology& GetTopology() const;
110 
111  /// Returns a mapper for remapping from the bound animation, if any,
112  /// to the Skeleton.
114  const UsdSkelAnimMapper& GetMapper() const;
115 
116  /// Returns an array of joint paths, given as tokens, describing
117  /// the order and parent-child relationships of joints in the skeleton.
118  ///
119  /// \sa UsdSkelSkeleton::GetJointOrder
121  VtTokenArray GetJointOrder() const;
122 
123  /// Compute joint transforms in joint-local space, at \p time.
124  /// This returns transforms in joint order of the skeleton.
125  /// If \p atRest is false and an animation source is bound, local transforms
126  /// defined by the animation are mapped into the skeleton's joint order.
127  /// Any transforms not defined by the animation source use the transforms
128  /// from the rest pose as a fallback value.
129  /// If valid transforms cannot be computed for the animation source, the
130  /// \p xforms are instead set to the rest transforms.
131  template <typename Matrix4>
135  bool atRest=false) const;
136 
137  /// Compute joint transforms in skeleton space, at \p time.
138  /// This concatenates joint transforms as computed from
139  /// ComputeJointLocalTransforms(). If \p atRest is true, any bound animation
140  /// source is ignored, and transforms are computed from the rest pose.
141  /// The skeleton-space transforms of the rest pose are cached internally.
142  template <typename Matrix4>
146  bool atRest=false) const;
147 
148  /// Compute joint transforms which, when concatenated against the rest pose,
149  /// produce joint transforms in joint-local space. More specifically, this
150  /// computes *restRelativeTransform* in:
151  /// \code
152  /// restRelativeTransform * restTransform = jointLocalTransform
153  /// \endcode
154  template <typename Matrix4>
157  UsdTimeCode time) const;
158 
159  /// Compute joint transforms in world space, at whatever time is configured
160  /// on \p xfCache.
161  /// This is equivalent to computing skel-space joint transforms with
162  /// CmoputeJointSkelTransforms(), and then concatenating all transforms
163  /// by the local-to-world transform of the Skeleton prim.
164  /// If \p atRest is true, any bound animation source is ignored, and
165  /// transforms are computed from the rest pose.
166  template <typename Matrix4>
169  UsdGeomXformCache* xfCache,
170  bool atRest=false) const;
171 
172  /// Compute transforms representing the change in transformation
173  /// of a joint from its rest pose, in skeleton space.
174  ///
175  /// I.e.,
176  /// \code
177  /// inverse(bindTransform)*jointTransform
178  /// \endcode
179  ///
180  /// These are the transforms usually required for skinning.
181  template <typename Matrix4>
184  UsdTimeCode time) const;
185 
186  /// Returns the world space joint transforms at bind time.
187  template <typename Matrix4>
189  bool GetJointWorldBindTransforms(VtArray<Matrix4>* xforms) const;
190 
192  std::string GetDescription() const;
193 
194 private:
195 
197  UsdSkelSkeletonQuery(const UsdSkel_SkelDefinitionRefPtr& definition,
198  const UsdSkelAnimQuery& anim=UsdSkelAnimQuery());
199 
200  bool _HasMappableAnim() const;
201 
202  template <typename Matrix4>
203  bool _ComputeJointLocalTransforms(VtArray<Matrix4>* xforms,
205  bool atRest=false) const;
206 
207  template <typename Matrix4>
208  bool _ComputeJointSkelTransforms(VtArray<Matrix4>* xforms,
210  bool atRest=false) const;
211 
212  template <typename Matrix4>
213  bool _ComputeSkinningTransforms(VtArray<Matrix4>* xforms,
214  UsdTimeCode time) const;
215 
216 private:
217  UsdSkel_SkelDefinitionRefPtr _definition;
218  UsdSkelAnimQuery _animQuery;
219  UsdSkelAnimMapper _animToSkelMapper;
220 
221  friend class UsdSkel_CacheImpl;
222 };
223 
224 
226 
227 #endif // PXR_USD_USD_SKEL_SKELETON_QUERY_H
GLenum query
Definition: glad.h:2772
GT_API const UT_StringHolder time
USDSKEL_API bool HasBindPose() const
USDSKEL_API bool ComputeSkinningTransforms(VtArray< Matrix4 > *xforms, UsdTimeCode time) const
USDSKEL_API const UsdSkelSkeleton & GetSkeleton() const
Returns the bound skeleton instance, if any.
USDSKEL_API bool ComputeJointRestRelativeTransforms(VtArray< Matrix4 > *xforms, UsdTimeCode time) const
friend bool operator==(const UsdSkelSkeletonQuery &lhs, const UsdSkelSkeletonQuery &rhs)
Definition: skeletonQuery.h:66
OutGridT const XformOp bool bool
USDSKEL_API bool HasRestPose() const
friend class UsdSkel_CacheImpl
USDSKEL_API VtTokenArray GetJointOrder() const
TF_DECLARE_REF_PTRS(UsdSkel_SkelDefinition)
USDSKEL_API bool GetJointWorldBindTransforms(VtArray< Matrix4 > *xforms) const
Returns the world space joint transforms at bind time.
USDSKEL_API const UsdSkelTopology & GetTopology() const
Returns the topology of the bound skeleton instance, if any.
USDSKEL_API UsdPrim GetPrim() const
USDSKEL_API bool ComputeJointLocalTransforms(VtArray< Matrix4 > *xforms, UsdTimeCode time, bool atRest=false) const
Definition: prim.h:116
#define USDSKEL_API
Definition: api.h:23
Definition: types.h:153
bool IsValid() const
Return true if this query is valid.
Definition: skeletonQuery.h:59
USDSKEL_API bool ComputeJointSkelTransforms(VtArray< Matrix4 > *xforms, UsdTimeCode time, bool atRest=false) const
USDSKEL_API bool ComputeJointWorldTransforms(VtArray< Matrix4 > *xforms, UsdGeomXformCache *xfCache, bool atRest=false) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USDSKEL_API friend size_t hash_value(const UsdSkelSkeletonQuery &query)
USDSKEL_API const UsdSkelAnimQuery & GetAnimQuery() const
friend bool operator!=(const UsdSkelSkeletonQuery &lhs, const UsdSkelSkeletonQuery &rhs)
Definition: skeletonQuery.h:74
USDSKEL_API std::string GetDescription() const
USDSKEL_API const UsdSkelAnimMapper & GetMapper() const