Skip to content

Commit c9c0cf9

Browse files
authored
EnvironmentControls: Add support for "flight" (#1585)
* EnvironmentControls: Add flight support * Add free rotation * Updates * fix focus * Remove lines * Stylistic
1 parent 386e49e commit c9c0cf9

7 files changed

Lines changed: 327 additions & 327 deletions

File tree

example/three/googleMapsExample.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ function init() {
135135
// controls
136136
controls = new GlobeControls( scene, transition.camera, renderer.domElement, null );
137137
controls.enableDamping = true;
138+
controls.enableFlight = true;
139+
controls.flightSpeed = 0.5;
140+
controls.maxAltitude = Math.PI / 2;
138141

139142
// initialize tiles
140143
reinstantiateTiles();

example/three/index.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
TilesRenderer,
3+
EnvironmentControls,
34
} from '3d-tiles-renderer';
45
import {
56
DebugTilesPlugin,
@@ -24,7 +25,6 @@ import {
2425
OrthographicCamera,
2526
Sphere,
2627
} from 'three';
27-
import { FlyOrbitControls } from './src/controls/FlyOrbitControls.js';
2828
import * as BufferGeometryUtils from 'three/addons/utils/BufferGeometryUtils.js';
2929
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
3030
import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';
@@ -144,6 +144,7 @@ function init() {
144144

145145
camera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
146146
camera.position.set( 400, 400, 400 );
147+
camera.lookAt( 0, 0, 0 );
147148
cameraHelper = new CameraHelper( camera );
148149
scene.add( cameraHelper );
149150

@@ -168,10 +169,12 @@ function init() {
168169
secondRenderer.domElement.style.outline = '#0f1416 solid 2px';
169170
secondRenderer.domElement.tabIndex = 1;
170171

171-
secondControls = new FlyOrbitControls( secondCamera, secondRenderer.domElement );
172-
secondControls.screenSpacePanning = false;
172+
secondControls = new EnvironmentControls( null, secondCamera, secondRenderer.domElement );
173+
secondControls.enableFlight = true;
174+
secondControls.flightSpeed = 200;
173175
secondControls.minDistance = 1;
174176
secondControls.maxDistance = 5000;
177+
secondControls.useFallbackPlane = false;
175178

176179
secondCameraHelper = new CameraHelper( secondCamera );
177180
scene.add( secondCameraHelper );
@@ -192,16 +195,20 @@ function init() {
192195
thirdPersonRenderer.domElement.style.bottom = '5px';
193196
thirdPersonRenderer.domElement.tabIndex = 1;
194197

195-
thirdPersonControls = new FlyOrbitControls( thirdPersonCamera, thirdPersonRenderer.domElement );
196-
thirdPersonControls.screenSpacePanning = false;
198+
thirdPersonControls = new EnvironmentControls( null, thirdPersonCamera, thirdPersonRenderer.domElement );
199+
thirdPersonControls.enableFlight = true;
200+
thirdPersonControls.flightSpeed = 200;
197201
thirdPersonControls.minDistance = 1;
198202
thirdPersonControls.maxDistance = 5000;
203+
thirdPersonControls.useFallbackPlane = false;
199204

200205
// controls
201-
controls = new FlyOrbitControls( camera, renderer.domElement );
202-
controls.screenSpacePanning = false;
206+
controls = new EnvironmentControls( null, camera, renderer.domElement );
207+
controls.enableFlight = true;
208+
controls.flightSpeed = 200;
203209
controls.minDistance = 1;
204210
controls.maxDistance = 5000;
211+
controls.useFallbackPlane = false;
205212

206213
// lights
207214
const dirLight = new DirectionalLight( 0xffffff, 4 );
@@ -217,6 +224,10 @@ function init() {
217224
offsetParent = new Group();
218225
scene.add( offsetParent );
219226

227+
controls.setScene( offsetParent );
228+
secondControls.setScene( offsetParent );
229+
thirdPersonControls.setScene( offsetParent );
230+
220231
geospatialRotationParent = new Group();
221232
offsetParent.add( geospatialRotationParent );
222233

@@ -405,28 +416,12 @@ function onPointerUp( e ) {
405416
if ( results.length ) {
406417

407418
const object = results[ 0 ].object;
408-
const info = tiles.getPluginByName( 'DEBUG_TILES_PLUGIN' ).getTileInformationFromActiveObject( object );
419+
const tile = tiles.getPluginByName( 'DEBUG_TILES_PLUGIN' ).getTileFromObject3D( object );
409420

410421
let str = '';
411-
for ( const key in info ) {
412-
413-
let val = info[ key ];
414-
if ( typeof val === 'number' ) {
415-
416-
val = Math.floor( val * 1e5 ) / 1e5;
417-
418-
}
419-
420-
let name = key;
421-
while ( name.length < 20 ) {
422-
423-
name += ' ';
424-
425-
}
426-
427-
str += `${ name } : ${ val }\n`;
428-
429-
}
422+
str += `geometricError : ${ tile.geometricError.toFixed( 3 ) }\n`;
423+
str += `error : ${ tile.traversal.error.toFixed( 3 ) }\n`;
424+
str += `refine : ${ tile.refine }\n`;
430425

431426
console.log( str );
432427

@@ -439,7 +434,7 @@ function updateOrthoCamera() {
439434
orthoCamera.position.copy( camera.position );
440435
orthoCamera.rotation.copy( camera.rotation );
441436

442-
const scale = camera.position.distanceTo( controls.target ) / 2.0;
437+
const scale = camera.position.distanceTo( controls.pivotPoint ) / 2.0;
443438
let aspect = window.innerWidth / window.innerHeight;
444439
if ( params.showSecondView ) {
445440

@@ -590,6 +585,10 @@ function animate() {
590585
window.tiles = tiles;
591586
if ( params.enableUpdate ) {
592587

588+
controls.update();
589+
secondControls.update();
590+
thirdPersonControls.update();
591+
593592
secondCamera.updateMatrixWorld();
594593
camera.updateMatrixWorld();
595594
orthoCamera.updateMatrixWorld();

0 commit comments

Comments
 (0)