feat: add STL file upload button and implement flat-bottom clamp logic in export

This commit is contained in:
CNCKitchen
2026-03-17 17:47:26 +01:00
parent 1d3e756245
commit cbe7e7ffef
2 changed files with 22 additions and 0 deletions
+14
View File
@@ -19,6 +19,7 @@ let currentBounds = null; // bounds of the original geometry
let activeMapEntry = null; // { name, texture, imageData, width, height }
let previewMaterial = null;
let isExporting = false;
let previewDebounce = null;
// ── Exclusion state ───────────────────────────────────────────────────────────
let excludedFaces = new Set(); // triangle indices in currentGeometry
@@ -636,6 +637,19 @@ async function handleExport() {
);
}
// Flat-bottom clamp: when bottom faces are masked (bottomAngleLimit > 0),
// any vertex that ended up below the original model's bottom layer gets
// snapped back up to that Z. Only the Z-value is changed.
if (settings.bottomAngleLimit > 0) {
const bottomZ = currentBounds.min.z;
const posArr = finalGeometry.attributes.position.array;
for (let i = 2; i < posArr.length; i += 3) {
if (posArr[i] < bottomZ) posArr[i] = bottomZ;
}
finalGeometry.attributes.position.needsUpdate = true;
finalGeometry.computeVertexNormals();
}
setProgress(0.97, 'Writing STL…');
await yieldFrame();