All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
blendShapeQuery.h
Go to the documentation of this file.
1//
2// Copyright 2019 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_BLEND_SHAPE_QUERY_H
8#define PXR_USD_USD_SKEL_BLEND_SHAPE_QUERY_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/usdSkel/api.h"
15#include "pxr/usd/usdSkel/inbetweenShape.h"
16
17#include "pxr/base/gf/vec3f.h"
18#include "pxr/base/tf/span.h"
19#include "pxr/base/vt/array.h"
20
21
22PXR_NAMESPACE_OPEN_SCOPE
23
24
26
27
33{
34public:
35
36 UsdSkelBlendShapeQuery() = default;
37
38 USDSKEL_API UsdSkelBlendShapeQuery(const UsdSkelBindingAPI& binding);
39
41 bool IsValid() const { return bool(_prim); }
42
44 explicit operator bool() const { return IsValid(); }
45
47 const UsdPrim& GetPrim() const { return _prim; }
48
50 USDSKEL_API UsdSkelBlendShape GetBlendShape(size_t blendShapeIndex) const;
51
53 USDSKEL_API UsdSkelInbetweenShape GetInbetween(size_t subShapeIndex) const;
54
56 USDSKEL_API size_t GetBlendShapeIndex(size_t subShapeIndex) const;
57
58 size_t GetNumBlendShapes() const { return _blendShapes.size(); }
59
60 size_t GetNumSubShapes() const { return _subShapes.size(); }
61
67 USDSKEL_API std::vector<VtIntArray>
69
75 USDSKEL_API std::vector<VtVec3fArray>
77
85 USDSKEL_API std::vector<VtVec3fArray>
87
97 USDSKEL_API bool
99 VtFloatArray* subShapeWeights,
100 VtUIntArray* blendShapeIndices,
101 VtUIntArray* subShapeIndices) const;
102
103
105 USDSKEL_API bool
107 VtFloatArray* subShapeWeights) const;
108
115 USDSKEL_API bool
117 const TfSpan<const float> subShapeWeights,
118 const TfSpan<const unsigned> blendShapeIndices,
119 const TfSpan<const unsigned> subShapeIndices,
120 const std::vector<VtIntArray>& blendShapePointIndices,
121 const std::vector<VtVec3fArray>& subShapePointOffsets,
122 TfSpan<GfVec3f> points) const;
123
132 USDSKEL_API bool
134 const TfSpan<const float> subShapeWeights,
135 const TfSpan<const unsigned> blendShapeIndices,
136 const TfSpan<const unsigned> subShapeIndices,
137 const std::vector<VtIntArray>& blendShapePointIndices,
138 const std::vector<VtVec3fArray>& subShapeNormalOffsets,
139 TfSpan<GfVec3f> noramls) const;
140
152 USDSKEL_API bool
153 ComputePackedShapeTable(VtVec4fArray* offsets,
154 VtVec2iArray* ranges) const;
155
156 USDSKEL_API
157 std::string GetDescription() const;
158
159private:
160
162 struct _SubShape {
163 _SubShape() = default;
164
165 _SubShape(unsigned blendShapeIndex, int inbetweenIndex, float weight)
166 : _blendShapeIndex(blendShapeIndex),
167 _inbetweenIndex(inbetweenIndex),
168 _weight(weight) {}
169
170 unsigned GetBlendShapeIndex() const { return _blendShapeIndex; }
171
172 int GetInbetweenIndex() const { return _inbetweenIndex; }
173
174 bool IsInbetween() const { return _inbetweenIndex >= 0; }
175 bool IsNullShape() const { return _weight == 0.0f; }
176 bool IsPrimaryShape() const { return _weight == 1.0f; }
177
178 float GetWeight() const { return _weight; }
179
180 private:
181 unsigned _blendShapeIndex = 0;
182 int _inbetweenIndex = 0;
183 float _weight = 0;
184 };
185
186 struct _SubShapeCompareByWeight {
187 bool operator()(const _SubShape& lhs, const _SubShape& rhs) const
188 { return lhs.GetWeight() < rhs.GetWeight(); }
189
190 bool operator()(float lhs, const _SubShape& rhs) const
191 { return lhs < rhs.GetWeight(); }
192 };
193
194 struct _BlendShape {
195 UsdSkelBlendShape shape;
196 size_t firstSubShape = 0;
197 size_t numSubShapes = 0;
198 };
199
200 UsdPrim _prim;
201 std::vector<_SubShape> _subShapes;
202 std::vector<_BlendShape> _blendShapes;
203 std::vector<UsdSkelInbetweenShape> _inbetweens;
204};
205
206PXR_NAMESPACE_CLOSE_SCOPE
207
208#endif // PXR_USD_USD_SKEL_BLEND_SHAPE_QUERY_H
Represents a range of contiguous elements.
Definition: span.h:71
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
Provides API for authoring and extracting all the skinning-related data that lives in the "geometry h...
Definition: bindingAPI.h:56
Describes a target blend shape, possibly containing inbetween shapes.
Definition: blendShape.h:49
Helper class used to resolve blend shape weights, including inbetweens.
USDSKEL_API bool ComputePackedShapeTable(VtVec4fArray *offsets, VtVec2iArray *ranges) const
Compute a packed shape table combining all sub-shapes.
USDSKEL_API bool ComputeSubShapeWeights(const TfSpan< const float > &weights, VtFloatArray *subShapeWeights, VtUIntArray *blendShapeIndices, VtUIntArray *subShapeIndices) const
Compute the resolved weights for all sub-shapes bound to this prim.
USDSKEL_API std::vector< VtIntArray > ComputeBlendShapePointIndices() const
Compute an array holding the point indices of all shapes.
USDSKEL_API size_t GetBlendShapeIndex(size_t subShapeIndex) const
Returns the blend shape index corresponding to the i'th sub-shape.
USDSKEL_API bool ComputeDeformedNormals(const TfSpan< const float > subShapeWeights, const TfSpan< const unsigned > blendShapeIndices, const TfSpan< const unsigned > subShapeIndices, const std::vector< VtIntArray > &blendShapePointIndices, const std::vector< VtVec3fArray > &subShapeNormalOffsets, TfSpan< GfVec3f > noramls) const
Deform normals using the resolved sub-shapes given by subShapeWeights, blendShapeIndices and subShape...
USDSKEL_API std::vector< VtVec3fArray > ComputeSubShapePointOffsets() const
Compute an array holding the point offsets of all sub-shapes.
USDSKEL_API bool ComputeDeformedPoints(const TfSpan< const float > subShapeWeights, const TfSpan< const unsigned > blendShapeIndices, const TfSpan< const unsigned > subShapeIndices, const std::vector< VtIntArray > &blendShapePointIndices, const std::vector< VtVec3fArray > &subShapePointOffsets, TfSpan< GfVec3f > points) const
Deform points using the resolved sub-shapes given by subShapeWeights, blendShapeIndices and subShapeI...
bool IsValid() const
Return true if this query is valid.
USDSKEL_API std::vector< VtVec3fArray > ComputeSubShapeNormalOffsets() const
Compute an array holding the normal offsets of all sub-shapes.
USDSKEL_API UsdSkelInbetweenShape GetInbetween(size_t subShapeIndex) const
Returns the inbetween shape corresponding to sub-shape i, if any.
const UsdPrim & GetPrim() const
Returns the prim the blend shapes apply to.
USDSKEL_API bool ComputeFlattenedSubShapeWeights(const TfSpan< const float > &weights, VtFloatArray *subShapeWeights) const
Compute a flattened array of weights for all sub-shapes.
USDSKEL_API UsdSkelBlendShape GetBlendShape(size_t blendShapeIndex) const
Returns the blend shape corresponding to blendShapeIndex.
Schema wrapper for UsdAttribute for authoring and introspecting attributes that serve as inbetween sh...