Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/apostololeg/terrain-navigator


https://github.com/apostololeg/terrain-navigator

Last synced: 26 days ago
JSON representation

Awesome Lists containing this project

README

        

# Terrain navigator

- get height data from mapbox API by coordinates
- cache height data in IndexDB
- create terrains far from observer position
- resize imageData for low-poly tiles
- [optimize rendering at very far distances](https://discourse.threejs.org/t/moving-the-camera-model-will-shake-if-the-coordinates-are-large/7214)
- rebuild tiles after change observer position

## Quick start

```js
import TerrainNavigator from 'terrain-navigator';

const scene: THREE.Scene;
const observer: THREE.Object3D;

const terrain = new TerrainNavigator({
mapBoxToken: MAPBOX_TOKEN,
container: scene,
material: new MeshPhongMaterial({
color: 0x424240,
shininess: 0.1,
// wireframe: true,
});,
zoom: 14,
scale: 0.125,
getPosition() {
return observer.target.position;
},
setPosition(pos) {
const { position } = observer.object;

Object.entries(pos).forEach(([key, val]) => {
if (Number.isFinite(val)) position[key] = val;
});
},
onTileRebuilded(tile, oldObject) {
if (oldObject) observer.removeTeleportTargets([oldObject]);

scene.add(tile.object);

if (tile.isNear) observer.addTeleportTargets([tile.object]);

editor.dyeTile(tile);
},
});

// every time you change the observer position:
terrain.update();
```

TODO:

- move data processing to Worker