Skip to content

Commit 5888882

Browse files
Merge pull request google#332 from donmccurdy/feat-dracoloader-parallel-decoding
DRACOLoader: Support requests for multiple files in parallel
2 parents 2677442 + 4fd6c39 commit 5888882

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

javascript/example/DRACOLoader.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ THREE.DRACOLoader = function(manager) {
2424
this.verbosity = 0;
2525
this.attributeOptions = {};
2626
this.drawMode = THREE.TrianglesDrawMode;
27-
// User defined unique id for attributes.
28-
this.attributeUniqueIdMap = {};
2927
// Native Draco attribute type to Three.JS attribute type.
3028
this.nativeAttributeMap = {
3129
'position' : 'POSITION',
@@ -104,14 +102,15 @@ THREE.DRACOLoader.prototype = {
104102
*/
105103
decodeDracoFile: function(rawBuffer, callback, attributeUniqueIdMap) {
106104
var scope = this;
107-
this.attributeUniqueIdMap = attributeUniqueIdMap || {};
108105
THREE.DRACOLoader.getDecoderModule()
109106
.then( function ( module ) {
110-
scope.decodeDracoFileInternal( rawBuffer, module.decoder, callback );
107+
scope.decodeDracoFileInternal( rawBuffer, module.decoder, callback,
108+
attributeUniqueIdMap );
111109
});
112110
},
113111

114-
decodeDracoFileInternal: function(rawBuffer, dracoDecoder, callback) {
112+
decodeDracoFileInternal: function(rawBuffer, dracoDecoder, callback,
113+
attributeUniqueIdMap) {
115114
/*
116115
* Here is how to use Draco Javascript decoder and get the geometry.
117116
*/
@@ -137,7 +136,7 @@ THREE.DRACOLoader.prototype = {
137136
throw new Error(errorMsg);
138137
}
139138
callback(this.convertDracoGeometryTo3JS(dracoDecoder, decoder,
140-
geometryType, buffer));
139+
geometryType, buffer, attributeUniqueIdMap));
141140
},
142141

143142
addAttributeToGeometry: function(dracoDecoder, decoder, dracoGeometry,
@@ -168,7 +167,7 @@ THREE.DRACOLoader.prototype = {
168167
},
169168

170169
convertDracoGeometryTo3JS: function(dracoDecoder, decoder, geometryType,
171-
buffer) {
170+
buffer, attributeUniqueIdMap) {
172171
if (this.getAttributeOptions('position').skipDequantization === true) {
173172
decoder.SkipAttributeTransform(dracoDecoder.POSITION);
174173
}
@@ -236,7 +235,7 @@ THREE.DRACOLoader.prototype = {
236235
for (var attributeName in this.nativeAttributeMap) {
237236
// The native attribute type is only used when no unique Id is
238237
// provided. For example, loading .drc files.
239-
if (this.attributeUniqueIdMap[attributeName] === undefined) {
238+
if (attributeUniqueIdMap[attributeName] === undefined) {
240239
var attId = decoder.GetAttributeId(dracoGeometry,
241240
dracoDecoder[this.nativeAttributeMap[attributeName]]);
242241
if (attId !== -1) {
@@ -251,8 +250,8 @@ THREE.DRACOLoader.prototype = {
251250
}
252251

253252
// Add attributes of user specified unique id. E.g. GLTF models.
254-
for (var attributeName in this.attributeUniqueIdMap) {
255-
var attributeId = this.attributeUniqueIdMap[attributeName];
253+
for (var attributeName in attributeUniqueIdMap) {
254+
var attributeId = attributeUniqueIdMap[attributeName];
256255
var attribute = decoder.GetAttributeByUniqueId(dracoGeometry,
257256
attributeId);
258257
this.addAttributeToGeometry(dracoDecoder, decoder, dracoGeometry,

0 commit comments

Comments
 (0)