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