如何将 Three.js 转换为 .stl 文件以进行 3D 打印? [英] How to convert Three.js to .stl files for 3D printing?
问题描述
我找到了一页链接:Convert Three.js to .stl用于 3D 打印?
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屋!