Three.js: ColladaLoader: Automatically setting of path breaks loading via files

Created on 9 Nov 2017  路  4Comments  路  Source: mrdoob/three.js

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 https://github.com/mrdoob/three.js/pull/12591#issuecomment-342179286

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
  • [x] All of them
OS
  • [x] All of them

All 4 comments

I like the suggestion. THREE.GLTFLoader handles this situation similarly. Do you want to make a PR for this :blush:?

I like the suggestion. THREE.GLTFLoader handles this situation similarly. Do you want to make a PR for this 馃槉?

Sure, I don't mind ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fuzihaofzh picture fuzihaofzh  路  3Comments

alexprut picture alexprut  路  3Comments

filharvey picture filharvey  路  3Comments

akshaysrin picture akshaysrin  路  3Comments

yqrashawn picture yqrashawn  路  3Comments