From 4acbb32391fbe8babd2c65a54c1b83ccb796d0b0 Mon Sep 17 00:00:00 2001 From: Wojciech Zielonka Date: Fri, 17 Jan 2020 14:19:46 +0100 Subject: [PATCH] Lazy dependencies loading Removal of an additional parameter replace const js loaders change --- examples/js/loaders/GLTFLoader.js | 16 ++++++++++++---- examples/jsm/loaders/GLTFLoader.d.ts | 4 ++-- examples/jsm/loaders/GLTFLoader.js | 16 ++++++++++++---- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/examples/js/loaders/GLTFLoader.js b/examples/js/loaders/GLTFLoader.js index db67a6be605bba..3f7087eceb0ddd 100644 --- a/examples/js/loaders/GLTFLoader.js +++ b/examples/js/loaders/GLTFLoader.js @@ -21,7 +21,7 @@ THREE.GLTFLoader = ( function () { constructor: GLTFLoader, - load: function ( url, onLoad, onProgress, onError ) { + load: function ( url, resolveDependencies = true, onLoad, onProgress, onError ) { var scope = this; @@ -78,7 +78,7 @@ THREE.GLTFLoader = ( function () { try { - scope.parse( data, resourcePath, function ( gltf ) { + scope.parse( data, resourcePath, resolveDependencies, function ( gltf ) { onLoad( gltf ); @@ -110,7 +110,7 @@ THREE.GLTFLoader = ( function () { }, - parse: function ( data, path, onLoad, onError ) { + parse: function ( data, path, resolveDependencies = true, onLoad, onError ) { var content; var extensions = {}; @@ -214,7 +214,15 @@ THREE.GLTFLoader = ( function () { } ); - parser.parse( onLoad, onError ); + if ( resolveDependencies ) { + + parser.parse( onLoad, onError ); + + } else { + + onLoad( { parser: parser } ); + + } } diff --git a/examples/jsm/loaders/GLTFLoader.d.ts b/examples/jsm/loaders/GLTFLoader.d.ts index 0910f66ac0281b..dc44a726632bd5 100644 --- a/examples/jsm/loaders/GLTFLoader.d.ts +++ b/examples/jsm/loaders/GLTFLoader.d.ts @@ -32,10 +32,10 @@ export class GLTFLoader extends Loader { dracoLoader: DRACOLoader | null; ddsLoader: DDSLoader | null; - load( url: string, onLoad: ( gltf: GLTF ) => void, onProgress?: ( event: ProgressEvent ) => void, onError?: ( event: ErrorEvent ) => void ) : void; + load( url: string, resolveDependencies: boolean, 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; + parse( data: ArrayBuffer | string, path: string, resolveDependencies: boolean, onLoad: ( gltf: GLTF ) => void, onError?: ( event: ErrorEvent ) => void ) : void; } diff --git a/examples/jsm/loaders/GLTFLoader.js b/examples/jsm/loaders/GLTFLoader.js index 8e459e5cec0a11..5b28a6c31463b9 100644 --- a/examples/jsm/loaders/GLTFLoader.js +++ b/examples/jsm/loaders/GLTFLoader.js @@ -88,7 +88,7 @@ var GLTFLoader = ( function () { constructor: GLTFLoader, - load: function ( url, onLoad, onProgress, onError ) { + load: function ( url, resolveDependencies = true, onLoad, onProgress, onError ) { var scope = this; @@ -145,7 +145,7 @@ var GLTFLoader = ( function () { try { - scope.parse( data, resourcePath, function ( gltf ) { + scope.parse( data, resourcePath, resolveDependencies, function ( gltf ) { onLoad( gltf ); @@ -177,7 +177,7 @@ var GLTFLoader = ( function () { }, - parse: function ( data, path, onLoad, onError ) { + parse: function ( data, path, resolveDependencies = true, onLoad, onError ) { var content; var extensions = {}; @@ -281,7 +281,15 @@ var GLTFLoader = ( function () { } ); - parser.parse( onLoad, onError ); + if ( resolveDependencies ) { + + parser.parse( onLoad, onError ); + + } else { + + onLoad( { parser: parser } ); + + } }