当前位置: 首页 > news >正文

cesium加载魔方立方体

 cesium加载多个小立方体,组合拼成一个大立方体。

地理坐标拼合的大立方体有错位问题。必须进行坐标转换。

 

<template><div class="map"><div id="mapContainer" ref="mapContainer" class="map-container"></div><div class="map-other"><Steps progress-dot :current="currentVal" @change="changeStepsEvt"><Step title="1"></Step><Step title="2"></Step><Step title="3"></Step><Step title="4"></Step></Steps></div></div>
</template>
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { Steps, Step } from 'ant-design-vue';
import * as THREE from 'three';
import { log } from 'console';
const currentVal = ref(0);
const win: AnyObject = window;
const Cesium = win.Cesium;
let viewer: any,cubeEntity: any = {};
let count = 0;
const init = () => {viewer = new Cesium.Viewer('mapContainer', {animation: false, //动画小部件baseLayerPicker: false, //地图图层组件infoBox: false, //信息框selectionIndicator: false, //选取指示器组件});// 获取CreditDisplay实例let creditDisplay = viewer.scene.frameState.creditDisplay;// 隐藏所有logocreditDisplay.show = false;// 立方体的边长const cubeSize = 100.0; // 100米边长// 第一个立方体的位置(成都经纬度,100米高度)const longitude = 104.0668;const latitude = 30.5728;const height = 100;const position1 = Cesium.Cartesian3.fromDegrees(longitude,latitude,height,);// 将地理坐标转换为局部坐标系const ellipsoid = viewer.scene.globe.ellipsoid;const origin = Cesium.Transforms.eastNorthUpToFixedFrame(position1,ellipsoid,);for (let i = 0; i < 3; i++) {for (let j = 0; j < 3; j++) {for (let k = 0; k < 3; k++) {const offset = new Cesium.Cartesian3(cubeSize * i,cubeSize * j,cubeSize * k,); // 在X轴上偏移const position = Cesium.Matrix4.multiplyByPoint(origin,offset,new Cesium.Cartesian3(),);cubeEntity[count] = viewer.entities.add({name: `Cube-${i}-${j}-${k}`,position: position,box: {dimensions: new Cesium.Cartesian3(cubeSize,cubeSize,cubeSize,),// material: Cesium.Color.fromRandom({ alpha: 1 }), // 半透明的蓝色material: Cesium.Color.fromBytes(177, 0, 4, 200), // 半透明的蓝色outline: true,outlineColor: Cesium.Color.WHITE,outlineWidth: 2,},});count++;}}}// 将视角调整到立方体的中心// viewer.zoomTo(viewer.entities);viewer.camera.flyTo({destination: Cesium.Cartesian3.fromDegrees(104.0658, 30.5682, 1200), // 目标位置和高度orientation: {heading: Cesium.Math.toRadians(30), // 相机航向角pitch: Cesium.Math.toRadians(-60), // 相机俯仰角roll: Cesium.Math.toRadians(0), // 相机滚转角},duration: 1, // 飞行持续时间(秒)});
};
onMounted(() => {init();
});
const colorList = [{color: Cesium.Color.fromBytes(177, 0, 4, 200),},{color: Cesium.Color.fromBytes(0, 206, 209, 200),},{color: Cesium.Color.fromBytes(106, 90, 205, 200),},{color: Cesium.Color.fromBytes(255, 255, 0, 100),},
];
const changeStepsEvt = (current) => {currentVal.value = current;for (let i = 0; i < count; i++) {cubeEntity[i].box.material = colorList[currentVal.value].color;}
};
setInterval(() => {currentVal.value++;if (currentVal.value >= 4) {currentVal.value = 0;}for (let i = 0; i < count; i++) {cubeEntity[i].box.material = colorList[currentVal.value].color;}
}, 3000);
</script>
<style lang="scss" scoped>
@import './index.scss';
</style>

http://www.lryc.cn/news/421256.html

相关文章:

  • unity 粒子系统学习
  • CogVideoX环境搭建推理测试
  • STL—容器—list【list的介绍和基本使用】【list的迭代器失效问题】
  • 【面试宝典】MySQL 面试问题
  • 【Cpp筑基】三、对象和类
  • 数据库原理面试-核心概念-问题理解
  • 【JavaScript】JavaScript里的“先斩后奏”之王 shift()方法
  • Python面试宝典第32题:课程表
  • 简单介绍BTC的Layer2项目RGB
  • 跨境电商卖家必看:搭建安全稳定测评自养号环境系统
  • 如何对open62541.h/open62541.c的UA_Client进行状态(在线/掉线)监控
  • 高等数学 第九讲 一元函数积分学的应用
  • django如何更新数据库字段并与数据库保持同步?
  • jenkins插件 SSH Publishers
  • Kafka Client客户端操作详解
  • 【HarmonyOS NEXT星河版开发学习】小型测试案例15-博客列表
  • go-zero中统一返回前端数据格式的几种方式
  • 【向量数据库】Ubuntu编译安装FAISS
  • 制造知识普及(九)--企业内部物料编码(IPN)与制造商物料编码(MPN)
  • 【整数规划】+【0—1规划】解决优化类问题(Matlab代码)
  • Linux下如何使用Curl进行网络请求
  • PostgreSQL 触发器
  • LeetCode——3131.找出与数组相加的整数I
  • 【SpringMVC】详细了解SpringMVC中WEB-INF 目录资源,视图解析器和静态资源放行的使用。
  • 如何学好uni-app
  • C++ QT使用stackwidget实现页面切换(含源码)
  • 打工人上班适合用的蓝牙耳机推荐?几款开放式耳机推荐
  • 一款.NET开发的AI无损放大工具
  • 编程新手必看:彻底理解!与~的取反操作
  • 【LeetCode】54. 螺旋矩阵