三维模型下载与动画控制
文章目录
1. 模型下载地址
-
3D Warehouse https://3dwarehouse.sketchup.com/
-
Sketchfab https://sketchfab.com/
-
STK模型下载:STK V11.2及以上版本提供了
CZML
导出功能,在导出时会让填写模型服务地址,默认的是http://assets.agi.com/models/
在导出CZML文件时STK会根据场景中每个对象设置的模型自动关联对应的模型地址(仅限于STK桌面端自带的三维模型)。然后可以打开CZML文件查看具体的模型地址,进行手动下载,如http://assets.agi.com/models/f-22a_raptor.gltf
可以根据STK自带的mdl模型来编写NodeJS脚本自动下载对应的gltf模型
/**
* 下载AGI三维模型
*/
// 文件下载 所需要的基本类
var fs = require("fs");
var path = require("path");
var request = require("request");
// 创建文件夹目录 判断文件是否创建
var dirPath = path.join(__dirname, "file");
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath);
console.log("文件夹创建成功");
} else {
console.log("文件夹已存在");
}
// 读取本地文件目录(STK安装目录)
const readDir = "D:\\Program Files\\AGI\\STK 11\\STKData\\VO\\Models\\Land";
fs.readdir(readDir, (err, files) => {
if (err) {
console.log("读取文件失败");
}
console.log(files);
files.forEach((item) => {
// 过滤后缀为gif的文件
let gifReg = /gif$/;
if (gifReg.test(item)) {
console.log(item);
// 截取模型名称
let modelName = item.slice(0, item.length - 4) + ".gltf";
let url = "https://assets.agi.com/models/" + modelName;
let stream = fs.createWriteStream(path.join(dirPath, modelName));
request(url).pipe(stream).on("close", function (err) {
console.log("文件[" + modelName + "]下载完毕");
});
}
})
})
2. 动画控制
主要在Cesium应用中进行三维模型的动画和关节控制,三维模型格式为gltf
格式。
动画控制可以分成两种:
-
模型内置动画:模型内部本身就包括动画,模型建模时就有动画,如直升机螺旋桨的旋转,体现在gltf文件中就是
animations
属性。另外Cesium提供了接口RunAnimation
可以控制是否运行动画。 -
通过模型关节手动控制:模型中包括一系列的关节,如火箭发动机喷火、一二级分离等,体现在gltf文件中就是
articulations
,配合Cesium的接口就可以控制模型在不同时刻具体关节的动作;关于如何在gltf文件中写入articulations属性,可以参考
[1]. https://agiweb.secure.force.com/faqs/articles/Keyword/What-Software-Setup-is-Required-to-Convert-Models-to-glTF
[2]. https://github.com/AnalyticalGraphicsInc/gmdf/tree/master/samples
[3]. https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/AGI_articulations/README.md