Skip to content

Commit a937972

Browse files
committed
fix: Load additional map data when moving head or rig
Flapping (in VR or via button) changes the rig position, while other controls changed the head So far we tracked the rig and wouldn't load additional data when moving e.g. with wasd controls Tracking the head's world position now works with both ways
1 parent eecb765 commit a937972

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ <h1>osm4vr</h1>
8383
<a-entity id="rightHand" laser-controls="hand: right" wing log2hud="target: rhud"></a-entity>
8484
</a-entity>
8585

86-
<a-entity osm-tiles="lat: 49.16; lon: 10.163; trackId: rig" rotation="-90 0 0" shadow="receive: true"></a-entity>
87-
<a-entity osm-geojson="lat: 49.16; lon: 10.163; radius_m: 500; src: #json-world; trackId: rig"></a-entity>
86+
<a-entity osm-tiles="lat: 49.16; lon: 10.163; trackId: head" rotation="-90 0 0" shadow="receive: true"></a-entity>
87+
<a-entity osm-geojson="lat: 49.16; lon: 10.163; radius_m: 500; src: #json-world; trackId: head"></a-entity>
8888
</a-scene>
8989

9090
<!-- Some javascript to interact with the scene and its contents -->
@@ -112,6 +112,7 @@ <h1>osm4vr</h1>
112112

113113
// set user position to origin
114114
document.getElementById('rig').object3D.position.set(0, 0, 0);
115+
document.getElementById('head').object3D.position.set(0, 0, 0);
115116

116117
let tiles = document.querySelector('a-entity[osm-tiles]');
117118
tiles.setAttribute('osm-tiles', `lat: ${lat}; lon: ${lon}`);

osm-geojson.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ AFRAME.registerComponent('osm-geojson', {
4646
this.onSrcLoaded = this.onSrcLoaded.bind(this);
4747
},
4848

49-
tick: function () {
50-
if (this.trackPosition) {
51-
this.loadTilesAround(this.trackPosition);
52-
}
53-
},
54-
5549
update: function (oldData) {
5650
if (this.data !== oldData) {
51+
this.trackElement = null;
5752
this.trackPosition = null;
5853
// reset the layer
5954
this.el.innerHTML = '';
@@ -72,13 +67,22 @@ AFRAME.registerComponent('osm-geojson', {
7267
// if trackId attribute is given, keep track of the element's position
7368
if (this.data.trackId) {
7469
let element = document.getElementById(this.data.trackId);
75-
if (element && element.object3D && element.object3D.position) {
76-
this.trackPosition = element.object3D.position;
70+
if (element && element.object3D) {
71+
this.trackElement = element;
72+
this.trackPosition = new THREE.Vector3();
7773
}
7874
}
7975
}
8076
},
8177

78+
tick: function () {
79+
if (this.trackElement) {
80+
// use world position to support movement of both head and rig
81+
this.trackElement.object3D.getWorldPosition(this.trackPosition);
82+
this.loadTilesAround(this.trackPosition);
83+
}
84+
},
85+
8286
onSrcLoaded: function (text) {
8387
let json = JSON.parse(text);
8488
if (this.data.lat == 0 && this.data.lon == 0) {

osm-tiles.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ AFRAME.registerComponent('osm-tiles', {
5252
// recreate the tiles layer
5353
update: function (oldData) {
5454
if (this.data !== oldData) {
55+
this.trackElement = null;
5556
this.trackPosition = null;
5657
// reset the layer
5758
this.el.innerHTML = '';
@@ -64,15 +65,18 @@ AFRAME.registerComponent('osm-tiles', {
6465
// if trackId attribute is given, keep track of the element's position
6566
if (this.data.trackId) {
6667
let element = document.getElementById(this.data.trackId);
67-
if (element && element.object3D && element.object3D.position) {
68-
this.trackPosition = element.object3D.position;
68+
if (element && element.object3D) {
69+
this.trackElement = element;
70+
this.trackPosition = new THREE.Vector3();
6971
}
7072
}
7173
}
7274
},
7375

7476
tick: function () {
75-
if (this.trackPosition) {
77+
if (this.trackElement) {
78+
// use world position to support movement of both head and rig
79+
this.trackElement.object3D.getWorldPosition(this.trackPosition);
7680
this.loadTilesAround(this.trackPosition);
7781
}
7882
},

0 commit comments

Comments
 (0)