Files
snapcad-studio/tests/unit/objExport.test.ts
T
Enes Yakıştır 33b0940012
Build and Push Docker Images / build (push) Canceled after 0s
CI / Typecheck and unit tests (push) Canceled after 0s
feat: SnapCAD Studio'yu YakHub deposuna taşı
- DWG/DXF içe aktarma ve .skf yeniden açma düzeltmeleri

- YakNet Bulut eşitlemede boş/eski kopya koruması ve yerel-only proje bildirimi

- Panelden içe aktarma duyuruları ve erişilebilir Türkçe hata mesajları

- AGPL-3.0 lisansı, README ve YakHub bağlantıları
2026-10-25 18:20:21 +03:00

56 lines
2.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { exportMeshesToObj, generateMtlContent, type ObjExportMesh } from "@/lib/objExport";
function duplicatedTetrahedron(): ObjExportMesh {
const a: [number, number, number] = [0, 0, 0];
const b: [number, number, number] = [10, 0, 0];
const c: [number, number, number] = [0, 10, 0];
const d: [number, number, number] = [0, 0, 10];
return {
name: "closed_tetrahedron",
vertices: [a, c, b, a, b, d, b, c, d, c, a, d],
faces: [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]],
};
}
describe("OBJ export", () => {
it("preserves OBJ's conventional Y-up coordinates", () => {
const obj = exportMeshesToObj([duplicatedTetrahedron()]);
const vertices = obj.split("\n").filter((line) => line.startsWith("v "));
expect(vertices).toContain("v 0 0 10");
expect(vertices).toContain("v 0 10 0");
});
it("welds coincident triangle vertices so a closed mesh has no boundary edges", () => {
const obj = exportMeshesToObj([duplicatedTetrahedron()]);
const vertices = obj.split("\n").filter((line) => line.startsWith("v "));
const faces = obj.split("\n").filter((line) => line.startsWith("f "));
const edgeUse = new Map<string, number>();
faces.forEach((line) => {
const [a, b, c] = line.slice(2).trim().split(/\s+/).map(Number);
[[a, b], [b, c], [c, a]].forEach(([start, end]) => {
const key = start < end ? `${start}:${end}` : `${end}:${start}`;
edgeUse.set(key, (edgeUse.get(key) ?? 0) + 1);
});
});
expect(vertices).toHaveLength(4);
expect(faces).toHaveLength(4);
expect([...edgeUse.values()].every((count) => count === 2)).toBe(true);
});
it("generates companion .mtl material library and references it in .obj", () => {
const mesh = duplicatedTetrahedron();
const colors = { closed_tetrahedron: "#ff5500" };
const mtl = generateMtlContent([mesh], colors);
const obj = exportMeshesToObj([mesh], { mtlFileName: "model.mtl", colors });
expect(mtl).toContain("newmtl Material_closed_tetrahedron");
expect(mtl).toContain("Kd 1 0.3333 0");
expect(obj).toContain("mtllib model.mtl");
expect(obj).toContain("usemtl Material_closed_tetrahedron");
});
});