aframe-babia-components 1.4.0 → 1.5.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 (38) hide show
  1. package/common/city-history.js +53 -0
  2. package/components/visualizers/babia-boats.js +229 -2060
  3. package/components/visualizers/babia-city-evocells.js +189 -0
  4. package/components/visualizers/babia-city-evostreets.js +163 -0
  5. package/components/visualizers/babia-city-gospermap.js +190 -0
  6. package/components/visualizers/babia-city-hexgrid.js +6 -0
  7. package/components/visualizers/babia-city-hilbert.js +5 -0
  8. package/components/visualizers/babia-city-history-resistant.js +5 -0
  9. package/components/visualizers/babia-city-morton.js +5 -0
  10. package/components/visualizers/babia-city-voronoi.js +3 -211
  11. package/components/visualizers/boats/interactions.js +194 -0
  12. package/components/visualizers/boats/layout.js +148 -0
  13. package/components/visualizers/boats/legend.js +135 -0
  14. package/components/visualizers/evocells/history.js +69 -0
  15. package/components/visualizers/evocells/layout.js +170 -0
  16. package/components/visualizers/evocells/rectangles.js +183 -0
  17. package/components/visualizers/evostreets/layout.js +171 -0
  18. package/components/visualizers/gospermap/curve.js +91 -0
  19. package/components/visualizers/gospermap/layout.js +221 -0
  20. package/components/visualizers/gospermap/prisms.js +152 -0
  21. package/components/visualizers/gospermap/regions.js +99 -0
  22. package/components/visualizers/gospermap/selection.js +65 -0
  23. package/components/visualizers/hexgrid/grid.js +70 -0
  24. package/components/visualizers/hexgrid/layout.js +90 -0
  25. package/components/visualizers/hexgrid/prisms.js +71 -0
  26. package/components/visualizers/hilbert/layout.js +131 -0
  27. package/components/visualizers/history-resistant/layout.js +128 -0
  28. package/components/visualizers/morton/layout.js +79 -0
  29. package/components/visualizers/peak-lot-plan.js +72 -0
  30. package/components/visualizers/prism-city.js +226 -0
  31. package/components/visualizers/voronoi/history.js +35 -0
  32. package/components/visualizers/voronoi/hover-legend.js +6 -1
  33. package/components/visualizers/voronoi/layout.js +58 -23
  34. package/dist/aframe-babia-components.js +5872 -3118
  35. package/dist/aframe-babia-components.min.js +1 -1
  36. package/dist/aframe-babia-components.min.js.map +1 -1
  37. package/index.js +7 -0
  38. package/package.json +1 -1
