当前位置:网站首页>Cesium drag 3D model
Cesium drag 3D model
2022-06-25 04:04:00 【Wang +v】
Cesium Drag and drop 3D Model
What effect does this place want to achieve ? Is the use of cesium Add a... To the map 3D Model , Then the drag and drop effect is realized .
Add a base station model
Then this blog post is not about adding models , But simply paste the code directly , I won't go into details .
// Add a base station model
function addSite() {
let position = Cesium.Cartesian3.fromDegrees(116.236393, 40.075119, 0);
// Set model orientation
let hpRoll = new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(0), 0, 0);
let orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpRoll);
// Add model
let model = viewer.entities.add({
id: 'site', // Model id
position: position, // Model location
orientation: orientation, // Model orientation
model: {
uri: './models/siteModel/scene.gltf', // Model path , Change into your own model
scale: 1,
show: true, // Whether the model is visible
},
description: ' Base station model ' // Add model description
});
viewer.trackedEntity = model; // View switch to model
}
The code above completes adding model functions to the interface .
Drag and drop
In fact, dragging is for this cesium Add a listening event .
For example, the simple logic analysis of drag and drop :
1、 Mouse down event , If there is a model , You can set a color for the model , Know which model is selected by pressing .
2、 Then listen for mouse drag events , Get the position of the mouse drag , Assign to model .
3、 Mouse up event , End the mouse movement event , Then change the color back .
// Registration events
function setHandler() {
handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
// Register mouse down events
handler.setInputAction((e) => {
const pick = viewer.scene.pick(e.position);
if (!Cesium.defined(pick)) {
return; };// If you click on a blank area , Then it doesn't go down
viewer.scene.screenSpaceCameraController.enableRotate = false;// Lock camera , Otherwise, the camera will move when the entity is moved later
pick.id.model.color = Cesium.Color.fromAlpha(Cesium.Color.RED, 1) // Set the color
// Register mouse drag events
viewer.screenSpaceEventHandler.setInputAction((arg) => {
// by viewer binding MOUSE_MOVE Event listener ( Execute function , Listening events )
const position = arg.endPosition;// arg Yes startPosition And endPosition Two attributes , That is, the position information before and after the movement :Cartesian2 object
const cartesian = viewer.scene.globe.pick(viewer.camera.getPickRay(position), viewer.scene);// take Cartesian2 To Cartesian3
pick.id.position._value = cartesian
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
// Bind the mouse up event
viewer.screenSpaceEventHandler.setInputAction(({
position }) => {
// by viewer binding LEFT_UP Event listener ( Execute function , Listening events )
viewer.scene.screenSpaceCameraController.enableRotate = true;// Unlock camera
pick.id.model.color = null // Set the color
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);// relieve viewer Of MOUSE_MOVE Event listener
}, Cesium.ScreenSpaceEventType.LEFT_UP)
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
}
When it's done, it's , It's so simple .
边栏推荐
- PHP代码审计1—PHP.ini的那些事
- Monitoring pancakeswap new token
- 2022-06-21-Flink-49(一. SQL手册)
- Work assessment of pharmacotherapeutics of Jilin University in March of the 22nd spring -00064
- 长沙“求才”:“下力气”与“出实招”并进,“快发展”和“慢生活”兼得
- Redis related-01
- AI writes its own code to let agents evolve! The big model of openai has the flavor of "human thought"
- Disassembly of Weima prospectus: the electric competition has ended and the intelligent qualifying has just begun
- 数学分析_笔记_第3章:极限
- Comprehensive operation of financial risk management X of Dongcai
猜你喜欢
Development of trading system (VIII) -- Construction of low delay network
MySQL modifies and deletes tables in batches according to the table prefix
Redis related-01
1.初识半音阶口琴
如何使用IDE自动签名调试鸿蒙应用
(ultra detailed onenet TCP protocol access) arduino+esp8266-01s accesses the Internet of things platform, uploads real-time collected data /tcp transparent transmission (and how to obtain and write Lu
Mobile mall project operation
Russian Airi Research Institute, etc. | SEMA: prediction of antigen B cell conformation characterization using deep transfer learning
Musk was sued for $258billion in MLM claims. TSMC announced the 2nm process. The Chinese Academy of Sciences found that the lunar soil contained water in the form of hydroxyl. Today, more big news is
Development of trading system (I) -- Introduction to trading system
随机推荐
Jilin University 22 spring March "official document writing" assignment assessment-00029
Cesium 拖拽3D模型
Development of trading system (IX) -- dark pool technology
Create SQLite table with shell script and add SQL statement -- General
cesium 图形标注圆形、正方形、多边形、椭圆等
【Rust投稿】捋捋 Rust 中的 impl Trait 和 dyn Trait
Musk: Twitter should learn from wechat and make 1billion people "live on it" into a super app
Deveco studio 3.0 editor configuration tips
Jilin University 22 spring March "automatic control principle" work assessment-00050
The problem that only the home page can be accessed under openSUSE Apache laravel
Musk was sued for $258billion in MLM claims. TSMC announced the 2nm process. The Chinese Academy of Sciences found that the lunar soil contained water in the form of hydroxyl. Today, more big news is
2D 照片变身 3D 模型,来看英伟达的 AI 新“魔法”!
9 necessary soft skills for program ape career development
[harmony OS] [arkui] ETS development graphics and animation drawing
智慧风电:数字孪生 3D 风机智能设备运维
俄罗斯AIRI研究院等 | SEMA:利用深度迁移学习进行抗原B细胞构象表征预测
uniapp 制作手机app程序, 使用uni.chooseVideo录制视频,视频播放模糊分辨率低的原因
js工具函数,自己封装一个节流函数
Internet Explorer died, and netizens started to build a true tombstone
The more AI evolves, the more it resembles the human brain! Meta found the "prefrontal cortex" of the machine. AI scholars and neuroscientists were surprised