有没有办法用 TextureLoader.load 向对象添加不同的纹理

Is there a way to add different textures to an object with TextureLoader.load

我想为盒子的每个面添加不同的纹理,但我不确定 loader.load 是否是这样做的方法,现在我有:

loader.load('img/brick.jpg', function ( texture ){
    var boxGeometry = new THREE.BoxGeometry( 3, 3, 3 );
    var boxMaterial =  new THREE.MeshLambertMaterial({
        map: texture,
        overdraw: 10 
    });

    var box = new THREE.Mesh( boxGeometry, boxMaterial );
    box.castShadow = true;

    scene.add(box);
}

是否可以在 loader.load 中添加更多图片,还是我必须使用其他方法?

您可以使用 loader.load 加载图像并将其存储在变量中:

var loader = new THREE.TextureLoader();

var brick = loader.load('img/brick.jpg');
var occlusion = loader.load('img/ao.jpg'); //Example texture
//More textures here

然后您可以像这样应用它:

var boxGeometry = new THREE.BoxGeometry( 3, 3, 3 );
var boxMaterial = new THREE.MeshLambertMaterial({ 
    map: brick,
    aoMap: occlusion, //An example use 
    overdraw: 10 
});
var box = new THREE.Mesh( boxGeometry, boxMaterial );
box.castShadow = true;

scene.add(box);

无需加载纹理并使用匿名回调,只需加载纹理,将其存储在变量中,然后在需要的地方应用。