-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
69 lines (55 loc) · 2.05 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
import * as three from "./three_app.js";
import * as mouse from "./three_mouse.js";
const interactive_meshes = {};
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);
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', onMeshTouchStart, 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 on_load(){
mouse.init(three.getCamera());
let interactive_meshes_list = three.getLightMeshList();
mouse.SetMeshList(interactive_meshes_list);
//convert list to map for more practicale usage in events
interactive_meshes_list.forEach(mesh => interactive_meshes[mesh.name] = mesh);
interactive_meshes_list.forEach(mesh => swap_light_state(mesh.name));
interactive_meshes_list.forEach(mesh => three.setBulbState(mesh.name,"highlight",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 onMeshMouseDown(e){
console.log(`Mesh Mouse Down on ${e.detail.name}`);
const switch_to_state = swap_light_state(e.detail.name);
three.setBulbState(e.detail.name,"switch",switch_to_state);
}
function onMeshTouchStart(e){
console.log(`Mesh Touch Start on ${e.detail.name}`)
const switch_to_state = swap_light_state(e.detail.name);
three.setBulbState(e.detail.name,"switch",switch_to_state);
}