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 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 PXR_USD_USD_SKEL_SKINNING_QUERY_H
25 #define PXR_USD_USD_SKEL_SKINNING_QUERY_H
26 
27 /// \file usdSkel/skinningQuery.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/usdSkel/api.h"
31 
32 #include "pxr/usd/usd/attribute.h"
33 #include "pxr/usd/usd/prim.h"
35 
37 
39 
40 #include <optional>
41 
43 
44 
45 class UsdGeomBoundable;
46 
47 
48 /// \class UsdSkelSkinningQuery
49 ///
50 /// Object used for querying resolved bindings for skinning.
52 {
53 public:
56 
57  /// Construct a new skining query for the resolved properties
58  /// set through the UsdSkelBindingAPI, as inherited on \p prim.
59  /// The resulting query will be marked valid only if the inherited
60  /// properties provide proper valid joint influences.
62  UsdSkelSkinningQuery(const UsdPrim& prim,
63  const VtTokenArray& skelJointOrder,
64  const VtTokenArray& blendShapeOrder,
65  const UsdAttribute& jointIndices,
66  const UsdAttribute& jointWeights,
67  const UsdAttribute& skinningMethod,
68  const UsdAttribute& geomBindTransform,
69  const UsdAttribute& joints,
70  const UsdAttribute& blendShapes,
71  const UsdRelationship& blendShapeTargets);
72 
73  /// Returns true if this query is valid.
74  bool IsValid() const { return bool(_prim); }
75 
76  /// Boolean conversion operator. Equivalent to IsValid().
77  explicit operator bool() const { return IsValid(); }
78 
79  const UsdPrim& GetPrim() const { return _prim; }
80 
81  /// Returns true if there are blend shapes associated with this prim.
83  bool HasBlendShapes() const;
84 
85  /// Returns true if joint influence data is associated with this prim.
87  bool HasJointInfluences() const;
88 
89  /// Returns the number of influences encoded for each component.
90  /// If the prim defines rigid joint influences, then this returns
91  /// the number of influences that map to every point. Otherwise,
92  /// this provides the number of influences per point.
93  /// \sa IsRigidlyDeformed
95  return _numInfluencesPerComponent;
96  }
97 
98  const TfToken& GetInterpolation() const { return _interpolation; }
99 
100  /// Returns true if the held prim has the same joint influences
101  /// across all points, or false otherwise.
103  bool IsRigidlyDeformed() const;
104 
106  return _skinningMethodAttr;
107  }
108 
110  return _geomBindTransformAttr;
111  }
112 
114  return _jointIndicesPrimvar;
115  }
116 
118  return _jointWeightsPrimvar;
119  }
120 
122  return _blendShapes;
123  }
124 
126  return _blendShapeTargets;
127  }
128 
129  /// Return a mapper for remapping from the joint order of the skeleton
130  /// to the local joint order of this prim, if any. Returns a null
131  /// pointer if the prim has no custom joint orer.
132  /// The mapper maps data from the order given by the \em joints order
133  /// on the Skeleton to the order given by the \em skel:joints property,
134  /// as optionally set through the UsdSkelBindingAPI.
136  return _jointMapper;
137  }
138 
139  /// \deprecated Use GetJointMapper.
140  const UsdSkelAnimMapperRefPtr& GetMapper() const { return _jointMapper; }
141 
142 
143  /// Return the mapper for remapping blend shapes from the order of the
144  /// bound SkelAnimation to the local blend shape order of this prim.
145  /// Returns a null reference if the underlying prim has no blend shapes.
146  /// The mapper maps data from the order given by the \em blendShapes order
147  /// on the SkelAnimation to the order given by the \em skel:blendShapes
148  /// property, as set through the UsdSkelBindingAPI.
150  return _blendShapeMapper;
151  }
152 
153  /// Get the custom joint order for this skinning site, if any.
155  bool GetJointOrder(VtTokenArray* jointOrder) const;
156 
157  /// Get the blend shapes for this skinning site, if any.
159  bool GetBlendShapeOrder(VtTokenArray* blendShapes) const;
160 
161  /// Populate \p times with the union of time samples for all properties
162  /// that affect skinning, independent of joint transforms and any
163  /// other prim-specific properties (such as points).
164  ///
165  /// \sa UsdAttribute::GetTimeSamples
167  bool GetTimeSamples(std::vector<double>* times) const;
168 
169  /// Populate \p times with the union of time samples within \p interval,
170  /// for all properties that affect skinning, independent of joint
171  /// transforms and any other prim-specific properties (such as points).
172  ///
173  /// \sa UsdAttribute::GetTimeSamplesInInterval
175  bool GetTimeSamplesInInterval(const GfInterval& interval,
176  std::vector<double>* times) const;
177 
178  /// Convenience method for computing joint influences.
179  /// In addition to querying influences, this will also perform
180  /// validation of the basic form of the weight data -- although
181  /// the array contents is not validated.
183  bool ComputeJointInfluences(VtIntArray* indices,
184  VtFloatArray* weights,
186 
187  /// Convenience method for computing joint influence, where constant
188  /// influences are expanded to hold values per point.
189  /// In addition to querying influences, this will also perform
190  /// validation of the basic form of the weight data -- although
191  /// the array contents is not validated.
194  size_t numPoints,
195  VtIntArray* indices,
196  VtFloatArray* weights,
198 
199  /// Compute skinned points using specified skinning method attr
200  /// (fallback to linear blend skinning if not specified)
201  /// Both \p xforms and \p points are given in _skeleton space_,
202  /// using the joint order of the bound skeleton.
203  /// Joint influences and the (optional) binding transform are computed
204  /// at time \p time (which will typically be unvarying).
205  ///
206  /// \sa UsdSkelSkeletonQuery::ComputeSkinningTransforms
207  template <typename Matrix4>
209  bool ComputeSkinnedPoints(const VtArray<Matrix4>& xforms,
210  VtVec3fArray* points,
212 
213  /// Compute skinned normals using specified skinning method attr
214  /// (fallback to linear blend skinning if not specified)
215  /// Both \p xforms and \p points are given in _skeleton space_,
216  /// using the joint order of the bound skeleton.
217  /// Joint influences and the (optional) binding transform are computed
218  /// at time \p time (which will typically be unvarying).
219  ///
220  /// \sa UsdSkelSkeletonQuery::ComputeSkinningTransforms
221  template <typename Matrix4>
223  bool ComputeSkinnedNormals(const VtArray<Matrix4>& xforms,
224  VtVec3fArray* points,
226 
227  /// Compute a skinning transform using specified skinning method attr
228  /// (fallback to linear blend skinning if not specified)
229  /// The \p xforms are given in _skeleton space_, using the joint order of
230  /// the bound skeleton.
231  /// Joint influences and the (optional) binding transform are computed
232  /// at time \p time (which will typically be unvarying).
233  /// If this skinning query holds non-constant joint influences,
234  /// no transform will be computed, and the function will return false.
235  ///
236  /// \sa UsdSkelSkeletonQuery::ComputeSkinningTransforms
237  template <typename Matrix4>
239  bool ComputeSkinnedTransform(const VtArray<Matrix4>& xforms,
240  Matrix4* xform,
242 
243  /// Helper for computing an *approximate* padding for use in extents
244  /// computations. The padding is computed as the difference between the
245  /// pivots of the \p skelRestXforms -- _skeleton space_ joint transforms
246  /// at rest -- and the extents of the skinned primitive.
247  /// This is intended to provide a suitable, constant metric for padding
248  /// joint extents as computed by UsdSkelComputeJointsExtent.
249  template <typename Matrix4>
251  float ComputeExtentsPadding(const VtArray<Matrix4>& skelRestXforms,
252  const UsdGeomBoundable& boundable) const;
253 
255  TfToken GetSkinningMethod() const;
256 
258  GfMatrix4d
260 
262  std::string GetDescription() const;
263 
264 private:
265 
266  void _InitializeJointInfluenceBindings(
267  const UsdAttribute& jointIndices,
268  const UsdAttribute& jointWeights);
269 
270  void _InitializeBlendShapeBindings(
271  const UsdAttribute& blendShapes,
272  const UsdRelationship& blendShapeTargets);
273 
274  UsdPrim _prim;
275  int _numInfluencesPerComponent = 1;
276  int _flags = 0;
277  TfToken _interpolation;
278 
279  UsdGeomPrimvar _jointIndicesPrimvar;
280  UsdGeomPrimvar _jointWeightsPrimvar;
281  UsdAttribute _skinningMethodAttr;
282  UsdAttribute _geomBindTransformAttr;
283  UsdAttribute _blendShapes;
284  UsdRelationship _blendShapeTargets;
285  UsdSkelAnimMapperRefPtr _jointMapper;
286  UsdSkelAnimMapperRefPtr _blendShapeMapper;
287  std::optional<VtTokenArray> _jointOrder;
288  std::optional<VtTokenArray> _blendShapeOrder;
289 };
290 
292 
293 #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:112
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:98
const UsdRelationship & GetBlendShapeTargetsRel() const
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
int GetNumInfluencesPerComponent() const
Definition: skinningQuery.h:94
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:74
USDSKEL_API TfToken GetSkinningMethod() const
const UsdAttribute & GetGeomBindTransformAttr() const
const UsdGeomPrimvar & GetJointWeightsPrimvar() const
USDSKEL_API std::string GetDescription() const
const UsdGeomPrimvar & GetJointIndicesPrimvar() const
USDSKEL_API bool ComputeVaryingJointInfluences(size_t numPoints, VtIntArray *indices, VtFloatArray *weights, UsdTimeCode time=UsdTimeCode::Default()) const
Definition: token.h:87
const UsdSkelAnimMapperRefPtr & GetBlendShapeMapper() const
std::shared_ptr< class UsdSkelAnimMapper > UsdSkelAnimMapperRefPtr
Definition: animMapper.h:45
USDSKEL_API bool ComputeSkinnedNormals(const VtArray< Matrix4 > &xforms, VtVec3fArray *points, UsdTimeCode time=UsdTimeCode::Default()) const
Definition: prim.h:133
USDSKEL_API bool IsRigidlyDeformed() const
USDSKEL_API GfMatrix4d GetGeomBindTransform(UsdTimeCode time=UsdTimeCode::Default()) const
#define USDSKEL_API
Definition: api.h:40
const UsdAttribute & GetSkinningMethodAttr() const
Definition: types.h:170
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:1432
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:91
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:79
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()