Loading...
Searching...
No Matches
blendShapeQuery.h
Go to the documentation of this file.
1//
2// Copyright 2019 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_BLEND_SHAPE_QUERY_H
25#define PXR_USD_USD_SKEL_BLEND_SHAPE_QUERY_H
26
28
29#include "pxr/pxr.h"
30#include "pxr/usd/usdSkel/api.h"
32#include "pxr/usd/usdSkel/inbetweenShape.h"
33
34#include "pxr/base/gf/vec3f.h"
35#include "pxr/base/tf/span.h"
36#include "pxr/base/vt/array.h"
37
38
39PXR_NAMESPACE_OPEN_SCOPE
40
41
43
44
50{
51public:
52
53 UsdSkelBlendShapeQuery() = default;
54
55 USDSKEL_API UsdSkelBlendShapeQuery(const UsdSkelBindingAPI& binding);
56
58 bool IsValid() const { return bool(_prim); }
59
61 explicit operator bool() const { return IsValid(); }
62
64 const UsdPrim& GetPrim() const { return _prim; }
65
67 USDSKEL_API UsdSkelBlendShape GetBlendShape(size_t blendShapeIndex) const;
68
70 USDSKEL_API UsdSkelInbetweenShape GetInbetween(size_t subShapeIndex) const;
71
73 USDSKEL_API size_t GetBlendShapeIndex(size_t subShapeIndex) const;
74
75 size_t GetNumBlendShapes() const { return _blendShapes.size(); }
76
77 size_t GetNumSubShapes() const { return _subShapes.size(); }
78
84 USDSKEL_API std::vector<VtIntArray>
86
92 USDSKEL_API std::vector<VtVec3fArray>
94
102 USDSKEL_API std::vector<VtVec3fArray>
104
114 USDSKEL_API bool
116 VtFloatArray* subShapeWeights,
117 VtUIntArray* blendShapeIndices,
118 VtUIntArray* subShapeIndices) const;
119
120
122 USDSKEL_API bool
124 VtFloatArray* subShapeWeights) const;
125
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>& subShapePointOffsets,
139 TfSpan<GfVec3f> points) const;
140
149 USDSKEL_API bool
151 const TfSpan<const float> subShapeWeights,
152 const TfSpan<const unsigned> blendShapeIndices,
153 const TfSpan<const unsigned> subShapeIndices,
154 const std::vector<VtIntArray>& blendShapePointIndices,
155 const std::vector<VtVec3fArray>& subShapeNormalOffsets,
156 TfSpan<GfVec3f> noramls) const;
157
169 USDSKEL_API bool
170 ComputePackedShapeTable(VtVec4fArray* offsets,
171 VtVec2iArray* ranges) const;
172
173 USDSKEL_API
174 std::string GetDescription() const;
175
176private:
177
179 struct _SubShape {
180 _SubShape() = default;
181
182 _SubShape(unsigned blendShapeIndex, int inbetweenIndex, float weight)
183 : _blendShapeIndex(blendShapeIndex),
184 _inbetweenIndex(inbetweenIndex),
185 _weight(weight) {}
186
187 unsigned GetBlendShapeIndex() const { return _blendShapeIndex; }
188
189 int GetInbetweenIndex() const { return _inbetweenIndex; }
190
191 bool IsInbetween() const { return _inbetweenIndex >= 0; }
192 bool IsNullShape() const { return _weight == 0.0f; }
193 bool IsPrimaryShape() const { return _weight == 1.0f; }
194
195 float GetWeight() const { return _weight; }
196
197 private:
198 unsigned _blendShapeIndex = 0;
199 int _inbetweenIndex = 0;
200 float _weight = 0;
201 };
202
203 struct _SubShapeCompareByWeight {
204 bool operator()(const _SubShape& lhs, const _SubShape& rhs) const
205 { return lhs.GetWeight() < rhs.GetWeight(); }
206
207 bool operator()(float lhs, const _SubShape& rhs) const
208 { return lhs < rhs.GetWeight(); }
209 };
210
211 struct _BlendShape {
212 UsdSkelBlendShape shape;
213 size_t firstSubShape = 0;
214 size_t numSubShapes = 0;
215 };
216
217 UsdPrim _prim;
218 std::vector<_SubShape> _subShapes;
219 std::vector<_BlendShape> _blendShapes;
220 std::vector<UsdSkelInbetweenShape> _inbetweens;
221};
222
223PXR_NAMESPACE_CLOSE_SCOPE
224
225#endif // PXR_USD_USD_SKEL_BLEND_SHAPE_QUERY_H
Represents a range of contiguous elements.
Definition: span.h:88
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:134
Provides API for authoring and extracting all the skinning-related data that lives in the "geometry h...
Definition: bindingAPI.h:73
Describes a target blend shape, possibly containing inbetween shapes.
Definition: blendShape.h:66
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...