我找到一页链接:Convert Three.js to .stl for 3D printing?
var exporter = new THREE.STLExporter();
var str = exporter.parse(scene);
console.log(str);
但是当我使用它们时,不导出 STL 文件。
那我该怎么办?
最佳答案
STLExporter.parse()
会将指定的对象导出为字符串。如果您希望将字符串保存为文件,则必须执行更多操作。作为一种简单的方法,您可以使用 FileSaver.js
将字符串保存到文件中。
首先,您必须下载 FileSaver.js
并将其包含在您的代码中。
使用 STLExporter 导出场景后,将结果字符串转换为 Blob然后使用 FileSaver.js 将 Blob 保存为文件,
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,您可以尝试以下方法,
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();
关于javascript - 如何将 Three.js 转换为 .STL 文件以进行 3D 打印?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48072408/