-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
73 lines (60 loc) · 2 KB
/
main.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import * as three from "./three_app.js";
import * as mouse from "./three_mouse.js";
var rooms_light_state = {};
var rooms;
$.getJSON("rooms.json", function(json_data) {
rooms = json_data;
main_init();
});
function main_init(){
three.init(on_load,rooms["glTF_Model"]);
window.addEventListener( 'mesh_mouse_enter', onMeshMouseEnter, false );
window.addEventListener( 'mesh_mouse_exit', onMeshMouseExit, false );
window.addEventListener( 'mesh_mouse_down', onMeshMouseDown, false );
window.addEventListener( 'mesh_touch_start', onMeshMouseDown, false );
}
function on_load(){
mouse.init(three.getCamera());
const mouse_mesh_list = three.getMouseMeshList();
mouse.SetMeshList(mouse_mesh_list);
mouse_mesh_list.forEach(mesh => {
if(mesh.userData.type == "light"){
three.setBulbState(mesh.name,"switch",false);
three.setBulbState(mesh.name,"init",true);
}
else if(mesh.userData.type == "lightgroup"){
three.setBulbState(mesh.name,"init",true);
}
});
three.animate();
}
function onMeshMouseEnter(e){
console.log(`Mesh Mouse Enter in ${e.detail.name}`);
document.getElementById('viewer').style.cursor = "pointer";
three.setBulbState(e.detail.name,"highlight",true);
}
function onMeshMouseExit(e){
console.log(`Mesh Mouse Exit out of ${e.detail.name}`)
document.getElementById('viewer').style.cursor = "default";
three.setBulbState(e.detail.name,"highlight",false);
}
function swap_light_state(name){
if(typeof rooms_light_state[name] == "undefined"){
rooms_light_state[name] = true;
}
else{
rooms_light_state[name] = ! rooms_light_state[name];
}
return rooms_light_state[name];
}
function onMeshMouseDown(e){
console.log(`Mesh Mouse Down on ${e.detail.name}`);
if(e.detail.type == "light"){
const current_state = three.getLightState(e.detail.name);
three.setBulbState(e.detail.name,"switch",!current_state);
}
else if(e.detail.type == "lightgroup"){
const current_state = three.getLightGroupState(e.detail.name);
three.setBulbGroupState(e.detail.name,"switch",!current_state);
}
}