浏览代码

GLTFLoader: Fix use of setPath with external resources (#27106)

* Fix for dispose error
sampleRenderTarget is being deleted and set to null by super.dispose();
the check for undefined was incorrect causing an attempt to call dispose on a null object.

* Removed disposal of sampleRenderTarget entierly

* Fix for setting path not affecting GLTF Sub Assets correctly.

* Fixed Comment

* Update GLTFLoader.js

Fix code style.

---------

Co-authored-by: Michael Herzog <[email protected]>
Jesse 1 年之前
父节点
当前提交
15d3a1d73f
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7 1
      examples/jsm/loaders/GLTFLoader.js

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

@@ -183,7 +183,13 @@ class GLTFLoader extends Loader {
 
 
 		} else if ( this.path !== '' ) {
 		} else if ( this.path !== '' ) {
 
 
-			resourcePath = this.path;
+			// If a base path is set, resources will be relative paths from that plus the relative path of the gltf file
+			// Example  path = 'https://my-cnd-server.com/', url = 'assets/models/model.gltf'
+			// resourcePath = 'https://my-cnd-server.com/assets/models/'
+			// referenced resource 'model.bin' will be loaded from 'https://my-cnd-server.com/assets/models/model.bin'
+			// referenced resource '../textures/texture.png' will be loaded from 'https://my-cnd-server.com/assets/textures/texture.png'
+			const relativeUrl = LoaderUtils.extractUrlBase( url );
+			resourcePath = LoaderUtils.resolveURL( relativeUrl, this.path );
 
 
 		} else {
 		} else {