【发布时间】:2021-07-07 05:22:47
【问题描述】:
我正在尝试从非索引 BufferGeometry 开始平滑网格的法线。 This question has been answered before 但是 Three.js api 已经发生了很大的变化,我无法让它在 r130 上工作
据我了解,我需要先合并顶点以获得索引的 BufferGeometry,然后重新计算法线,但这似乎不起作用。
这是一个使用默认立方体的最小示例:
// Scene
const scene = new THREE.Scene();
// Geometry
const boxGeometry = new THREE.BoxGeometry(.7,.7,.7);
// Materials
const shadedMaterial = new THREE.MeshStandardMaterial();
shadedMaterial.metalness = 0.4;
shadedMaterial.roughness = 0.4;
shadedMaterial.color = new THREE.Color(0xffffff);
// Mesh
const smoothBoxGeometry=BufferGeometryUtils
.mergeVertices(new THREE.BufferGeometry().copy(boxGeometry))
smoothBoxGeometry.computeVertexNormals();
smoothBoxGeometry.computeBoundingBox();
smoothBoxGeometry.normalizeNormals();
const box = new THREE.Mesh(smoothBoxGeometry, shadedMaterial);
scene.add(box);
flat shaded cube instead of expected smooth shaded cube
我错过了什么?
【问题讨论】:
-
问题被回答并接受后,请勿编辑问题。
标签: javascript three.js rendering smoothing normals