【发布时间】:2019-10-11 11:35:45
【问题描述】:
AFrame 性能文档 (https://github.com/aframevr/aframe/blob/master/docs/introduction/best-practices.md) 建议使用预烘焙光照。我已经这样做了,所以现在我希望我的网格使用平面着色。但是我不清楚如何做到这一点?
<a-gltf-model src="..." material="shader: flat">
这没有效果。我还尝试迭代 three.js 中的节点并将每种材料设置为平面,但这也不起作用。尝试一堆东西的完整代码:
<html>
<head>
<script src="https://aframe.io/releases/0.9.2/aframe.min.js"></script>
</head>
<body>
<a-scene background="color: #000000">
<!-- Box.gltf from https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/Box/glTF -->
<a-gltf-model id="gltf" src="Box.gltf" position="-1 1 -2"></a-gltf-model>
<a-box position="1 1 -2" material="shader: flat; color: red"></a-box>
</a-scene>
<script>
var office = document.getElementById( 'gltf' );
office.addEventListener( 'object3dset', () => {
const mesh = office.getObject3D( 'mesh' );
mesh.children[0].material.flatShading = true;
mesh.children[0].material.needsUpdate = true;
mesh.children[0].geometry.normalsNeedUpdate = true;
mesh.traverse( node => {
if ( node.isMesh === undefined || node.isMesh === false ) {
return;
}
node.material.flatShading = true;
node.material.needsUpdate = true;
node.geometry.normalsNeedUpdate = true;
} );
} );
</script>
</body>
</html>
呈现如下:
网格(左侧)有阴影,而盒子(右侧)是平面阴影。如何将我的网格设置为使用平面着色?
【问题讨论】:
-
three.js 中的“平面阴影”表示阴影是“分面的”。也许你想要的是“不亮的阴影”。为此使用
MeshBasicMaterial;它不响应灯光。 -
感谢您的评论并为使用不正确的术语道歉。是的,“未点亮的阴影”听起来是对的。你能建议我如何在上面的 AFrame/Three.js 代码中做到这一点吗?
-
哦,这确实有效!谢谢!将发布答案