javascript - 用 ObjectLoader 加载的三个.js 对象无法更改不透明度
问题描述
我有一个存储在 JSON 文件中的 THREE.js 对象。我想设置对象的不透明度,但没有任何改变,仍然完全不透明。
我在 THREE.WebGLRenderer 104、Google Chrome 76、Windows 10 上运行。我已经尝试了在 google 上找到的所有其他东西,但没有任何改变。
loader.load(
"objects/brain-simple-mesh.json",
function ( obj ) {
obj.traverse((node) => {
if (node.material) {
node.material.opacity = 0.5;
node.material.alphaTest = 0.5;
node.material.transparent = true;
}
});
window.group = new THREE.Object3D();
//reajustments
obj.rotation.z = -0.5;
obj.rotation.x = 0.09;
group.add(window.obj=obj);
scene.add( group );
//look at object
camera.position.z = 10;
setInterval(function(){
//rotate object
window.group.rotation.y+=0.03;
}, 100);
},
function ( xhr ) {
//progress bar
document.getElementById('loader').style.display = 'none';
document.getElementById('progress').style.width = (xhr.loaded / ( xhr.total > 0 ? xhr.total : 9719635 ) * 100) + '%';
},
function ( err ) {
//error
console.error( 'An error happened' );
});
我希望看到一个半透明的大脑模型,我得到的是一些便宜的、完全不透明的盗版模型。
网址:http: //im--age.rf.gd/u0/Terminal%20Man/
解决方案
当我检查您的node.material
对象时,我注意到虽然透明度设置为 true,并且不透明度设置为 0.5,但该depthWrite
值仍设置为 true。然后我查看了您的代码,发现您正在设置node.depthWrite = false
. 但这需要在材质上设置。尝试:
node.material.depthWrite = false;
当我下载您的 JSON 并在本地运行您的代码时,这有所不同。
因此,例如,在您链接到的网站上,您obj.traverse()
应该如下所示:
obj.traverse((node) => {
if (node.material) {
node.material.transparent = true;
node.material.opacity = 0.5;
node.material.depthWrite = false; // not node.depthWrite
}
});
推荐阅读
- reactjs - React 中的即时实时通知
- nginx - NGINX:如何管理不同的可见性(LAN 与 Internet)
- javascript - 如何创建粗体和斜体文本等...像stackoverflow?
- sql - MS SQL Server - 如何使用分层查询创建视图
- excel - 使用带有空列的 VBA 自动双击排序列
- node.js - 使用 nodejs (electron) 成为 SIP UA
- javascript - 如何让组件“等待”状态在反应中更新?
- amazon-web-services - 使用java获取集群下的文档数据库实例
- wso2 - 在 Kubernetes 设置中的 WSO2 API Manager 3.2.0 中找不到请求目标错误的有效证书路径
- r - 使用 MLeval 包的颜色线和颜色图例的错误组合