Переглянути джерело

[extensions][gltf] - support external content urls when not pre-configured by setting the workingPath per model

Dave Buchhofer 3 роки тому
батько
коміт
df96cf5ca6
2 змінених файлів з 15 додано та 12 видалено
  1. 10 3
      src/base/LoaderBase.js
  2. 5 9
      src/three/GLTFExtensionLoader.js

+ 10 - 3
src/base/LoaderBase.js

@@ -24,9 +24,7 @@ export class LoaderBase {
 
 				if ( this.workingPath === '' ) {
 
-					const splits = url.split( /\\\//g );
-					splits.pop();
-					this.workingPath = splits.join( '/' );
+					this.workingPath = this.workingPathForURL( url );
 
 				}
 
@@ -50,6 +48,15 @@ export class LoaderBase {
 
 	}
 
+	workingPathForURL( url ) {
+
+		const splits = url.split( '/' );
+		splits.pop();
+		const workingPath = splits.join( '/' );
+		return workingPath + '/';
+
+	}
+
 	parse( buffer ) {
 
 	}

+ 5 - 9
src/three/GLTFExtensionLoader.js

@@ -16,17 +16,13 @@ export class GLTFExtensionLoader extends LoaderBase {
 		return new Promise( ( resolve, reject ) => {
 
 			const manager = this.manager;
-			const loader = manager.getHandler( 'path.gltf' ) || manager.getHandler( 'path.glb' ) || new GLTFLoader( manager );
+			let loader = manager.getHandler( 'path.gltf' ) || manager.getHandler( 'path.glb' ) || new GLTFLoader( manager );
 
-			// GLTFLoader assumes the working path ends in a slash
-			let workingPath = this.workingPath;
-			if ( ! /[\\/]$/.test( workingPath ) ) {
+			// assume any pre-registered loader has paths configured as the user desires, but if we're making
+			// a new loader, use the working path during parse to support relative uris on other hosts
+			const resourcePath = loader.resourcePath || loader.path || this.workingPath;
 
-				workingPath += '/';
-
-			}
-
-			loader.parse( buffer, workingPath, model => {
+			loader.parse( buffer, resourcePath, model => {
 
 				resolve( model );