如何使用新的 THREE.TextureLoader 加载多个纹理 [英] How do I load multiple textures with the new THREE.TextureLoader
问题描述
如何使用 Three.js 的新 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');
...
Google chrome 的开发者工具给出以下警告:
And Google chrome's developer tool give the following warning:
THREE.ImageUtils.loadTexture 已被弃用.用THREE.TextureLoader() 代替.
THREE.ImageUtils.loadTexture is being deprecated. Use THREE.TextureLoader() instead.
我对新的 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 ) {});
我做错了什么?
推荐答案
加载器返回纹理,其实很简单:
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');
您可以看到 r74dev 示例已经使用新语法进行了更新:https://github.com/mrdoob/three.js/blob/dev/examples/webgl_decals.html#L49-L51
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
这篇关于如何使用新的 THREE.TextureLoader 加载多个纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!