aframe-babia-components 1.2.9 → 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.
Files changed (52) hide show
  1. package/components/filters/babia-selector.js +33 -21
  2. package/components/filters/babia-treebuilder.js +14 -13
  3. package/components/others/babia-navigator.js +94 -37
  4. package/components/others/babia-poster.js +369 -368
  5. package/components/others/babia-slider.js +63 -25
  6. package/components/others/common.js +60 -80
  7. package/components/visualizers/babia-html.js +95 -118
  8. package/components/visualizers/babia-map.js +796 -0
  9. package/dist/aframe-babia-components.js +7249 -6492
  10. package/dist/aframe-babia-components.min.js +1 -1
  11. package/dist/aframe-babia-components.min.js.LICENSE.txt +1 -1
  12. package/dist/aframe-babia-components.min.js.map +1 -1
  13. package/docs/APIs/OTHERS.md +4 -4
  14. package/docs/CONTRIBUTING.md +34 -25
  15. package/docs/RELEASE_NOTES.md +9 -2
  16. package/docs/Tutorials/HOW_TO_USE_BABIA_MAP.md +554 -0
  17. package/docs/Tutorials/ejemplo1.png +0 -0
  18. package/docs/Tutorials/ejemplo2.png +0 -0
  19. package/docs/Tutorials/ejemplo3.png +0 -0
  20. package/docs/Tutorials/pyramids.png +0 -0
  21. package/docs/Tutorials/singular.png +0 -0
  22. package/docs/Tutorials/terrain-vr-scenario.png +0 -0
  23. package/docs/Tutorials/terrain.png +0 -0
  24. package/examples/boats/boats2/data.json +206 -13
  25. package/examples/charts/pie/index.html +0 -5
  26. package/examples/demos/map-terrain/assets/360-panorama.jpg +0 -0
  27. package/examples/demos/map-terrain/assets/floor-texture.jpg +0 -0
  28. package/examples/demos/map-terrain/assets/mapTextures/512sample.webp +0 -0
  29. package/examples/demos/map-terrain/assets/mapTextures/defaultTexture.webp +0 -0
  30. package/examples/demos/map-terrain/assets/maps/defaultMap.png +0 -0
  31. package/examples/demos/map-terrain/assets/maps/example.png +0 -0
  32. package/examples/demos/map-terrain/assets/metalic-texture.jpg +0 -0
  33. package/examples/demos/map-terrain/dist/aframe-lounge-component.min.js +1 -0
  34. package/examples/demos/map-terrain/index.html +82 -0
  35. package/examples/demos/map-terrain/index_gallery.html +188 -0
  36. package/examples/demos/map-terrain/main_data.json +1 -0
  37. package/examples/demos/map-terrain/pyramids.html +130 -0
  38. package/examples/js/aframe-orbit-controls-component.js +1060 -0
  39. package/examples/ui/pie/index.html +0 -1
  40. package/index.html +15 -0
  41. package/index.js +1 -0
  42. package/package.json +5 -5
  43. package/tests/screenshots/other_snapshots.js/pyramids.png +0 -0
  44. package/tests/screenshots/other_snapshots.js/singular.png +0 -0
  45. package/tests/screenshots/other_snapshots.js/terrain-vr-scenario.png +0 -0
  46. package/tests/screenshots/other_snapshots.js/terrain.png +0 -0
  47. package/webpack.common.js +1 -1
  48. package/webpack.dev.js +17 -0
  49. package/examples/demos/citations/babiaxr.json +0 -1
  50. package/examples/demos/citations/citations.html +0 -72
  51. package/examples/demos/citations/music.mp3 +0 -0
  52. package/examples/demos/citations/stl.js +0 -28
@@ -3,22 +3,18 @@ let findNavComponent = require('../others/common').findNavComponent;
3
3
  let parseJson = require('../others/common').parseJson;
4
4
 
5
5
  class Selectable {
6
- /*
7
- * @param list {array} List of items to select from
8
- * @param field {string} Field name used to select (present in all items)
6
+ /**
7
+ * Create a new Selectable object.
8
+ *
9
+ * @param {string} field - Field of the data to select.
10
+ * @param {number} [current=-2] - Current value of the selection. If -2, it will be set to 0.
11
+ * @param {number} [step=1] - Step value for the selection.
12
+ * @param {number} [speed=1] - Speed value for the selection.
13
+ * @param {string} [state='play'] - State of the selection. 'play' or 'pause'.
14
+ * @param {string} [direction='forward'] - Direction of the selection. 'forward' or 'rewind'.
9
15
  */
10
- constructor(list, field, current, step, speed, state, direction) {
11
- this.data = {};
12
- for (let item of list) {
13
- let selector = item[field];
14
- if ( this.data[selector] ) {
15
- this.data[selector].push(item);
16
- } else {
17
- this.data[selector] = [item];
18
- };
19
- }
20
- this.selectors = Object.keys(this.data).sort();
21
- this.length = this.selectors.length;
16
+ constructor(field, current, step, speed, state, direction) {
17
+ this.field = field;
22
18
  if (!step){
23
19
  this.step = 1
24
20
  } else {
@@ -46,6 +42,23 @@ class Selectable {
46
42
  }
47
43
  }
48
44
 
45
+ /**
46
+ * Update the internal data structure with a new list of items
47
+ * @param list {array} List of items to select from
48
+ */
49
+ updateData(list) {
50
+ this.data = {};
51
+ for (let item of list) {
52
+ let selector = item[this.field];
53
+ if ( this.data[selector] ) {
54
+ this.data[selector].push(item);
55
+ } else {
56
+ this.data[selector] = [item];
57
+ };
58
+ }
59
+ this.selectors = Object.keys(this.data).sort();
60
+ this.length = this.selectors.length;
61
+ }
49
62
  next() {
50
63
  let selected = this.data[this.selectors[this.current]];
51
64
  if (this.current + this.step <= this.length - 1){
@@ -106,7 +119,7 @@ AFRAME.registerComponent('babia-selector', {
106
119
  // Id of the querier where the data comes from
107
120
  from: { type: 'string' },
108
121
  // Id of the querier where the data comes from
109
- controller: { type: 'string' },
122
+ controller: { type: 'string', default: '' },
110
123
  // Field to use as selector
111
124
  select: { type: 'string', default: 'date'},
112
125
  // Timeout for moving to the next selection
@@ -134,6 +147,8 @@ AFRAME.registerComponent('babia-selector', {
134
147
  init: function () {
135
148
  this.notiBuffer = new NotiBuffer();
136
149
  this.navNotiBuffer = new NotiBuffer();
150
+ // Create a Selectable object, set its values
151
+ this.selectable = new Selectable(this.data.select, this.data.current_value, this.data.step, this.data.speed);
137
152
  },
138
153
 
139
154
  /**
@@ -167,7 +182,7 @@ AFRAME.registerComponent('babia-selector', {
167
182
  }
168
183
 
169
184
  // find controller
170
- if (data.controller != oldData.controller){
185
+ if (data.controller && (data.controller != oldData.controller)){
171
186
  this.selectorController = document.querySelector('#' + data.controller)
172
187
  // Unregister for old navigator
173
188
  if (this.navComponent) {
@@ -338,10 +353,7 @@ AFRAME.registerComponent('babia-selector', {
338
353
  newData: undefined,
339
354
 
340
355
  processData: function (_data) {
341
- // Create a Selectable object, and set the updating interval
342
- if (!this.selectable){
343
- this.selectable = new Selectable(_data, this.data.select, this.data.current_value, this.data.step, this.data.speed);
344
- }
356
+ this.selectable.updateData(_data);
345
357
  this.navNotiBuffer.set({type: 'position', value: this.selectable.current, label: this.selectable.selectors[this.selectable.current-1]})
346
358
  let self = this;
347
359
  this.nextSelect();
@@ -85,32 +85,33 @@ AFRAME.registerComponent('babia-treebuilder', {
85
85
  for (let i = 0; i < paths.length; i++) {
86
86
  let path = paths[i][data.field].split(data.split_by);
87
87
  let currentLevel = tree;
88
+ let currentUid = '';
89
+
88
90
  for (let j = 0; j < path.length; j++) {
89
91
  // Check if starts with the split char
90
92
  if (!path[j]) { continue }
91
-
93
+
92
94
  let part = path[j];
93
- //console.log("currentLevel", currentLevel)
94
95
  let existingPath = findWhere(currentLevel, 'name', part);
95
-
96
+
96
97
  if (existingPath) {
97
98
  currentLevel = existingPath.children;
99
+ currentUid = existingPath.uid; // Update the UID accumulator
98
100
  } else {
99
- let newPart = {}
101
+ let newPart = {};
100
102
  if (j === path.length - 1) {
101
- newPart = paths[i]
103
+ newPart = paths[i];
102
104
  } else {
103
- newPart['children'] = []
104
- }
105
- let findUid = paths[i][data.field].split(data.split_by + part + data.split_by)
106
- // No pop if it is a building beacuse it breaks
107
- if (findUid.length > 1) {
108
- let rest = findUid.pop()
105
+ newPart['children'] = [];
109
106
  }
110
- newPart['uid'] = findUid.join(data.split_by + part + data.split_by) + data.split_by + part
111
- newPart['name'] = part
107
+
108
+ // Create the UID for the part of the path
109
+ newPart['uid'] = currentUid ? currentUid + data.split_by + part : part;
110
+ newPart['name'] = part;
111
+
112
112
  currentLevel.push(newPart);
113
113
  currentLevel = newPart.children;
114
+ currentUid = newPart['uid']; // Update the UID accumulator
114
115
  }
115
116
  }
116
117
  }
@@ -9,9 +9,9 @@ const NotiBuffer = require("../../common/noti-buffer").NotiBuffer;
9
9
  AFRAME.registerComponent('babia-navigator', {
10
10
  schema: {
11
11
  // Current direction
12
- direction: { type: 'string', default: ''},
12
+ direction: { type: 'string', default: '' },
13
13
  // Current state
14
- state: { type: 'string', default: ''},
14
+ state: { type: 'string', default: '' },
15
15
  },
16
16
 
17
17
  /**
@@ -19,7 +19,7 @@ AFRAME.registerComponent('babia-navigator', {
19
19
  */
20
20
  multiple: false,
21
21
  sliderEl: undefined,
22
-
22
+
23
23
  /**
24
24
  * Initial creation and setting of the mesh.
25
25
  */
@@ -33,6 +33,7 @@ AFRAME.registerComponent('babia-navigator', {
33
33
  */
34
34
 
35
35
  update: function (oldData) {
36
+ let self = this
36
37
  let data = this.data;
37
38
  if ((data.state) && (data.state != oldData.state)) {
38
39
  this.controlNavigator(data.state)
@@ -40,9 +41,28 @@ AFRAME.registerComponent('babia-navigator', {
40
41
  if ((data.direction) && (data.direction != oldData.direction)) {
41
42
  this.controlNavigator(data.direction)
42
43
  }
44
+
45
+ // Generate interface in the hand
46
+ if (document.querySelector('#babia-menu-hand')) {
47
+ let hand_ui = document.querySelector('#babia-menu-hand')
48
+ hand_ui.parentNode.removeChild(hand_ui)
49
+ insertInterfaceOnHand(self, self.handController)
50
+ }
51
+
52
+ document.addEventListener('controllerconnected', (event) => {
53
+ // while (self.el.firstChild)
54
+ // self.el.firstChild.remove();
55
+ // event.detail.name ----> which VR controller
56
+ controller = event.detail.name;
57
+ let hand = event.target.getAttribute(controller).hand
58
+ if (hand === 'left' && !document.querySelector('#babia-menu-hand')) {
59
+ self.handController = event.target.id
60
+ insertInterfaceOnHand(self, self.handController)
61
+ }
62
+ });
43
63
  },
44
64
 
45
- initializeControls: function(){
65
+ initializeControls: function () {
46
66
  // Initialize Slider
47
67
  this.sliderEl = document.createElement('a-entity');
48
68
  this.sliderEl.min = 0
@@ -53,103 +73,103 @@ AFRAME.registerComponent('babia-navigator', {
53
73
  min: this.sliderEl.min,
54
74
  max: this.sliderEl.max,
55
75
  value: this.current
56
- });
76
+ });
57
77
  // When implement with selector, add the attributes
58
78
  this.sliderEl.classList.add("babiaxraycasterclass");
59
79
  this.sliderEl.id = "timeline"
60
- this.sliderEl.setAttribute('scale', {x:2.3, y:2.3, z:2.3})
80
+ this.sliderEl.setAttribute('scale', { x: 2.3, y: 2.3, z: 2.3 })
61
81
  this.el.appendChild(this.sliderEl);
62
82
 
63
83
  // Initialize Controls
64
84
  this.controlsEl = document.createElement('a-entity');
65
- this.controlsEl.setAttribute('babia-controls', "");
85
+ this.controlsEl.setAttribute('babia-controls', "");
66
86
  this.controlsEl.classList.add("babiaxraycasterclass");
67
- this.controlsEl.setAttribute('scale', {x:0.15, y:0.15, z:0.3})
87
+ this.controlsEl.setAttribute('scale', { x: 0.15, y: 0.15, z: 0.3 })
68
88
  this.controlsEl.object3D.position.y = -0.5;
69
89
  this.el.appendChild(this.controlsEl);
70
90
 
71
91
  // Initialize Step Controller
72
92
  this.stepControllerEl = document.createElement('a-entity');
73
- this.stepControllerEl.setAttribute('babia-step-controller', "");
93
+ this.stepControllerEl.setAttribute('babia-step-controller', "");
74
94
  this.stepControllerEl.classList.add("babiaxraycasterclass");
75
95
  this.stepControllerEl.object3D.position.x = 2.5;
76
96
  this.el.appendChild(this.stepControllerEl);
77
97
 
78
98
  // Initialize Speed Controller
79
99
  this.speedControllerEl = document.createElement('a-entity');
80
- this.speedControllerEl.setAttribute('babia-speed-controller', "");
100
+ this.speedControllerEl.setAttribute('babia-speed-controller', "");
81
101
  this.speedControllerEl.classList.add("babiaxraycasterclass");
82
102
  this.speedControllerEl.object3D.position.x = 3;
83
103
  this.el.appendChild(this.speedControllerEl);
84
104
  },
85
105
 
86
- updateSlider: function(evt){
106
+ updateSlider: function (evt) {
87
107
  let value = this.sliderEl.getAttribute('babia-slider').value
88
- if (evt ==='skipNext'){
108
+ if (evt === 'skipNext') {
89
109
  value++
90
- } else if (evt === 'skipPrev'){
110
+ } else if (evt === 'skipPrev') {
91
111
  value--
92
112
  }
93
113
  // Out of range
94
- if (((evt === 'skipPrev') && (value >= 0)) || ((evt === 'skipNext') && (value <= this.sliderEl.max))){
114
+ if (((evt === 'skipPrev') && (value >= 0)) || ((evt === 'skipNext') && (value <= this.sliderEl.max))) {
95
115
  this.current = value
96
116
  this.notiBuffer.set('babiaSetPosition' + this.current)
97
117
  } else {
98
- if (this.controlsEl.querySelector('.babiaPause')){
118
+ if (this.controlsEl.querySelector('.babiaPause')) {
99
119
  this.current = value
100
120
  processData('pause')
101
121
  }
102
122
  }
103
-
123
+
104
124
  },
105
- registerBack: function(prodComponent){
125
+ registerBack: function (prodComponent) {
106
126
  this.selector = prodComponent;
107
127
  this.prodComponent = prodComponent;
108
128
 
109
129
  // Register for the new one
110
- if (this.prodComponent.navNotiBuffer){
130
+ if (this.prodComponent.navNotiBuffer) {
111
131
  this.navNotiBufferId = this.prodComponent.navNotiBuffer.register(this.processData.bind(this));
112
132
  }
113
133
  },
114
134
 
115
- unregisterBack: function(prodComponent) {
135
+ unregisterBack: function (prodComponent) {
116
136
  prodComponent.navNotiBuffer.unregister(this.navNotiBufferId)
117
137
  },
118
138
 
119
- processData: function(data){
120
- if (data == 'pause'){
139
+ processData: function (data) {
140
+ if (data == 'pause') {
121
141
  this.controlsEl.setAttribute('babia-controls', 'state', 'pause')
122
- } else if (data == 'rewind'){
142
+ } else if (data == 'rewind') {
123
143
  this.el.setAttribute('babia-navigator', 'direction', 'rewind')
124
- } else if (data == 'forward'){
144
+ } else if (data == 'forward') {
125
145
  this.el.setAttribute('babia-navigator', 'direction', 'forward')
126
- } else if (data.type){
127
- if (data.type === 'position'){
128
- if (!this.sliderEl){
146
+ } else if (data.type) {
147
+ if (data.type === 'position') {
148
+ if (!this.sliderEl) {
129
149
  this.initializeControls()
130
150
  }
131
- if (this.data.direction != 'rewind'){
151
+ if (this.data.direction != 'rewind') {
132
152
  this.current = data.value - 1
133
153
  } else {
134
154
  this.current = data.value + 1
135
155
  }
136
-
137
- if ((this.current >= this.sliderEl.min) && (this.current <= this.sliderEl.max)){
138
- if (data.label){
156
+
157
+ if ((this.current >= this.sliderEl.min) && (this.current <= this.sliderEl.max)) {
158
+ if (data.label) {
139
159
  this.sliderEl.setAttribute('babia-slider', {
140
160
  label: data.label,
141
161
  value: this.current
142
- })
162
+ })
143
163
  } else {
144
164
  this.sliderEl.setAttribute('babia-slider', 'value', this.current)
145
165
  }
146
166
  }
147
- } else if (data.type === 'step'){
148
- this.stepControllerEl.setAttribute('babia-step-controller', 'value', data.value)
149
- } else if (data.type === 'speed'){
167
+ } else if (data.type === 'step') {
168
+ this.stepControllerEl.setAttribute('babia-step-controller', 'value', data.value)
169
+ } else if (data.type === 'speed') {
150
170
  this.speedControllerEl.setAttribute('babia-speed-controller', 'value', data.value)
151
171
  }
152
- }
172
+ }
153
173
  },
154
174
 
155
175
  /**
@@ -175,6 +195,43 @@ AFRAME.registerComponent('babia-navigator', {
175
195
  this.updateSlider(evt)
176
196
  } else {
177
197
  this.notiBuffer.set(evt + value)
178
- }
198
+ }
179
199
  },
180
- })
200
+ })
201
+
202
+ let insertInterfaceOnHand = (self, hand) => {
203
+ let hand_entity = document.getElementById(hand)
204
+ let scale = 0.1
205
+
206
+ // self.interface.id = 'babia-menu-hand'
207
+ self.el.setAttribute('scale', { x: scale, y: scale, z: scale })
208
+ // self.el.setAttribute('position', { x: -scale * self.el.width / 2, y: scale * self.el.height / 2, z: -0.1 })
209
+ self.el.setAttribute('position', { x: 0, y: 0, z: -0.1 })
210
+ self.el.setAttribute('rotation', { x: -60 })
211
+ hand_entity.appendChild(self.el)
212
+
213
+ // Initialize Controls
214
+ self.el.removeChild(self.controlsEl)
215
+ self.controlsEl = document.createElement('a-entity');
216
+ self.controlsEl.setAttribute('babia-controls', "");
217
+ self.controlsEl.classList.add("babiaxraycasterclass");
218
+ self.controlsEl.setAttribute('scale', { x: 0.15, y: 0.15, z: 0.3 })
219
+ self.controlsEl.object3D.position.y = -0.5;
220
+ self.el.appendChild(self.controlsEl);
221
+
222
+ openCloseMenu(self.handController, self.el)
223
+ }
224
+
225
+ let openCloseMenu = (hand_id, entity_menu) => {
226
+ let menu_opened = true
227
+ let entity_hand = document.getElementById(hand_id)
228
+ entity_hand.addEventListener('gripdown', function () {
229
+ if (menu_opened) {
230
+ menu_opened = false
231
+ entity_menu.setAttribute('visible', false)
232
+ } else {
233
+ menu_opened = true
234
+ entity_menu.setAttribute('visible', true)
235
+ }
236
+ })
237
+ }