【问题标题】:Is there a way to add different textures to an object with TextureLoader.load有没有办法使用 TextureLoader.load 向对象添加不同的纹理
【发布时间】:2017-02-10 06:00:24
【问题描述】:

我想为盒子的每个面添加不同的纹理,但我不确定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 中添加更多图像,还是必须使用其他方法?

【问题讨论】:

    标签: javascript three.js load loader


    【解决方案1】:

    您可以使用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);
    

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

    【讨论】:

    • 这确实有效!但现在我不确定如何真正让面孔看起来不同?因为它一次只在所有墙壁上显示一种纹理。
    • @acurate 问题是您使用的是MeshLambertMaterial,它只允许为整个网格提供贴图,其中贴图被复制到所有面。
    • @acurate 如果你想实现人脸贴图,请看this帖子。
    猜你喜欢
    • 2021-09-05
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2020-06-27
    • 2020-04-12
    • 2018-05-13
    • 1970-01-01
    相关资源
    最近更新 更多