@@ -4,13 +4,15 @@ define([
4
4
'../Core/IndexDatatype' ,
5
5
'../Core/RuntimeError' ,
6
6
'../ThirdParty/draco-decoder-gltf' ,
7
+ '../ThirdParty/GltfPipeline/byteLengthForComponentType' ,
7
8
'./createTaskProcessorWorker'
8
9
] , function (
9
10
ComponentDatatype ,
10
11
defined ,
11
12
IndexDatatype ,
12
13
RuntimeError ,
13
14
draco ,
15
+ byteLengthForComponentType ,
14
16
createTaskProcessorWorker ) {
15
17
'use strict' ;
16
18
@@ -53,45 +55,16 @@ define([
53
55
var attribute = dracoDecoder . GetAttributeByUniqueId ( dracoGeometry , compressedAttribute ) ;
54
56
var numComponents = attribute . num_components ( ) ;
55
57
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 ;
69
58
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 ;
87
60
var transform = new draco . AttributeQuantizationTransform ( ) ;
88
61
if ( transform . InitFromAttribute ( attribute ) ) {
89
62
var minValues = new Array ( numComponents ) ;
90
63
for ( i = 0 ; i < numComponents ; ++ i ) {
91
64
minValues [ i ] = transform . min_value ( i ) ;
92
65
}
93
66
94
- decodedAttributeData [ attributeName ] . data . quantization = {
67
+ quantization = {
95
68
quantizationBits : transform . quantization_bits ( ) ,
96
69
minValues : minValues ,
97
70
range : transform . range ( ) ,
@@ -102,12 +75,46 @@ define([
102
75
103
76
transform = new draco . AttributeOctahedronTransform ( ) ;
104
77
if ( transform . InitFromAttribute ( attribute ) ) {
105
- decodedAttributeData [ attributeName ] . data . quantization = {
78
+ quantization = {
106
79
quantizationBits : transform . quantization_bits ( ) ,
107
80
octEncoded : true
108
81
} ;
109
82
}
110
83
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
+ } ;
111
118
}
112
119
}
113
120
0 commit comments