cesium 爬取别人的3dtiles (nodejs 实现)

我们用node js 来 一个小工具 爬取别人的3dtiles 但是不保证 复杂节点 类似点云这种不行


let axios = require('axios');
const fs = require('fs');
const path = require('path');

function downloadFile(urlPath, file) {
return new Promise((resolve, reject) => {
var lashIndex1 = file.lastIndexOf("\\");
var lashIndex2 = file.lastIndexOf("/");
var lashIndex = lashIndex1 > lashIndex2 ? lashIndex1 : lashIndex2;
let lastPath = file.substring(0, lashIndex);
fs.mkdir(lastPath, {recursive: true}, async (err) => {
if (err) {
console.log("目录创建错误");
return;
};
const writer = fs.createWriteStream(file);
const response = await axios({
url: urlPath,
method: "GET",
responseType: "stream",
});
response.data.pipe(writer);
writer.on("finish", (e)=>{
console.log("downloadFile下载完成",urlPath)
resolve(e)
});
writer.on("error", (error) => {
console.log("downloadFile报错了", urlPath, error)
reject();
});
});
});
}

const writeFileRecursive = function (downPath, buffer) {
return new Promise((reslove, reject) => {
let lastPath = downPath.substring(0, downPath.lastIndexOf("\\"));
fs.mkdir(lastPath, {recursive: true}, (err) => {
if (err) return reject(err);
fs.writeFile(downPath, buffer, function (err) {
if (err) {
console.log("writeFileRecursive报错", downPath, err)
return reject(err);
}
console.log("下载json完成", downPath);
return reslove();
});
});
});

}

async function loop2(root, absolutePath, downPath, rootDir) {
if (root.content) {

 更多参考 https://xiaozhuanlan.com/topic/0168235947
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值