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

Updated Draco decoder javascript to the latest version. #11249

Merged
merged 1 commit into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ THREE.DRACOLoader = function(manager) {
THREE.DefaultLoadingManager;
this.materials = null;
this.verbosity = 0;
this.dracoDecoderType = {};
};


Expand All @@ -32,7 +33,7 @@ THREE.DRACOLoader.prototype = {
loader.setPath(this.path);
loader.setResponseType('arraybuffer');
loader.load(url, function(blob) {
onLoad(scope.decodeDracoFile(blob));
scope.decodeDracoFile(blob, onLoad);
}, onProgress, onError);
},

Expand All @@ -44,8 +45,19 @@ THREE.DRACOLoader.prototype = {
this.verbosity = level;
},

decodeDracoFile: function(rawBuffer) {
const dracoDecoder = THREE.DRACOLoader.getDecoder();
setDracoDecoderType: function(dracoDecoderType) {
this.dracoDecoderType = dracoDecoderType;
},

decodeDracoFile: function(rawBuffer, callback) {
const scope = this;
THREE.DRACOLoader.getDecoder(this.dracoDecoderType,
function(dracoDecoder) {
scope.decodeDracoFileInternal(rawBuffer, dracoDecoder, callback);
});
},

decodeDracoFileInternal : function(rawBuffer, dracoDecoder, callback) {
/*
* Here is how to use Draco Javascript decoder and get the geometry.
*/
Expand All @@ -70,11 +82,12 @@ THREE.DRACOLoader.prototype = {
console.error(errorMsg);
throw new Error(errorMsg);
}
return this.convertDracoGeometryTo3JS(wrapper, geometryType, buffer);
callback(this.convertDracoGeometryTo3JS(dracoDecoder, wrapper,
geometryType, buffer));
},

convertDracoGeometryTo3JS: function(wrapper, geometryType, buffer) {
const dracoDecoder = THREE.DRACOLoader.getDecoder();
convertDracoGeometryTo3JS: function(dracoDecoder, wrapper, geometryType,
buffer) {
let dracoGeometry;
const start_time = performance.now();
if (geometryType == dracoDecoder.TRIANGULAR_MESH) {
Expand Down Expand Up @@ -263,26 +276,38 @@ THREE.DRACOLoader.prototype = {
return geometry;
},

isVersionSupported: function(version) {
return THREE.DRACOLoader.getDecoder().isVersionSupported(version);
isVersionSupported: function(version, callback) {
return THREE.DRACOLoader.getDecoder(this.dracoDecoderType,
function(decoder) { return decoder.isVersionSupported(version); });
}
};

/**
* Returns a singleton instance of the DracoModule decoder. Creating multiple
* copies of the decoder is expensive.
* Creates and returns a singleton instance of the DracoModule decoder.
* The module loading is done asynchronously for WebAssembly. Initialized module
* can be accessed through the callback function |onDracoModuleLoadedCallback|.
*/
THREE.DRACOLoader.getDecoder = (function() {
let decoder;

return function() {
return function(dracoDecoderType, onDracoModuleLoadedCallback) {
if (typeof DracoModule === 'undefined') {
throw new Error('THREE.DRACOLoader: DracoModule not found.');
}

decoder = decoder || DracoModule();

return decoder;
if (typeof decoder !== 'undefined') {
// Module already initialized.
if (typeof onDracoModuleLoadedCallback !== 'undefined') {
onDracoModuleLoadedCallback(decoder);
}
} else {
dracoDecoderType['onModuleLoaded'] = function(module) {
if (typeof onDracoModuleLoadedCallback === 'function') {
decoder = module;
onDracoModuleLoadedCallback(module);
}
};
DracoModule(dracoDecoderType);
}
};

})();
26 changes: 26 additions & 0 deletions examples/js/loaders/draco/draco_decoder.js

Large diffs are not rendered by default.

25 changes: 0 additions & 25 deletions examples/js/loaders/draco_decoder.js

This file was deleted.

4 changes: 2 additions & 2 deletions examples/webgl_loader_draco.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<a href="https://github.com/google/draco" target="_blank">DRACO</a> loader
</div>
<script src="../build/three.js"></script>
<script src="js/loaders/draco_decoder.js"></script>
<script src="js/loaders/DRACOLoader.js"></script>
<script src="js/loaders/draco/draco_decoder.js"></script>
<script src="js/loaders/draco/DRACOLoader.js"></script>
<script>

var camera, scene, renderer;
Expand Down