mirror of https://github.com/AxioDL/metaforce.git
Fix skin binding unordered_map use
This commit is contained in:
parent
5c59acddf2
commit
92e2c03a01
|
@ -315,7 +315,8 @@ struct Mesh {
|
||||||
float weight = 0.f;
|
float weight = 0.f;
|
||||||
SkinBind() = default;
|
SkinBind() = default;
|
||||||
explicit SkinBind(Connection& conn);
|
explicit SkinBind(Connection& conn);
|
||||||
operator bool() const { return vg_idx != UINT32_MAX; }
|
bool valid() const { return vg_idx != UINT32_MAX; }
|
||||||
|
bool operator==(const SkinBind& other) const { return vg_idx == other.vg_idx && weight == other.weight; }
|
||||||
};
|
};
|
||||||
std::vector<std::array<SkinBind, MaxSkinEntries>> skins;
|
std::vector<std::array<SkinBind, MaxSkinEntries>> skins;
|
||||||
std::vector<size_t> contiguousSkinVertCounts;
|
std::vector<size_t> contiguousSkinVertCounts;
|
||||||
|
@ -323,7 +324,7 @@ struct Mesh {
|
||||||
static size_t countSkinBinds(const std::array<SkinBind, MaxSkinEntries>& arr) {
|
static size_t countSkinBinds(const std::array<SkinBind, MaxSkinEntries>& arr) {
|
||||||
size_t ret = 0;
|
size_t ret = 0;
|
||||||
for (const auto& b : arr)
|
for (const auto& b : arr)
|
||||||
if (b)
|
if (b.valid())
|
||||||
++ret;
|
++ret;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
@ -823,7 +824,7 @@ struct hash<array<hecl::blender::Mesh::SkinBind, 16>> {
|
||||||
size_t operator()(const array<hecl::blender::Mesh::SkinBind, 16>& val) const noexcept {
|
size_t operator()(const array<hecl::blender::Mesh::SkinBind, 16>& val) const noexcept {
|
||||||
size_t h = 0;
|
size_t h = 0;
|
||||||
for (const auto& bind : val) {
|
for (const auto& bind : val) {
|
||||||
if (!bind)
|
if (!bind.valid())
|
||||||
break;
|
break;
|
||||||
hecl::hash_combine_impl(h, std::hash<float>()(bind.vg_idx));
|
hecl::hash_combine_impl(h, std::hash<float>()(bind.vg_idx));
|
||||||
hecl::hash_combine_impl(h, std::hash<float>()(bind.weight));
|
hecl::hash_combine_impl(h, std::hash<float>()(bind.weight));
|
||||||
|
|
|
@ -825,11 +825,11 @@ void Mesh::normalizeSkinBinds() {
|
||||||
for (auto& skin : skins) {
|
for (auto& skin : skins) {
|
||||||
float accum = 0.f;
|
float accum = 0.f;
|
||||||
for (const SkinBind& bind : skin)
|
for (const SkinBind& bind : skin)
|
||||||
if (bind)
|
if (bind.valid())
|
||||||
accum += bind.weight;
|
accum += bind.weight;
|
||||||
if (accum > FLT_EPSILON) {
|
if (accum > FLT_EPSILON) {
|
||||||
for (SkinBind& bind : skin)
|
for (SkinBind& bind : skin)
|
||||||
if (bind)
|
if (bind.valid())
|
||||||
bind.weight /= accum;
|
bind.weight /= accum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1030,7 +1030,7 @@ void Mesh::SkinBanks::Bank::addSkins(const Mesh& parent, const std::vector<uint3
|
||||||
for (uint32_t sidx : skinIdxs) {
|
for (uint32_t sidx : skinIdxs) {
|
||||||
m_skinIdxs.push_back(sidx);
|
m_skinIdxs.push_back(sidx);
|
||||||
for (const SkinBind& bind : parent.skins[sidx]) {
|
for (const SkinBind& bind : parent.skins[sidx]) {
|
||||||
if (!bind)
|
if (!bind.valid())
|
||||||
break;
|
break;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (uint32_t bidx : m_boneIdxs) {
|
for (uint32_t bidx : m_boneIdxs) {
|
||||||
|
|
|
@ -147,7 +147,7 @@ HMDLBuffers Mesh::getHMDLBuffers(bool absoluteCoords, PoolSkinIndex& poolSkinInd
|
||||||
if (it == bank.m_boneIdxs.cend())
|
if (it == bank.m_boneIdxs.cend())
|
||||||
break;
|
break;
|
||||||
for (const SkinBind& bind : binds) {
|
for (const SkinBind& bind : binds) {
|
||||||
if (!bind)
|
if (!bind.valid())
|
||||||
break;
|
break;
|
||||||
if (bind.vg_idx == *it) {
|
if (bind.vg_idx == *it) {
|
||||||
vec.simd[j] = bind.weight;
|
vec.simd[j] = bind.weight;
|
||||||
|
|
|
@ -10,7 +10,7 @@ template <typename T>
|
||||||
static void insert_unique_attr(std::unordered_map<T, uint32_t>& set, const T& attr) {
|
static void insert_unique_attr(std::unordered_map<T, uint32_t>& set, const T& attr) {
|
||||||
if (set.find(attr) == set.cend()) {
|
if (set.find(attr) == set.cend()) {
|
||||||
size_t sz = set.size();
|
size_t sz = set.size();
|
||||||
set[attr] = sz;
|
set.insert(std::make_pair(attr, sz));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,7 +391,7 @@ MeshOptimizer::MeshOptimizer(Connection& conn, const std::vector<Material>& mate
|
||||||
for (uint32_t i = 0; i < vert_count.val; ++i) {
|
for (uint32_t i = 0; i < vert_count.val; ++i) {
|
||||||
verts.emplace_back(conn);
|
verts.emplace_back(conn);
|
||||||
insert_unique_attr(b_pos, verts.back().co);
|
insert_unique_attr(b_pos, verts.back().co);
|
||||||
if (verts.back().skin_ents[0])
|
if (verts.back().skin_ents[0].valid())
|
||||||
insert_unique_attr(b_skin, verts.back().skin_ents);
|
insert_unique_attr(b_skin, verts.back().skin_ents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue