aframe-babia-components 1.2.8 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/filters/babia-selector.js +33 -21
- package/components/filters/babia-treebuilder.js +14 -13
- package/components/others/babia-navigator.js +94 -37
- package/components/others/babia-poster.js +369 -368
- package/components/others/babia-slider.js +63 -25
- package/components/others/common.js +60 -80
- package/components/visualizers/babia-doughnut.js +2 -1
- package/components/visualizers/babia-html.js +95 -118
- package/components/visualizers/babia-map.js +796 -0
- package/components/visualizers/babia-pie.js +2 -1
- package/dist/aframe-babia-components.js +7247 -6488
- package/dist/aframe-babia-components.min.js +1 -1
- package/dist/aframe-babia-components.min.js.LICENSE.txt +1 -1
- package/dist/aframe-babia-components.min.js.map +1 -1
- package/docs/APIs/OTHERS.md +4 -4
- package/docs/CONTRIBUTING.md +34 -25
- package/docs/RELEASE_NOTES.md +13 -2
- package/docs/Tutorials/HOW_TO_USE_BABIA_MAP.md +554 -0
- package/docs/Tutorials/ejemplo1.png +0 -0
- package/docs/Tutorials/ejemplo2.png +0 -0
- package/docs/Tutorials/ejemplo3.png +0 -0
- package/docs/Tutorials/pyramids.png +0 -0
- package/docs/Tutorials/singular.png +0 -0
- package/docs/Tutorials/terrain-vr-scenario.png +0 -0
- package/docs/Tutorials/terrain.png +0 -0
- package/examples/boats/boats2/data.json +206 -13
- package/examples/demos/map-terrain/assets/360-panorama.jpg +0 -0
- package/examples/demos/map-terrain/assets/floor-texture.jpg +0 -0
- package/examples/demos/map-terrain/assets/mapTextures/512sample.webp +0 -0
- package/examples/demos/map-terrain/assets/mapTextures/defaultTexture.webp +0 -0
- package/examples/demos/map-terrain/assets/maps/defaultMap.png +0 -0
- package/examples/demos/map-terrain/assets/maps/example.png +0 -0
- package/examples/demos/map-terrain/assets/metalic-texture.jpg +0 -0
- package/examples/demos/map-terrain/dist/aframe-lounge-component.min.js +1 -0
- package/examples/demos/map-terrain/index.html +82 -0
- package/examples/demos/map-terrain/index_gallery.html +188 -0
- package/examples/demos/map-terrain/main_data.json +1 -0
- package/examples/demos/map-terrain/pyramids.html +130 -0
- package/examples/js/aframe-orbit-controls-component.js +1060 -0
- package/examples/ui/pie/index.html +0 -1
- package/index.html +15 -0
- package/index.js +1 -0
- package/package.json +5 -5
- package/tests/screenshots/other_snapshots.js/pyramids.png +0 -0
- package/tests/screenshots/other_snapshots.js/singular.png +0 -0
- package/tests/screenshots/other_snapshots.js/terrain-vr-scenario.png +0 -0
- package/tests/screenshots/other_snapshots.js/terrain.png +0 -0
- package/webpack.common.js +1 -1
- package/webpack.dev.js +17 -0
- package/examples/demos/citations/babiaxr.json +0 -1
- package/examples/demos/citations/citations.html +0 -72
- package/examples/demos/citations/music.mp3 +0 -0
- package/examples/demos/citations/stl.js +0 -28
|
@@ -1,383 +1,384 @@
|
|
|
1
1
|
if (typeof AFRAME === 'undefined') {
|
|
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
|
-
active: {
|
|
49
|
-
type: 'boolean',
|
|
50
|
-
default: true,
|
|
51
|
-
},
|
|
52
|
-
openIconImage: {
|
|
53
|
-
type: 'asset',
|
|
54
|
-
default: ''
|
|
55
|
-
},
|
|
56
|
-
openIconRadius: {
|
|
57
|
-
type: 'number',
|
|
58
|
-
default: 0.3
|
|
59
|
-
},
|
|
60
|
-
openIconColor: {
|
|
61
|
-
type: 'string',
|
|
62
|
-
default: 'white'
|
|
63
|
-
},
|
|
64
|
-
closeIconImage: {
|
|
65
|
-
type: 'asset',
|
|
66
|
-
default: ''
|
|
67
|
-
},
|
|
68
|
-
closeIconRadius: {
|
|
69
|
-
type: 'number',
|
|
70
|
-
default: 0.3
|
|
71
|
-
},
|
|
72
|
-
closeIconColor: {
|
|
73
|
-
type: 'string',
|
|
74
|
-
default: 'white'
|
|
75
|
-
},
|
|
76
|
-
image: {
|
|
77
|
-
type: 'string',
|
|
78
|
-
default: ''
|
|
79
|
-
},
|
|
80
|
-
imageWidth: {
|
|
81
|
-
type: 'number',
|
|
82
|
-
default: 2
|
|
83
|
-
},
|
|
84
|
-
imageHeight: {
|
|
85
|
-
type: 'number',
|
|
86
|
-
default: 2
|
|
87
|
-
},
|
|
88
|
-
posterBoxWidth: {
|
|
89
|
-
type: 'number',
|
|
90
|
-
default: 4
|
|
91
|
-
},
|
|
92
|
-
posterBoxHeight: {
|
|
93
|
-
type: 'number',
|
|
94
|
-
default: 4
|
|
95
|
-
},
|
|
96
|
-
posterBoxColor: {
|
|
97
|
-
type: 'string',
|
|
98
|
-
default: 'white'
|
|
99
|
-
},
|
|
100
|
-
posterBoxPadding: {
|
|
101
|
-
type: 'number',
|
|
102
|
-
default: 0.2
|
|
103
|
-
}
|
|
2
|
+
throw new Error(
|
|
3
|
+
'Component attempted to register before AFRAME was available.'
|
|
4
|
+
);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Poster Popup component for A-Frame.
|
|
9
|
+
*/
|
|
10
|
+
AFRAME.registerComponent('babia-poster', {
|
|
11
|
+
schema: {
|
|
12
|
+
title: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
default: 'New Poster'
|
|
15
|
+
},
|
|
16
|
+
titleColor: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
default: 'black'
|
|
19
|
+
},
|
|
20
|
+
titleFont: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
default: 'mozillavr'
|
|
23
|
+
},
|
|
24
|
+
titleWrapCount: {
|
|
25
|
+
type: 'number',
|
|
26
|
+
default: 24
|
|
27
|
+
},
|
|
28
|
+
body: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
default: 'This poster has no body yet.'
|
|
31
|
+
},
|
|
32
|
+
bodyColor: {
|
|
33
|
+
type: 'string',
|
|
34
|
+
default: 'black'
|
|
35
|
+
},
|
|
36
|
+
bodyFont: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
default: 'mozillavr'
|
|
39
|
+
},
|
|
40
|
+
bodyWrapCount: {
|
|
41
|
+
type: 'number',
|
|
42
|
+
default: 30
|
|
43
|
+
},
|
|
44
|
+
openOn: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
default: 'click'
|
|
104
47
|
},
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
titleEl: null,
|
|
109
|
-
bodyEl: null,
|
|
110
|
-
imageEl: null,
|
|
111
|
-
hasImage: false,
|
|
112
|
-
/**
|
|
113
|
-
* Spawns the entities required to support this poster.
|
|
114
|
-
*/
|
|
115
|
-
init() {
|
|
116
|
-
this.cameraEl = document.querySelector('[camera]');
|
|
117
|
-
this.generateOpenIcon()
|
|
118
|
-
this.spawnEntities();
|
|
119
|
-
this.el.emit('loaded');
|
|
48
|
+
active: {
|
|
49
|
+
type: 'boolean',
|
|
50
|
+
default: true,
|
|
120
51
|
},
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
tick() {
|
|
125
|
-
if (this.isOpen) {
|
|
126
|
-
this.positionPosterPlane();
|
|
127
|
-
}
|
|
52
|
+
openIconImage: {
|
|
53
|
+
type: 'asset',
|
|
54
|
+
default: ''
|
|
128
55
|
},
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
remove() {
|
|
133
|
-
const { openOn } = this.data;
|
|
134
|
-
this.el.removeEventListener(
|
|
135
|
-
openOn,
|
|
136
|
-
this.togglePosterOpen.bind(this)
|
|
137
|
-
);
|
|
138
|
-
this.closeIconEl.removeEventListener(
|
|
139
|
-
openOn,
|
|
140
|
-
this.togglePosterOpen.bind(this)
|
|
141
|
-
);
|
|
56
|
+
openIconRadius: {
|
|
57
|
+
type: 'number',
|
|
58
|
+
default: 0.3
|
|
142
59
|
},
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
*/
|
|
147
|
-
update() {
|
|
148
|
-
this.generateTitle();
|
|
149
|
-
this.generateBody();
|
|
150
|
-
this.generateImage();
|
|
60
|
+
openIconColor: {
|
|
61
|
+
type: 'string',
|
|
62
|
+
default: 'white'
|
|
151
63
|
},
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
togglePosterOpen(event) {
|
|
156
|
-
// If the close icon is clicked, close the poster.
|
|
157
|
-
if (event.target.getAttribute('id') === `${this.el.getAttribute('id')}--close-icon`) {
|
|
158
|
-
this.posterPlaneEl.setAttribute('visible', false);
|
|
159
|
-
this.isOpen = false;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// If the open icon is clicked, and the poster is active, open the poster.
|
|
163
|
-
if (this.data.active && event.target.getAttribute('id') === this.el.getAttribute('id')) {
|
|
164
|
-
this.positionPosterPlane();
|
|
165
|
-
this.posterPlaneEl.setAttribute('visible', true);
|
|
166
|
-
this.isOpen = true;
|
|
167
|
-
}
|
|
64
|
+
closeIconImage: {
|
|
65
|
+
type: 'asset',
|
|
66
|
+
default: ''
|
|
168
67
|
},
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
generateOpenIcon() {
|
|
173
|
-
const {
|
|
174
|
-
openIconRadius: radius,
|
|
175
|
-
openIconColor: color,
|
|
176
|
-
openIconImage: src,
|
|
177
|
-
openOn
|
|
178
|
-
} = this.data;
|
|
179
|
-
|
|
180
|
-
this.el.setAttribute('geometry', {
|
|
181
|
-
primitive: 'circle',
|
|
182
|
-
radius
|
|
183
|
-
});
|
|
184
|
-
this.el.setAttribute('material', {
|
|
185
|
-
color,
|
|
186
|
-
src
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
this.el.addEventListener(openOn, this.togglePosterOpen.bind(this));
|
|
68
|
+
closeIconRadius: {
|
|
69
|
+
type: 'number',
|
|
70
|
+
default: 0.3
|
|
190
71
|
},
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
generateCloseIcon() {
|
|
195
|
-
const {
|
|
196
|
-
closeIconRadius: radius,
|
|
197
|
-
closeIconColor: color,
|
|
198
|
-
closeIconImage: src,
|
|
199
|
-
posterBoxWidth: width,
|
|
200
|
-
posterBoxHeight: height,
|
|
201
|
-
openOn
|
|
202
|
-
} = this.data;
|
|
203
|
-
|
|
204
|
-
const closeIcon = document.createElement('a-entity');
|
|
205
|
-
closeIcon.setAttribute('id', `${this.el.getAttribute('id')}--close-icon`);
|
|
206
|
-
closeIcon.setAttribute('position', {
|
|
207
|
-
x: width / 2,
|
|
208
|
-
y: height / 2,
|
|
209
|
-
z: 0.01
|
|
210
|
-
});
|
|
211
|
-
closeIcon.setAttribute('geometry', {
|
|
212
|
-
primitive: 'circle',
|
|
213
|
-
radius
|
|
214
|
-
});
|
|
215
|
-
closeIcon.setAttribute('material', {
|
|
216
|
-
color,
|
|
217
|
-
src
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
closeIcon.addEventListener(openOn, this.togglePosterOpen.bind(this));
|
|
221
|
-
|
|
222
|
-
this.closeIconEl = closeIcon;
|
|
223
|
-
return closeIcon;
|
|
72
|
+
closeIconColor: {
|
|
73
|
+
type: 'string',
|
|
74
|
+
default: 'white'
|
|
224
75
|
},
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
generateTitle() {
|
|
229
|
-
const {
|
|
230
|
-
title: value,
|
|
231
|
-
titleColor: color,
|
|
232
|
-
titleFont: font,
|
|
233
|
-
titleWrapCount: wrapCount,
|
|
234
|
-
posterBoxWidth: width,
|
|
235
|
-
posterBoxHeight: height,
|
|
236
|
-
posterBoxPadding: padding,
|
|
237
|
-
imageHeight
|
|
238
|
-
} = this.data;
|
|
239
|
-
|
|
240
|
-
const title = this.titleEl || document.createElement('a-entity');
|
|
241
|
-
title.setAttribute('id', `${this.el.getAttribute('id')}--title`);
|
|
242
|
-
title.setAttribute('text', {
|
|
243
|
-
value: value.substring(0, wrapCount),
|
|
244
|
-
color,
|
|
245
|
-
font,
|
|
246
|
-
wrapCount,
|
|
247
|
-
width: width - padding * 2,
|
|
248
|
-
baseline: 'top',
|
|
249
|
-
anchor: 'left'
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
let y = height / 2 - padding;
|
|
253
|
-
if (this.hasImage) {
|
|
254
|
-
y -= imageHeight / 2;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
title.setAttribute('position', {
|
|
258
|
-
x: -(width / 2) + padding,
|
|
259
|
-
y,
|
|
260
|
-
z: 0.01
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
this.titleEl = title;
|
|
264
|
-
return title;
|
|
76
|
+
image: {
|
|
77
|
+
type: 'string',
|
|
78
|
+
default: ''
|
|
265
79
|
},
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
generateBody() {
|
|
270
|
-
const {
|
|
271
|
-
body: value,
|
|
272
|
-
bodyColor: color,
|
|
273
|
-
bodyFont: font,
|
|
274
|
-
bodyWrapCount: wrapCount,
|
|
275
|
-
posterBoxWidth: width,
|
|
276
|
-
posterBoxHeight: height,
|
|
277
|
-
posterBoxPadding: padding,
|
|
278
|
-
imageHeight
|
|
279
|
-
} = this.data;
|
|
280
|
-
|
|
281
|
-
const body = this.bodyEl || document.createElement('a-entity');
|
|
282
|
-
body.setAttribute('id', `${this.el.getAttribute('id')}--title`);
|
|
283
|
-
body.setAttribute('text', {
|
|
284
|
-
value,
|
|
285
|
-
color,
|
|
286
|
-
font,
|
|
287
|
-
wrapCount,
|
|
288
|
-
width: width - padding * 2,
|
|
289
|
-
baseline: 'top',
|
|
290
|
-
anchor: 'left'
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
let y = height / 2 - padding * 3;
|
|
294
|
-
if (this.hasImage) {
|
|
295
|
-
y -= imageHeight / 2;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
body.setAttribute('position', {
|
|
299
|
-
x: -(width / 2) + padding,
|
|
300
|
-
y,
|
|
301
|
-
z: 0.01
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
this.bodyEl = body;
|
|
305
|
-
return body;
|
|
80
|
+
imageWidth: {
|
|
81
|
+
type: 'number',
|
|
82
|
+
default: 2
|
|
306
83
|
},
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
generateImage() {
|
|
311
|
-
const {
|
|
312
|
-
image: src,
|
|
313
|
-
imageWidth: width,
|
|
314
|
-
imageHeight: height,
|
|
315
|
-
posterBoxHeight
|
|
316
|
-
} = this.data;
|
|
317
|
-
|
|
318
|
-
if (!src.length) {
|
|
319
|
-
return null;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const image = this.imageEl || document.createElement('a-image');
|
|
323
|
-
image.setAttribute('id', `${this.el.getAttribute('id')}--image`);
|
|
324
|
-
image.setAttribute('src', src);
|
|
325
|
-
image.setAttribute('width', width);
|
|
326
|
-
image.setAttribute('height', height);
|
|
327
|
-
image.setAttribute('position', {
|
|
328
|
-
x: 0,
|
|
329
|
-
y: posterBoxHeight / 2,
|
|
330
|
-
z: 0.01
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
this.hasImage = true;
|
|
334
|
-
this.imageEl = image;
|
|
335
|
-
return image;
|
|
84
|
+
imageHeight: {
|
|
85
|
+
type: 'number',
|
|
86
|
+
default: 2
|
|
336
87
|
},
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
generatePosterPlane() {
|
|
341
|
-
const {
|
|
342
|
-
posterBoxWidth: width,
|
|
343
|
-
posterBoxHeight: height,
|
|
344
|
-
posterBoxPadding: padding,
|
|
345
|
-
posterBoxColor: color
|
|
346
|
-
} = this.data;
|
|
347
|
-
|
|
348
|
-
const plane = this.posterPlaneEl || document.createElement('a-entity');
|
|
349
|
-
plane.setAttribute('id', `${this.el.getAttribute('id')}--poster-plane`);
|
|
350
|
-
plane.setAttribute('position', { x: 0, y: 0, z: 0.5 });
|
|
351
|
-
plane.setAttribute('visible', false);
|
|
352
|
-
plane.setAttribute('geometry', {
|
|
353
|
-
primitive: 'plane',
|
|
354
|
-
width: width + padding,
|
|
355
|
-
height: height + padding
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
const image = this.generateImage();
|
|
359
|
-
if (image) {
|
|
360
|
-
plane.appendChild(this.generateImage());
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
plane.setAttribute('material', { color });
|
|
364
|
-
plane.appendChild(this.generateCloseIcon());
|
|
365
|
-
plane.appendChild(this.generateTitle());
|
|
366
|
-
plane.appendChild(this.generateBody());
|
|
367
|
-
|
|
368
|
-
this.posterPlaneEl = plane;
|
|
369
|
-
|
|
370
|
-
return plane;
|
|
88
|
+
posterBoxWidth: {
|
|
89
|
+
type: 'number',
|
|
90
|
+
default: 4
|
|
371
91
|
},
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
this.cameraEl.object3D.getWorldPosition()
|
|
376
|
-
);
|
|
377
|
-
this.posterPlaneEl.object3D.lookAt(vector);
|
|
378
|
-
}
|
|
92
|
+
posterBoxHeight: {
|
|
93
|
+
type: 'number',
|
|
94
|
+
default: 4
|
|
379
95
|
},
|
|
380
|
-
|
|
381
|
-
|
|
96
|
+
posterBoxColor: {
|
|
97
|
+
type: 'string',
|
|
98
|
+
default: 'white'
|
|
99
|
+
},
|
|
100
|
+
posterBoxPadding: {
|
|
101
|
+
type: 'number',
|
|
102
|
+
default: 0.2
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
multiple: true,
|
|
106
|
+
posterPlaneEl: null,
|
|
107
|
+
closeIconEl: null,
|
|
108
|
+
titleEl: null,
|
|
109
|
+
bodyEl: null,
|
|
110
|
+
imageEl: null,
|
|
111
|
+
hasImage: false,
|
|
112
|
+
/**
|
|
113
|
+
* Spawns the entities required to support this poster.
|
|
114
|
+
*/
|
|
115
|
+
init() {
|
|
116
|
+
this.cameraEl = document.querySelector('[camera]');
|
|
117
|
+
this.generateOpenIcon()
|
|
118
|
+
this.spawnEntities();
|
|
119
|
+
this.el.emit('loaded');
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* If the component is open, ensure it always faces the camera.
|
|
123
|
+
*/
|
|
124
|
+
tick() {
|
|
125
|
+
if (this.isOpen) {
|
|
126
|
+
this.positionPosterPlane();
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* When this component is removed, destruct event listeners.
|
|
131
|
+
*/
|
|
132
|
+
remove() {
|
|
133
|
+
const { openOn } = this.data;
|
|
134
|
+
this.el.removeEventListener(
|
|
135
|
+
openOn,
|
|
136
|
+
this.togglePosterOpen.bind(this)
|
|
137
|
+
);
|
|
138
|
+
this.closeIconEl.removeEventListener(
|
|
139
|
+
openOn,
|
|
140
|
+
this.togglePosterOpen.bind(this)
|
|
141
|
+
);
|
|
142
|
+
},
|
|
143
|
+
/**
|
|
144
|
+
* When this component is updated, re-calculate title, body, image, and
|
|
145
|
+
* poster plane to incorporate changes.
|
|
146
|
+
*/
|
|
147
|
+
update() {
|
|
148
|
+
this.generateTitle();
|
|
149
|
+
this.generateBody();
|
|
150
|
+
this.generateImage();
|
|
151
|
+
},
|
|
152
|
+
/**
|
|
153
|
+
* Handles opening and closing the poster plane.
|
|
154
|
+
*/
|
|
155
|
+
togglePosterOpen(event) {
|
|
156
|
+
// If the close icon is clicked, close the poster.
|
|
157
|
+
if (event.target.getAttribute('id') === `${this.el.getAttribute('id')}--close-icon`) {
|
|
158
|
+
this.posterPlaneEl.setAttribute('visible', false);
|
|
159
|
+
this.isOpen = false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// If the open icon is clicked, and the poster is active, open the poster.
|
|
163
|
+
if (this.data.active && event.target.getAttribute('id') === this.el.getAttribute('id')) {
|
|
164
|
+
this.positionPosterPlane();
|
|
165
|
+
this.posterPlaneEl.setAttribute('visible', true);
|
|
166
|
+
this.isOpen = true;
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
/**
|
|
170
|
+
* Generates the open icon.
|
|
171
|
+
*/
|
|
172
|
+
generateOpenIcon() {
|
|
173
|
+
const {
|
|
174
|
+
openIconRadius: radius,
|
|
175
|
+
openIconColor: color,
|
|
176
|
+
openIconImage: src,
|
|
177
|
+
openOn
|
|
178
|
+
} = this.data;
|
|
179
|
+
|
|
180
|
+
this.el.setAttribute('geometry', {
|
|
181
|
+
primitive: 'circle',
|
|
182
|
+
radius
|
|
183
|
+
});
|
|
184
|
+
this.el.setAttribute('material', {
|
|
185
|
+
color,
|
|
186
|
+
src
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
this.el.addEventListener(openOn, this.togglePosterOpen.bind(this));
|
|
190
|
+
},
|
|
191
|
+
/**
|
|
192
|
+
* Generates the close icon.
|
|
193
|
+
*/
|
|
194
|
+
generateCloseIcon() {
|
|
195
|
+
const {
|
|
196
|
+
closeIconRadius: radius,
|
|
197
|
+
closeIconColor: color,
|
|
198
|
+
closeIconImage: src,
|
|
199
|
+
posterBoxWidth: width,
|
|
200
|
+
posterBoxHeight: height,
|
|
201
|
+
openOn
|
|
202
|
+
} = this.data;
|
|
203
|
+
|
|
204
|
+
const closeIcon = document.createElement('a-entity');
|
|
205
|
+
closeIcon.setAttribute('id', `${this.el.getAttribute('id')}--close-icon`);
|
|
206
|
+
closeIcon.setAttribute('position', {
|
|
207
|
+
x: width / 2,
|
|
208
|
+
y: height / 2,
|
|
209
|
+
z: 0.01
|
|
210
|
+
});
|
|
211
|
+
closeIcon.setAttribute('geometry', {
|
|
212
|
+
primitive: 'circle',
|
|
213
|
+
radius
|
|
214
|
+
});
|
|
215
|
+
closeIcon.setAttribute('material', {
|
|
216
|
+
color,
|
|
217
|
+
src
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
closeIcon.addEventListener(openOn, this.togglePosterOpen.bind(this));
|
|
221
|
+
|
|
222
|
+
this.closeIconEl = closeIcon;
|
|
223
|
+
return closeIcon;
|
|
224
|
+
},
|
|
225
|
+
/**
|
|
226
|
+
* Generates the title text.
|
|
227
|
+
*/
|
|
228
|
+
generateTitle() {
|
|
229
|
+
const {
|
|
230
|
+
title: value,
|
|
231
|
+
titleColor: color,
|
|
232
|
+
titleFont: font,
|
|
233
|
+
titleWrapCount: wrapCount,
|
|
234
|
+
posterBoxWidth: width,
|
|
235
|
+
posterBoxHeight: height,
|
|
236
|
+
posterBoxPadding: padding,
|
|
237
|
+
imageHeight
|
|
238
|
+
} = this.data;
|
|
239
|
+
|
|
240
|
+
const title = this.titleEl || document.createElement('a-entity');
|
|
241
|
+
title.setAttribute('id', `${this.el.getAttribute('id')}--title`);
|
|
242
|
+
title.setAttribute('text', {
|
|
243
|
+
value: value.substring(0, wrapCount),
|
|
244
|
+
color,
|
|
245
|
+
font,
|
|
246
|
+
wrapCount,
|
|
247
|
+
width: width - padding * 2,
|
|
248
|
+
baseline: 'top',
|
|
249
|
+
anchor: 'left'
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
let y = height / 2 - padding;
|
|
253
|
+
if (this.hasImage) {
|
|
254
|
+
y -= imageHeight / 2;
|
|
382
255
|
}
|
|
383
|
-
|
|
256
|
+
|
|
257
|
+
title.setAttribute('position', {
|
|
258
|
+
x: -(width / 2) + padding,
|
|
259
|
+
y,
|
|
260
|
+
z: 0.01
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
this.titleEl = title;
|
|
264
|
+
return title;
|
|
265
|
+
},
|
|
266
|
+
/**
|
|
267
|
+
* Generates the body text entity.
|
|
268
|
+
*/
|
|
269
|
+
generateBody() {
|
|
270
|
+
const {
|
|
271
|
+
body: value,
|
|
272
|
+
bodyColor: color,
|
|
273
|
+
bodyFont: font,
|
|
274
|
+
bodyWrapCount: wrapCount,
|
|
275
|
+
posterBoxWidth: width,
|
|
276
|
+
posterBoxHeight: height,
|
|
277
|
+
posterBoxPadding: padding,
|
|
278
|
+
imageHeight
|
|
279
|
+
} = this.data;
|
|
280
|
+
|
|
281
|
+
const body = this.bodyEl || document.createElement('a-entity');
|
|
282
|
+
body.setAttribute('id', `${this.el.getAttribute('id')}--title`);
|
|
283
|
+
body.setAttribute('text', {
|
|
284
|
+
value,
|
|
285
|
+
color,
|
|
286
|
+
font,
|
|
287
|
+
wrapCount,
|
|
288
|
+
width: width - padding * 2,
|
|
289
|
+
baseline: 'top',
|
|
290
|
+
anchor: 'left'
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
let y = height / 2 - padding * 3;
|
|
294
|
+
if (this.hasImage) {
|
|
295
|
+
y -= imageHeight / 2;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
body.setAttribute('position', {
|
|
299
|
+
x: -(width / 2) + padding,
|
|
300
|
+
y,
|
|
301
|
+
z: 0.01
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
this.bodyEl = body;
|
|
305
|
+
return body;
|
|
306
|
+
},
|
|
307
|
+
/**
|
|
308
|
+
* Generates the image entity.
|
|
309
|
+
*/
|
|
310
|
+
generateImage() {
|
|
311
|
+
const {
|
|
312
|
+
image: src,
|
|
313
|
+
imageWidth: width,
|
|
314
|
+
imageHeight: height,
|
|
315
|
+
posterBoxHeight
|
|
316
|
+
} = this.data;
|
|
317
|
+
|
|
318
|
+
if (!src.length) {
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const image = this.imageEl || document.createElement('a-image');
|
|
323
|
+
image.setAttribute('id', `${this.el.getAttribute('id')}--image`);
|
|
324
|
+
image.setAttribute('src', src);
|
|
325
|
+
image.setAttribute('width', width);
|
|
326
|
+
image.setAttribute('height', height);
|
|
327
|
+
image.setAttribute('position', {
|
|
328
|
+
x: 0,
|
|
329
|
+
y: posterBoxHeight / 2,
|
|
330
|
+
z: 0.01
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
this.hasImage = true;
|
|
334
|
+
this.imageEl = image;
|
|
335
|
+
return image;
|
|
336
|
+
},
|
|
337
|
+
/**
|
|
338
|
+
* Generates the poster plane.
|
|
339
|
+
*/
|
|
340
|
+
generatePosterPlane() {
|
|
341
|
+
const {
|
|
342
|
+
posterBoxWidth: width,
|
|
343
|
+
posterBoxHeight: height,
|
|
344
|
+
posterBoxPadding: padding,
|
|
345
|
+
posterBoxColor: color
|
|
346
|
+
} = this.data;
|
|
347
|
+
|
|
348
|
+
const plane = this.posterPlaneEl || document.createElement('a-entity');
|
|
349
|
+
plane.setAttribute('id', `${this.el.getAttribute('id')}--poster-plane`);
|
|
350
|
+
plane.setAttribute('position', { x: 0, y: 0, z: 0.5 });
|
|
351
|
+
plane.setAttribute('visible', false);
|
|
352
|
+
plane.setAttribute('geometry', {
|
|
353
|
+
primitive: 'plane',
|
|
354
|
+
width: width + padding,
|
|
355
|
+
height: height + padding
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const image = this.generateImage();
|
|
359
|
+
if (image) {
|
|
360
|
+
plane.appendChild(this.generateImage());
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
plane.setAttribute('material', { color });
|
|
364
|
+
plane.appendChild(this.generateCloseIcon());
|
|
365
|
+
plane.appendChild(this.generateTitle());
|
|
366
|
+
plane.appendChild(this.generateBody());
|
|
367
|
+
|
|
368
|
+
this.posterPlaneEl = plane;
|
|
369
|
+
|
|
370
|
+
return plane;
|
|
371
|
+
},
|
|
372
|
+
positionPosterPlane() {
|
|
373
|
+
if (this.posterPlaneEl && this.cameraEl) {
|
|
374
|
+
const cameraWorldPos = new THREE.Vector3();
|
|
375
|
+
this.cameraEl.object3D.getWorldPosition(cameraWorldPos);
|
|
376
|
+
|
|
377
|
+
const vector = this.posterPlaneEl.object3D.parent.worldToLocal(cameraWorldPos);
|
|
378
|
+
this.posterPlaneEl.object3D.lookAt(vector);
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
spawnEntities() {
|
|
382
|
+
this.el.appendChild(this.generatePosterPlane());
|
|
383
|
+
}
|
|
384
|
+
});
|