Three.js: FBX with dds and tga textures

Created on 30 Jan 2018  路  11Comments  路  Source: mrdoob/three.js

Description of the problem

The FBXLoader doesn't load FBX files with built-in DDS and TGA textures.

The function used to Load up the FBX file:

function build3d( scale ) {

    const deferred = $q.defer();

    const manager = new THREE.LoadingManager();

    manager.onProgress = function ( item, loaded, total ) {

        $log.info( item, loaded, total );

    };

    const onProgress = function ( xhr ) {

        if ( xhr.lengthComputable ) {

            const percentComplete = xhr.loaded / xhr.total * 100;

            $log.warn( Math.round( percentComplete, 2 ) + '% downloaded' );

        }

    };

    const onError = function ( xhr ) {

        $log.error( xhr );

    };

    const loader = new THREE.FBXLoader( manager );

    loader.load( 'resources/models/Stockcar.FBX', object => {

        object.traverse( child => {

            if ( child instanceof THREE.Mesh ) {

                child.receiveShadow = true;
                child.castShadow = true;

            }

        } );

        object.name = this.name;
        object.scale.set( this.size.length * scale, this.size.width * scale, this.size.height * scale );
        deferred.resolve( object );

    }, onProgress, onError );

    return deferred.promise;

}

Here's a screenshot of Chrome's console:
https://ibb.co/mx33g6

Browser
  • [ ] All of them
  • [x] Chrome
  • [ ] Firefox
  • [x] Internet Explorer
  • [x] Edge
OS
  • [ ] All of them
  • [x] Windows
  • [ ] macOS
  • [ ] Linux
  • [x] Android
  • [ ] iOS
Loaders

Most helpful comment

I've added support here #13227

@cmiguelcabral the model you shared with me is still not loading correctly, but I'm not sure what the reasons are. It's possible that there are problems with your DDS textures, since I'm getting errors from the DDSLoader, but only for a few of them.

If you can create a couple of simple models that use TGA and DDS (preferably just a cube with a texture), I'll investigate this further.

All 11 comments

Can you share your files? It should be fairly easy to make this work, but I haven't come across FBX files with these texture types before.

@looeee Just sent you an e-mail with the file.
It really need to be dds and/or tga because it uses the texture's alpha channel to define transparencies and reflections, png or jpg doesn't has any alpha channel.

It really need to be dds and/or tga because it uses the texture's alpha channel to define transparencies and reflections, png or jpg doesn't has any alpha channel.

png has alpha channel...

I've added support here #13227

@cmiguelcabral the model you shared with me is still not loading correctly, but I'm not sure what the reasons are. It's possible that there are problems with your DDS textures, since I'm getting errors from the DDSLoader, but only for a few of them.

If you can create a couple of simple models that use TGA and DDS (preferably just a cube with a texture), I'll investigate this further.

@looeee
The model I sent you opens nice on ClockStone's ViewFBX, that's why I think it is ok.
I'll make some simple model using one or two textures from each dds and tga from this same model I sent you.

Do you think this could related to the "Real-World Scale" mapping feature on 3ds Max? I think this model has some materials with that option turned on.

@looeee
Here is a simple model using some of the previews one's textures. In the FBX there's 4 objects, two using dds textures and and the other two with the same textures converted to png:
https://1drv.ms/u/s!AuFgusJuBTNnhJ8PG8W4tHOjLHjysg

As you can see in those screenshots, ViewFBX can handle this textures:
image

image

@cmiguelcabral I'm getting the same error here as with the previous model, from the DDSLoader:

Uncaught RangeError: Invalid typed array length: 524288
    at typedArrayConstructByArrayBuffer (<anonymous>)
    at new Uint8Array (native)
    at THREE.DDSLoader.parse [as _parser] (http://threejs.test/examples/js/loaders/DDSLoader.js:252:21)

Can you share the DDS textures separately? I'll test them to see if they load on their own.
Just put them in a zip file and upload it here.

@looeee
There they are:
There you have the textures in DDS and the same ones converted to PNG.

Textures.zip

@looeee
Did you test the textures I sent you?

@cmiguelcabral sorry, I haven't had time to look into this further.

I've just tested them, they are all working correctly when loaded directly with the DDSLoader.
So the issue must be that the approach I'm using for other texture types in the FBXLoader doesn't work with compressed textures.

Was this page helpful?
0 / 5 - 0 ratings