Skip to content

Commit 6f3a49f

Browse files
authored
Merge branch 'dev-2.0' into webgpu-perf
2 parents eda2725 + 61a824f commit 6f3a49f

6 files changed

Lines changed: 100 additions & 1 deletion

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
.nyc_output/*
44
# .vscode/settings.json
5+
# optional local preferences for vscode
6+
local.code-workspace
7+
58
node_modules/*
69

710
analyzer/

.vscode/extensions.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
// List of extensions which should be recommended for users of this workspace.
66
"recommendations": [
7-
"eg2.vscode-npm-script",
87
"yzhang.markdown-all-in-one",
98
"dbaeumer.vscode-eslint"
109
],

src/webgl/ShapeBuilder.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,27 @@ export class ShapeBuilder {
313313
}
314314
}
315315

316+
// Normalize nearly identical consecutive vertices to prevent tessellation artifacts
317+
// This addresses numerical precision issues in libtess when consecutive vertices
318+
// have coordinates that are almost (but not exactly) equal (e.g., differing by ~1e-8)
319+
const epsilon = 1e-6;
320+
for (const contour of contours) {
321+
const stride = this.tessyVertexSize;
322+
for (let i = stride; i < contour.length; i += stride) {
323+
const prevX = contour[i - stride];
324+
const prevY = contour[i - stride + 1];
325+
const currX = contour[i];
326+
const currY = contour[i + 1];
327+
328+
if (Math.abs(currX - prevX) < epsilon) {
329+
contour[i] = prevX;
330+
}
331+
if (Math.abs(currY - prevY) < epsilon) {
332+
contour[i + 1] = prevY;
333+
}
334+
}
335+
}
336+
316337
const polyTriangles = this._triangulate(contours);
317338

318339
// If there were no valid faces, we still want to use the original vertices

test/unit/visual/cases/webgl.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,4 +1242,77 @@ visualSuite('WebGL', function() {
12421242
screenshot();
12431243
});
12441244
});
1245+
1246+
visualSuite('Tessellation', function() {
1247+
visualTest('Handles nearly identical consecutive vertices', function(p5, screenshot) {
1248+
p5.createCanvas(400, 400, p5.WEBGL);
1249+
1250+
const contours = [
1251+
[
1252+
[-3.8642425537109375, -6.120738636363637, 0],
1253+
[3.2025188099254267, -6.120738636363637, 0],
1254+
[3.2025188099254267, -4.345170454545455, 0],
1255+
[-3.8642425537109375, -4.345170454545455, 0],
1256+
[-3.8642425537109375, -6.120738636363637, 0]
1257+
],
1258+
[
1259+
[-1.8045834628018462, 4.177556818181818, 0],
1260+
[-1.8045834628018462, -9.387784090909093, 0],
1261+
[0.29058699174360836, -9.387784090909093, 0],
1262+
[0.2905869917436083, 3.609374411367136, 0],
1263+
[0.31044303036623855, 4.068235883781435, 0],
1264+
[0.38522861430307975, 4.522728865422799, 0],
1265+
[0.548044378107245, 4.941051136363637, 0],
1266+
[0.8364672032828204, 5.2932224887960775, 0],
1267+
[1.2227602871981542, 5.526988636363637, 0],
1268+
[1.6572258237923885, 5.634502949876295, 0],
1269+
[2.101666537198154, 5.669034090909091, 0],
1270+
[2.6695604948237173, 5.633568761673102, 0],
1271+
[3.0249619917436084, 5.5625, 0],
1272+
[3.4510983553799726, 7.4446022727272725, 0],
1273+
[2.8568950819856695, 7.613138889205699, 0],
1274+
[2.3751340936529037, 7.676962586830456, 0],
1275+
[1.8892600236717598, 7.693181792704519, 0],
1276+
[1.2922705720786674, 7.649533731133848, 0],
1277+
[0.7080836288276859, 7.519788939617751, 0],
1278+
[0.14854153719815422, 7.311434659090909, 0],
1279+
[-0.38643934048179873, 7.00959666478984, 0],
1280+
[-0.858113258144025, 6.61653855366859, 0],
1281+
[-1.25415732643821, 6.1484375, 0],
1282+
[-1.5108595282965422, 5.697682732328092, 0],
1283+
[-1.6824918355513252, 5.207533878495854, 0],
1284+
[-1.7762971052870198, 4.695933154267308, 0],
1285+
[-1.8045834628018462, 4.177556818181818, 0]
1286+
]
1287+
];
1288+
1289+
p5.background('red');
1290+
p5.push();
1291+
p5.stroke(0);
1292+
p5.fill('#EEE');
1293+
p5.scale(15);
1294+
p5.beginShape();
1295+
for (const contour of contours) {
1296+
p5.beginContour();
1297+
for (const v of contour) {
1298+
p5.vertex(...v);
1299+
}
1300+
p5.endContour();
1301+
}
1302+
p5.endShape();
1303+
1304+
p5.stroke(0, 255, 0);
1305+
p5.strokeWeight(5);
1306+
p5.beginShape(p5.POINTS);
1307+
for (const contour of contours) {
1308+
for (const v of contour) {
1309+
p5.vertex(...v);
1310+
}
1311+
}
1312+
p5.endShape();
1313+
p5.pop();
1314+
1315+
screenshot();
1316+
});
1317+
});
12451318
});
6.57 KB
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}

0 commit comments

Comments
 (0)