【问题标题】:Three.js use multiple materials on one meshThree.js 在一个网格上使用多种材质
【发布时间】:2021-03-23 04:06:50
【问题描述】:

我正在尝试了解如何将多种材质添加到网格中。我想采用现有材料并将另一种稍微透明的材料应用于现有网格。现在,将它作为一个数组传递它就消失了。我知道我错过了一些东西,只是不确定那是什么。最终目标是让新材料的不透明度在现有材料上输入/输出。

原创素材

const originalMaterial = child.material.clone();

新材料

const newMaterial = new THREE.MeshStandardMaterial({
 name: 'New Mat',
 map: newTexture,
 emissiveMap: newTextureMap,
 side: THREE.DoubleSide,
 opacity: .5,
 transparent: true
});

组合它们

child.material = [originalMaterial, newMaterial]
child.material.needsUpdate = true

【问题讨论】:

    标签: javascript three.js aframe 8thwall-web


    【解决方案1】:

    WebGL 不允许在单个网格上使用多种材质。这就是THREE.Mesh 构造函数only allows one geometry, and one material 的原因。

    要做你想做的,你可以创建两个网格,一个材质的透明度设置为 0.5。但更常见的是,您只使用单个网格,并分配不透明度through the .alphaMap texture 的变化。这将为您提供更大的灵活性,因为您可以在单个对象上拥有更多透明度值,而无需为每个对象创建新材质:

    var textureLoader = new THREE.TextureLoader();
    var alphaTexture = textureLoader.load("path/to/alpha.png");
    mesh.material.alphaMap = alphaTexture;
    
    mesh.material.transparent = true; // <- don't forget this!
    

    【讨论】:

    • 这是个好主意!我将在我试图实现这一目标的其他模型上进行尝试。现在,我能够克隆我的网格并将我的新材质添加到其中,然后将克隆的网格淡入/淡出,这就是诀窍。
    猜你喜欢
    • 2023-03-23
    • 2015-01-16
    • 2017-06-14
    • 2013-03-23
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 1970-01-01
    相关资源
    最近更新 更多