From cc24b566ba98e2148d92f0feec4b395f56f057ca Mon Sep 17 00:00:00 2001 From: Wojciech Zielonka Date: Fri, 17 Jan 2020 18:12:21 +0100 Subject: [PATCH] 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 ); + + } }