javascript - 如何将 Three.js 转换为 .STL 文件以进行 3D 打印?

标签 javascript three.js 3d

我找到一页链接: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 并将其包含在您的代码中。

Download link:

使用 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/

相关文章:

actionscript-3 - 通过 ActionScript 3 在 Flash 中设置舞台消失点

javascript - 动画滚动脚本防止从外部链接访问本地 anchor 位置

three.js - 如何在三个js中不倾斜的情况下向上移动相机

javascript - 遍历 THREE.JS 中的 getObjectByName

java - 如何在2D平面上投影3D?

c++ - SFML + OpenGL : Unable to draw cube

c# - 将 C# 数据结构传递给 javascript

JavaScript 未从地址栏运行

javascript - 使用正则表达式在 Javascript 中形成一个没有前导零的数字

javascript - 三个js阴影