Skip to content

Commit 7c91654

Browse files
committed
Fix rounding of values close to 0 when computing smooth normals
1 parent 773eb0d commit 7c91654

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/webgl/p5.Geometry.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,10 @@ p5.Geometry = class Geometry {
291291
const vertexIndices = {};
292292
const uniqueVertices = [];
293293

294+
const power = Math.pow(10, roundToPrecision);
295+
const rounded = val => Math.round(val * power) / power;
294296
const getKey = vert =>
295-
`${vert.x.toFixed(roundToPrecision)},${vert.y.toFixed(roundToPrecision)},${vert.z.toFixed(roundToPrecision)}`;
297+
`${rounded(vert.x)},${rounded(vert.y)},${rounded(vert.z)}`;
296298

297299
// loop through each vertex and add uniqueVertices
298300
for (let i = 0; i < vertices.length; i++) {

0 commit comments

Comments
 (0)