Skip to content

Commit

Permalink
Merge pull request #540 from FrankGalligan/fix_minmax_for_some_attrib…
Browse files Browse the repository at this point in the history
…utes

Fix quantized minmax for for some attributes.
  • Loading branch information
lilleyse authored Apr 20, 2020
2 parents c095278 + 7f67db8 commit 16c8d08
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/replaceWithDecompressedPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ function calculateQuantizedMinMax(semantic, attributeAccessor, quantizationBitsV
if (semantic.indexOf('_') > 0) { // Skip user-defined semantics prefixed with underscore
attributeName = attributeName.substring(0, semantic.indexOf('_'));
}
if (attributeName !== 'POSITION' && attributeName !== 'NORMAL' && attributeName !== 'COLOR' && attributeName !== 'TEXCOORD') {
attributeName = 'GENERIC';
}
const quantizationBits = quantizationBitsValues[attributeName];
const maxQuantizedValue = (1 << (quantizationBits)) - 1;
const inverseDelta = maxQuantizedValue / range;
Expand All @@ -246,6 +249,12 @@ function calculateQuantizedMinMax(semantic, attributeAccessor, quantizationBitsV
for (let c = 0; c < numberOfComponents; ++c) {
dequantizedMin[c] = (quantizedMin[c] * delta) + attributeAccessor.min[c];
dequantizedMax[c] = (quantizedMax[c] * delta) + attributeAccessor.min[c];

// Round to the nearest integer.
if (attributeAccessor.componentType !== WebGLConstants.FLOAT) {
dequantizedMin[c] = Math.ceil(dequantizedMin[c] - 0.5);
dequantizedMax[c] = Math.floor(dequantizedMax[c] + 0.5);
}
}

return {
Expand Down

0 comments on commit 16c8d08

Please sign in to comment.