Skip to content

Commit

Permalink
Individual weights Linearly Normalized
Browse files Browse the repository at this point in the history
  • Loading branch information
akulagrawal committed May 21, 2018
1 parent f1b663f commit acd98d3
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/COLLADA2GLTFWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1620,27 +1620,18 @@ bool COLLADA2GLTF::Writer::writeController(const COLLADAFW::Controller* controll
std::tie(type, joints, weights) = _skinData[skinControllerDataId];
int numberOfComponents = GLTF::Accessor::getNumberOfComponents(type);

float maxweight = 0.0, minweight = 0.0;
if (weights.size() > 0) {
maxweight = *weights[0];
minweight = *weights[0];
}
for (size_t i = 1; i < weights.size(); i++) {
maxweight = std::max(maxweight, *weights[i]);
minweight = std::min(minweight, *weights[i]);
}
if (maxweight == minweight) {
if (maxweight > 0) {
for (size_t i = 0; i < weights.size(); i++) {
*weights[i] = 1;
}
}
}
else {
for (size_t i = 0; i < weights.size(); i++) {
*weights[i] = (*weights[i] - minweight) / (maxweight - minweight);
}
}
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 acd98d3

Please sign in to comment.