Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRACOLoader: Support requests for multiple files in parallel #332

Merged
merged 1 commit into from
Jan 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions javascript/example/DRACOLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ THREE.DRACOLoader = function(manager) {
this.verbosity = 0;
this.attributeOptions = {};
this.drawMode = THREE.TrianglesDrawMode;
// User defined unique id for attributes.
this.attributeUniqueIdMap = {};
// Native Draco attribute type to Three.JS attribute type.
this.nativeAttributeMap = {
'position' : 'POSITION',
Expand Down Expand Up @@ -104,14 +102,15 @@ THREE.DRACOLoader.prototype = {
*/
decodeDracoFile: function(rawBuffer, callback, attributeUniqueIdMap) {
var scope = this;
this.attributeUniqueIdMap = attributeUniqueIdMap || {};
THREE.DRACOLoader.getDecoderModule()
.then( function ( module ) {
scope.decodeDracoFileInternal( rawBuffer, module.decoder, callback );
scope.decodeDracoFileInternal( rawBuffer, module.decoder, callback,
attributeUniqueIdMap );
});
},

decodeDracoFileInternal: function(rawBuffer, dracoDecoder, callback) {
decodeDracoFileInternal: function(rawBuffer, dracoDecoder, callback,
attributeUniqueIdMap) {
/*
* Here is how to use Draco Javascript decoder and get the geometry.
*/
Expand All @@ -137,7 +136,7 @@ THREE.DRACOLoader.prototype = {
throw new Error(errorMsg);
}
callback(this.convertDracoGeometryTo3JS(dracoDecoder, decoder,
geometryType, buffer));
geometryType, buffer, attributeUniqueIdMap));
},

addAttributeToGeometry: function(dracoDecoder, decoder, dracoGeometry,
Expand Down Expand Up @@ -168,7 +167,7 @@ THREE.DRACOLoader.prototype = {
},

convertDracoGeometryTo3JS: function(dracoDecoder, decoder, geometryType,
buffer) {
buffer, attributeUniqueIdMap) {
if (this.getAttributeOptions('position').skipDequantization === true) {
decoder.SkipAttributeTransform(dracoDecoder.POSITION);
}
Expand Down Expand Up @@ -236,7 +235,7 @@ THREE.DRACOLoader.prototype = {
for (var attributeName in this.nativeAttributeMap) {
// The native attribute type is only used when no unique Id is
// provided. For example, loading .drc files.
if (this.attributeUniqueIdMap[attributeName] === undefined) {
if (attributeUniqueIdMap[attributeName] === undefined) {
var attId = decoder.GetAttributeId(dracoGeometry,
dracoDecoder[this.nativeAttributeMap[attributeName]]);
if (attId !== -1) {
Expand All @@ -251,8 +250,8 @@ THREE.DRACOLoader.prototype = {
}

// Add attributes of user specified unique id. E.g. GLTF models.
for (var attributeName in this.attributeUniqueIdMap) {
var attributeId = this.attributeUniqueIdMap[attributeName];
for (var attributeName in attributeUniqueIdMap) {
var attributeId = attributeUniqueIdMap[attributeName];
var attribute = decoder.GetAttributeByUniqueId(dracoGeometry,
attributeId);
this.addAttributeToGeometry(dracoDecoder, decoder, dracoGeometry,
Expand Down