当前位置:网站首页>Learning event binding of 3D visualization from scratch
Learning event binding of 3D visualization from scratch
2022-06-24 08:08:00 【User 8763535】
Let's understand the concept first : event , It's an action performed by a user or browser . for example :click、load And so on are the names of the events . Event handler , It's a function that responds to events . The name of the event handler is given by “on” At the beginning .
for example : event click ---> Event handler onclick( Event handlers are usually lowercase letters ).
ThingJS There are many events built into the system , Than a click of a mouse 、 Keyboard entry 、 Hierarchy changes, etc . You can monitor these events , Carry out corresponding business logic processing in the event callback .
Global binding events and local binding events
Operation and digital twin visualization scene changes , Will trigger corresponding events . You can monitor these events , Then do the corresponding processing in the callback method , adopt on() Method binding event .
1、 Global binding : adopt app.on() The binding event , You can add conditions in the global environment to specify which objects to bind the event to , The conditional rule is the same as query Conditions of use .
// The binding event
app.on("click", function(ev) {
console.log("you click!");
});matters needing attention :
After global binding , Newly created eligible objects can also take effect .
2、 Local binding : For a digital twin visualization object , perhaps query Query results of (Selector), adopt on Interface binding events , It's called local binding . Bind to global , Conditions can be added to the event , Indicates that this event binding is for all digital twin visualization objects in the collection .
obj.on("click", function(ev) {
console.log(ev.object.name);
});Practical application , Create a mouse click event in the digital twin visualization scene , Print picked up objects id; Double click event , Create a ball in place ; And add mouse over events to all building objects .
The complete code is as follows :
var app = new THING.App({
url: 'https://www.thingjs.com/static/models/storehouse'
});
// Mouse click event , Print picked up objects id( single click double-click All triggered Double click will trigger twice Click )
app.on('click', function(ev) {
if (ev.picked) {
console.log('Click : ' + ev.object.id);
}
});
// Mouse click event , Print picked up objects id
app.on(THING.EventType.SingleClick, function(ev) {
if (ev.picked) {
console.log('SingleClick : ' + ev.object.id);
}
});
// Double click event , Create a ball in place
app.on('dblclick', function(ev) {
console.log('dblClick');
// e.button 0 Left key 2 Right click
if (!ev.picked || ev.button != 0) { return; }
app.create({
type: 'Sphere',
radius: 0.5,
position: ev.pickedPosition
});
});
// To all building objects , Add mouse over events
app.on('mouseenter', '.Building', function (ev) {
ev.object.style.outlineColor = '#0000FF';
});
app.on('mouseleave', '.Building', function (ev) {
ev.object.style.outlineColor = null;
});—————————————————
Digital twin Visualization :https://www.thingjs.com/
边栏推荐
- Latest news of awtk: new usage of grid control
- Moonwell Artemis is now online moonbeam network
- Resolution error: LNK2019 unresolved external symbol
- Part 1: building OpenGL environment
- 【资料上新】迅为基于3568开发板的NPU开发资料全面升级
- Review of postgraduate English final exam
- Solve the problem of notebook keyboard disabling failure
- 3-列表简介
- [测试开发]初识软件测试
- Ke Yi fallible point
猜你喜欢

Configure your own free Internet domain name with ngrok

Echart 心得 (一): 有关Y轴yAxis属性

Vulnhub target: boredhackerblog_ CLOUD AV

热赛道上的冷思考:乘数效应才是东数西算的根本要求

直播回顾 | 云原生混部系统 Koordinator 架构详解(附完整PPT)

『C语言』系统日期&时间

Oracle advanced SQL qualified query

模型效果优化,试一下多种交叉验证的方法(系统实操)

开放合作,共赢未来 | 福昕鲲鹏加入金兰组织

Signature analysis of app x-zse-96 in a Q & a community
随机推荐
Timer usage notes
Thread considerations
Leetcode 515 find the leetcode path of the maximum [bfs binary tree] heroding in each row
从 jsonpath 和 xpath 到 SPL
Chapter 1 overview of canvas
Unity culling related technologies
宝塔面板安装php7.2安装phalcon3.3.2
Open cooperation and win-win future | Fuxin Kunpeng joins Jinlan organization
[test development] first knowledge of software testing
Auto usage example
Gossip: what happened to 3aC?
Decltype usage introduction
Backup and restore SQL Server Databases locally
Swift extension networkutil (network monitoring) (source code)
解决错误: LNK2019 无法解析的外部符号
On the H5 page, the Apple phone blocks the content when using fixed to locate the bottom of the tabbar
OC extension detects whether an app is installed on the mobile phone (source code)
解决笔记本键盘禁用失败问题
Synchronous FIFO
Pagoda panel installation php7.2 installation phalcon3.3.2