Skip to content

Commit

Permalink
Add support for the 3DTILES_ELLIPSOID extension (#901)
Browse files Browse the repository at this point in the history
* Add support for ellipsoid extension

* Remove lunar ellipsoid
  • Loading branch information
gkjohnson authored Jan 1, 2025
1 parent 25b99de commit 1df8cfa
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 14 deletions.
2 changes: 0 additions & 2 deletions example/ionLunar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
GlobeControls,
TilesRenderer,
LUNAR_ELLIPSOID,
} from '3d-tiles-renderer';
import {
CesiumIonAuthPlugin,
Expand Down Expand Up @@ -42,7 +41,6 @@ function reinstantiateTiles() {
localStorage.setItem( 'ionApiKey', params.apiKey );

tiles = new TilesRenderer();
tiles.ellipsoid.copy( LUNAR_ELLIPSOID );
tiles.registerPlugin( new CesiumIonAuthPlugin( { apiToken: params.apiKey, assetId: '2684829', autoRefreshToken: true } ) );
tiles.registerPlugin( new TileCompressionPlugin() );
tiles.registerPlugin( new UpdateOnChangePlugin() );
Expand Down
7 changes: 6 additions & 1 deletion src/base/TilesRendererBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ export class TilesRendererBase {
this.rootLoadingState = LOADING;
this.invokeOnePlugin( plugin => plugin.loadRootTileSet && plugin.loadRootTileSet() )
.then( () => this.rootLoadingState = LOADED )
.catch( () => this.rootLoadingState = FAILED );
.catch( err => {

this.rootLoadingState = FAILED;
console.error( err );

} );

}

Expand Down
3 changes: 0 additions & 3 deletions src/base/constants.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export const WGS84_RADIUS;
export const WGS84_FLATTENING;
export const WGS84_HEIGHT;

export const LUNAR_RADIUS;
export const LUNAR_HEIGHT;
4 changes: 0 additions & 4 deletions src/base/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@ export const LOADED = 3;
export const WGS84_RADIUS = 6378137;
export const WGS84_FLATTENING = 1 / 298.257223563;
export const WGS84_HEIGHT = - ( WGS84_FLATTENING * WGS84_RADIUS - WGS84_RADIUS );

// https://nssdc.gsfc.nasa.gov/planetary/factsheet/moonfact.html
export const LUNAR_HEIGHT = 1736.0 * 1e3;
export const LUNAR_RADIUS = 1738.1 * 1e3;
21 changes: 20 additions & 1 deletion src/three/TilesRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ export class TilesRenderer extends TilesRendererBase {
.then( () => {

// cache the gltf tile set rotation matrix
const upAxis = this.rootTileSet.asset && this.rootTileSet.asset.gltfUpAxis || 'y';
const { asset, extensions } = this.rootTileSet;
const upAxis = asset && asset.gltfUpAxis || 'y';
switch ( upAxis.toLowerCase() ) {

case 'x':
Expand All @@ -350,6 +351,24 @@ export class TilesRenderer extends TilesRendererBase {

}

// update the ellipsoid based on the extension
if ( '3DTILES_ellipsoid' in extensions ) {

const ext = extensions[ '3DTILES_ellipsoid' ];
const { ellipsoid } = this;
ellipsoid.name = ext.body;
if ( ext.radii ) {

ellipsoid.radius.set( ...ext.radii );

} else {

ellipsoid.radius.set( 1, 1, 1 );

}

}

this.dispatchEvent( { type: 'load-content' } );

} );
Expand Down
1 change: 1 addition & 0 deletions src/three/math/Ellipsoid.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const OBJECT_FRAME: Frames;
export class Ellipsoid {

radius: Vector3;
name: string;

constructor( x: number, y: number, z: number );
getCartographicToPosition( lat: number, lon: number, height: number, target: Vector3 ): Vector3;
Expand Down
1 change: 1 addition & 0 deletions src/three/math/Ellipsoid.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class Ellipsoid {

constructor( x = 1, y = 1, z = 1 ) {

this.name = '';
this.radius = new Vector3( x, y, z );

}
Expand Down
1 change: 0 additions & 1 deletion src/three/math/GeoConstants.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Ellipsoid } from './Ellipsoid';

export const WGS84_ELLIPSOID : Ellipsoid;
export const LUNAR_ELLIPSOID : Ellipsoid;
4 changes: 2 additions & 2 deletions src/three/math/GeoConstants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WGS84_RADIUS, WGS84_HEIGHT, LUNAR_RADIUS, LUNAR_HEIGHT } from '../../base/constants.js';
import { WGS84_RADIUS, WGS84_HEIGHT } from '../../base/constants.js';
import { Ellipsoid } from './Ellipsoid.js';

export const WGS84_ELLIPSOID = new Ellipsoid( WGS84_RADIUS, WGS84_RADIUS, WGS84_HEIGHT );
export const LUNAR_ELLIPSOID = new Ellipsoid( LUNAR_RADIUS, LUNAR_RADIUS, LUNAR_HEIGHT );
WGS84_ELLIPSOID.name = 'WGS84 Earth';

0 comments on commit 1df8cfa

Please sign in to comment.