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

若如初见. 提交于 2020-01-01 11:46:10

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/35015251/how-do-i-load-multiple-textures-with-the-new-three-textureloader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!