I found one page link: Convert Three.js to .stl for 3D printing?
var exporter = new THREE.STLExporter();
var str = exporter.parse(scene);
console.log(str);
But when I'm using them, not export a stl file.
How can I do then?
I found one page link: Convert Three.js to .stl for 3D printing?
var exporter = new THREE.STLExporter();
var str = exporter.parse(scene);
console.log(str);
But when I'm using them, not export a stl file.
How can I do then?
Share Improve this question edited Mar 12, 2023 at 17:04 3CxEZiVlQ 39.5k11 gold badges84 silver badges93 bronze badges asked Jan 3, 2018 at 6:39 pandapanda 631 silver badge5 bronze badges1 Answer
Reset to default 5The STLExporter.parse()
will export the specified object to a string. If you wish to save the string as a file you have to perform some more operations. As a simple approach you can use FileSaver.js
for saving the string to a file.
First of all you have to download and include FileSaver.js
in your code.
Download link:
After exporting the scene using STLExporter, convert the resulting string to a Blob and then save the Blob as a file using FileSaver.js,
var exporter = new THREE.STLExporter();
var str = exporter.parse( scene ); // Export the scene
var blob = new Blob( [str], { type : 'text/plain' } ); // Generate Blob from the string
saveAs( blob, 'file.stl' ); //Save the Blob to file.stl
If you are not familiar with FileSaver.js you can try the following method,
var exporter = new THREE.STLExporter();
var str = exporter.parse( scene ); // Export the scene
var blob = new Blob( [str], { type : 'text/plain' } ); // Generate Blob from the string
//saveAs( blob, 'file.stl' ); //Save the Blob to file.stl
//Following code will help you to save the file without FileSaver.js
var link = document.createElement('a');
link.style.display = 'none';
document.body.appendChild(link);
link.href = URL.createObjectURL(blob);
link.download = 'Scene.stl';
link.click();