Skip to content

Commit f328e62

Browse files
authored
Merge pull request #483 from AR-js-org/shaking-fix
Shaking fix for new-location-based components
2 parents 6a0f0b6 + 347d1a4 commit f328e62

File tree

5 files changed

+146
-9
lines changed

5 files changed

+146
-9
lines changed

aframe/examples/new-location-based/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,4 @@ These examples have been written specifically, or adapted, for the `new-location
1818

1919
- `osm-ways` : A more complex example showing how more specialised geodata can be rendered with AR.js. Downloads OpenStreetMap ways (roads, paths) from a GeoJSON API, reprojects them into Spherical Mercator, and adds them to the scene as polylines made up of individual triangles.
2020

21-
## Coming soon!
22-
23-
The use of smoothing to reduce "shaking" artefacts, currently implemented in the "classic" AR.js location-based components, has been implemented as a PR for the `new-location-based` components. It is likely to be available in the next release (3.4.3).
21+
- `smoothing` : A version of `basic-js` with a smoothing factor applied.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>AR.js A-Frame</title>
5+
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
6+
<!-- Assumes AR.js build is in the 'AR.js' directory -->
7+
<script type='text/javascript' src='../../../../three.js/build/ar-threex-location-only.js'></script>
8+
<script type='text/javascript' src='../../../build/aframe-ar.js'></script>
9+
<script src='index.js'></script>
10+
</head>
11+
<body>
12+
<a-scene vr-mode-ui='enabled: false' arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false' renderer='antialias: true; alpha: true'>
13+
<a-camera look-controls-enabled='false' arjs-device-orientation-controls='smoothingFactor:0.1' gps-new-camera='gpsMinDistance: 5'></a-camera>
14+
</a-scene>
15+
<div id='setloc' style='position:absolute; left: 10px; bottom: 2%; z-index:999; background-color: blue; color: white; padding: 10px'>
16+
Lat:<input id="lat" value="51.049" />
17+
Lon: <input id="lon" value="-0.723"/>
18+
Min Acc: <input id='minacc' value='1000' /> <input type='button' id='go' value='go' />
19+
</div>
20+
</body>
21+
</html>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
window.onload = () => {
2+
let testEntitiesAdded = false;
3+
alert('If testing the lat/lon manual input on a mobile device, please turn off your GPS to avoid the real location being detected.');
4+
const el = document.querySelector("[gps-new-camera]");
5+
el.addEventListener("gps-camera-update-position", e => {
6+
if(!testEntitiesAdded) {
7+
alert(`Got first GPS position: lon ${e.detail.position.longitude} lat ${e.detail.position.latitude}`);
8+
// Add four boxes to the north (red), south (yellow), west (blue)
9+
// and east (red) of the initial GPS position
10+
const properties = [{
11+
color: 'red',
12+
latDis: 0.001,
13+
lonDis: 0
14+
},{
15+
color: 'yellow',
16+
latDis: -0.001,
17+
lonDis: 0
18+
},{
19+
color: 'blue',
20+
latDis: 0,
21+
lonDis: -0.001
22+
},{
23+
color: 'green',
24+
latDis: 0,
25+
lonDis: 0.001
26+
}
27+
];
28+
for(const prop of properties) {
29+
const entity = document.createElement("a-box");
30+
entity.setAttribute("scale", {
31+
x: 20,
32+
y: 20,
33+
z: 20
34+
});
35+
entity.setAttribute('material', { color: prop.color } );
36+
entity.setAttribute('gps-new-entity-place', {
37+
latitude: e.detail.position.latitude + prop.latDis,
38+
longitude: e.detail.position.longitude + prop.lonDis
39+
});
40+
41+
document.querySelector("a-scene").appendChild(entity);
42+
}
43+
testEntitiesAdded = true;
44+
}
45+
});
46+
47+
document.getElementById("go").addEventListener("click", e=> {
48+
const lat = document.getElementById('lat').value;
49+
const lon = document.getElementById('lon').value;
50+
const minacc = document.getElementById('minacc').value;
51+
52+
el.setAttribute('gps-new-camera', { simulateLatitude: lat, simulateLongitude: lon, positionMinAccuracy: minacc } );
53+
});
54+
};

three.js/build/ar-threex-location-only.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)