当前位置:网站首页>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 .
边栏推荐
- 1.初识半音阶口琴
- Work assessment of Biopharmaceutics of Jilin University in March of the 22nd spring -00031
- [team learning] SQL programming language notes - task04
- js工具函数,自己封装一个节流函数
- Redis related-02
- Russian Airi Research Institute, etc. | SEMA: prediction of antigen B cell conformation characterization using deep transfer learning
- PHP代码审计1—PHP.ini的那些事
- 用CPU方案打破内存墙?学PayPal堆傲腾扩容量,漏查欺诈交易量可降至1/30
- Redis related-01
- x86 CPU,危!最新漏洞引发热议,黑客可远程窃取密钥,英特尔“全部处理器”受影响...
猜你喜欢

The programmer reality show is coming again! Hulan, as the host, carried the lamp to fill the knowledge. The SSS boss had a bachelor's degree in pharmacy. Zhu Jun and Zhang Min from Tsinghua joined th

Maybe it's the wrong reason

2022-06-21-flink-49 (I. SQL manual)

PHP代码审计1—PHP.ini的那些事

IE寿终正寝,网友们搞起了真·墓碑……

Development of trading system (II) -- market data

Maintenant, les oreilles vont entrer dans le métacosme.

(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

Wuenda, the new course of machine learning is coming again! Free auditing, Xiaobai friendly

严重的PHP缺陷可导致QNAP NAS 设备遭RCE攻击
随机推荐
Work assessment of Biopharmaceutics of Jilin University in March of the 22nd spring -00005
Tensorflow, danger! Google itself is the one who abandoned it
DAP数据调度功能完善说明
China's SkyEye found suspicious signals of extraterrestrial civilization. Musk said that the Starship began its orbital test flight in July. Netinfo office: app should not force users to agree to proc
Wechat development related
client-go gin的简单整合十-Update
Interview with Mo Tianlun | ivorysql wangzhibin - ivorysql, an Oracle compatible open source database based on PostgreSQL
Xidian AI ranked higher than Qingbei in terms of AI majors, and Nantah ranked the first in China in 2022 in terms of soft science majors
Create SQLite table with shell script and add SQL statement -- General
完美洗牌问题
【Rust投稿】捋捋 Rust 中的 impl Trait 和 dyn Trait
2022-06-21-flink-49 (I. SQL manual)
Cesium 拖拽3D模型
The era of copilot free is over! The official version is 67 yuan / month, and the student party and the defenders of popular open source projects can prostitute for nothing
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
“语法糖”——我的编程新知
Windows 2003 64 bit system PHP running error: 1% is not a valid Win32 Application
Now, the ear is going into the metauniverse
JS tool function, self encapsulating a throttling function