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 
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"
34 #include "pxr/usd/usd/relationship.h"
35 
36 #include "pxr/usd/usdGeom/primvar.h"
37 
39 
40 
41 PXR_NAMESPACE_OPEN_SCOPE
42 
43 
44 class UsdGeomBoundable;
45 
46 
51 {
52 public:
53  USDSKEL_API
55 
60  USDSKEL_API
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 
73  bool IsValid() const { return bool(_prim); }
74 
76  explicit operator bool() const { return IsValid(); }
77 
78  const UsdPrim& GetPrim() const { return _prim; }
79 
81  USDSKEL_API
82  bool HasBlendShapes() const;
83 
85  USDSKEL_API
86  bool HasJointInfluences() const;
87 
94  return _numInfluencesPerComponent;
95  }
96 
97  const TfToken& GetInterpolation() const { return _interpolation; }
98 
101  USDSKEL_API
102  bool IsRigidlyDeformed() const;
103 
104  const UsdAttribute& GetSkinningMethodAttr() const {
105  return _skinningMethodAttr;
106  }
107 
108  const UsdAttribute& GetGeomBindTransformAttr() const {
109  return _geomBindTransformAttr;
110  }
111 
112  const UsdGeomPrimvar& GetJointIndicesPrimvar() const {
113  return _jointIndicesPrimvar;
114  }
115 
116  const UsdGeomPrimvar& GetJointWeightsPrimvar() const {
117  return _jointWeightsPrimvar;
118  }
119 
120  const UsdAttribute& GetBlendShapesAttr() const {
121  return _blendShapes;
122  }
123 
124  const UsdRelationship& GetBlendShapeTargetsRel() const {
125  return _blendShapeTargets;
126  }
127 
134  const UsdSkelAnimMapperRefPtr& GetJointMapper() const {
135  return _jointMapper;
136  }
137 
139  const UsdSkelAnimMapperRefPtr& GetMapper() const { return _jointMapper; }
140 
141 
148  const UsdSkelAnimMapperRefPtr& GetBlendShapeMapper() const {
149  return _blendShapeMapper;
150  }
151 
153  USDSKEL_API
154  bool GetJointOrder(VtTokenArray* jointOrder) const;
155 
157  USDSKEL_API
158  bool GetBlendShapeOrder(VtTokenArray* blendShapes) const;
159 
165  USDSKEL_API
166  bool GetTimeSamples(std::vector<double>* times) const;
167 
173  USDSKEL_API
174  bool GetTimeSamplesInInterval(const GfInterval& interval,
175  std::vector<double>* times) const;
176 
181  USDSKEL_API
182  bool ComputeJointInfluences(VtIntArray* indices,
183  VtFloatArray* weights,
184  UsdTimeCode time=UsdTimeCode::Default()) const;
185 
191  USDSKEL_API
193  size_t numPoints,
194  VtIntArray* indices,
195  VtFloatArray* weights,
196  UsdTimeCode time=UsdTimeCode::Default()) const;
197 
206  template <typename Matrix4>
207  USDSKEL_API
208  bool ComputeSkinnedPoints(const VtArray<Matrix4>& xforms,
209  VtVec3fArray* points,
210  UsdTimeCode time=UsdTimeCode::Default()) const;
211 
220  template <typename Matrix4>
221  USDSKEL_API
222  bool ComputeSkinnedNormals(const VtArray<Matrix4>& xforms,
223  VtVec3fArray* points,
224  UsdTimeCode time=UsdTimeCode::Default()) const;
225 
236  template <typename Matrix4>
237  USDSKEL_API
238  bool ComputeSkinnedTransform(const VtArray<Matrix4>& xforms,
239  Matrix4* xform,
240  UsdTimeCode time=UsdTimeCode::Default()) const;
241 
248  template <typename Matrix4>
249  USDSKEL_API
250  float ComputeExtentsPadding(const VtArray<Matrix4>& skelRestXforms,
251  const UsdGeomBoundable& boundable) const;
252 
253  USDSKEL_API
254  TfToken GetSkinningMethod() const;
255 
256  USDSKEL_API
257  GfMatrix4d
258  GetGeomBindTransform(UsdTimeCode time=UsdTimeCode::Default()) const;
259 
260  USDSKEL_API
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  boost::optional<VtTokenArray> _jointOrder;
287  boost::optional<VtTokenArray> _blendShapeOrder;
288 };
289 
290 PXR_NAMESPACE_CLOSE_SCOPE
291 
292 #endif // PXR_USD_USD_SKEL_SKINNING_QUERY_H
USDSKEL_API bool GetTimeSamplesInInterval(const GfInterval &interval, std::vector< double > *times) const
Populate times with the union of time samples within interval, for all properties that affect skinnin...
USDSKEL_API float ComputeExtentsPadding(const VtArray< Matrix4 > &skelRestXforms, const UsdGeomBoundable &boundable) const
Helper for computing an approximate padding for use in extents computations.
Object used for querying resolved bindings for skinning.
Definition: skinningQuery.h:50
const UsdSkelAnimMapperRefPtr & GetJointMapper() const
Return a mapper for remapping from the joint order of the skeleton to the local joint order of this p...
USDSKEL_API bool GetBlendShapeOrder(VtTokenArray *blendShapes) const
Get the blend shapes for this skinning site, if any.
USDSKEL_API bool ComputeJointInfluences(VtIntArray *indices, VtFloatArray *weights, UsdTimeCode time=UsdTimeCode::Default()) const
Convenience method for computing joint influences.
USDSKEL_API bool HasBlendShapes() const
Returns true if there are blend shapes associated with this prim.
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:176
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
const UsdSkelAnimMapperRefPtr & GetBlendShapeMapper() const
Return the mapper for remapping blend shapes from the order of the bound SkelAnimation to the local b...
USDSKEL_API bool ComputeSkinnedPoints(const VtArray< Matrix4 > &xforms, VtVec3fArray *points, UsdTimeCode time=UsdTimeCode::Default()) const
Compute skinned points using specified skinning method attr (fallback to linear blend skinning if not...
Boundable introduces the ability for a prim to persistently cache a rectilinear, local-space,...
Definition: boundable.h:82
bool IsValid() const
Returns true if this query is valid.
Definition: skinningQuery.h:73
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:134
A basic mathematical interval class.
Definition: interval.h:50
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:228
int GetNumInfluencesPerComponent() const
Returns the number of influences encoded for each component.
Definition: skinningQuery.h:93
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
Definition: relationship.h:128
USDSKEL_API bool ComputeVaryingJointInfluences(size_t numPoints, VtIntArray *indices, VtFloatArray *weights, UsdTimeCode time=UsdTimeCode::Default()) const
Convenience method for computing joint influence, where constant influences are expanded to hold valu...
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for 'default'.
Definition: timeCode.h:113
const UsdSkelAnimMapperRefPtr & GetMapper() const
USDSKEL_API bool IsRigidlyDeformed() const
Returns true if the held prim has the same joint influences across all points, or false otherwise.
USDSKEL_API bool GetTimeSamples(std::vector< double > *times) const
Populate times with the union of time samples for all properties that affect skinning,...
Schema wrapper for UsdAttribute for authoring and introspecting attributes that are primvars.
Definition: primvar.h:261
USDSKEL_API bool GetJointOrder(VtTokenArray *jointOrder) const
Get the custom joint order for this skinning site, if any.
USDSKEL_API bool ComputeSkinnedTransform(const VtArray< Matrix4 > &xforms, Matrix4 *xform, UsdTimeCode time=UsdTimeCode::Default()) const
Compute a skinning transform using specified skinning method attr (fallback to linear blend skinning ...
USDSKEL_API bool ComputeSkinnedNormals(const VtArray< Matrix4 > &xforms, VtVec3fArray *points, UsdTimeCode time=UsdTimeCode::Default()) const
Compute skinned normals using specified skinning method attr (fallback to linear blend skinning if no...
USDSKEL_API bool HasJointInfluences() const
Returns true if joint influence data is associated with this prim.