How to convert Three.js to .stl files for 3D printing?

若如初见. 提交于 2021-01-28 02:37:58

问题


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?


回答1:


The 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();


来源:https://stackoverflow.com/questions/48072408/how-to-convert-three-js-to-stl-files-for-3d-printing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!