@@ -0,0 +1,189 @@
1
+ /* global AFRAME */
2
+ const {colors, findProdComponent, parseJson} = require('../others/common');
3
+ const {NotiBuffer} = require('../../common/noti-buffer');
4
+ const {planFor} = require('../../common/city-history');
5
+ const {EvoCellsPlan} = require('./evocells/history');
6
+ const {number} = require('./voronoi/layout');
7
+ const {CityPrisms} = require('./voronoi/prisms');
8
+ const {CellLabel} = require('./voronoi/hover-legend');
9
+ const {QuarterSelection} = require('./voronoi/quarter-selection');
10
+ const name = 'babia-city-evocells', THREE = AFRAME.THREE;
11
+
12
+ function paint(color, cell, d, range) {
13
+ if (cell.quarter) return color.set(d.base_color);
14
+ const v = cell.data[d.color];
15
+ if (!d.color || v == null || v === '') return color.set(d.building_color);
16
+ const n = number(v);
17
+ if (Number.isFinite(n)) {
18
+ const t = range.colorMax > range.colorMin ? (n - range.colorMin) / (range.colorMax - range.colorMin) : 0.5;
19
+ return color.setHSL((1 - t) * 0.62, 0.72, 0.48);
20
+ }
21
+ let hash = 0;
22
+ for (const ch of String(v)) hash = (31 * hash + ch.charCodeAt(0)) >>> 0;
23
+ return color.set(colors.get(hash, 'categoric'));
24
+ }
25
+
26
+ AFRAME.registerComponent(name, {
27
+ schema: {
28
+ data: {type: 'asset'},
29
+ from: {type: 'string'},
30
+ field: {default: 'uid'},
31
+ area: {type: 'string'},
32
+ width: {default: 'width'},
33
+ depth: {default: 'depth'},
34
+ height: {default: 'height'},
35
+ color: {type: 'string'},
36
+ size: {default: 8},
37
+ separation: {default: 0.08},
38
+ border: {default: 0.12},
39
+ zone_elevation: {default: 0.08},
40
+ minBuildingHeight: {default: 0.03},
41
+ maxBuildingHeight: {default: 2},
42
+ diffBuildingHeight: {default: false},
43
+ base_color: {type: 'color', default: '#98e690'},
44
+ building_color: {type: 'color', default: '#E6B9A1'},
45
+ quarterHighlightColor: {type: 'color', default: '#2867CC'},
46
+ legend: {default: true},
47
+ animation: {default: true},
48
+ animationDuration: {default: 500},
49
+ time_evolution_reserve_space: {type: 'boolean', default: true}
50
+ },
51
+ init: function() {
52
+ this.notiBuffer = new NotiBuffer();
53
+ this.prisms = new CityPrisms(THREE, this.el);
54
+ this.el.setObject3D(name, this.prisms.group);
55
+ this.selection = new QuarterSelection(THREE, this.el.sceneEl.object3D);
56
+ this.keys = new Set();
57
+ this.cursors = new Set();
58
+ this.onDisconnect = e => this.forget(e.currentTarget);
59
+ this.onMove = () => {
60
+ this.overCanvas = true;
61
+ };
62
+ this.onLeave = () => {
63
+ this.overCanvas = false;
64
+ this.hover();
65
+ };
66
+ this.addedClass = !this.el.classList.contains('babiaxraycasterclass');
67
+ this.el.classList.add('babiaxraycasterclass');
68
+ },
69
+ update: function(old) {
70
+ const d = this.data;
71
+ const remap = ['field', 'area', 'width', 'depth', 'size', 'border', 'separation'].some(k => d[k] !== old[k]);
72
+ if (remap) this.plan = null;
73
+ if (d.data !== old.data || (!d.data && d.from !== old.from)) {
74
+ this.unsubscribe();
75
+ if (!d.data || !old.data) {
76
+ this.plan = null;
77
+ this.selection.set(null, this.prisms, d);
78
+ }
79
+ if (d.data) return this.processData(parseJson(d.data));
80
+ if (!d.from || document.getElementById(d.from)) this.producer = findProdComponent(d, this.el);
81
+ if (this.producer?.notiBuffer) {
82
+ if (this.producer.notiBuffer.data === undefined) this.processData([]);
83
+ this.token = this.producer.notiBuffer.register(tree => this.processData(tree));
84
+ } else
85
+ this.processData([]);
86
+ return;
87
+ }
88
+ if (!d.animation || d.animationDuration <= 0) this.prisms.finish();
89
+ if (!d.legend) this.label?.hide();
90
+ if (this.newData != null && (remap || [
91
+ 'height', 'color', 'minBuildingHeight', 'maxBuildingHeight', 'diffBuildingHeight', 'zone_elevation',
92
+ 'building_color', 'base_color', 'quarterHighlightColor', 'time_evolution_reserve_space'
93
+ ].some(k => d[k] !== old[k])))
94
+ this.draw(false);
95
+ },
96
+ processData: function(tree) {
97
+ this.newData = tree;
98
+ this.draw(this.data.animation && this.prisms.meshes.size > 0);
99
+ this.notiBuffer.set(tree);
100
+ },
101
+ draw: function(animate) {
102
+ const d = this.data;
103
+ this.plan = planFor(EvoCellsPlan, this.plan, d, this.producer);
104
+ const {cells, keys, range} = this.plan.frame(this.newData);
105
+ this.keys = keys;
106
+ this.label?.hide();
107
+ this.prisms.set(
108
+ cells, keys, animate && cells.length ? Math.max(0, d.animationDuration) : 0,
109
+ (c, cell) => paint(c, cell, d, range));
110
+ const mesh = this.selection.mesh;
111
+ if (mesh) this.selection.set(keys.has(mesh.userData.cell.key) ? mesh : null, this.prisms, d);
112
+ },
113
+ play: function() {
114
+ const canvas = this.el.sceneEl.canvas;
115
+ canvas?.addEventListener('mousemove', this.onMove);
116
+ canvas?.addEventListener('mouseleave', this.onLeave);
117
+ },
118
+ pause: function() {
119
+ const canvas = this.el.sceneEl.canvas;
120
+ canvas?.removeEventListener('mousemove', this.onMove);
121
+ canvas?.removeEventListener('mouseleave', this.onLeave);
122
+ for (const c of this.cursors) c.removeEventListener('controllerdisconnected', this.onDisconnect);
123
+ this.cursors.clear();
124
+ this.overCanvas = false;
125
+ this.label?.hide();
126
+ },
127
+ tick: function(time, delta) {
128
+ this.prisms.step(delta);
129
+ this.selection.update(this.prisms);
130
+ if (this.cursors.size && this.data.legend) this.hover();
131
+ },
132
+ picked: function(hit) {
133
+ const mesh = hit?.object, cell = mesh?.userData.cell;
134
+ return cell && mesh.parent === this.prisms.group && mesh.visible && this.keys.has(cell.key) ? cell : null;
135
+ },
136
+ hover: function() {
137
+ let best;
138
+ for (const c of this.cursors) {
139
+ if (c.components.cursor?.data.rayOrigin === 'mouse' &&
140
+ (!this.overCanvas || best || this.el.sceneEl.is('vr-mode')))
141
+ continue;
142
+ const ray = c.components.raycaster, hit = ray?.data.enabled && ray.getIntersection(this.el),
143
+ cell = this.picked(hit);
144
+ if (cell && !cell.quarter) best = hit;
145
+ }
146
+ if (!best || !this.data.legend) return this.label?.hide();
147
+ if (!this.label) this.label = new CellLabel(THREE, this.el.sceneEl.object3D);
148
+ this.label.show(best.object.userData.cell, best.point, this.data);
149
+ },
150
+ forget: function(cursor) {
151
+ if (!this.cursors.delete(cursor)) return;
152
+ cursor.removeEventListener('controllerdisconnected', this.onDisconnect);
153
+ this.hover();
154
+ },
155
+ events: {
156
+ mouseenter: function(e) {
157
+ const c = e.detail?.cursorEl;
158
+ if (!c?.components.raycaster) return;
159
+ this.cursors.add(c);
160
+ c.addEventListener('controllerdisconnected', this.onDisconnect);
161
+ this.hover();
162
+ },
163
+ mouseleave: function(e) { this.forget(e.detail?.cursorEl); },
164
+ click: function(e) {
165
+ const hit = e.detail?.intersection, cell = this.picked(hit);
166
+ if (!cell) return;
167
+ const {id, data, quarter} = cell, detail = {id, data, quarter};
168
+ if (quarter) {
169
+ detail.selected = this.selection.mesh !== hit.object;
170
+ this.selection.set(detail.selected ? hit.object : null, this.prisms, this.data);
171
+ }
172
+ this.el.emit('babia-evocells-select', detail);
173
+ }
174
+ },
175
+ unsubscribe: function() {
176
+ this.producer?.notiBuffer.unregister(this.token);
177
+ this.producer = null;
178
+ },
179
+ remove: function() {
180
+ this.unsubscribe();
181
+ this.plan = null;
182
+ this.selection.dispose();
183
+ this.label?.dispose();
184
+ this.prisms.clear();
185
+ this.keys.clear();
186
+ this.el.removeObject3D(name);
187
+ if (this.addedClass) this.el.classList.remove('babiaxraycasterclass');
188
+ }
189
+ });
@@ -0,0 +1,163 @@
1
+ /* global AFRAME */
2
+ const {findProdComponent, parseJson, colors} = require('../others/common');
3
+ const {NotiBuffer} = require('../../common/noti-buffer');
4
+ const {StreetPlan, defaults} = require('./evostreets/layout');
5
+ const {planFor} = require('../../common/city-history');
6
+ const {CityPrisms} = require('./voronoi/prisms');
7
+ const {CellLabel} = require('./voronoi/hover-legend');
8
+ const {QuarterSelection} = require('./voronoi/quarter-selection');
9
+ const {number} = require('./voronoi/layout');
10
+ const name = 'babia-city-evostreets', THREE = AFRAME.THREE;
11
+
12
+ function colorize(color, cell, d, range) {
13
+ if (cell.quarter) return color.set(d.base_color);
14
+ const value = cell.data[d.color];
15
+ if (!d.color || value == null || value === '') return color.set(d.building_color);
16
+ const n = number(value);
17
+ if (Number.isFinite(n)) {
18
+ const t = range.colorMax > range.colorMin ? (n - range.colorMin) / (range.colorMax - range.colorMin) : 0.5;
19
+ return color.setHSL((1-t)*0.62, 0.72, 0.48);
20
+ }
21
+ let hash = 0;
22
+ for (const ch of String(value)) hash = (31 * hash + ch.charCodeAt(0)) >>> 0;
23
+ return color.set(colors.get(hash, 'categoric'));
24
+ }
25
+
26
+ AFRAME.registerComponent(name, {
27
+ schema: {
28
+ ...Object.fromEntries(Object.entries(defaults).map(([k, v]) => [k, {default: v}])),
29
+ data: {type: 'asset'}, from: {type: 'string'}, animation: {default: true}, animationDuration: {default: 500},
30
+ legend: {default: true}, base_color: {type: 'color', default: '#98e690'},
31
+ building_color: {type: 'color', default: '#E6B9A1'}, quarterHighlightColor: {type: 'color', default: '#2867CC'}
32
+ },
33
+ init: function () {
34
+ this.notiBuffer = new NotiBuffer();
35
+ this.revision = -1;
36
+ this.prisms = new CityPrisms(THREE, this.el);
37
+ this.el.setObject3D(name, this.prisms.group);
38
+ this.selection = new QuarterSelection(THREE, this.el.sceneEl.object3D);
39
+ this.cursors = new Set();
40
+ this.onDisconnect = e => this.forget(e.currentTarget);
41
+ this.onCanvasMove = () => { this.overCanvas = true; };
42
+ this.onCanvasLeave = () => { this.overCanvas = false; this.hover(); };
43
+ this.addedClass = !this.el.classList.contains('babiaxraycasterclass');
44
+ this.el.classList.add('babiaxraycasterclass');
45
+ },
46
+ update: function (old) {
47
+ const d = this.data;
48
+ const remap = ['field','area','width','depth'].some(k => d[k] !== old[k]);
49
+ const resize = ['size','separation','border'].some(k => d[k] !== old[k]);
50
+ if (remap) this.plan = null;
51
+ else if (resize && this.plan) this.plan.fit = null;
52
+ if (d.data !== old.data || (!d.data && d.from !== old.from)) {
53
+ this.unsubscribe();
54
+ // A second inline snapshot is a stream update, not a new producer.
55
+ if (!d.data || !old.data) {
56
+ this.revision = -1;
57
+ this.plan = null;
58
+ this.selection.set(null, this.prisms, d);
59
+ }
60
+ if (d.data) return this.processData(parseJson(d.data));
61
+ if (!d.from || document.getElementById(d.from)) this.producer = findProdComponent(d, this.el);
62
+ if (this.producer?.notiBuffer) {
63
+ if (this.producer.notiBuffer.data === undefined) this.processData([]);
64
+ this.token = this.producer.notiBuffer.register(tree => this.processData(tree));
65
+ } else this.processData([]);
66
+ return;
67
+ }
68
+ if (!d.animation || d.animationDuration <= 0) this.prisms.finish();
69
+ if (!d.legend) this.label?.hide();
70
+ if (this.newData == null) return;
71
+ if (remap || resize || ['time_evolution_reserve_space','height','minBuildingHeight','maxBuildingHeight','diffBuildingHeight','zone_elevation','color',
72
+ 'building_color','base_color','quarterHighlightColor'].some(k => d[k] !== old[k])) this.draw(false);
73
+ },
74
+ processData: function (tree) {
75
+ this.newData = tree;
76
+ this.revision++;
77
+ this.draw(this.data.animation && this.prisms.meshes.size > 0);
78
+ this.notiBuffer.set(tree);
79
+ },
80
+ draw: function (animate) {
81
+ const d = this.data;
82
+ this.plan = planFor(StreetPlan, this.plan, d, this.producer);
83
+ const {cells, keys, range} = this.plan.frame(this.newData, this.plan.clock?.selectedIndex ?? this.revision);
84
+ this.keys = keys;
85
+ this.label?.hide();
86
+ this.prisms.set(cells, keys, animate && cells.length ? Math.max(0, d.animationDuration) : 0,
87
+ (color, cell) => colorize(color, cell, d, range));
88
+ const mesh = this.selection.mesh;
89
+ if (mesh) this.selection.set(keys.has(mesh.userData.cell.key) ? mesh : null, this.prisms, d);
90
+ },
91
+ play: function () {
92
+ const canvas = this.el.sceneEl.canvas;
93
+ canvas?.addEventListener('mousemove', this.onCanvasMove);
94
+ canvas?.addEventListener('mouseleave', this.onCanvasLeave);
95
+ },
96
+ pause: function () {
97
+ const canvas = this.el.sceneEl.canvas;
98
+ canvas?.removeEventListener('mousemove', this.onCanvasMove);
99
+ canvas?.removeEventListener('mouseleave', this.onCanvasLeave);
100
+ for (const cursor of this.cursors) cursor.removeEventListener('controllerdisconnected', this.onDisconnect);
101
+ this.cursors.clear();
102
+ this.label?.hide();
103
+ },
104
+ tick: function (time, delta) {
105
+ this.prisms.step(delta);
106
+ this.selection.update(this.prisms);
107
+ if (this.data.legend && this.cursors.size) this.hover();
108
+ },
109
+ pick: function (hit) {
110
+ const mesh = hit?.object, cell = mesh?.userData.cell;
111
+ return mesh?.parent === this.prisms.group && mesh.visible && cell && !cell.connector && this.keys.has(cell.key) ? cell : null;
112
+ },
113
+ hover: function () {
114
+ let best;
115
+ for (const cursor of this.cursors) {
116
+ if (cursor.components.cursor?.data.rayOrigin === 'mouse' && (!this.overCanvas || best || this.el.sceneEl.is('vr-mode'))) continue;
117
+ const ray = cursor.components.raycaster, hit = ray?.data.enabled && ray.getIntersection(this.el);
118
+ const cell = this.pick(hit);
119
+ if (cell && !cell.quarter) best = hit;
120
+ }
121
+ if (!best || !this.data.legend) return this.label?.hide();
122
+ if (!this.label) this.label = new CellLabel(THREE, this.el.sceneEl.object3D);
123
+ this.label.show(best.object.userData.cell, best.point, this.data);
124
+ },
125
+ forget: function (cursor) {
126
+ if (!this.cursors.delete(cursor)) return;
127
+ cursor.removeEventListener('controllerdisconnected', this.onDisconnect);
128
+ this.hover();
129
+ },
130
+ events: {
131
+ mouseenter: function (e) {
132
+ const cursor = e.detail?.cursorEl;
133
+ if (!cursor?.components.raycaster) return;
134
+ this.cursors.add(cursor);
135
+ cursor.addEventListener('controllerdisconnected', this.onDisconnect);
136
+ this.hover();
137
+ },
138
+ mouseleave: function (e) { this.forget(e.detail?.cursorEl); },
139
+ click: function (e) {
140
+ const hit = e.detail?.intersection, cell = this.pick(hit);
141
+ if (!cell) return;
142
+ const {id, data, quarter} = cell, detail = {id, data, quarter};
143
+ if (quarter) {
144
+ detail.selected = this.selection.mesh !== hit.object;
145
+ this.selection.set(detail.selected ? hit.object : null, this.prisms, this.data);
146
+ }
147
+ this.el.emit('babia-evostreets-select', detail);
148
+ }
149
+ },
150
+ unsubscribe: function () {
151
+ this.producer?.notiBuffer.unregister(this.token);
152
+ this.producer = null;
153
+ },
154
+ remove: function () {
155
+ this.unsubscribe();
156
+ this.plan = null;
157
+ this.selection.dispose();
158
+ this.label?.dispose();
159
+ this.prisms.clear();
160
+ this.el.removeObject3D(name);
161
+ if (this.addedClass) this.el.classList.remove('babiaxraycasterclass');
162
+ }
163
+ });
@@ -0,0 +1,190 @@
1
+ /* global AFRAME */
2
+ const {colors, findProdComponent, parseJson} = require('../others/common');
3
+ const {NotiBuffer} = require('../../common/noti-buffer');
4
+ const {planFor} = require('../../common/city-history');
5
+ const {GosperPlan} = require('./gospermap/layout');
6
+ const {number} = require('./voronoi/layout');
7
+ const {GosperPrisms} = require('./gospermap/prisms');
8
+ const {CellLabel} = require('./voronoi/hover-legend');
9
+ const {DistrictSelection} = require('./gospermap/selection');
10
+ const name = 'babia-city-gospermap', THREE = AFRAME.THREE;
11
+
12
+ function paint(color, cell, d, range) {
13
+ if (cell.quarter) return color.set(d.base_color);
14
+ const v = cell.data[d.color];
15
+ if (!d.color || v == null || v === '') return color.set(d.building_color);
16
+ const n = number(v);
17
+ if (Number.isFinite(n)) {
18
+ const t = range.colorMax > range.colorMin ? (n - range.colorMin) / (range.colorMax - range.colorMin) : 0.5;
19
+ return color.setHSL((1 - t) * 0.62, 0.72, 0.48);
20
+ }
21
+ let hash = 0;
22
+ for (const ch of String(v)) hash = (31 * hash + ch.charCodeAt(0)) >>> 0;
23
+ return color.set(colors.get(hash, 'categoric'));
24
+ }
25
+
26
+ AFRAME.registerComponent(name, {
27
+ schema: {
28
+ data: {type: 'asset'},
29
+ from: {type: 'string'},
30
+ field: {default: 'uid'},
31
+ area: {type: 'string'},
32
+ width: {default: 'width'},
33
+ depth: {default: 'depth'},
34
+ height: {default: 'height'},
35
+ color: {type: 'string'},
36
+ size: {default: 8},
37
+ separation: {default: 0.08},
38
+ border: {default: 0.12},
39
+ zone_elevation: {default: 0.08},
40
+ minBuildingHeight: {default: 0.03},
41
+ maxBuildingHeight: {default: 2},
42
+ diffBuildingHeight: {default: false},
43
+ base_color: {type: 'color', default: '#98e690'},
44
+ building_color: {type: 'color', default: '#E6B9A1'},
45
+ quarterHighlightColor: {type: 'color', default: '#2867CC'},
46
+ legend: {default: true},
47
+ animation: {default: true},
48
+ animationDuration: {default: 500},
49
+ time_evolution_reserve_space: {type: 'boolean', default: true}
50
+ },
51
+ init: function() {
52
+ this.notiBuffer = new NotiBuffer();
53
+ this.prisms = new GosperPrisms(THREE, this.el);
54
+ this.el.setObject3D(name, this.prisms.group);
55
+ this.selection = new DistrictSelection(THREE, this.el.sceneEl.object3D);
56
+ this.keys = new Set();
57
+ this.cursors = new Set();
58
+ this.onDisconnect = e => this.forget(e.currentTarget);
59
+ this.onMove = () => {
60
+ this.overCanvas = true;
61
+ };
62
+ this.onLeave = () => {
63
+ this.overCanvas = false;
64
+ this.hover();
65
+ };
66
+ this.addedClass = !this.el.classList.contains('babiaxraycasterclass');
67
+ this.el.classList.add('babiaxraycasterclass');
68
+ },
69
+ update: function(old) {
70
+ const d = this.data;
71
+ const remap = ['field', 'area', 'width', 'depth'].some(k => d[k] !== old[k]);
72
+ if (remap) this.plan = null;
73
+ if (d.data !== old.data || (!d.data && d.from !== old.from)) {
74
+ this.unsubscribe();
75
+ if (!d.data || !old.data) {
76
+ this.plan = null;
77
+ this.selection.set(null, this.prisms, d);
78
+ }
79
+ if (d.data) return this.processData(parseJson(d.data));
80
+ if (!d.from || document.getElementById(d.from)) this.producer = findProdComponent(d, this.el);
81
+ if (this.producer?.notiBuffer) {
82
+ if (this.producer.notiBuffer.data === undefined) this.processData([]);
83
+ this.token = this.producer.notiBuffer.register(tree => this.processData(tree));
84
+ } else
85
+ this.processData([]);
86
+ return;
87
+ }
88
+ if (!d.animation || d.animationDuration <= 0) this.prisms.finish();
89
+ if (!d.legend) this.label?.hide();
90
+ if (this.newData != null && (remap || [
91
+ 'size', 'border', 'separation', 'height', 'color', 'minBuildingHeight', 'maxBuildingHeight',
92
+ 'diffBuildingHeight', 'zone_elevation', 'building_color', 'base_color', 'quarterHighlightColor',
93
+ 'time_evolution_reserve_space'
94
+ ].some(k => d[k] !== old[k])))
95
+ this.draw(false);
96
+ },
97
+ processData: function(tree) {
98
+ this.newData = tree;
99
+ this.draw(this.data.animation && this.prisms.meshes.size > 0);
100
+ this.notiBuffer.set(tree);
101
+ },
102
+ draw: function(animate) {
103
+ const d = this.data;
104
+ this.plan = planFor(GosperPlan, this.plan, d, this.producer);
105
+ const {cells, keys, range} = this.plan.frame(this.newData);
106
+ this.keys = keys;
107
+ this.label?.hide();
108
+ const duration =
109
+ animate && cells.length && Number.isFinite(d.animationDuration) ? Math.max(0, d.animationDuration) : 0;
110
+ this.prisms.set(cells, keys, duration, (color, cell) => paint(color, cell, d, range));
111
+ const mesh = this.selection.mesh;
112
+ if (mesh) this.selection.set(keys.has(mesh.userData.cell.key) ? mesh : null, this.prisms, d);
113
+ },
114
+ play: function() {
115
+ const canvas = this.el.sceneEl.canvas;
116
+ canvas?.addEventListener('mousemove', this.onMove);
117
+ canvas?.addEventListener('mouseleave', this.onLeave);
118
+ },
119
+ pause: function() {
120
+ const canvas = this.el.sceneEl.canvas;
121
+ canvas?.removeEventListener('mousemove', this.onMove);
122
+ canvas?.removeEventListener('mouseleave', this.onLeave);
123
+ for (const c of this.cursors) c.removeEventListener('controllerdisconnected', this.onDisconnect);
124
+ this.cursors.clear();
125
+ this.overCanvas = false;
126
+ this.label?.hide();
127
+ },
128
+ tick: function(time, delta) {
129
+ this.prisms.step(delta);
130
+ this.selection.update(this.prisms);
131
+ if (this.cursors.size && this.data.legend) this.hover();
132
+ },
133
+ picked: function(hit) {
134
+ const mesh = hit?.object, cell = mesh?.userData.cell;
135
+ return cell && mesh.parent === this.prisms.group && mesh.visible && this.keys.has(cell.key) ? cell : null;
136
+ },
137
+ hover: function() {
138
+ let best;
139
+ for (const c of this.cursors) {
140
+ if (c.components.cursor?.data.rayOrigin === 'mouse' &&
141
+ (!this.overCanvas || best || this.el.sceneEl.is('vr-mode')))
142
+ continue;
143
+ const ray = c.components.raycaster, hit = ray?.data.enabled && ray.getIntersection(this.el),
144
+ cell = this.picked(hit);
145
+ if (cell && !cell.quarter) best = hit;
146
+ }
147
+ if (!best || !this.data.legend) return this.label?.hide();
148
+ if (!this.label) this.label = new CellLabel(THREE, this.el.sceneEl.object3D);
149
+ this.label.show(best.object.userData.cell, best.point, this.data);
150
+ },
151
+ forget: function(cursor) {
152
+ if (!this.cursors.delete(cursor)) return;
153
+ cursor.removeEventListener('controllerdisconnected', this.onDisconnect);
154
+ this.hover();
155
+ },
156
+ events: {
157
+ mouseenter: function(e) {
158
+ const c = e.detail?.cursorEl;
159
+ if (!c?.components.raycaster) return;
160
+ this.cursors.add(c);
161
+ c.addEventListener('controllerdisconnected', this.onDisconnect);
162
+ this.hover();
163
+ },
164
+ mouseleave: function(e) { this.forget(e.detail?.cursorEl); },
165
+ click: function(e) {
166
+ const hit = e.detail?.intersection, cell = this.picked(hit);
167
+ if (!cell) return;
168
+ const {id, data, quarter} = cell, detail = {id, data, quarter};
169
+ if (quarter) {
170
+ detail.selected = this.selection.mesh !== hit.object;
171
+ this.selection.set(detail.selected ? hit.object : null, this.prisms, this.data);
172
+ }
173
+ this.el.emit('babia-gospermap-select', detail);
174
+ }
175
+ },
176
+ unsubscribe: function() {
177
+ this.producer?.notiBuffer.unregister(this.token);
178
+ this.producer = null;
179
+ },
180
+ remove: function() {
181
+ this.unsubscribe();
182
+ this.plan = null;
183
+ this.selection.dispose();
184
+ this.label?.dispose();
185
+ this.prisms.clear();
186
+ this.keys.clear();
187
+ this.el.removeObject3D(name);
188
+ if (this.addedClass) this.el.classList.remove('babiaxraycasterclass');
189
+ }
190
+ });
@@ -0,0 +1,6 @@
1
+ /* global AFRAME */
2
+ const prismCity = require('./prism-city');
3
+ const {HexGridPlan} = require('./hexgrid/layout');
4
+ const {HexPrisms} = require('./hexgrid/prisms');
5
+
6
+ AFRAME.registerComponent('babia-city-hexgrid', prismCity(HexGridPlan, 'babia-hexgrid-select', HexPrisms));
@@ -0,0 +1,5 @@
1
+ /* global AFRAME */
2
+ const prismCity = require('./prism-city');
3
+ const {HilbertPlan} = require('./hilbert/layout');
4
+
5
+ AFRAME.registerComponent('babia-city-hilbert', prismCity(HilbertPlan, 'babia-hilbert-select'));
@@ -0,0 +1,5 @@
1
+ /* global AFRAME */
2
+ const prismCity = require('./prism-city');
3
+ const {HistoryResistantPlan} = require('./history-resistant/layout');
4
+
5
+ AFRAME.registerComponent('babia-city-history-resistant', prismCity(HistoryResistantPlan, 'babia-history-resistant-select'));
@@ -0,0 +1,5 @@
1
+ /* global AFRAME */
2
+ const prismCity = require('./prism-city');
3
+ const {MortonPlan} = require('./morton/layout');
4
+
5
+ AFRAME.registerComponent('babia-city-morton', prismCity(MortonPlan, 'babia-morton-select'));