OpenJSCAD.org
OpenJSCAD.org copied to clipboard
Three.js scene export to dxf
Could you help me to use this library to export my three.js scene to dxf?
function exportSceneToSTL(scene) {
const exporter = new STLExporter();
return exporter.parse(scene, { binary: false }); // ASCII STL
}
async function convertSTLtoDXF(stlString) {
let deserializedStl = stlDeserializer.deserialize(
{
output: "csg", //jscad
},
stlString
);
console.log("CSG data were got");
console.log(dxfSerializer);
let dxfStringArray = dxfSerializer.serialize(deserializedStl);
console.log("DXF data were got");
return dxfStringArray;
}
function downloadDXF(dxfString, filename = "scene.dxf") {
const blob = new Blob([dxfString], { type: "application/dxf" });
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = filename;
link.click();
}
/**
* Action Listeners
*/
// Export on spacebar press
window.addEventListener("keydown", async (event) => {
if (event.code === "Space") {
const stlString = exportSceneToSTL(scene);
const dxfString = await convertSTLtoDXF(stlString);
downloadDXF(dxfString);
}
});
I tried this steps, but it returns Uncaught (in promise) Error: only JSCAD geometries can be serialized to DXF error...
(The code is inspired from this discussion)
Sounds like could be possible. Can you make scene with a simple cube, and paste ouput of
console.log("CSG data were got",deserializedStl); here.
The error means that the input to dxfSerializer.serialize() did not contain any JSCAD geometries. So, double check the results of stlDeserializer.deserialize(), or exporter.parse(). You are probably close.