Skip to content

Commit

Permalink
Merge pull request #187 from akulagrawal/master
Browse files Browse the repository at this point in the history
Normalize bone weights #185
  • Loading branch information
lasalvavida authored May 23, 2018
2 parents 1ed629e + c596b76 commit aaf3971
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/COLLADA2GLTFWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,19 @@ bool COLLADA2GLTF::Writer::writeController(const COLLADAFW::Controller* controll
std::tie(type, joints, weights) = _skinData[skinControllerDataId];
int numberOfComponents = GLTF::Accessor::getNumberOfComponents(type);

for (size_t i = 0; i < weights.size(); i++) {
float weightSum = 0;
float* weight = weights[i];
for (size_t j = 0; j < numberOfComponents; j++) {
weightSum = weightSum + std::abs(weight[j]);
}
if (weightSum > 0) {
for (size_t j = 0; j < numberOfComponents; j++) {
weight[j] = weight[j] / weightSum;
}
}
}

COLLADAFW::UniqueId meshId = skinController->getSource();
GLTF::Mesh* mesh = _meshInstances[meshId];

Expand Down

0 comments on commit aaf3971

Please sign in to comment.