ColladaLoader: Automatically setting of path breaks loading via files

With the ColladaLoader I have the following problem.
When trying to load a model via files (instead of url) it won’t find textures.
I used the approach to load the files described in #12591 (comment)

But unfortunately the the ColladaLoader always extracts an url base path from the passed .dae file and if it is empty it sets it to ‘./’ . IMO it is just wrong. If I want to have an path set I should set it on my own.

So for example in ‘extraFiles’ (see linked comment above) I have the key ‘filename.png’ but it tries to access ‘./filename.png’ (because of the default behaivour to set ‘./’ ) which of course doesn’t exists.

So my suggestion is to rewrite it like it is in the ObjLoader:

Before:

	load: function ( url, onLoad, onProgress, onError ) {

		var scope = this;

		var path = THREE.Loader.prototype.extractUrlBase( url ); // REMOVE THIS LINE!

		var loader = new THREE.FileLoader( scope.manager );
		loader.load( url, function ( text ) {

			onLoad( scope.parse( text, path ) );

		}, onProgress, onError );

	},

After:

	load: function ( url, onLoad, onProgress, onError ) {

		var scope = this;

		var loader = new THREE.FileLoader( scope.manager );
		loader.setPath( scope.path );
		loader.load( url, function ( text ) {

			onLoad( scope.parse( text, scope.path ) );

		}, onProgress, onError );

	},
	
	setPath: function ( value ) {

		this.path = value;

	},

The only problem I see with this new approach is that it could break current implementations.
So probably we should make an fallback like:

	load: function ( url, onLoad, onProgress, onError ) {

		var scope = this;

                scope.path = scope.path === undefined ? THREE.Loader.prototype.extractUrlBase( url ) : scope.path; 
		var loader = new THREE.FileLoader( scope.manager );
		loader.setPath( scope.path );
		loader.load( url, function ( text ) {

			onLoad( scope.parse( text, scope.path) );

		}, onProgress, onError );

	},

In this fallback case the user would at least get the possibility to set the path himself to an empty string ( ” ), if required.

@Mugen87 😉

Three.js version
  • [ x ] r88
Browser
  • All of them
OS
  • All of them

Author: Fantashit

1 thought on “ColladaLoader: Automatically setting of path breaks loading via files

Comments are closed.