Skip to content

JSONLoader(), callback called before uv texture image is loaded #4602

@ssatguru

Description

@ssatguru

I have an object (exported from Blender) which is uv mapped and has a uv texture image.
If I use JSONLoader() to load it , the callback function is called before the image is loaded.
If I immediately try to render it in the callback, it fails.
If I wait few seconds and render it, it works.
This fails

var loader = new THREE.JSONLoader(true);
loader.load('Carl.js',
            function ( geometry, materials ) {
                var material = new THREE.MeshFaceMaterial( materials );
                mesh = new THREE.Mesh(geometry, material);
                scene.add(mesh);
                renderer.render(scene, camera);
            }
);

This works

var loader = new THREE.JSONLoader(true);
loader.load('Carl.js',
            function ( geometry, materials ) {
                var material = new THREE.MeshFaceMaterial( materials );
                mesh = new THREE.Mesh(geometry, material);
                scene.add(mesh);
                setTimeout(
                    function(){
                        renderer.render(scene, camera);
                    },
                    2000
                );
            }
);

I took a quick look at the source

JSONLoader calls 
    Loader.initMaterials() which calls
        Loader.createMaterial() which calls
            load_image()

load_image loads image asynchronously.
Looks like JSONLoader doesn't wait on this and calls callback function immediately.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions