-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
68 lines (54 loc) · 2.03 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
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);
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 on_load(){
mouse.init(three.getCamera());
let interactive_meshes_names = rooms["MeshList"];
let interactive_meshes_list = three.getObjects(interactive_meshes_names);
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);
three.animate();
}
function onMeshMouseEnter(e){
console.log(`Mesh Mouse Enter in ${e.detail.name}`);
document.getElementById('viewer').style.cursor = "pointer";
three.setBulbState(interactive_meshes[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(interactive_meshes[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}`);
const switch_to_state = swap_light_state(e.detail.name);
three.setBulbState(interactive_meshes[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(interactive_meshes[e.detail.name],"switch",switch_to_state);
}