Skip to content

Commit 2044d9a

Browse files
committed
Fix quantized byteLength
1 parent 846b17a commit 2044d9a

File tree

4 files changed

+44
-36
lines changed

4 files changed

+44
-36
lines changed

Source/Scene/DracoLoader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ define([
2525
*/
2626
function DracoLoader() {}
2727

28-
// Maximum concurrency to use when deocding draco models
28+
// Maximum concurrency to use when decoding draco models
2929
DracoLoader._maxDecodingConcurrency = Math.max(FeatureDetection.hardwareConcurrency - 1, 1);
3030

3131
// Exposed for testing purposes

Source/Scene/Model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ define([
14331433

14341434
// Only ARRAY_BUFFER here. ELEMENT_ARRAY_BUFFER created below.
14351435
ForEach.bufferView(model.gltf, function(bufferView, id) {
1436-
if (bufferView.target === WebGLConstants.ARRAY_BUFFER) {
1436+
if (bufferView.target === WebGLConstants.ARRAY_BUFFER && !DracoLoader.hasExtension(model)) {
14371437
vertexBuffersToCreate.enqueue(id);
14381438
}
14391439
});

Source/Scene/ModelUtility.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ define([
512512
var uniformMap = {};
513513
for (var attribute in decodedAttributes) {
514514
if (decodedAttributes.hasOwnProperty(attribute)) {
515-
var quantization = decodedAttributes[attribute].quantization;
515+
var decodedData = decodedAttributes[attribute];
516+
var quantization = decodedData.quantization;
516517

517518
if (!defined(quantization)) {
518519
continue;
@@ -536,7 +537,7 @@ define([
536537
uniformMap[uniformVarNameNormConstant] = getScalarUniformFunction(normConstant).func;
537538

538539
var uniformVarNameMin = uniformVarName + '_min';
539-
switch (decodedAttributes[attribute].componentsPerAttribute) {
540+
switch (decodedData.componentsPerAttribute) {
540541
case 1:
541542
uniformMap[uniformVarNameMin] = getScalarUniformFunction(quantization.minValues).func;
542543
break;

Source/Workers/decodeDraco.js

+39-32
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ define([
44
'../Core/IndexDatatype',
55
'../Core/RuntimeError',
66
'../ThirdParty/draco-decoder-gltf',
7+
'../ThirdParty/GltfPipeline/byteLengthForComponentType',
78
'./createTaskProcessorWorker'
89
], function(
910
ComponentDatatype,
1011
defined,
1112
IndexDatatype,
1213
RuntimeError,
1314
draco,
15+
byteLengthForComponentType,
1416
createTaskProcessorWorker) {
1517
'use strict';
1618

@@ -53,45 +55,16 @@ define([
5355
var attribute = dracoDecoder.GetAttributeByUniqueId(dracoGeometry, compressedAttribute);
5456
var numComponents = attribute.num_components();
5557

56-
if (attribute.data_type() === 4) {
57-
attributeData = new draco.DracoInt32Array();
58-
// Uint16Array is used because there is not currently a way to retrieve the maximum
59-
// value up front via the draco decoder API. Max values over 65535 require a Uint32Array.
60-
vertexArray = new Uint16Array(numPoints * numComponents);
61-
dracoDecoder.GetAttributeInt32ForAllPoints(dracoGeometry, attribute, attributeData);
62-
} else {
63-
attributeData = new draco.DracoFloat32Array();
64-
vertexArray = new Float32Array(numPoints * numComponents);
65-
dracoDecoder.GetAttributeFloatForAllPoints(dracoGeometry, attribute, attributeData);
66-
}
67-
68-
var vertexArrayLength = vertexArray.length;
6958
var i;
70-
for (i = 0; i < vertexArrayLength; ++i) {
71-
vertexArray[i] = attributeData.GetValue(i);
72-
}
73-
74-
draco.destroy(attributeData);
75-
76-
decodedAttributeData[attributeName] = {
77-
array : vertexArray,
78-
data : {
79-
componentsPerAttribute : numComponents,
80-
byteOffset : attribute.byte_offset(),
81-
byteStride : attribute.byte_stride(),
82-
normalized : attribute.normalized(),
83-
componentDatatype : ComponentDatatype.fromTypedArray(vertexArray)
84-
}
85-
};
86-
59+
var quantization;
8760
var transform = new draco.AttributeQuantizationTransform();
8861
if (transform.InitFromAttribute(attribute)) {
8962
var minValues = new Array(numComponents);
9063
for (i = 0; i < numComponents; ++i) {
9164
minValues[i] = transform.min_value(i);
9265
}
9366

94-
decodedAttributeData[attributeName].data.quantization = {
67+
quantization = {
9568
quantizationBits : transform.quantization_bits(),
9669
minValues : minValues,
9770
range : transform.range(),
@@ -102,12 +75,46 @@ define([
10275

10376
transform = new draco.AttributeOctahedronTransform();
10477
if (transform.InitFromAttribute(attribute)) {
105-
decodedAttributeData[attributeName].data.quantization = {
78+
quantization = {
10679
quantizationBits : transform.quantization_bits(),
10780
octEncoded : true
10881
};
10982
}
11083
draco.destroy(transform);
84+
85+
var vertexArrayLength = numPoints * numComponents;
86+
if (defined(quantization)) {
87+
attributeData = new draco.DracoInt32Array();
88+
vertexArray = new Int16Array(vertexArrayLength);
89+
dracoDecoder.GetAttributeInt32ForAllPoints(dracoGeometry, attribute, attributeData);
90+
} else if (attribute.data_type() === 4) {
91+
attributeData = new draco.DracoInt32Array();
92+
// Uint16Array is used because there is not currently a way to retrieve the maximum
93+
// value up front via the draco decoder API. Max values over 65535 require a Uint32Array.
94+
vertexArray = new Uint16Array(vertexArrayLength);
95+
dracoDecoder.GetAttributeInt32ForAllPoints(dracoGeometry, attribute, attributeData);
96+
} else {
97+
attributeData = new draco.DracoFloat32Array();
98+
vertexArray = new Float32Array(vertexArrayLength);
99+
dracoDecoder.GetAttributeFloatForAllPoints(dracoGeometry, attribute, attributeData);
100+
}
101+
102+
for (i = 0; i < vertexArrayLength; ++i) {
103+
vertexArray[i] = attributeData.GetValue(i);
104+
}
105+
106+
var componentDatatype = ComponentDatatype.fromTypedArray(vertexArray);
107+
decodedAttributeData[attributeName] = {
108+
array : vertexArray,
109+
data : {
110+
componentsPerAttribute : numComponents,
111+
componentDatatype : componentDatatype,
112+
byteOffset : attribute.byte_offset(),
113+
byteStride : byteLengthForComponentType(componentDatatype) * numComponents,
114+
normalized : attribute.normalized(),
115+
quantization : quantization
116+
}
117+
};
111118
}
112119
}
113120

0 commit comments

Comments
 (0)