From 1df8cfa6ae64eeb3b2ff450eac889e19dc976ec1 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Wed, 1 Jan 2025 17:40:50 +0900 Subject: [PATCH] Add support for the 3DTILES_ELLIPSOID extension (#901) * Add support for ellipsoid extension * Remove lunar ellipsoid --- example/ionLunar.js | 2 -- src/base/TilesRendererBase.js | 7 ++++++- src/base/constants.d.ts | 3 --- src/base/constants.js | 4 ---- src/three/TilesRenderer.js | 21 ++++++++++++++++++++- src/three/math/Ellipsoid.d.ts | 1 + src/three/math/Ellipsoid.js | 1 + src/three/math/GeoConstants.d.ts | 1 - src/three/math/GeoConstants.js | 4 ++-- 9 files changed, 30 insertions(+), 14 deletions(-) diff --git a/example/ionLunar.js b/example/ionLunar.js index efefb9baa..f1c3224b9 100644 --- a/example/ionLunar.js +++ b/example/ionLunar.js @@ -1,7 +1,6 @@ import { GlobeControls, TilesRenderer, - LUNAR_ELLIPSOID, } from '3d-tiles-renderer'; import { CesiumIonAuthPlugin, @@ -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() ); diff --git a/src/base/TilesRendererBase.js b/src/base/TilesRendererBase.js index 60bce8212..5ca4b3f6c 100644 --- a/src/base/TilesRendererBase.js +++ b/src/base/TilesRendererBase.js @@ -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 ); + + } ); } diff --git a/src/base/constants.d.ts b/src/base/constants.d.ts index 1356011cc..660a216a9 100644 --- a/src/base/constants.d.ts +++ b/src/base/constants.d.ts @@ -1,6 +1,3 @@ export const WGS84_RADIUS; export const WGS84_FLATTENING; export const WGS84_HEIGHT; - -export const LUNAR_RADIUS; -export const LUNAR_HEIGHT; diff --git a/src/base/constants.js b/src/base/constants.js index 043b7288b..90c4a7770 100644 --- a/src/base/constants.js +++ b/src/base/constants.js @@ -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; diff --git a/src/three/TilesRenderer.js b/src/three/TilesRenderer.js index 84138fddc..6759dabaa 100644 --- a/src/three/TilesRenderer.js +++ b/src/three/TilesRenderer.js @@ -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': @@ -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' } ); } ); diff --git a/src/three/math/Ellipsoid.d.ts b/src/three/math/Ellipsoid.d.ts index 8743c7393..3f38df910 100644 --- a/src/three/math/Ellipsoid.d.ts +++ b/src/three/math/Ellipsoid.d.ts @@ -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; diff --git a/src/three/math/Ellipsoid.js b/src/three/math/Ellipsoid.js index 717193a67..6f2695647 100644 --- a/src/three/math/Ellipsoid.js +++ b/src/three/math/Ellipsoid.js @@ -28,6 +28,7 @@ export class Ellipsoid { constructor( x = 1, y = 1, z = 1 ) { + this.name = ''; this.radius = new Vector3( x, y, z ); } diff --git a/src/three/math/GeoConstants.d.ts b/src/three/math/GeoConstants.d.ts index a4e7fca0e..723276913 100644 --- a/src/three/math/GeoConstants.d.ts +++ b/src/three/math/GeoConstants.d.ts @@ -1,4 +1,3 @@ import { Ellipsoid } from './Ellipsoid'; export const WGS84_ELLIPSOID : Ellipsoid; -export const LUNAR_ELLIPSOID : Ellipsoid; diff --git a/src/three/math/GeoConstants.js b/src/three/math/GeoConstants.js index d98605494..f356b1912 100644 --- a/src/three/math/GeoConstants.js +++ b/src/three/math/GeoConstants.js @@ -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';