var cub_texture,loader; cub_texture= new THREE.Texture(); loader= new THREE.ImageLoader(); loader.addEventListener('load',function(event){ cub_texture.image=event.content; cub_texture.needsUpdate=true; }); loader.load('./img/textBox.jpg'); var cub_material = new THREE.MeshBasicMaterial({ map:cub_texture, overdraw:true }); 

The page on which the code is executed:

I tried it this way, but it also does not work:

 loader.load(''./img/textBox.jpg'',function(event){ cub_texture.image=event.content; cub_texture.needsUpdate=true; }); 

How to do right?

  • '' ./img/textBox.jpg '' Did you write two single quotes instead of double quotes? Or did you miss this typo when you asked a question? - Duck Learns to Hide
  • In life, I didn’t work with three.js, but first, obviously, it is necessary to do it in the second way, since the loader never has a node house and the methods from the home interface like "addEventListener" will not work. Secondly, not the event comes to the callback method of the load, but the image itself. Thirdly. You have a function on the page "animatuion" called, do not be so. - Duck Learns to Hide

1 answer 1

 var cube_geometry = new THREE.CubeGeometry(100, 100, 100); cube_two_texture = new THREE.TextureLoader().load( 'img.jpg' );//load texture var cube_two_material = new THREE.MeshBasicMaterial({map: cube_two_texture}); var cube_two = new THREE.Mesh(cube_geometry, cube_two_material); cube_two.position.y = -200; scene.add(cube_two); 

like that