【发布时间】:2019-07-05 23:54:10
【问题描述】:
我正在尝试下载 .obj 文件,我从顶点的二进制数组生成客户端。问题是有太多顶点无法放入浏览器窗口内存中
exportOBJ() {
var output = 'o object_export\n';
var i, j, k, l, x, y, z;
var vertices = this._vertices.array;
for (i = 0; i < vertices.length; i += 3) {
x = vertices[i];
y = vertices[i + 1];
z = vertices[i + 2];
output += 'v ' + x + ' ' + y + ' ' + z + '\n';
}
//Other data...
}
//保存方法
function (data) {
var blob = new Blob([data], { type: 'text/obj;charset=utf-8;' });
if (navigator.msSaveBlob) { // IE 10+
navigator.msSaveBlob(blob, filename);
} else {
var link = document.createElement("a");
if (link.download !== undefined) { // feature detection
// Browsers that support HTML5 download attribute
var url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", 'export.obj');
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
})
所以这适用于小的顶点文件,但是当有很多顶点时,比如 10M,浏览器窗口会崩溃。 我研究过使用文件流,但据我所知,这不是客户端。 https://github.com/jimmywarting/StreamSaver.js 也是如此,我也需要能够上传。
【问题讨论】:
标签: javascript html file stream