-
Notifications
You must be signed in to change notification settings - Fork 0
/
webxr.js
126 lines (114 loc) · 3.42 KB
/
webxr.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// AFRAME Exporter for Blender - https://silverslade.itch.io/a-frame-blender-exporter
window.addEventListener('enter-vr', e => {
if (AFRAME.utils.device.checkHeadsetConnected()) {
if (document.getElementById("cursor")) {
document.getElementById("cursor").remove();
}
}
});
// Components
AFRAME.registerComponent('toggle-handler', {
schema: {
target: { default: '#' }
},
init: function () {
var data = this.data;
//alert(data.target);
var toggle_obj = document.getElementById(data.target);
if (toggle_obj) {
toggle_obj.setAttribute("visible", "false");
}
this.el.addEventListener('click', function () {
var toggle_obj = document.getElementById(data.target);
let value = toggle_obj.getAttribute("visible");
if (value == true) {
toggle_obj.setAttribute("visible", "false");
}
else {
toggle_obj.setAttribute("visible", "true");
}
})
}
});
AFRAME.registerComponent('link-handler', {
schema: {
target: { default: '#' }
},
init: function () {
var data = this.data;
this.el.addEventListener('click', function () {
//alert(data.target);
if (data.target != "") {
//window.location.href = data.target;
window.open(data.target);
}
})
}
});
// click to jump next images
AFRAME.registerComponent('images-handler', {
init: function () {
var data = this.data;
//alert(data.target);
//let images = this.data.array;
this.el.addEventListener('click', function () {
//this.setAttribute('color', data.color);
//alert(data.action);
let value = this.getAttribute("src");
//alert(value);
if (value == "#image_1") {
this.setAttribute("src", "#image_2");
}
else {
this.setAttribute("src", "#image_1");
}
})
}
});
// init function is called after onload event
function init() {
var isMobile = AFRAME.utils.device.isMobile();
if (isMobile) {
// do stuff
}
}
/**
* Specifies an envMap on an entity, without replacing any existing material
* properties.
* From: https://github.com/colinfizgig/aframe_Components/blob/master/components/light-map-geometry.js
*/
AFRAME.registerComponent('light-map-geometry', {
schema: {
path: { default: '' },
format: { default: 'RGBFormat' },
intensity: { default: 1.0 }
},
init: function () {
const data = this.data;
const el = this.el;
this.texture = new THREE.TextureLoader().load(data.path);
this.intensity = data.intensity;
this.applyLightMap();
this.el.addEventListener('object3dset', this.applyLightMap.bind(this));
},
applyLightMap: function () {
const mesh = this.el.getObject3D('mesh');
const lightMap = this.texture;
this.texture.flipY = false;
const el = this.el
const value = this.intensity;
if (!mesh) return;
mesh.traverse(function (node) {
//if (node.geometry && node.geometry.type == "BufferGeometry") {
//console.log(node);
//console.log(node.geometry.attributes);
//node.geometry.attributes.uv2 = node.geometry.attributes.uv.clone();
//}
if (node.material && 'lightMap' in node.material) {
node.material.lightMap = lightMap;
node.material.lightMapIntensity = value;
node.material.needsUpdate = true;
}
});
}
});