How to write my 3D Vase geometry to a file for 3D printing? (like .obj or .stl)

I need my vase to be 3D printed.

https://codepen.io/michielschukking/pen/azmbpzP

So I add the line:

import { STLExporter } from ‘three/addons/exporters/STLExporter.js’;

To convert my Vase to STL.

I am experimenting with:

exporter = new STLExporter();
const result = exporter.parse( mesh );
saveString( result, ‘hexagon_thing.stl’ );

at the end of my mesh-creation.

Now it gives me this.

ReferenceError: Can't find variable: exporter

Maybe it is something very simple, I have no experience using imports. It gives me the same for saveString.

Than one last remark:

All the hexagons as a separate .stl would be fun so I can print them in different colors.

The whole thing as one .stl for the first experiments would be handy as a start. This way is looks like somthing (a vase) easily, which is fun and stimulating, because it is my first 3D print (ever!) as well.

Thanks for the help in advance!

STLExporter is not part of the three namespace but imported independently from jsm/examples (addons) like so…

import { STLExporter } from 'three/addons/exporters/STLExporter.js';

And used without the THREE namespace like so…

new STLExporter();

Ok I changed the original question. Thx

const exporter = new STLExporter();

ReferenceError: Can’t find variable: saveString

I thought this came with the STLExporter import.

Does anyone know how to actually save to an stl having come this far?

I can also instead of codepen do it on my local environment.

Any help is greatly appreciated! (It needs to go to a 3D printer)

This is a function built into the three.js stl exporter example, not a method of STLExporter itself, have a look at the following functionality, save and saveString…

1 Like

Don’t you know the line(s) that writes the .stl file from my geometry? (Or any other file type like .obj)

I’ve rewritten my example, used a custom geometry instead of cylinders, added the export to STL: https://codepen.io/prisoner849/full/RNGroMj

4 Likes

It sounds like you’re relatively new to JS? You are getting tripped up on some js syntax, like requiring variables to be declared with “const” or “let” before using them.
If you are using an LLM, you can perhaps ask the LLM to write the STLExport boilerplate for you…

For instance:

“can you give me a function in threejs that downloads a supplied scene in STL format to the user?”

import { STLExporter } from 'three/addons/exporters/STLExporter.js';

function downloadSceneAsSTL(scene, fileName = 'asteroid_system.stl') {
    const exporter = new STLExporter();
    
    // Parse the scene. 
    // binary: true produces a smaller file and is standard for 3D printing.
    const result = exporter.parse(scene, { binary: true });
    
    // Create a Blob from the data
    const blob = new Blob([result], { type: 'application/octet-stream' });
    
    // Create a hidden link and click it to trigger download
    const link = document.createElement('a');
    link.style.display = 'none';
    document.body.appendChild(link);
    
    link.href = URL.createObjectURL(blob);
    link.download = fileName;
    link.click();
    
    // Clean up
    document.body.removeChild(link);
    URL.revokeObjectURL(link.href);
}

...


window.addEventListener('keydown', (e) => {
    if (e.key === 's') {
        console.log("Exporting STL...");
        downloadSceneAsSTL(scene);
    }
});

2 Likes

Thank you very much. That will lead to at least one 3D print maybe already this week.

We are waiting impatiently for a video of your finished vase. Something like this:

https://imgur.com/gallery/shiny-polygon-vase-OZGFcBf

1 Like

Haha, hopefully next week. Converted the .stl for the printer to start printing but the machine didn’t work.

Succes! My first 3D print ever. It came out of the printer one week ago.

7 Likes

Thanks for posting! Looks beautiful.

1 Like