From cc24b566ba98e2148d92f0feec4b395f56f057ca Mon Sep 17 00:00:00 2001 From: Wojciech Zielonka Date: Fri, 17 Jan 2020 18:12:21 +0100 Subject: [PATCH 1/2] Lazy dependencies loading Removal of an additional parameter replace const js loaders change markDefs setLazyLoad() --- examples/js/loaders/GLTFLoader.js | 19 ++++++++++++++++++- examples/jsm/loaders/GLTFLoader.d.ts | 3 ++- examples/jsm/loaders/GLTFLoader.js | 19 ++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/examples/js/loaders/GLTFLoader.js b/examples/js/loaders/GLTFLoader.js index db67a6be605bba..174c3e6ca56577 100644 --- a/examples/js/loaders/GLTFLoader.js +++ b/examples/js/loaders/GLTFLoader.js @@ -14,6 +14,7 @@ THREE.GLTFLoader = ( function () { this.dracoLoader = null; this.ddsLoader = null; + this.lazy = false; } @@ -96,6 +97,12 @@ THREE.GLTFLoader = ( function () { }, + setLazyLoad: function ( lazy ) { + + this.lazy = lazy; + + }, + setDRACOLoader: function ( dracoLoader ) { this.dracoLoader = dracoLoader; @@ -214,7 +221,17 @@ THREE.GLTFLoader = ( function () { } ); - parser.parse( onLoad, onError ); + if ( this.lazy ) { + + parser.markDefs(); + + onLoad( { parser: parser } ); + + } else { + + parser.parse( onLoad, onError ); + + } } diff --git a/examples/jsm/loaders/GLTFLoader.d.ts b/examples/jsm/loaders/GLTFLoader.d.ts index 0910f66ac0281b..ec0c442622ea64 100644 --- a/examples/jsm/loaders/GLTFLoader.d.ts +++ b/examples/jsm/loaders/GLTFLoader.d.ts @@ -31,12 +31,13 @@ export class GLTFLoader extends Loader { constructor( manager?: LoadingManager ); dracoLoader: DRACOLoader | null; ddsLoader: DDSLoader | null; + lazy: boolean | false; load( url: string, onLoad: ( gltf: GLTF ) => void, onProgress?: ( event: ProgressEvent ) => void, onError?: ( event: ErrorEvent ) => void ) : void; setDRACOLoader( dracoLoader: DRACOLoader ): GLTFLoader; setDDSLoader( ddsLoader: DDSLoader ): GLTFLoader; parse( data: ArrayBuffer | string, path: string, onLoad: ( gltf: GLTF ) => void, onError?: ( event: ErrorEvent ) => void ) : void; - + setLazyLoad( lazy: boolean ) : void; } export class GLTFParser { diff --git a/examples/jsm/loaders/GLTFLoader.js b/examples/jsm/loaders/GLTFLoader.js index 8e459e5cec0a11..b060071834da13 100644 --- a/examples/jsm/loaders/GLTFLoader.js +++ b/examples/jsm/loaders/GLTFLoader.js @@ -81,6 +81,7 @@ var GLTFLoader = ( function () { this.dracoLoader = null; this.ddsLoader = null; + this.lazy = false; } @@ -163,6 +164,12 @@ var GLTFLoader = ( function () { }, + setLazyLoad: function ( lazy ) { + + this.lazy = lazy; + + }, + setDRACOLoader: function ( dracoLoader ) { this.dracoLoader = dracoLoader; @@ -281,7 +288,17 @@ var GLTFLoader = ( function () { } ); - parser.parse( onLoad, onError ); + if ( this.lazy ) { + + parser.markDefs(); + + onLoad( { parser: parser } ); + + } else { + + parser.parse( onLoad, onError ); + + } } From 8a13ec3a495d91e730746707dcf7593940813344 Mon Sep 17 00:00:00 2001 From: Wojciech Zielonka Date: Mon, 20 Jan 2020 12:27:01 +0100 Subject: [PATCH 2/2] Code review fixes --- examples/js/loaders/GLTFLoader.js | 8 +++----- examples/jsm/loaders/GLTFLoader.d.ts | 2 +- examples/jsm/loaders/GLTFLoader.js | 8 +++----- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/examples/js/loaders/GLTFLoader.js b/examples/js/loaders/GLTFLoader.js index 406e61c8bed0ff..2fc573ff653c4c 100644 --- a/examples/js/loaders/GLTFLoader.js +++ b/examples/js/loaders/GLTFLoader.js @@ -223,8 +223,6 @@ THREE.GLTFLoader = ( function () { if ( this.lazy ) { - parser.markDefs(); - onLoad( { parser: parser } ); } else { @@ -1467,6 +1465,9 @@ THREE.GLTFLoader = ( function () { } + // Mark the special nodes/meshes in json for efficient parse + this.markDefs(); + } GLTFParser.prototype.parse = function ( onLoad, onError ) { @@ -1478,9 +1479,6 @@ THREE.GLTFLoader = ( function () { // Clear the loader cache this.cache.removeAll(); - // Mark the special nodes/meshes in json for efficient parse - this.markDefs(); - Promise.all( [ this.getDependencies( 'scene' ), diff --git a/examples/jsm/loaders/GLTFLoader.d.ts b/examples/jsm/loaders/GLTFLoader.d.ts index ec0c442622ea64..ce3d06917942de 100644 --- a/examples/jsm/loaders/GLTFLoader.d.ts +++ b/examples/jsm/loaders/GLTFLoader.d.ts @@ -31,13 +31,13 @@ export class GLTFLoader extends Loader { constructor( manager?: LoadingManager ); dracoLoader: DRACOLoader | null; ddsLoader: DDSLoader | null; - lazy: boolean | false; load( url: string, onLoad: ( gltf: GLTF ) => void, onProgress?: ( event: ProgressEvent ) => void, onError?: ( event: ErrorEvent ) => void ) : void; setDRACOLoader( dracoLoader: DRACOLoader ): GLTFLoader; setDDSLoader( ddsLoader: DDSLoader ): GLTFLoader; parse( data: ArrayBuffer | string, path: string, onLoad: ( gltf: GLTF ) => void, onError?: ( event: ErrorEvent ) => void ) : void; setLazyLoad( lazy: boolean ) : void; + } export class GLTFParser { diff --git a/examples/jsm/loaders/GLTFLoader.js b/examples/jsm/loaders/GLTFLoader.js index a6c1c3df66367a..a4f862b7643481 100644 --- a/examples/jsm/loaders/GLTFLoader.js +++ b/examples/jsm/loaders/GLTFLoader.js @@ -291,8 +291,6 @@ var GLTFLoader = ( function () { if ( this.lazy ) { - parser.markDefs(); - onLoad( { parser: parser } ); } else { @@ -1535,6 +1533,9 @@ var GLTFLoader = ( function () { } + // Mark the special nodes/meshes in json for efficient parse + this.markDefs(); + } GLTFParser.prototype.parse = function ( onLoad, onError ) { @@ -1546,9 +1547,6 @@ var GLTFLoader = ( function () { // Clear the loader cache this.cache.removeAll(); - // Mark the special nodes/meshes in json for efficient parse - this.markDefs(); - Promise.all( [ this.getDependencies( 'scene' ),