cesium - 在 Cesium 中提取 glTF 矩形模型的中心坐标
问题描述
我有一个描述矩形的简单 glTF 文件。
我需要在铯中检索那个矩形的中心。
一种方法是“读取”glTF 文件本身中的一些值。我手动完成了它并且有效。就是这样。
这是 glTF 文件开头的内容:
{
"accessors": {
"accessor_15": {
"bufferView": "bufferView_21",
"byteOffset": 0,
"byteStride": 0,
"componentType": 5123,
"count": 6,
"type": "SCALAR"
},
"accessor_17": {
"bufferView": "bufferView_22",
"byteOffset": 0,
"byteStride": 12,
"componentType": 5126,
"count": 4,
"max": [
50,
148,
4
],
"min": [
-52,
140,
-64
],
"type": "VEC3"
},
"accessor_19": {
"bufferView": "bufferView_22",
"byteOffset": 48,
"byteStride": 8,
"componentType": 5126,
"count": 4,
"max": [
0,
1
],
"min": [
-1,
0
],
"type": "VEC2"
}
},
我注意到该accessor_17
元素实际上包含沿每个轴的最小值和最大值:x、y 和 z。
如果我对每个取平均值,这显然给了我(-1, 144, -30)
矩形的中心,如果我在 Cesium 中绘制一个点viewer.entities.add()
,它会显示在预期的位置。
现在,我怎样才能以编程方式做到这一点?例如,我想到的方法是在加载 glTF 之后在我的 Cesium 代码中提取 x、y 和 z 的这些最小值和最大值。这可能以简单的方式吗?或者您是否在 JavaScript 代码中看到任何其他优雅的方式来做到这一点?
这是我加载 glTF 文件的方式:
const modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(position);
const model = await scene.primitives.add(
Cesium.Model.fromGltf({
id: 1,
url: `./gltf/my_model.gltf`,
modelMatrix: modelMatrix,
scale: 1,
show: true
})
);
解决方案
推荐阅读
- cron - Spring 4 Cron 表达式执行
- sql - 用于检索只有“emp”而没有其他任何内容的行的 Sql 查询
- .net - dot-net core Api 和 mssql 主机在 Aws Ec2 ubuntu 服务器上使用 jenkins 和 nginx
- c# - 显示 DataTable 取决于文件内容
- angularjs - Spring ERROR MultipartException:当前请求不是多部分请求
- windows - 使用 PowerShell 7 和 Windows PowerShell 兼容性进行错误处理
- regex - 使用正则表达式匹配“复杂”字符串
- python - 在我的主窗口之外的小部件中创建的 QMenu 没有出现
- r - 考试 num_to_schoice 包括错误的替代方案
- typescript - Mochawesome 在 afterEach 中使用 AddContext 和 cypress