Three.js MeshBasicMaterial无法正常工作 [英] Three.js MeshBasicMaterial doesn't work as expected

查看:930
本文介绍了Three.js MeshBasicMaterial无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Three.js创建纹理.

I am trying to create a texture with Three.js.

我的texture_f1来源是一个.png文件,意味着您可以通过它看到背景.

My source of texture_f1 is a .png file witch means you can see the background through it.

问题是,如果我尝试设置背景color: 0xffffff,它不会 与map:结合使用.

The problem is that if i try to set background color: 0xffffff it doesn't work in combination with map:.

如果仅设置color:0xffffff,则返回白色,但是当与map一起使用时:像var material_f1 = new THREE.MeshBasicMaterial({ map: texture_f1, color: 0xffffff});这样,我可以通过.png黑色看到背景.

If i set only the color:0xffffff , it return a white, but when use with map: like this var material_f1 = new THREE.MeshBasicMaterial({ map: texture_f1, color: 0xffffff}); i can see the background through the .png black .

推荐答案

如果具有透明纹理,则必须将material.transparent设置为true.

If you have a transparent texture, you must set material.transparent to true.

var material = new THREE.MeshBasicMaterial( {
    color: 0xffffff,
    map: texture,
    transparent: true
} )

请注意,材质颜色不会显示"透明纹理-它会着色纹理.

Note that the material color does not "show through" the transparent texture -- it tints the texture.

如果要使材质颜色显示"透明纹理,则需要使用ShaderMaterial并创建自定义着色器.

If you want the material color to "show through" the transparent texture, then you need to use ShaderMaterial, instead, and create a custom shader.

此stackoverflow答案.

three.js r.71

three.js r.71

这篇关于Three.js MeshBasicMaterial无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