Normalize skinning weights from Blender

This commit is contained in:
Jack Andersen 2016-09-08 18:18:56 -10:00
parent d5e0536d63
commit 3438cb34a3
4 changed files with 17 additions and 1 deletions

View File

@ -653,6 +653,7 @@ BlenderConnection::DataStream::Mesh::Mesh
for (uint32_t j=0 ; j<bindCount ; ++j) for (uint32_t j=0 ; j<bindCount ; ++j)
binds.emplace_back(conn); binds.emplace_back(conn);
} }
normalizeSkinBinds();
/* Assume 16 islands per material for reserve */ /* Assume 16 islands per material for reserve */
if (materialSets.size()) if (materialSets.size())

View File

@ -15,6 +15,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <float.h>
#include <string> #include <string>
#include <functional> #include <functional>
#include <iostream> #include <iostream>
@ -430,6 +431,19 @@ public:
std::vector<std::vector<SkinBind>> skins; std::vector<std::vector<SkinBind>> skins;
std::vector<size_t> contiguousSkinVertCounts; std::vector<size_t> contiguousSkinVertCounts;
void normalizeSkinBinds()
{
for (std::vector<SkinBind>& skin : skins)
{
float accum = 0.f;
for (const SkinBind& bind : skin)
accum += bind.weight;
if (accum > FLT_EPSILON)
for (SkinBind& bind : skin)
bind.weight /= accum;
}
}
/** Islands of the same material/skinBank are represented here */ /** Islands of the same material/skinBank are represented here */
struct Surface struct Surface
{ {

View File

@ -135,6 +135,7 @@ HMDLBuffers BlenderConnection::DataStream::Mesh::getHMDLBuffers(bool absoluteCoo
{ {
const SkinBanks::Bank& bank = skinBanks.banks[s.skinBankIdx]; const SkinBanks::Bank& bank = skinBanks.banks[s.skinBankIdx];
const std::vector<SkinBind>& binds = skins[v.iSkin]; const std::vector<SkinBind>& binds = skins[v.iSkin];
auto it = bank.m_boneIdxs.cbegin(); auto it = bank.m_boneIdxs.cbegin();
for (size_t i=0 ; i<weightVecCount ; ++i) for (size_t i=0 ; i<weightVecCount ; ++i)
{ {

2
hecl/extern/boo vendored

@ -1 +1 @@
Subproject commit a96b5879657efb449326a56826bb944b8892b7d6 Subproject commit c33f8d5d3cd1675d851fbf96a1b30ac4fae90dfc