|
1 | 1 | import { BoxGeometry, CylinderGeometry, Vector3 } from 'three'; |
2 | 2 | import { TextGeometry } from 'three/addons/geometries/TextGeometry.js'; |
3 | 3 | import { Font, FontLoader } from 'three/addons/loaders/FontLoader.js'; |
| 4 | +import { mergeVertices } from 'three/addons/utils/BufferGeometryUtils.js'; |
4 | 5 | import { ADDITION, Brush, Evaluator, SUBTRACTION } from 'three-bvh-csg'; |
5 | 6 |
|
6 | 7 | import { MathMinMax } from '$lib/Math'; |
@@ -506,25 +507,32 @@ const generateMesh = async ( |
506 | 507 | await reportProgress(); // Circle added to positive mesh |
507 | 508 | } |
508 | 509 |
|
| 510 | + // Fix non-manifold edges: snap near-duplicate CSG seam vertices to identical values. |
| 511 | + // mergeVertices: non-indexed → indexed (deduplicates vertices within epsilon) |
| 512 | + // toNonIndexed: indexed → non-indexed (expands back, but shared edge vertices are now exact) |
| 513 | + const gMain = mergeVertices(mesh.geometry).toNonIndexed(); |
| 514 | + const gHollow = mergeVertices(meshHollow.geometry).toNonIndexed(); |
| 515 | + const gPositive = mergeVertices(meshPositive.geometry).toNonIndexed(); |
| 516 | + |
509 | 517 | return { |
510 | 518 | main: { |
511 | | - vertexArray: new Float32Array(mesh.geometry.attributes['position'].array), |
| 519 | + vertexArray: new Float32Array(gMain.attributes['position'].array), |
512 | 520 | dimensions: { |
513 | 521 | width: adjustedPanelWidth + 2 * EDGE_THICKNESS, |
514 | 522 | height: adjustedPanelHeight + 2 * EDGE_THICKNESS, |
515 | 523 | depth: needHeight + BOTTOM_THICKNESS |
516 | 524 | } |
517 | 525 | }, |
518 | 526 | hollow: { |
519 | | - vertexArray: new Float32Array(meshHollow.geometry.attributes['position'].array), |
| 527 | + vertexArray: new Float32Array(gHollow.attributes['position'].array), |
520 | 528 | dimensions: { |
521 | 529 | width: adjustedPanelWidth + 2 * EDGE_THICKNESS, |
522 | 530 | height: adjustedPanelHeight + 2 * EDGE_THICKNESS, |
523 | 531 | depth: hollowHeight + BOTTOM_THICKNESS |
524 | 532 | } |
525 | 533 | }, |
526 | 534 | positive: { |
527 | | - vertexArray: new Float32Array(meshPositive.geometry.attributes['position'].array), |
| 535 | + vertexArray: new Float32Array(gPositive.attributes['position'].array), |
528 | 536 | dimensions: { |
529 | 537 | width: panel.width, |
530 | 538 | height: panel.height, |
|
0 commit comments