< Retour

Three.js mesh smoothing

mesh.material.flatShading = false;
    
mesh.mergeVertices(); // ajouter cette ligne si ça ne marche pas sans
mesh.computeVertexNormals();
// mesh.computeFaceNormals();

Si l'on part d'une BufferGeometry

Il faut d'abord convertir en Geometry, avant de reconvertir en BufferGeometry

const tempGeo = new THREE.Geometry().fromBufferGeometry(child.geometry);
tempGeo.mergeVertices();
tempGeo.computeVertexNormals();
tempGeo.computeFaceNormals();
child.geometry = new THREE.BufferGeometry().fromGeometry(tempGeo);

Dans le cas d'un objet composé

shoes.traverse(function (child) {
    if (child instanceof THREE.Mesh) {
        child.material.flatShading = false;
        const tempGeo = new THREE.Geometry().fromBufferGeometry(child.geometry);
        tempGeo.mergeVertices();
        tempGeo.computeVertexNormals();
        tempGeo.computeFaceNormals();
        child.geometry = new THREE.BufferGeometry().fromGeometry(tempGeo);
    }
});