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 
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& geomBindTransform,
67  const UsdAttribute& joints,
68  const UsdAttribute& blendShapes,
69  const UsdRelationship& blendShapeTargets);
70 
72  bool IsValid() const { return bool(_prim); }
73 
75  explicit operator bool() const { return IsValid(); }
76 
77  const UsdPrim& GetPrim() const { return _prim; }
78 
80  USDSKEL_API
81  bool HasBlendShapes() const;
82 
84  USDSKEL_API
85  bool HasJointInfluences() const;
86 
93  return _numInfluencesPerComponent;
94  }
95 
96  const TfToken& GetInterpolation() const { return _interpolation; }
97 
100  USDSKEL_API
101  bool IsRigidlyDeformed() const;
102 
103  const UsdAttribute& GetGeomBindTransformAttr() const {
104  return _geomBindTransformAttr;
105  }
106 
107  const UsdGeomPrimvar& GetJointIndicesPrimvar() const {
108  return _jointIndicesPrimvar;
109  }
110 
111  const UsdGeomPrimvar& GetJointWeightsPrimvar() const {
112  return _jointWeightsPrimvar;
113  }
114 
115  const UsdAttribute& GetBlendShapesAttr() const {
116  return _blendShapes;
117  }
118 
119  const UsdRelationship& GetBlendShapeTargetsRel() const {
120  return _blendShapeTargets;
121  }
122 
129  const UsdSkelAnimMapperRefPtr& GetJointMapper() const {
130  return _jointMapper;
131  }
132 
134  const UsdSkelAnimMapperRefPtr& GetMapper() const { return _jointMapper; }
135 
136 
143  const UsdSkelAnimMapperRefPtr& GetBlendShapeMapper() const {
144  return _blendShapeMapper;
145  }
146 
148  USDSKEL_API
149  bool GetJointOrder(VtTokenArray* jointOrder) const;
150 
152  USDSKEL_API
153  bool GetBlendShapeOrder(VtTokenArray* blendShapes) const;
154 
160  USDSKEL_API
161  bool GetTimeSamples(std::vector<double>* times) const;
162 
168  USDSKEL_API
169  bool GetTimeSamplesInInterval(const GfInterval& interval,
170  std::vector<double>* times) const;
171 
176  USDSKEL_API
177  bool ComputeJointInfluences(VtIntArray* indices,
178  VtFloatArray* weights,
179  UsdTimeCode time=UsdTimeCode::Default()) const;
180 
186  USDSKEL_API
188  size_t numPoints,
189  VtIntArray* indices,
190  VtFloatArray* weights,
191  UsdTimeCode time=UsdTimeCode::Default()) const;
192 
200  template <typename Matrix4>
201  USDSKEL_API
202  bool ComputeSkinnedPoints(const VtArray<Matrix4>& xforms,
203  VtVec3fArray* points,
204  UsdTimeCode time=UsdTimeCode::Default()) const;
205 
213  template <typename Matrix4>
214  USDSKEL_API
215  bool ComputeSkinnedNormals(const VtArray<Matrix4>& xforms,
216  VtVec3fArray* points,
217  UsdTimeCode time=UsdTimeCode::Default()) const;
218 
228  template <typename Matrix4>
229  USDSKEL_API
230  bool ComputeSkinnedTransform(const VtArray<Matrix4>& xforms,
231  Matrix4* xform,
232  UsdTimeCode time=UsdTimeCode::Default()) const;
233 
240  template <typename Matrix4>
241  USDSKEL_API
242  float ComputeExtentsPadding(const VtArray<Matrix4>& skelRestXforms,
243  const UsdGeomBoundable& boundable) const;
244 
245  USDSKEL_API
246  GfMatrix4d
247  GetGeomBindTransform(UsdTimeCode time=UsdTimeCode::Default()) const;
248 
249  USDSKEL_API
250  std::string GetDescription() const;
251 
252 private:
253 
254  void _InitializeJointInfluenceBindings(
255  const UsdAttribute& jointIndices,
256  const UsdAttribute& jointWeights);
257 
258  void _InitializeBlendShapeBindings(
259  const UsdAttribute& blendShapes,
260  const UsdRelationship& blendShapeTargets);
261 
262  UsdPrim _prim;
263  int _numInfluencesPerComponent = 1;
264  int _flags = 0;
265  TfToken _interpolation;
266 
267  UsdGeomPrimvar _jointIndicesPrimvar;
268  UsdGeomPrimvar _jointWeightsPrimvar;
269  UsdAttribute _geomBindTransformAttr;
270  UsdAttribute _blendShapes;
271  UsdRelationship _blendShapeTargets;
272  UsdSkelAnimMapperRefPtr _jointMapper;
273  UsdSkelAnimMapperRefPtr _blendShapeMapper;
274  boost::optional<VtTokenArray> _jointOrder;
275  boost::optional<VtTokenArray> _blendShapeOrder;
276 };
277 
278 PXR_NAMESPACE_CLOSE_SCOPE
279 
280 #endif // PXR_USD_USD_SKEL_SKINNING_QUERY_H
Object used for querying resolved bindings for skinning.
Definition: skinningQuery.h:50
const UsdSkelAnimMapperRefPtr & GetBlendShapeMapper() const
Return the mapper for remapping blend shapes from the order of the bound SkelAnimation to the local b...
int GetNumInfluencesPerComponent() const
Returns the number of influences encoded for each component.
Definition: skinningQuery.h:92
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 bool HasJointInfluences() const
Returns true if joint influence data is associated with this prim.
Scenegraph object for authoring and retrieving numeric, string, and array valued data, sampled over time.
Definition: attribute.h:176
USDSKEL_API bool GetJointOrder(VtTokenArray *jointOrder) const
Get the custom joint order for this skinning site, if any.
USDSKEL_API bool ComputeSkinnedNormals(const VtArray< Matrix4 > &xforms, VtVec3fArray *points, UsdTimeCode time=UsdTimeCode::Default()) const
Compute skinned normals using linear blend skinning.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
USDSKEL_API bool IsRigidlyDeformed() const
Returns true if the held prim has the same joint influences across all points, or false otherwise...
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
USDSKEL_API bool HasBlendShapes() const
Returns true if there are blend shapes associated with this prim.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
Boundable introduces the ability for a prim to persistently cache a rectilinear, local-space, extent.
Definition: boundable.h:82
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:132
A basic mathematical interval class.
Definition: interval.h:50
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:229
USDSKEL_API bool ComputeSkinnedTransform(const VtArray< Matrix4 > &xforms, Matrix4 *xform, UsdTimeCode time=UsdTimeCode::Default()) const
Compute a skinning transform using linear blend skinning.
USDSKEL_API bool GetBlendShapeOrder(VtTokenArray *blendShapes) const
Get the blend shapes for this skinning site, if any.
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
Definition: relationship.h:128
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 float ComputeExtentsPadding(const VtArray< Matrix4 > &skelRestXforms, const UsdGeomBoundable &boundable) const
Helper for computing an approximate padding for use in extents computations.
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for &#39;default&#39;.
Definition: timeCode.h:113
bool IsValid() const
Returns true if this query is valid.
Definition: skinningQuery.h:72
USDSKEL_API bool ComputeSkinnedPoints(const VtArray< Matrix4 > &xforms, VtVec3fArray *points, UsdTimeCode time=UsdTimeCode::Default()) const
Compute skinned points using linear blend skinning.
USDSKEL_API bool ComputeJointInfluences(VtIntArray *indices, VtFloatArray *weights, UsdTimeCode time=UsdTimeCode::Default()) const
Convenience method for computing joint influences.
Schema wrapper for UsdAttribute for authoring and introspecting attributes that are primvars...
Definition: primvar.h:260
const UsdSkelAnimMapperRefPtr & GetMapper() const
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...
USDSKEL_API bool GetTimeSamples(std::vector< double > *times) const
Populate times with the union of time samples for all properties that affect skinning, independent of joint transforms and any other prim-specific properties (such as points).