根据矩阵偏移默认位置 - Gis · Cesium

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* @author M.k
* @date 2023-08-08 14:15:22
*/

import { Cartographic, Cartesian3, Matrix4, Math as CMath } from "cesium";
import fs from "fs-extra";

import sceneTree from "./scenetree.json" assert { type: "json" };

// 模型矩阵
const modelMatrix = [
0.8602507530759164, -0.03947296554882054, -0.5083409552879833, 0,
0.037086637569903456, 0.9992020380754338, -0.014827960738338308, 0,
0.5085206221443497, -0.006096892378968544, 0.8610282252965016, 0,
14058.754155613598, 1150.0035471664742, -5630.882251806557, 1,
];

// 添加位置属性
nodeVisitor(sceneTree.scenes);

// 写入文件
fs.writeJsonSync("./scenetree.new.json", sceneTree);

// 访问节点并添加位置属性
function nodeVisitor(data) {
if (!data?.length) return;
data.forEach((d) => {
if (d.sphere) {
// 节点原始笛卡尔坐标系位置
const nodeCenter = new Cartesian3(...d.sphere.slice(0, 3));
// 节点偏移矩阵
const nodeMatrix = new Matrix4();
Matrix4.multiplyByTranslation(modelMatrix, nodeCenter, nodeMatrix);
// 节点目标笛卡尔坐标系位置
const nodeCartesian = Matrix4.getTranslation(nodeMatrix, nodeCenter);
// 节点经纬度弧度
const nodeCartographic = Cartographic.fromCartesian(nodeCartesian);

// 经纬度&高度
const lng = CMath.toDegrees(nodeCartographic.longitude);
const lat = CMath.toDegrees(nodeCartographic.latitude);
const height = nodeCartographic.height;

// 添加位置属性
d.position = [lng, lat, height];
}
nodeVisitor(d.children);
});
}

根据矩阵偏移默认位置 - Gis · Cesium
https://wanmeishijie.xyz/notes/gis/cesium/根据矩阵偏移默认位置/
作者
发布于
2024年3月13日
许可协议