Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I load multiple textures with the new THREE.TextureLoader

How do I load multiple textures with the new THREE.TextureLoader from Three.js ?

At the moment I'm loading my textures like this:

  var texture1 = THREE.ImageUtils.loadTexture('texture1.jpg');
  var texture2 = THREE.ImageUtils.loadTexture('texture2.jpg');
  var texture3 = THREE.ImageUtils.loadTexture('texture3.jpg');
  var texture4 = THREE.ImageUtils.loadTexture('texture4.jpg');
  var texture5 = THREE.ImageUtils.loadTexture('texture5.jpg');
  ...

And Google chrome's developer tool give the following warning:

THREE.ImageUtils.loadTexture is being deprecated. Use THREE.TextureLoader() instead.

My attempt with the new THREE.TextureLoader:

var loader = new THREE.TextureLoader();

loader.load('texture1.jpg',function ( texture1 ) {});
loader.load('texture2.jpg',function ( texture2 ) {});
loader.load('texture3.jpg',function ( texture3 ) {});
loader.load('texture4.jpg',function ( texture4 ) {});
loader.load('texture5.jpg',function ( texture5 ) {});

What am I doing wrong?

TextureLoader

like image 466
Alexander Hein Avatar asked Jan 26 '16 13:01

Alexander Hein


Video Answer


1 Answers

The loader returns the texture, its actually pretty straightforward:

var loader = new THREE.TextureLoader();
var texture1 = loader.load('texture1.jpg');
var texture2 = loader.load('texture2.jpg');

You can see that the r74dev examples already got updated with the new syntax: https://github.com/mrdoob/three.js/blob/dev/examples/webgl_decals.html#L49-L51

like image 132
Falk Thiele Avatar answered Nov 14 '22 22:11

Falk Thiele