diff --git a/docs/examples/loaders/GLTFLoader.html b/docs/examples/loaders/GLTFLoader.html index dbb7988bf2b57d..f85d115fd48743 100644 --- a/docs/examples/loaders/GLTFLoader.html +++ b/docs/examples/loaders/GLTFLoader.html @@ -156,6 +156,34 @@
+ [page:String value] — When true, [page:Function parse] and [page:Function load] will return an object with the parser property set. +
++ When lazy loading is enabled and the provided url points to a .gltf file [page:Function load] will only download the .gltf file. [page:Function parse] and [page:Function load] will not call parser.parse() or parser.getDependency(). Examples: +
+
+ var loader = new THREE.GLTFLoader();
+
+ loader.setLazy(true);
+
+ loader.load('foo.gltf', function ( gltf ) {
+
+ var parser = gltf.parser;
+
+ // Modify the glTF before calling parse
+ parser.json.node[ 3 ].extensions = { EXT_foo: { bufferView: 3 } };
+
+ // Load part of the gltf
+ parser.getDependency( "bufferView", 1 ).then( createNavMesh );
+
+ // Load the entire glTF
+ parser.parse( function ( scene, scenes, cameras, animations, json ) { } );
+
+ } );
+
+
[page:ArrayBuffer data] — glTF asset to parse, as an ArrayBuffer or JSON string.
diff --git a/examples/js/loaders/GLTFLoader.js b/examples/js/loaders/GLTFLoader.js
index 8946d295adebc2..6e279560ae0d7e 100644
--- a/examples/js/loaders/GLTFLoader.js
+++ b/examples/js/loaders/GLTFLoader.js
@@ -12,6 +12,7 @@ THREE.GLTFLoader = ( function () {
this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
this.dracoLoader = null;
+ this.lazy = false;
}
@@ -76,6 +77,13 @@ THREE.GLTFLoader = ( function () {
},
+ setLazy: function ( lazy ) {
+
+ this.lazy = lazy;
+ return this;
+
+ },
+
parse: function ( data, path, onLoad, onError ) {
var content;
@@ -172,6 +180,17 @@ THREE.GLTFLoader = ( function () {
} );
+ if ( this.lazy ) {
+
+ // Mark the special nodes/meshes in json for efficient parse
+ this.markDefs();
+
+ onLoad( { parser: parser } );
+
+ return;
+
+ }
+
parser.parse( function ( scene, scenes, cameras, animations, json ) {
var glTF = {