// Converts 3MF files to GLB via the Python/trimesh sidecar, so the browser can // render Bambu/MakerWorld production-extension 3MFs (which the JS 3MFLoader can't). const { runScript } = require('./python'); // Returns { glb, volume_cm3, bbox, faces } or throws. async function convert3mfToGlb(inputPath, outputPath) { const { err, stdout, stderr } = await runScript('convert_3mf.py', [inputPath, outputPath], { timeout: 120000 }); let result = null; try { result = JSON.parse(stdout.trim().split('\n').pop()); } catch { /* handled below */ } if (result && result.error) throw new Error(result.error); if (err) { if (err.killed) throw new Error('Timed out converting this 3MF for preview.'); throw new Error(stderr ? stderr.trim().split('\n').slice(-3).join(' ') : err.message); } if (!result) throw new Error('Converter returned unparseable output.'); return result; } module.exports = { convert3mfToGlb };