25 Eigen::Index vertexIndex)
26 : character(character) {
27 const auto& skinWeights = *character.skinWeights;
31 const auto w = skinWeights.weight(vertexIndex, i);
32 const auto parentBone = skinWeights.index(vertexIndex, i);
34 if (parentBone < character.inverseBindPose.size() &&
36 boneWeights[nBoneWeights++] = {
41 (character.inverseBindPose[parentBone].template
cast<T>() *
47 boneWeights.begin(), boneWeights.begin() + nBoneWeights, std::greater<
BoneWeightT<T>>());
56 const Eigen::Vector3<T>& locatorPosition,
58 : character(character) {
62 const auto parentBone = locator.
parents[i];
63 if (w > 0 && parentBone < character.inverseBindPose.size() &&
65 boneWeights[nBoneWeights++] = {
70 (character.inverseBindPose[parentBone].template
cast<T>() *
71 locatorPosition.template
cast<T>()))};
75 boneWeights.begin(), boneWeights.begin() + nBoneWeights, std::greater<
BoneWeightT<T>>());
80 return nBoneWeights == 0;
93 for (
int i = 1; i < nBoneWeights; ++i) {
94 boneWeights[i - 1] = boneWeights[i];
101 while (i < nBoneWeights && boneWeights[i - 1].parentBone < boneWeights[i].parentBone) {
102 std::swap(boneWeights[i - 1], boneWeights[i]);
106 if (i < nBoneWeights && boneWeights[i - 1].parentBone == boneWeights[i].parentBone) {
108 boneWeights[i - 1] += boneWeights[i];
112 while (i < nBoneWeights) {
113 boneWeights[i - 1] = boneWeights[i];
125void SkinningWeightIteratorT<T>::checkInvariants() {
127 if (nBoneWeights > 0) {
130 for (
int i = 0; i < nBoneWeights; ++i) {
131 MT_CHECK(boneWeights[i].parentBone < this->character.skeleton.joints.size());
132 MT_CHECK(boneWeights[i].weight > 0 && boneWeights[i].weight <= 1.001);
133 MT_CHECK(i == 0 || boneWeights[i - 1].parentBone > boneWeights[i].parentBone);
134 sum += boneWeights[i].weight;
136 MT_CHECK(sum > 0.99f && sum < 1.01f);
#define MT_CHECK(condition,...)
Runtime check macros with two interchangeable backends:
SkinningWeightIteratorT(const Character &character, const MeshT< T > &restMesh, const SkeletonStateT< T > &skelState, Eigen::Index vertexIndex)
std::tuple< size_t, T, Eigen::Vector3< T > > next()
constexpr size_t kInvalidIndex
Sentinel value indicating an invalid or unset size_t index.
constexpr uint32_t kMaxSkinJoints
Maximum number of joints that can influence a single vertex.
decltype(auto) cast(const ContainerType< ObjectType > &originalContainer)
Casts the scalar type of objects in a container that support the cast<>() method.
Eigen::Vector3< T > weightedWorldSpacePoint
A character model with skeletal structure, mesh, and optional components.
A generic mesh representation with support for vertices, faces, lines, and texture coordinates.
std::vector< Eigen::Vector3< T > > vertices
List of mesh vertices in 3D space.
Represents the complete state of a skeleton.
JointStateListT< T > jointState
Computed joint states for all joints in the skeleton.
A locator attached to multiple joints, with its runtime position determined by blending the skinning ...
Eigen::Matrix< uint32_t, kMaxSkinJoints, 1 > parents
Indices of the parent joints used for skinning.
Eigen::Matrix< float, kMaxSkinJoints, 1 > skinWeights
Skinning weight for each entry in parents. Typically sums to 1.0.