Kaynağa Gözat

Merge pull request #14030 from takahirox/GLTFLoaderSetResourcePath

GLTFLoader: Rename .setPath with .setResourcePath
Mr.doob 6 yıl önce
ebeveyn
işleme
042bd735fc

+ 9 - 1
docs/examples/loaders/GLTFLoader.html

@@ -160,7 +160,15 @@
 		Begin loading from url and call the callback function with the parsed response content.
 		</p>
 
-		<h3>[method:null setPath]( [param:String path] )</h3>
+		<h3>[method:GLTFLoader setPath]( [param:String path] )</h3>
+		<p>
+		[page:String path] — Base path.
+		</p>
+		<p>
+		Set the base path for the .gltf/.glb file.
+		</p>
+
+		<h3>[method:GLTFLoader setResourcePath]( [param:String path] )</h3>
 		<p>
 		[page:String path] — Base path for loading additional resources e.g. textures and .bin data.
 		</p>

+ 25 - 3
examples/js/loaders/GLTFLoader.js

@@ -25,7 +25,21 @@ THREE.GLTFLoader = ( function () {
 
 			var scope = this;
 
-			var path = this.path !== undefined ? this.path : THREE.LoaderUtils.extractUrlBase( url );
+			var resourcePath;
+
+			if ( this.resourcePath !== undefined ) {
+
+				resourcePath = this.resourcePath;
+
+			} else if ( this.path !== undefined ) {
+
+				resourcePath = this.path;
+
+			} else {
+
+				resourcePath = THREE.LoaderUtils.extractUrlBase( url );
+
+			}
 
 			// Tells the LoadingManager to track an extra item, which resolves after
 			// the model is fully loaded. This means the count of items loaded will
@@ -51,13 +65,14 @@ THREE.GLTFLoader = ( function () {
 
 			var loader = new THREE.FileLoader( scope.manager );
 
+			loader.setPath( this.path );
 			loader.setResponseType( 'arraybuffer' );
 
 			loader.load( url, function ( data ) {
 
 				try {
 
-					scope.parse( data, path, function ( gltf ) {
+					scope.parse( data, resourcePath, function ( gltf ) {
 
 						onLoad( gltf );
 
@@ -89,6 +104,13 @@ THREE.GLTFLoader = ( function () {
 
 		},
 
+		setResourcePath: function ( value ) {
+
+			this.resourcePath = value;
+			return this;
+
+		},
+
 		setDRACOLoader: function ( dracoLoader ) {
 
 			this.dracoLoader = dracoLoader;
@@ -186,7 +208,7 @@ THREE.GLTFLoader = ( function () {
 
 			var parser = new GLTFParser( json, extensions, {
 
-				path: path || this.path || '',
+				path: path || this.resourcePath || '',
 				crossOrigin: this.crossOrigin,
 				manager: this.manager