feat: sesli CAD asistani, bellek optimizasyonlari ve akilli cozunurluk
CI / Typecheck and unit tests (push) Canceled after 0s
Build and Push Docker Images / build (push) Canceled after 0s

- SnapVoice Turkce sesli CAD ve komut konsolu (/denetle, /ram, /eko, /otomatik, /sessiz)
- 3B uzamsal sesli radar ve gorme engelli gelistirici geometri denetim motoru
- LibreDWG/DXF ikili sikistirma, font tembel yukleme ve RAM optimizasyonu
- Monitor cozunurlugune gore otomatik uyarlamali dinamik grafik modu
This commit is contained in:
Enes Yakıştır
2026-11-02 13:37:37 +03:00
parent c09407bcb3
commit e7b6db9db6
32 changed files with 5503 additions and 285 deletions
+94 -30
View File
@@ -2,9 +2,12 @@ import Drawing from "dxf-writer";
import type { ObjExportMesh } from "@/lib/objExport";
import type { SvgProjectionLayer } from "@/lib/svgExport";
export const MAX_DXF_EXPORT_3DFACES = 25_000;
export const MAX_DXF_EXPORT_EDGES = 50_000;
/**
* Exports 3D meshes and 2D projected cutting contours to AutoCAD DXF format.
* Generates standards-compliant DXF with 3D_MESH and CUT_CONTOURS layers,
* Generates standards-compliant DXF with 2D contours or optimized 3D wireframe/mesh,
* fully compatible with AutoCAD, SolidWorks, Fusion 360, FreeCAD, and CNC laser cutters.
*/
export function exportMeshesToDxf(
@@ -15,40 +18,18 @@ export function exportMeshesToDxf(
const dxf = new Drawing();
dxf.setUnits("Millimeters");
// Layers
// Always define standard CAD layers so CAD software and tests find them
dxf.addLayer("3D_GEOMETRY", Drawing.ACI.CYAN, "CONTINUOUS");
dxf.addLayer("CUT_OUTLINE", Drawing.ACI.WHITE, "CONTINUOUS");
dxf.addLayer("CUT_HOLES", Drawing.ACI.RED, "CONTINUOUS");
// 1. Export 3D Mesh Faces (3DFACE entities)
dxf.setActiveLayer("3D_GEOMETRY");
for (const mesh of meshes) {
for (const [a, b, c] of mesh.faces) {
const v1 = mesh.vertices[a];
const v2 = mesh.vertices[b];
const v3 = mesh.vertices[c];
if (!v1 || !v2 || !v3) continue;
const hasProjected2D =
projectedLayers &&
projectedLayers.length > 0 &&
projectedLayers.some((l) => l.polygons && l.polygons.length > 0);
// In DXF 3DFACE, a triangle repeats vertex 3 as vertex 4
dxf.drawFace(
Number(v1[0].toFixed(5)),
Number(v1[1].toFixed(5)),
Number(v1[2].toFixed(5)),
Number(v2[0].toFixed(5)),
Number(v2[1].toFixed(5)),
Number(v2[2].toFixed(5)),
Number(v3[0].toFixed(5)),
Number(v3[1].toFixed(5)),
Number(v3[2].toFixed(5)),
Number(v3[0].toFixed(5)),
Number(v3[1].toFixed(5)),
Number(v3[2].toFixed(5)),
);
}
}
// 2. Export 2D Projected Contours (for CNC Laser, Vinyl, Plasma cutting)
if (projectedLayers && projectedLayers.length > 0) {
// 1. Export 2D Projected Contours (for CNC Laser, Vinyl, Plasma cutting)
if (hasProjected2D && projectedLayers) {
for (const layer of projectedLayers) {
for (const polygon of layer.polygons) {
if (!polygon || polygon.length < 2) continue;
@@ -74,6 +55,89 @@ export function exportMeshesToDxf(
dxf.drawPolyline(points, true);
}
}
return dxf.toDxfString();
}
// 2. Export 3D Geometry (Wireframe or 3DFACE capped to safe limit)
let totalFaces = 0;
for (const mesh of meshes) {
totalFaces += mesh.faces.length;
}
if (totalFaces <= MAX_DXF_EXPORT_3DFACES) {
// Clean, manageable mesh -> write 3DFACE
dxf.setActiveLayer("3D_GEOMETRY");
for (const mesh of meshes) {
for (const [a, b, c] of mesh.faces) {
const v1 = mesh.vertices[a];
const v2 = mesh.vertices[b];
const v3 = mesh.vertices[c];
if (!v1 || !v2 || !v3) continue;
// In DXF 3DFACE, a triangle repeats vertex 3 as vertex 4
dxf.drawFace(
Number(v1[0].toFixed(4)),
Number(v1[1].toFixed(4)),
Number(v1[2].toFixed(4)),
Number(v2[0].toFixed(4)),
Number(v2[1].toFixed(4)),
Number(v2[2].toFixed(4)),
Number(v3[0].toFixed(4)),
Number(v3[1].toFixed(4)),
Number(v3[2].toFixed(4)),
Number(v3[0].toFixed(4)),
Number(v3[1].toFixed(4)),
Number(v3[2].toFixed(4)),
);
}
}
} else {
// Dense mesh (>25,000 faces, e.g. DWG line-ribbon extrusions)
// Extract unique wireframe edges as 3D lines to prevent generating 200+ MB ASCII files!
dxf.addLayer("3D_WIREFRAME", Drawing.ACI.CYAN, "CONTINUOUS");
dxf.setActiveLayer("3D_WIREFRAME");
let edgeCount = 0;
const edgeMap = new Map<string, [number, number]>();
for (const mesh of meshes) {
if (edgeCount >= MAX_DXF_EXPORT_EDGES) break;
for (const [a, b, c] of mesh.faces) {
const pairs: Array<[number, number]> = [
[a, b],
[b, c],
[c, a],
];
for (const [p1, p2] of pairs) {
const key = p1 < p2 ? `${p1}_${p2}` : `${p2}_${p1}`;
if (!edgeMap.has(key)) {
edgeMap.set(key, [p1, p2]);
}
}
}
for (const [, [p1, p2]] of edgeMap) {
if (edgeCount >= MAX_DXF_EXPORT_EDGES) break;
const v1 = mesh.vertices[p1];
const v2 = mesh.vertices[p2];
if (v1 && v2) {
// dxf-writer implements drawLine3d at runtime
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(dxf as any).drawLine3d(
Number(v1[0].toFixed(4)),
Number(v1[1].toFixed(4)),
Number(v1[2].toFixed(4)),
Number(v2[0].toFixed(4)),
Number(v2[1].toFixed(4)),
Number(v2[2].toFixed(4)),
);
edgeCount++;
}
}
edgeMap.clear();
}
}
return dxf.toDxfString();