Javascript 如何将Three.js转换为.stl文件进行3D打印?

Javascript 如何将Three.js转换为.stl文件进行3D打印?,javascript,3d,stl,three.js,Javascript,3d,Stl,Three.js,我找到了一个页面链接: 但是当我使用它们时,不要导出stl文件 我该怎么办?STLExporter.parse()将指定的对象导出为字符串。如果希望将字符串保存为文件,则必须执行更多操作。作为一种简单的方法,您可以使用FileSaver.js将字符串保存到文件中 首先,您必须下载并在代码中包含FileSaver.js 使用STLExporter导出场景后,将生成的字符串转换为,然后使用FileSaver.js将Blob另存为文件 var exporter = new THREE.STLExpo

我找到了一个页面链接:

但是当我使用它们时,不要导出stl文件


我该怎么办?

STLExporter.parse()将指定的对象导出为字符串。如果希望将字符串保存为文件,则必须执行更多操作。作为一种简单的方法,您可以使用
FileSaver.js
将字符串保存到文件中

首先,您必须下载并在代码中包含
FileSaver.js

使用STLExporter导出场景后,将生成的字符串转换为,然后使用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();

我尝试了你的建议并成功了,非常感谢!然后,这里我有这么多的网格,我如何合并它们并导出到stl文件?再次感谢@熊猫,如果你导出场景,它将包含添加到场景中的所有网格mm.,但我发现只包含最后一个网格,其他网格不包含。可能是我的错误,我会再次检查,非常感谢Hariv,我知道原因。所有网格的位置默认为世界坐标系,无法保存其位置,翻译等。如何解决它?我不明白你想说什么,但在我的情况下,加载导出的场景后,我将所有网格都放在正确的位置。
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();