HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
skinningQuery.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_SKINNING_QUERY_H
8 #define PXR_USD_USD_SKEL_SKINNING_QUERY_H
9 
10 /// \file usdSkel/skinningQuery.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdSkel/api.h"
14 
15 #include "pxr/usd/usd/attribute.h"
16 #include "pxr/usd/usd/prim.h"
18 
20 
22 
23 #include <optional>
24 
26 
27 
28 class UsdGeomBoundable;
29 
30 
31 /// \class UsdSkelSkinningQuery
32 ///
33 /// Object used for querying resolved bindings for skinning.
35 {
36 public:
39 
40  /// Construct a new skining query for the resolved properties
41  /// set through the UsdSkelBindingAPI, as inherited on \p prim.
42  /// The resulting query will be marked valid only if the inherited
43  /// properties provide proper valid joint influences.
45  UsdSkelSkinningQuery(const UsdPrim& prim,
46  const VtTokenArray& skelJointOrder,
47  const VtTokenArray& blendShapeOrder,
48  const UsdAttribute& jointIndices,
49  const UsdAttribute& jointWeights,
50  const UsdAttribute& skinningMethod,
51  const UsdAttribute& geomBindTransform,
52  const UsdAttribute& joints,
53  const UsdAttribute& blendShapes,
54  const UsdRelationship& blendShapeTargets);
55 
56  /// Returns true if this query is valid.
57  bool IsValid() const { return bool(_prim); }
58 
59  /// Boolean conversion operator. Equivalent to IsValid().
60  explicit operator bool() const { return IsValid(); }
61 
62  const UsdPrim& GetPrim() const { return _prim; }
63 
64  /// Returns true if there are blend shapes associated with this prim.
66  bool HasBlendShapes() const;
67 
68  /// Returns true if joint influence data is associated with this prim.
70  bool HasJointInfluences() const;
71 
72  /// Returns the number of influences encoded for each component.
73  /// If the prim defines rigid joint influences, then this returns
74  /// the number of influences that map to every point. Otherwise,
75  /// this provides the number of influences per point.
76  /// \sa IsRigidlyDeformed
78  return _numInfluencesPerComponent;
79  }
80 
81  const TfToken& GetInterpolation() const { return _interpolation; }
82 
83  /// Returns true if the held prim has the same joint influences
84  /// across all points, or false otherwise.
86  bool IsRigidlyDeformed() const;
87 
89  return _skinningMethodAttr;
90  }
91 
93  return _geomBindTransformAttr;
94  }
95 
97  return _jointIndicesPrimvar;
98  }
99 
101  return _jointWeightsPrimvar;
102  }
103 
105  return _blendShapes;
106  }
107 
109  return _blendShapeTargets;
110  }
111 
112  /// Return a mapper for remapping from the joint order of the skeleton
113  /// to the local joint order of this prim, if any. Returns a null
114  /// pointer if the prim has no custom joint orer.
115  /// The mapper maps data from the order given by the \em joints order
116  /// on the Skeleton to the order given by the \em skel:joints property,
117  /// as optionally set through the UsdSkelBindingAPI.
119  return _jointMapper;
120  }
121 
122  /// \deprecated Use GetJointMapper.
123  const UsdSkelAnimMapperRefPtr& GetMapper() const { return _jointMapper; }
124 
125 
126  /// Return the mapper for remapping blend shapes from the order of the
127  /// bound SkelAnimation to the local blend shape order of this prim.
128  /// Returns a null reference if the underlying prim has no blend shapes.
129  /// The mapper maps data from the order given by the \em blendShapes order
130  /// on the SkelAnimation to the order given by the \em skel:blendShapes
131  /// property, as set through the UsdSkelBindingAPI.
133  return _blendShapeMapper;
134  }
135 
136  /// Get the custom joint order for this skinning site, if any.
138  bool GetJointOrder(VtTokenArray* jointOrder) const;
139 
140  /// Get the blend shapes for this skinning site, if any.
142  bool GetBlendShapeOrder(VtTokenArray* blendShapes) const;
143 
144  /// Populate \p times with the union of time samples for all properties
145  /// that affect skinning, independent of joint transforms and any
146  /// other prim-specific properties (such as points).
147  ///
148  /// \sa UsdAttribute::GetTimeSamples
150  bool GetTimeSamples(std::vector<double>* times) const;
151 
152  /// Populate \p times with the union of time samples within \p interval,
153  /// for all properties that affect skinning, independent of joint
154  /// transforms and any other prim-specific properties (such as points).
155  ///
156  /// \sa UsdAttribute::GetTimeSamplesInInterval
158  bool GetTimeSamplesInInterval(const GfInterval& interval,
159  std::vector<double>* times) const;
160 
161  /// Convenience method for computing joint influences.
162  /// In addition to querying influences, this will also perform
163  /// validation of the basic form of the weight data -- although
164  /// the array contents is not validated.
166  bool ComputeJointInfluences(VtIntArray* indices,
167  VtFloatArray* weights,
169 
170  /// Convenience method for computing joint influence, where constant
171  /// influences are expanded to hold values per point.
172  /// In addition to querying influences, this will also perform
173  /// validation of the basic form of the weight data -- although
174  /// the array contents is not validated.
177  size_t numPoints,
178  VtIntArray* indices,
179  VtFloatArray* weights,
181 
182  /// Compute skinned points using specified skinning method attr
183  /// (fallback to linear blend skinning if not specified)
184  /// Both \p xforms and \p points are given in _skeleton space_,
185  /// using the joint order of the bound skeleton.
186  /// Joint influences and the (optional) binding transform are computed
187  /// at time \p time (which will typically be unvarying).
188  ///
189  /// \sa UsdSkelSkeletonQuery::ComputeSkinningTransforms
190  template <typename Matrix4>
192  bool ComputeSkinnedPoints(const VtArray<Matrix4>& xforms,
193  VtVec3fArray* points,
195 
196  /// Compute skinned normals using specified skinning method attr
197  /// (fallback to linear blend skinning if not specified)
198  /// Both \p xforms and \p points are given in _skeleton space_,
199  /// using the joint order of the bound skeleton.
200  /// Joint influences and the (optional) binding transform are computed
201  /// at time \p time (which will typically be unvarying).
202  ///
203  /// \sa UsdSkelSkeletonQuery::ComputeSkinningTransforms
204  template <typename Matrix4>
206  bool ComputeSkinnedNormals(const VtArray<Matrix4>& xforms,
207  VtVec3fArray* points,
209 
210  /// Compute a skinning transform using specified skinning method attr
211  /// (fallback to linear blend skinning if not specified)
212  /// The \p xforms are given in _skeleton space_, using the joint order of
213  /// the bound skeleton.
214  /// Joint influences and the (optional) binding transform are computed
215  /// at time \p time (which will typically be unvarying).
216  /// If this skinning query holds non-constant joint influences,
217  /// no transform will be computed, and the function will return false.
218  ///
219  /// \sa UsdSkelSkeletonQuery::ComputeSkinningTransforms
220  template <typename Matrix4>
222  bool ComputeSkinnedTransform(const VtArray<Matrix4>& xforms,
223  Matrix4* xform,
225 
226  /// Helper for computing an *approximate* padding for use in extents
227  /// computations. The padding is computed as the difference between the
228  /// pivots of the \p skelRestXforms -- _skeleton space_ joint transforms
229  /// at rest -- and the extents of the skinned primitive.
230  /// This is intended to provide a suitable, constant metric for padding
231  /// joint extents as computed by UsdSkelComputeJointsExtent.
232  template <typename Matrix4>
234  float ComputeExtentsPadding(const VtArray<Matrix4>& skelRestXforms,
235  const UsdGeomBoundable& boundable) const;
236 
238  TfToken GetSkinningMethod() const;
239 
241  GfMatrix4d
243 
245  std::string GetDescription() const;
246 
247 private:
248 
249  void _InitializeJointInfluenceBindings(
250  const UsdAttribute& jointIndices,
251  const UsdAttribute& jointWeights);
252 
253  void _InitializeBlendShapeBindings(
254  const UsdAttribute& blendShapes,
255  const UsdRelationship& blendShapeTargets);
256 
257  UsdPrim _prim;
258  int _numInfluencesPerComponent = 1;
259  int _flags = 0;
260  TfToken _interpolation;
261 
262  UsdGeomPrimvar _jointIndicesPrimvar;
263  UsdGeomPrimvar _jointWeightsPrimvar;
264  UsdAttribute _skinningMethodAttr;
265  UsdAttribute _geomBindTransformAttr;
266  UsdAttribute _blendShapes;
267  UsdRelationship _blendShapeTargets;
268  UsdSkelAnimMapperRefPtr _jointMapper;
269  UsdSkelAnimMapperRefPtr _blendShapeMapper;
270  std::optional<VtTokenArray> _jointOrder;
271  std::optional<VtTokenArray> _blendShapeOrder;
272 };
273 
275 
276 #endif // PXR_USD_USD_SKEL_SKINNING_QUERY_H
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
static constexpr UsdTimeCode Default()
Definition: timeCode.h:113
USDSKEL_API bool GetBlendShapeOrder(VtTokenArray *blendShapes) const
Get the blend shapes for this skinning site, if any.
GT_API const UT_StringHolder time
const TfToken & GetInterpolation() const
Definition: skinningQuery.h:81
const UsdRelationship & GetBlendShapeTargetsRel() const
int GetNumInfluencesPerComponent() const
Definition: skinningQuery.h:77
USDSKEL_API float ComputeExtentsPadding(const VtArray< Matrix4 > &skelRestXforms, const UsdGeomBoundable &boundable) const
const UsdAttribute & GetBlendShapesAttr() const
bool IsValid() const
Returns true if this query is valid.
Definition: skinningQuery.h:57
USDSKEL_API TfToken GetSkinningMethod() const
OutGridT const XformOp bool bool
const UsdAttribute & GetGeomBindTransformAttr() const
Definition: skinningQuery.h:92
const UsdGeomPrimvar & GetJointWeightsPrimvar() const
USDSKEL_API std::string GetDescription() const
const UsdGeomPrimvar & GetJointIndicesPrimvar() const
Definition: skinningQuery.h:96
USDSKEL_API bool ComputeVaryingJointInfluences(size_t numPoints, VtIntArray *indices, VtFloatArray *weights, UsdTimeCode time=UsdTimeCode::Default()) const
Definition: token.h:70
const UsdSkelAnimMapperRefPtr & GetBlendShapeMapper() const
std::shared_ptr< class UsdSkelAnimMapper > UsdSkelAnimMapperRefPtr
Definition: animMapper.h:28
UT_Matrix4T< Float > Matrix4
Definition: APEX_Include.h:68
USDSKEL_API bool ComputeSkinnedNormals(const VtArray< Matrix4 > &xforms, VtVec3fArray *points, UsdTimeCode time=UsdTimeCode::Default()) const
Definition: prim.h:116
USDSKEL_API bool IsRigidlyDeformed() const
USDSKEL_API GfMatrix4d GetGeomBindTransform(UsdTimeCode time=UsdTimeCode::Default()) const
#define USDSKEL_API
Definition: api.h:23
const UsdAttribute & GetSkinningMethodAttr() const
Definition: skinningQuery.h:88
Definition: types.h:153
USDSKEL_API bool ComputeJointInfluences(VtIntArray *indices, VtFloatArray *weights, UsdTimeCode time=UsdTimeCode::Default()) const
USDSKEL_API bool GetTimeSamplesInInterval(const GfInterval &interval, std::vector< double > *times) const
USDSKEL_API bool ComputeSkinnedPoints(const VtArray< Matrix4 > &xforms, VtVec3fArray *points, UsdTimeCode time=UsdTimeCode::Default()) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USDSKEL_API bool ComputeSkinnedTransform(const VtArray< Matrix4 > &xforms, Matrix4 *xform, UsdTimeCode time=UsdTimeCode::Default()) const
USDSKEL_API bool HasJointInfluences() const
Returns true if joint influence data is associated with this prim.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
const UsdSkelAnimMapperRefPtr & GetJointMapper() const
USDSKEL_API bool GetTimeSamples(std::vector< double > *times) const
USDSKEL_API bool HasBlendShapes() const
Returns true if there are blend shapes associated with this prim.
const UsdPrim & GetPrim() const
Definition: skinningQuery.h:62
const UsdSkelAnimMapperRefPtr & GetMapper() const
USDSKEL_API bool GetJointOrder(VtTokenArray *jointOrder) const
Get the custom joint order for this skinning site, if any.
USDSKEL_API UsdSkelSkinningQuery()