fix(assembly): 조립 설명서 카메라 범위를 부품별로 따로 내보내 계산 — 열린 메시 STL이 합치기에 실패해 카메라가 잘리던 문제

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-05 23:11:23 +09:00
1 parent e34ba072a7
commit 6fa535376f
1 file changed
+24 -11
+24 -11
View File
@@ -228,19 +228,32 @@ async function doRender(workspace: string, projectId: string, assembly: Assembly
return { ok: true, png };
};
// 부품을 하나씩 따로 내보내 범위를 합친다. 한꺼번에 내보내면 OpenSCAD가 부품들을 합치(union)는데,
// import한 STL이 닫힌 메시가 아니면 합치기가 실패해 닫힌 부품만 남은 채 범위가 작게 계산되고 카메라가 잘린다.
// 변환만 붙은 부품 하나는 합치기를 거치지 않으므로 이 방식은 열린 메시에도 안전하다.
const bboxOf = async (items: { part: AssemblyPart; exploded?: boolean }[]) => {
const n = ++counter;
const scadFile = path.join(tmp, `b${n}.scad`);
const stl = path.join(tmp, `b${n}.stl`);
const ex = assembly.explode;
fs.writeFileSync(scadFile, buildWrapperScad(sc.abs, items.map(i => ({
call: i.part.call,
offset: i.exploded ? [i.part.offset[0] * ex, i.part.offset[1] * ex, i.part.offset[2] * ex] as [number, number, number] : undefined,
}))));
// 2021.01은 기본이 ASCII STL이라 binstl로 강제(readStlBBox는 바이너리만 지원)
const r = await runOpenscad(['-o', stl, '--export-format', 'binstl', scadFile], 120_000);
if (!r.ok) return { ok: false as const, error: `형상 범위 계산 실패: ${r.detail}` };
try { return { ok: true as const, bbox: readStlBBox(stl) }; } catch (e: any) { return { ok: false as const, error: `형상 범위 계산 실패: ${String(e?.message || e)}` }; }
const min: [number, number, number] = [Infinity, Infinity, Infinity];
const max: [number, number, number] = [-Infinity, -Infinity, -Infinity];
let triangleCount = 0;
for (const i of items) {
const n = ++counter;
const scadFile = path.join(tmp, `b${n}.scad`);
const stl = path.join(tmp, `b${n}.stl`);
fs.writeFileSync(scadFile, buildWrapperScad(sc.abs, [{
call: i.part.call,
offset: i.exploded ? [i.part.offset[0] * ex, i.part.offset[1] * ex, i.part.offset[2] * ex] as [number, number, number] : undefined,
}]));
// 2021.01은 기본이 ASCII STL이라 binstl로 강제(readStlBBox는 바이너리만 지원)
const r = await runOpenscad(['-o', stl, '--export-format', 'binstl', scadFile], 120_000);
if (!r.ok) return { ok: false as const, error: `형상 범위 계산 실패(${i.part.name}): ${r.detail}` };
try {
const b = readStlBBox(stl);
for (let k = 0; k < 3; k++) { if (b.min[k] < min[k]) min[k] = b.min[k]; if (b.max[k] > max[k]) max[k] = b.max[k]; }
triangleCount += b.triangleCount;
} catch (e: any) { return { ok: false as const, error: `형상 범위 계산 실패(${i.part.name}): ${String(e?.message || e)}` }; }
}
return { ok: true as const, bbox: { min, max, triangleCount } };
};
const compose = async (job: any, outPng: string) => {