Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
skin_weights.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
9
11
12#include <gsl/util>
13
14namespace momentum {
15
17 const std::vector<std::vector<size_t>>& ind,
18 const std::vector<std::vector<float>>& wgt) {
19 MT_CHECK(ind.size() == wgt.size(), "{} is not {}", ind.size(), wgt.size());
20 index = IndexMatrix::Zero(ind.size(), kMaxSkinJoints);
21 weight = WeightMatrix::Zero(ind.size(), kMaxSkinJoints);
22
23 // TODO: silently truncates per-vertex influences beyond kMaxSkinJoints; consider
24 // warning or renormalizing the kept weights when ind[i].size() > kMaxSkinJoints.
25 for (size_t i = 0; i < ind.size(); i++) {
26 for (size_t j = 0; j < std::min(ind[i].size(), size_t(kMaxSkinJoints)); j++) {
27 index(i, j) = gsl::narrow_cast<uint32_t>(ind[i][j]);
28 weight(i, j) = wgt[i][j];
29 }
30 }
31}
32
33bool SkinWeights::operator==(const SkinWeights& skinWeights) const {
34 return index.isApprox(skinWeights.index) && weight.isApprox(skinWeights.weight);
35}
36
37} // namespace momentum
#define MT_CHECK(condition,...)
Runtime check macros with two interchangeable backends:
Definition checks.h:36
constexpr uint32_t kMaxSkinJoints
Maximum number of joints that can influence a single vertex.
Linear blend skinning weights for a character mesh: per-vertex joint indices and influence weights.
WeightMatrix weight
Joint influence weights per vertex.
IndexMatrix index
Joint indices influencing each vertex.
bool operator==(const SkinWeights &skinWeights) const
Approximate equality on index and weight using Eigen's isApprox.
void set(const std::vector< std::vector< size_t > > &ind, const std::vector< std::vector< float > > &wgt)
Populates index and weight from ragged per-vertex influence lists.