@@ -258,46 +258,48 @@ Object.assign(pc, function () {
258
258
var numPoints = outputGeometry . num_points ( ) ;
259
259
260
260
// helper function to decode data stream with id to TypedArray of appropriate type
261
- var extractDracoAttributeInfo = function ( uniqueId , storageType , componentSizeInBytes , normalize ) {
261
+ var extractDracoAttributeInfo = function ( uniqueId ) {
262
262
var attribute = decoder . GetAttributeByUniqueId ( outputGeometry , uniqueId ) ;
263
263
var numValues = numPoints * attribute . num_components ( ) ;
264
- componentSizeInBytes = normalize ? 4 : componentSizeInBytes ; // if normalized, always decompress to float32 buffer
265
- var dataSize = numValues * componentSizeInBytes ;
266
- var ptr = decoderModule . _malloc ( dataSize ) ;
267
- var values , k ;
268
-
269
- switch ( storageType ) {
270
- case pc . TYPE_FLOAT32 :
271
- decoder . GetAttributeDataArrayForAllPoints ( outputGeometry , attribute , decoderModule . DT_FLOAT32 , dataSize , ptr ) ;
272
- values = new Float32Array ( decoderModule . HEAPF32 . buffer , ptr , numValues ) . slice ( ) ;
264
+ var dracoFormat = attribute . data_type ( ) ;
265
+ var ptr , values , componentSizeInBytes , storageType ;
266
+
267
+ // storage format is based on draco attribute data type
268
+ switch ( dracoFormat ) {
269
+
270
+ case decoderModule . DT_UINT8 :
271
+ storageType = pc . TYPE_UINT8 ;
272
+ componentSizeInBytes = 1 ;
273
+ ptr = decoderModule . _malloc ( numValues * componentSizeInBytes ) ;
274
+ decoder . GetAttributeDataArrayForAllPoints ( outputGeometry , attribute , decoderModule . DT_UINT8 , numValues * componentSizeInBytes , ptr ) ;
275
+ values = new Uint8Array ( decoderModule . HEAPU8 . buffer , ptr , numValues ) . slice ( ) ;
273
276
break ;
274
277
275
- case pc . TYPE_UINT8 :
276
- if ( normalize ) {
277
- decoder . GetAttributeDataArrayForAllPoints ( outputGeometry , attribute , decoderModule . DT_FLOAT32 , dataSize , ptr ) ;
278
- valuesFloat32 = new Float32Array ( decoderModule . HEAPF32 . buffer , ptr , numValues ) . slice ( ) ;
279
-
280
- values = new Uint8ClampedArray ( numValues ) ;
281
- for ( k = 0 ; k < numValues ; k ++ )
282
- values [ k ] = valuesFloat32 [ k ] * 255 ;
283
- } else {
284
- decoder . GetAttributeDataArrayForAllPoints ( outputGeometry , attribute , decoderModule . DT_UINT8 , dataSize , ptr ) ;
285
- values = new Uint8Array ( decoderModule . HEAPU8 . buffer , ptr , numValues ) . slice ( ) ;
286
- }
278
+ case decoderModule . DT_UINT16 :
279
+ storageType = pc . TYPE_UINT16 ;
280
+ componentSizeInBytes = 2 ;
281
+ ptr = decoderModule . _malloc ( numValues * componentSizeInBytes ) ;
282
+ decoder . GetAttributeDataArrayForAllPoints ( outputGeometry , attribute , decoderModule . DT_UINT16 , numValues * componentSizeInBytes , ptr ) ;
283
+ values = new Uint16Array ( decoderModule . HEAPU16 . buffer , ptr , numValues ) . slice ( ) ;
287
284
break ;
288
285
286
+ case decoderModule . DT_FLOAT32 :
289
287
default :
290
- // #ifdef DEBUG
291
- console . error ( "Element type not implemented: " + storageType ) ;
292
- // #endif
288
+ storageType = pc . TYPE_FLOAT32 ;
289
+ componentSizeInBytes = 4 ;
290
+ ptr = decoderModule . _malloc ( numValues * componentSizeInBytes ) ;
291
+ decoder . GetAttributeDataArrayForAllPoints ( outputGeometry , attribute , decoderModule . DT_FLOAT32 , numValues * componentSizeInBytes , ptr ) ;
292
+ values = new Float32Array ( decoderModule . HEAPF32 . buffer , ptr , numValues ) . slice ( ) ;
293
293
break ;
294
294
}
295
295
296
296
decoderModule . _free ( ptr ) ;
297
297
298
298
return {
299
299
values : values ,
300
- numComponents : attribute . num_components ( )
300
+ numComponents : attribute . num_components ( ) ,
301
+ componentSizeInBytes : componentSizeInBytes ,
302
+ storageType : storageType
301
303
} ;
302
304
} ;
303
305
@@ -309,20 +311,17 @@ Object.assign(pc, function () {
309
311
if ( attributes . hasOwnProperty ( attrib ) && semanticMap . hasOwnProperty ( attrib ) ) {
310
312
var semanticInfo = semanticMap [ attrib ] ;
311
313
var semantic = semanticInfo . semantic ;
312
- var storageType = semanticInfo . storageType ;
313
- var componentSizeInBytes = semanticInfo . byteSize ;
314
- var normalize = semanticMap [ attrib ] . normalize ;
315
- var attributeInfo = extractDracoAttributeInfo ( attributes [ attrib ] , storageType , componentSizeInBytes , normalize ) ;
314
+ var attributeInfo = extractDracoAttributeInfo ( attributes [ attrib ] ) ;
316
315
317
316
vertexDesc . push ( {
318
317
semantic : semantic ,
319
318
components : attributeInfo . numComponents ,
320
- type : storageType ,
319
+ type : attributeInfo . storageType ,
321
320
normalize : semanticMap [ attrib ] . normalize
322
321
} ) ;
323
322
324
323
// store the info we'll need to copy this data into the vertex buffer
325
- var size = attributeInfo . numComponents * componentSizeInBytes ;
324
+ var size = attributeInfo . numComponents * attributeInfo . componentSizeInBytes ;
326
325
sourceDesc [ semantic ] = {
327
326
values : attributeInfo . values ,
328
327
buffer : attributeInfo . values . buffer ,
@@ -396,15 +395,15 @@ Object.assign(pc, function () {
396
395
var meshes = [ ] ;
397
396
398
397
var semanticMap = {
399
- 'POSITION' : { semantic : pc . SEMANTIC_POSITION , storageType : pc . TYPE_FLOAT32 , byteSize : 4 } ,
400
- 'NORMAL' : { semantic : pc . SEMANTIC_NORMAL , storageType : pc . TYPE_FLOAT32 , byteSize : 4 } ,
401
- 'TANGENT' : { semantic : pc . SEMANTIC_TANGENT , storageType : pc . TYPE_FLOAT32 , byteSize : 4 } ,
402
- 'BINORMAL' : { semantic : pc . SEMANTIC_BINORMAL , storageType : pc . TYPE_FLOAT32 , byteSize : 4 } ,
403
- 'COLOR_0' : { semantic : pc . SEMANTIC_COLOR , storageType : pc . TYPE_UINT8 , byteSize : 1 , normalize : true } ,
404
- 'JOINTS_0' : { semantic : pc . SEMANTIC_BLENDINDICES , storageType : pc . TYPE_UINT8 , byteSize : 1 } ,
405
- 'WEIGHTS_0' : { semantic : pc . SEMANTIC_BLENDWEIGHT , storageType : pc . TYPE_FLOAT32 , byteSize : 4 } ,
406
- 'TEXCOORD_0' : { semantic : pc . SEMANTIC_TEXCOORD0 , storageType : pc . TYPE_FLOAT32 , byteSize : 4 } ,
407
- 'TEXCOORD_1' : { semantic : pc . SEMANTIC_TEXCOORD1 , storageType : pc . TYPE_FLOAT32 , byteSize : 4 }
398
+ 'POSITION' : { semantic : pc . SEMANTIC_POSITION } ,
399
+ 'NORMAL' : { semantic : pc . SEMANTIC_NORMAL } ,
400
+ 'TANGENT' : { semantic : pc . SEMANTIC_TANGENT } ,
401
+ 'BINORMAL' : { semantic : pc . SEMANTIC_BINORMAL } ,
402
+ 'COLOR_0' : { semantic : pc . SEMANTIC_COLOR } ,
403
+ 'JOINTS_0' : { semantic : pc . SEMANTIC_BLENDINDICES } ,
404
+ 'WEIGHTS_0' : { semantic : pc . SEMANTIC_BLENDWEIGHT } ,
405
+ 'TEXCOORD_0' : { semantic : pc . SEMANTIC_TEXCOORD0 } ,
406
+ 'TEXCOORD_1' : { semantic : pc . SEMANTIC_TEXCOORD1 }
408
407
} ;
409
408
410
409
meshData . primitives . forEach ( function ( primitive ) {
0 commit comments