Skip to content

Three.js scene export to dxf #1398

@Azure-Phoenix

Description

@Azure-Phoenix

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions