Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Map / Globe controls #434

Merged
merged 65 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
becee8f
Add support for globe controls
gkjohnson Dec 26, 2023
8a4bf53
Globe controls progress
gkjohnson Dec 27, 2023
bb64692
Add comments
gkjohnson Dec 27, 2023
9ea6cbc
Cleanup
gkjohnson Dec 28, 2023
e44cad2
Add detach
gkjohnson Dec 28, 2023
ff344b7
Clean up
gkjohnson Dec 28, 2023
a62919d
Add angle clamping
gkjohnson Dec 28, 2023
8651e6b
Update controls
gkjohnson Dec 28, 2023
efa428e
Add min and max distance
gkjohnson Dec 28, 2023
4a99384
Add snap back
gkjohnson Dec 28, 2023
55d3c3a
Add better pivot point
gkjohnson Dec 28, 2023
a64f8cc
Update pivot
gkjohnson Dec 28, 2023
2c391b3
Update params
gkjohnson Dec 28, 2023
5ed9cad
Improve pivot mesh transform
gkjohnson Dec 28, 2023
81842dd
Add initial support for pointers
gkjohnson Dec 29, 2023
331591a
Get touch controls working
gkjohnson Dec 29, 2023
556e7dc
Add better touch support
gkjohnson Dec 29, 2023
b806054
Simplification
gkjohnson Dec 29, 2023
630de00
Simplification
gkjohnson Dec 29, 2023
a23dbd2
More updates
gkjohnson Dec 29, 2023
8e14dee
Comment
gkjohnson Dec 29, 2023
b290796
Fix pivot icon display
gkjohnson Dec 29, 2023
0ebf0c5
more simplify
gkjohnson Dec 29, 2023
2c23a69
Fix touch action init
gkjohnson Dec 29, 2023
ee0f1fb
Offset fixes
gkjohnson Dec 29, 2023
b094658
Fix issue with reverse dragg
gkjohnson Dec 30, 2023
3348bb8
Update globe controls
gkjohnson Dec 30, 2023
610f90b
Add set frame function
gkjohnson Dec 30, 2023
ab8a031
Updates
gkjohnson Dec 30, 2023
b0ff8ed
Fix rotation
gkjohnson Dec 30, 2023
dd00ca4
Reuse function
gkjohnson Dec 30, 2023
ef832cf
Fix drag issue
gkjohnson Dec 30, 2023
23914bc
Add shared direction update function
gkjohnson Dec 30, 2023
4e9376a
fixes to zoom logic
gkjohnson Dec 30, 2023
fbccc0f
Cleanup
gkjohnson Dec 31, 2023
52effdf
More cleanup
gkjohnson Dec 31, 2023
9e345df
Fix zoom
gkjohnson Dec 31, 2023
c100be5
Fix zoom scaling
gkjohnson Dec 31, 2023
73123d9
Add function for getting the up direction
gkjohnson Dec 31, 2023
1e5c546
Zoom based on distance to tileset
gkjohnson Dec 31, 2023
6cabaf1
Merge remote-tracking branch 'origin/master' into globe-controls
gkjohnson Dec 31, 2023
0db2e5f
Fix dragging
gkjohnson Jan 1, 2024
5fb73e5
Add Maps, GlobeControls
gkjohnson Jan 1, 2024
b127af8
Fix zoom
gkjohnson Jan 1, 2024
968fd0c
Improvements
gkjohnson Jan 1, 2024
38ad5db
Fix drag reorientation issue
gkjohnson Jan 1, 2024
9cadcc7
Fix zoom issue
gkjohnson Jan 1, 2024
991487e
Separate tiles
gkjohnson Jan 1, 2024
7ba20eb
Fix globe orientation
gkjohnson Jan 1, 2024
e9a8bc4
Fix up orientation issue, embed "getUpDirection
gkjohnson Jan 1, 2024
50360a9
Cleanup
gkjohnson Jan 1, 2024
b498c06
Move to controls folder
gkjohnson Jan 1, 2024
a47bd0d
Cleanup
gkjohnson Jan 1, 2024
0040ab5
clean up, comments
gkjohnson Jan 1, 2024
638c4d3
Move getUpDirection function
gkjohnson Jan 1, 2024
5ff26b1
Fix rotation limit
gkjohnson Jan 1, 2024
e8bb741
Update google maps example
gkjohnson Jan 1, 2024
ee1910b
Start cleanup of google tiles example
gkjohnson Jan 1, 2024
9c24b8a
More example update
gkjohnson Jan 1, 2024
91df6ec
Small fixes, demo update, fix to FadeRenderer
gkjohnson Jan 1, 2024
e164c2d
Fix pivot point
gkjohnson Jan 1, 2024
7c802f7
setFrame to _setFrame, reuse pivot cast
gkjohnson Jan 2, 2024
1ec6ccb
Fix touch zoom
gkjohnson Jan 2, 2024
952fdec
Fix touch rotation
gkjohnson Jan 2, 2024
71f4ef7
Fixes
gkjohnson Jan 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 39 additions & 102 deletions example/googleMapsExample.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
import { GeoUtils, WGS84_ELLIPSOID, WGS84_RADIUS, DebugGoogleTilesRenderer as GoogleTilesRenderer } from '../src/index.js';
import { GeoUtils, WGS84_ELLIPSOID, DebugGoogleTilesRenderer as GoogleTilesRenderer } from '../src/index.js';
import {
Scene,
WebGLRenderer,
PerspectiveCamera,
Raycaster,
Box3,
MathUtils,
} from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min.js';
import * as BufferGeometryUtils from 'three/examples/jsm/utils/BufferGeometryUtils.js';
import { estimateBytesUsed } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
import Stats from 'three/examples/jsm/libs/stats.module.js';

