Browse Source

GLTFLoader: Allow json objects (#24801)

* GLTFLoader: Allow json objects

This pull requests will additionally allow you to pass through parsed json objects rather than only Buffers and strings.

#24764

* Spaces after and before brackets
Benjamin 2 years ago
parent
commit
321106c2bf
1 changed files with 9 additions and 7 deletions
  1. 9 7
      examples/jsm/loaders/GLTFLoader.js

+ 9 - 7
examples/jsm/loaders/GLTFLoader.js

@@ -284,15 +284,15 @@ class GLTFLoader extends Loader {
 
 
 	parse( data, path, onLoad, onError ) {
 	parse( data, path, onLoad, onError ) {
 
 
-		let content;
+		let json;
 		const extensions = {};
 		const extensions = {};
 		const plugins = {};
 		const plugins = {};
 
 
 		if ( typeof data === 'string' ) {
 		if ( typeof data === 'string' ) {
 
 
-			content = data;
+			json = JSON.parse( data );
 
 
-		} else {
+		} else if( data instanceof ArrayBuffer ) {
 
 
 			const magic = LoaderUtils.decodeText( new Uint8Array( data, 0, 4 ) );
 			const magic = LoaderUtils.decodeText( new Uint8Array( data, 0, 4 ) );
 
 
@@ -309,17 +309,19 @@ class GLTFLoader extends Loader {
 
 
 				}
 				}
 
 
-				content = extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content;
+				json = JSON.parse( extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content );
 
 
 			} else {
 			} else {
 
 
-				content = LoaderUtils.decodeText( new Uint8Array( data ) );
+				json = JSON.parse( LoaderUtils.decodeText( new Uint8Array( data ) ) );
 
 
 			}
 			}
 
 
-		}
+		} else {
 
 
-		const json = JSON.parse( content );
+			json = data;
+
+		}
 
 
 		if ( json.asset === undefined || json.asset.version[ 0 ] < 2 ) {
 		if ( json.asset === undefined || json.asset.version[ 0 ] < 2 ) {