I’m trying to edit the positions of an IcosahedronGeometry, but when I do then it removes the smooth shading on it. Even if I just iterate through the vertices and set them equal to their default positions and call computeVertexNormals, then this still breaks the smooth shading. Is there something more that needs to be done here?
var sphereGeometry = new THREE.IcosahedronGeometry( 30, 3 );
for (let i = 0; i < sphereGeometry.attributes.position.count; i++) {
const x = sphereGeometry.attributes.position.getX(i);
const y = sphereGeometry.attributes.position.getY(i);
const z = sphereGeometry.attributes.position.getZ(i);
sphereGeometry.attributes.position.setXYZ(i, x, y, z);
}
sphereGeometry.computeVertexNormals();
var sphereMaterial = new THREE.MeshLambertMaterial( {color: 0x8888ff} );
var sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
scene.add(sphere);
var sphereGeometry = new THREE.IcosahedronGeometry( 30, 3 );
for (let i = 0; i < sphereGeometry.attributes.position.count; i++) {
const x = sphereGeometry.attributes.position.getX(i);
const y = sphereGeometry.attributes.position.getY(i);
const z = sphereGeometry.attributes.position.getZ(i);
sphereGeometry.attributes.position.setXYZ(i, x, y + 20, z); // shift the geometry 20 units up
}
//sphereGeometry.computeVertexNormals();
I’ve got smooth shading.
IcoshedronGeometry is a non-indexed buffer geometry.
so that works only if you’re not changing the shape of the mesh. If the shape changes the normals will still reflect the default positions, which is why I was calling the computeVertexNormals. I can create another codepen later to illustrate that