JSONLoader(), callback called before uv texture image is loaded
See original GitHub issueI 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.
Issue Analytics
- State:
- Created 9 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Three.js r72 - Texture marked for update but image is ...
Texture loading is asynchronous. You need to put the bulk of your code in the loader callback. texture = THREE.ImageUtils.
Read more >Working with Blender - Packt Hub
In this function, we specify the URL we want to load (points to the exported JSON file), a callback that is called when...
Read more >Texture – three.js docs
An image object, typically created using the TextureLoader.load method. This can be any image (e.g., PNG, JPG, GIF, DDS) or video (e.g., MP4,...
Read more >CS307: Texture Mapping
There are two key parts to the code: loading the image texture and mapping ... provide an anonymous callback function that calls the...
Read more >WebGL2 Using 2 or More Textures
In this case we'll wait for all the images to load before we draw ... It creates a new Image object, sets the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

https://www.youtube.com/watch?v=wkDd-x0EkFU
@mrdoob any workaround? How can
LoadingManagerhelp on this ? Shall I provide a fiddle ? I can reproduce the issue with a 40kb texture on a 3G network