-
Notifications
You must be signed in to change notification settings - Fork 7
/
isvr-init-assets-component.js
149 lines (110 loc) · 7.27 KB
/
isvr-init-assets-component.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
AFRAME.registerComponent('isvr-init-assets', {
schema: {
url: {
default: ''
}
},
init: function() {
this.xmlhttp = new XMLHttpRequest();
this.xmlhttp.onreadystatechange = this.responseHandler.bind(this);
this.xmlhttp.open('GET', this.data.url, true);
this.xmlhttp.send();
},
responseHandler: function() {
var self = this;
if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {
var obj = JSON.parse(this.xmlhttp.responseText);
/* 1st photo sphere asset, to show immediately */
var photosphere_image = new Image();
photosphere_image.onload = (function(content_id) {
return function() {
var image_elem = document.createElement('img');
image_elem.setAttribute('id', 'img-photosphere-1');
image_elem.setAttribute('data-content-id', content_id);
image_elem.setAttribute('src', this.src);
var assets = document.querySelector('a-assets');
assets.appendChild(image_elem);
var sphere = document.querySelector('#photosphere');
sphere.setAttribute('material', 'src', '#img-photosphere-1');
sphere.setAttribute('data-content-id', content_id);
//sphere.emit('photosphere-fade-in');
var photosphere_texture_loaded_listener = function() {
document.querySelector('#photosphere-loading').setAttribute('visible', false);
document.querySelector('#photosphere-loading-background').setAttribute('visible', false);
document.querySelector('#photosphere-loading').emit('stop-photosphere-loading-anim');
document.querySelector('#photosphere-start-btn').setAttribute('visible', true);
document.querySelector('#intro-0').addEventListener('click', function(evt) {
document.querySelector('#photosphere-start-btn-circle').emit('stop-photosphere-start-btn-anim');
// workaround because of interference with menu
document.querySelector('#intro-0').setAttribute('position', { x: 0, y: 100, z: -2.1 });
document.querySelector('#intro-0').setAttribute('visible', false);
var hotspots = document.querySelectorAll('.hotspot-wrapper-content-id-' + content_id);
for (var i = 0; i < hotspots.length; i++) {
hotspots[i].setAttribute('visible', true);
}
hotspots = document.querySelectorAll('.hotspot-content-id-' + content_id);
for (var i = 0; i < hotspots.length; i++) {
hotspots[i].setAttribute('visible', true);
}
var title = document.querySelector('#photosphere-title-content-id-' + content_id);
if (title != null && title.getAttribute('data-shown') == 'false') {
title.setAttribute('position', { x: 0, y: 1.6, z: -2.1 });
title.setAttribute('visible', true);
title.setAttribute('data-shown', 'true');
setTimeout(function() {
title.setAttribute('visible', false);
// workaround because of interference with menu
title.setAttribute('position', { x: 0, y: 10, z: -2.1 });
}, 10000);
}
sphere.removeEventListener('materialtextureloaded', photosphere_texture_loaded_listener);
});
};
sphere.addEventListener('materialtextureloaded', photosphere_texture_loaded_listener);
}
}(obj['photo-spheres'][0]['photo-sphere']['#content-id']));
photosphere_image.src = obj['photo-spheres'][0]['photo-sphere']['#uri']['#value'];
/* photo sphere thumbnail assets */
for (var i=0; i<obj['photo-spheres'].length; i++) {
var id = obj.from + i;
var photosphere_thumb_image = new Image();
photosphere_thumb_image.onload = (function(id, i, content_id) {
return function() {
var image_elem = document.createElement('img');
image_elem.setAttribute('id', 'img-photosphere-thumb-' + id);
image_elem.setAttribute('data-content-id', content_id);
image_elem.setAttribute('src', this.src);
var assets = document.querySelector('a-assets');
assets.appendChild(image_elem);
var thumb = document.querySelector('#photosphere-thumb-' + (i+1));
// img-photosphere-1 has already been loaded
if (id != 1) {
var photosphere_image = new Image();
photosphere_image.onload = (function(id, thumb, content_id) {
return function() {
var image_elem = document.createElement('img');
image_elem.setAttribute('id', 'img-photosphere-' + id);
image_elem.setAttribute('data-content-id', content_id);
image_elem.setAttribute('src', this.src);
var assets = document.querySelector('a-assets');
assets.appendChild(image_elem);
document.querySelector('#photosphere-loading-' + (i+1)).setAttribute('visible', false);
document.querySelector('#photosphere-loading-' + (i+1)).emit('stop-photosphere-loading-anim-' + (i+1));
thumb.setAttribute('material', 'src', '#img-photosphere-thumb-' + id);
thumb.setAttribute('visible', true);
}
}(id, thumb, content_id));
photosphere_image.src = obj['photo-spheres'][i]['photo-sphere']['#uri']['#value'];
} else {
document.querySelector('#photosphere-loading-' + (i+1)).setAttribute('visible', false);
document.querySelector('#photosphere-loading-' + (i+1)).emit('stop-photosphere-loading-anim-' + (i+1));
thumb.setAttribute('material', 'src', '#img-photosphere-thumb-' + id);
thumb.setAttribute('visible', true);
}
}
}(id, i, obj['photo-spheres'][i]['photo-sphere']['#content-id']));
photosphere_thumb_image.src = obj['photo-spheres'][i]['photo-sphere']['photo-sphere-navigation-preview-image']['#uri']['#value'];
} /* for */
} /* if */
}
});