@@ -104,7 +104,8 @@ DRACOLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
104104
105105 var taskConfig = {
106106 attributeIDs : this . defaultAttributeIDs ,
107- attributeTypes : this . defaultAttributeTypes
107+ attributeTypes : this . defaultAttributeTypes ,
108+ useUniqueIDs : false
108109 } ;
109110
110111 this . decodeGeometry ( buffer , taskConfig )
@@ -120,7 +121,8 @@ DRACOLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
120121
121122 var taskConfig = {
122123 attributeIDs : attributeIDs || this . defaultAttributeIDs ,
123- attributeTypes : attributeTypes || this . defaultAttributeTypes
124+ attributeTypes : attributeTypes || this . defaultAttributeTypes ,
125+ useUniqueIDs : ! ! attributeIDs
124126 } ;
125127
126128 this . decodeGeometry ( buffer , taskConfig ) . then ( callback ) ;
@@ -461,12 +463,32 @@ DRACOLoader.DRACOWorker = function () {
461463
462464 var geometry = { index : null , attributes : [ ] } ;
463465
464- // Add attributes of user specified unique id .
466+ // Gather all vertex attributes .
465467 for ( var attributeName in attributeIDs ) {
466468
467469 var attributeType = self [ attributeTypes [ attributeName ] ] ;
468- var attributeId = attributeIDs [ attributeName ] ;
469- var attribute = decoder . GetAttributeByUniqueId ( dracoGeometry , attributeId ) ;
470+
471+ var attribute ;
472+ var attributeID ;
473+
474+ // A Draco file may be created with default vertex attributes, whose attribute IDs
475+ // are mapped 1:1 from their semantic name (POSITION, NORMAL, ...). Alternatively,
476+ // a Draco file may contain a custom set of attributes, identified by known unique
477+ // IDs. glTF files always do the latter, and `.drc` files typically do the former.
478+ if ( taskConfig . useUniqueIDs ) {
479+
480+ attributeID = attributeIDs [ attributeName ] ;
481+ attribute = decoder . GetAttributeByUniqueId ( dracoGeometry , attributeID ) ;
482+
483+ } else {
484+
485+ attributeID = decoder . GetAttributeId ( dracoGeometry , draco [ attributeIDs [ attributeName ] ] ) ;
486+
487+ if ( attributeID === - 1 ) continue ;
488+
489+ attribute = decoder . GetAttribute ( dracoGeometry , attributeID ) ;
490+
491+ }
470492
471493 geometry . attributes . push ( decodeAttribute ( draco , decoder , dracoGeometry , attributeName , attributeType , attribute ) ) ;
472494
0 commit comments