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
|
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); }); }
|