如何将Three.js转换为.stl文件以进行3D打印? [英] How to convert Three.js to .stl files for 3D printing?
问题描述
我找到了一个页面链接:将Three.js转换为.stl用于3D打印?
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);
但是当我使用它们时,不要导出stl文件.
But when I'm using them, not export a stl file.
那我该怎么办?
推荐答案
STLExporter.parse()
将指定的对象导出为字符串.如果希望将字符串另存为文件,则必须执行一些其他操作.作为一种简单的方法,您可以使用 FileSaver.js
将字符串保存到文件中.
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.
首先,您必须下载 FileSaver.js
并将其包含在代码中.
First of all you have to download and include FileSaver.js
in your code.
使用STLExporter导出场景后,将结果字符串转换为Blob ,然后使用FileSaver.js将Blob保存为文件,
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
如果您不熟悉FileSaver.js,可以尝试以下方法,
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();
这篇关于如何将Three.js转换为.stl文件以进行3D打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!