import { MapControls } from './src/lib/MapControls.js';
import { GlobeControls } from './src/controls/GlobeControls.js';

let camera, controls, scene, renderer, tiles;
let statsContainer, stats;

const raycaster = new Raycaster();
raycaster.firstHitOnly = true;

const apiKey = localStorage.getItem( 'googleApiKey' ) ?? 'put-your-api-key-here';

const params = {

'enableUpdate': true,
'enableCacheDisplay': false,
'enableRendererStats': false,
'apiKey': apiKey,
enableCacheDisplay: false,
enableRendererStats: false,
apiKey: apiKey,

'displayBoxBounds': false,
'displaySphereBounds': false,
'displayRegionBounds': false,
'reload': reinstantiateTiles,
displayBoxBounds: false,
displayRegionBounds: false,

};

Expand All @@ -42,8 +34,6 @@ animate();

function reinstantiateTiles() {

localStorage.setItem( 'googleApiKey', params.apiKey );

if ( tiles ) {

scene.remove( tiles.group );
Expand All @@ -52,6 +42,8 @@ function reinstantiateTiles() {

}

localStorage.setItem( 'googleApiKey', params.apiKey );

tiles = new GoogleTilesRenderer( params.apiKey );
tiles.group.rotation.x = - Math.PI / 2;

Expand All @@ -69,6 +61,8 @@ function reinstantiateTiles() {
tiles.setResolutionFromRenderer( camera, renderer );
tiles.setCamera( camera );

controls.setScene( tiles.group );

}

function init() {
Expand All @@ -82,14 +76,11 @@ function init() {
document.body.appendChild( renderer.domElement );

camera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 160000000 );
camera.position.set( 7326000, 10279000, - 823000 );
camera.position.set( 4800000, 2570000, 14720000 );
camera.lookAt( 0, 0, 0 );

// controls
controls = new MapControls( camera, renderer.domElement );
controls.minDistance = 1;
controls.maxDistance = Infinity;
controls.minPolarAngle = Math.PI / 4;
controls.target.set( 0, 0, 1 );
controls = new GlobeControls( scene, camera, renderer.domElement );

reinstantiateTiles();

Expand All @@ -103,30 +94,14 @@ function init() {
const mapsOptions = gui.addFolder( 'Google Tiles' );
mapsOptions.add( params, 'apiKey' );
mapsOptions.add( params, 'reload' );
mapsOptions.open();

const debug = gui.addFolder( 'Debug Options' );
debug.add( params, 'displayBoxBounds' );
debug.add( params, 'displaySphereBounds' );
debug.add( params, 'displayRegionBounds' );

const exampleOptions = gui.addFolder( 'Example Options' );
exampleOptions.add( params, 'enableUpdate' ).onChange( v => {

tiles.parseQueue.autoUpdate = v;
tiles.downloadQueue.autoUpdate = v;

if ( v ) {

tiles.parseQueue.scheduleJobRun();
tiles.downloadQueue.scheduleJobRun();

}

} );
exampleOptions.add( params, 'enableCacheDisplay' );
exampleOptions.add( params, 'enableRendererStats' );
gui.open();

statsContainer = document.createElement( 'div' );
document.getElementById( 'info' ).appendChild( statsContainer );
Expand All @@ -152,39 +127,6 @@ function onWindowResize() {

}

function updateControls() {

const raycaster = new Raycaster();
raycaster.ray.origin.copy( controls.target ).normalize().multiplyScalar( WGS84_RADIUS * 1.5 );
raycaster.ray.direction.copy( raycaster.ray.origin ).normalize().multiplyScalar( - 1 );
raycaster.firstHitOnly = true;

const hit = raycaster.intersectObject( scene, true )[ 0 ];
if ( hit ) {

controls.target.copy( hit.point );

} else {

controls.target.normalize().multiplyScalar( WGS84_RADIUS );

}
controls.panPlane.copy( controls.target ).normalize();

const dist = camera.position.length();
camera.position.copy( controls.target ).normalize().multiplyScalar( dist );
camera.lookAt( controls.target );
controls.update();

const box = new Box3();
tiles.getBounds( box );

camera.far = dist;
camera.near = Math.max( 1, dist - Math.max( ...box.min, ...box.max ) );
camera.updateProjectionMatrix();

}

function updateHash() {

if ( ! tiles ) {
Expand All @@ -195,7 +137,7 @@ function updateHash() {

const res = {};
const mat = tiles.group.matrixWorld.clone().invert();
const vec = controls.target.clone().applyMatrix4( mat );
const vec = camera.position.clone().applyMatrix4( mat );
WGS84_ELLIPSOID.getPositionToCartographic( vec, res );

res.lat *= MathUtils.RAD2DEG;
Expand All @@ -215,11 +157,11 @@ function initFromHash() {
}

const [ lat, lon ] = tokens;
WGS84_ELLIPSOID.getCartographicToPosition( lat * MathUtils.DEG2RAD, lon * MathUtils.DEG2RAD, 0, controls.target );
WGS84_ELLIPSOID.getCartographicToPosition( lat * MathUtils.DEG2RAD, lon * MathUtils.DEG2RAD, 0, camera.position );

tiles.group.updateMatrixWorld();
controls.target.applyMatrix4( tiles.group.matrixWorld );
updateControls();
camera.position.applyMatrix4( tiles.group.matrixWorld ).multiplyScalar( 2 );
camera.lookAt( 0, 0, 0 );

}

Expand All @@ -229,36 +171,35 @@ function animate() {

if ( ! tiles ) return;

updateControls();
controls.update();

// update options
tiles.setResolutionFromRenderer( camera, renderer );
tiles.setCamera( camera );
tiles.displayBoxBounds = params.displayBoxBounds;
tiles.displayRegionBounds = params.displayRegionBounds;

// update tiles
if ( params.enableUpdate ) {
camera.updateMatrixWorld();
tiles.update();

camera.updateMatrixWorld();
tiles.update();

}

render();
renderer.render( scene, camera );
stats.update();

}
updateHtml();

function render() {
}

// render primary view
renderer.render( scene, camera );
function updateHtml() {

// render html text updates
const cacheFullness = tiles.lruCache.itemList.length / tiles.lruCache.maxSize;
let str = `Downloading: ${ tiles.stats.downloading } Parsing: ${ tiles.stats.parsing } Visible: ${ tiles.visibleTiles.size }`;
let str = '';

if ( params.enableCacheDisplay ) {

str += `Downloading: ${ tiles.stats.downloading } Parsing: ${ tiles.stats.parsing } Visible: ${ tiles.visibleTiles.size }<br/>`;

const geomSet = new Set();
tiles.traverse( tile => {

Expand All @@ -282,18 +223,18 @@ function render() {
let count = 0;
geomSet.forEach( g => {

count += BufferGeometryUtils.estimateBytesUsed( g );
count += estimateBytesUsed( g );

} );
str += `<br/>Cache: ${ ( 100 * cacheFullness ).toFixed( 2 ) }% ~${ ( count / 1000 / 1000 ).toFixed( 2 ) }mb`;
str += `Cache: ${ ( 100 * cacheFullness ).toFixed( 2 ) }% ~${ ( count / 1000 / 1000 ).toFixed( 2 ) }mb<br/>`;

}

if ( params.enableRendererStats ) {

const memory = renderer.info.memory;
const programCount = renderer.info.programs.length;
str += `<br/>Geometries: ${ memory.geometries } Textures: ${ memory.textures } Programs: ${ programCount }`;
str += `Geometries: ${ memory.geometries } Textures: ${ memory.textures } Programs: ${ programCount }`;

}

Expand All @@ -303,15 +244,11 @@ function render() {

}

if ( tiles ) {

const mat = tiles.group.matrixWorld.clone().invert();
const vec = camera.position.clone().applyMatrix4( mat );

const res = {};
WGS84_ELLIPSOID.getPositionToCartographic( vec, res );
document.getElementById( 'credits' ).innerText = GeoUtils.toLatLonString( res.lat, res.lon ) + '\n' + tiles.getCreditsString();
const mat = tiles.group.matrixWorld.clone().invert();
const vec = camera.position.clone().applyMatrix4( mat );

}
const res = {};
WGS84_ELLIPSOID.getPositionToCartographic( vec, res );
document.getElementById( 'credits' ).innerText = GeoUtils.toLatLonString( res.lat, res.lon ) + '\n' + tiles.getCreditsString();

}
2 changes: 1 addition & 1 deletion example/src/FadeTilesRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function onTileVisibilityChange( scene, tile, visible ) {

}

if ( ! isRootTile || ! this.fadeRootTiles || this.initialLayerRendered ) {
if ( ! isRootTile || this.fadeRootTiles || this.initialLayerRendered ) {

this._fadeManager.fadeIn( scene );

Expand Down
Loading
Loading