Hello!
I want to texturize a json object, loaded with object loader:
var objectLoader = new THREE.ObjectLoader();
objectLoader.load("js/teapot-claraio.json", function ( obj ) {
obj.position.set(0,-1,0);
scene.add(obj);
console.log(obj);
// obj.scale.set(2,2,2);
// var textureLoader = new THREE.TextureLoader();
// teapotTexture = textureLoader.load('img/textures/crate0/crate0_diffuse.png',
// function (material) {
// obj.material.map = material;
// console.log('material loaded!');
// }
// );
var imgObj = new Image();
imgObj.onload = function() {
var textureLoader = new THREE.TextureLoader();
teapotTexture = textureLoader.load(imgObj.src,
function (material) {
obj.material.map = material;
console.log('material loaded!');
}
);
}
imgObj.src = 'img/textures/crate0/crate0_diffuse.png';
} );
but the texture may not load on first loading of the page, even if I use imgObj.onload. Why it is happening?