瀏覽代碼

Removed ellipsoid correction from core

Petter 4 年之前
父節點
當前提交
48a67dec8e
共有 4 個文件被更改,包括 40 次插入45 次删除
  1. 34 0
      example/ionExample.js
  2. 0 2
      src/base/TilesRendererBase.d.ts
  3. 0 2
      src/base/TilesRendererBase.js
  4. 6 41
      src/three/TilesRenderer.js

+ 34 - 0
example/ionExample.js

@@ -19,6 +19,8 @@ import {
 	CameraHelper,
 	Raycaster,
 	Vector2,
+	Vector3,
+	Quaternion,
 	Mesh,
 	CylinderBufferGeometry,
 	MeshBasicMaterial,
@@ -79,6 +81,20 @@ let params = {
 init();
 animate();
 
+function rotationBetweenDirections( dir1, dir2 ) {
+
+	const rotation = new Quaternion();
+	const a = new Vector3().crossVectors( dir1, dir2 );
+	rotation.x = a.x;
+	rotation.y = a.y;
+	rotation.z = a.z;
+	rotation.w = 1 + dir1.clone().dot( dir2 );
+	rotation.normalize();
+
+	return rotation;
+
+}
+
 function setupTiles() {
 
 	tiles.fetchOptions.mode = 'cors';
@@ -164,6 +180,24 @@ function reinstantiateTiles() {
 
 				};
 
+				tiles.onLoadTileSet = () => {
+
+					const position = new Vector3().setFromMatrixPosition( tiles.getRootMatrix() );
+					const distanceToEllipsoidCenter = position.length();
+
+					const surfaceDirection = position.normalize();
+					const up = new Vector3( 0, 1, 0 );
+					const rotationToNorthPole = rotationBetweenDirections( surfaceDirection, up );
+
+					tiles.group.quaternion.x = rotationToNorthPole.x;
+					tiles.group.quaternion.y = rotationToNorthPole.y;
+					tiles.group.quaternion.z = rotationToNorthPole.z;
+					tiles.group.quaternion.w = rotationToNorthPole.w;
+
+					tiles.group.position.y = - distanceToEllipsoidCenter;
+
+				};
+
 				setupTiles();
 
 			} )

+ 0 - 2
src/base/TilesRendererBase.d.ts

@@ -16,8 +16,6 @@ export class TilesRendererBase {
 	fetchOptions : Object;
 	/** function to preprocess the url for each individual tile */
 	onPreprocessURL : (uri: string | URL) => URL | string | null;
-	/** Does the tileset exist on the surface of an ellipsoid. If undefined, tries determine by distance from origin */
-	isGeoReferenced: boolean | undefined;
 
 	lruCache : LRUCache;
 	parseQueue : PriorityQueue;

+ 0 - 2
src/base/TilesRendererBase.js

@@ -39,8 +39,6 @@ export class TilesRendererBase {
 		this.rootURL = url;
 		this.fetchOptions = {};
 
-		this.isGeoReferenced = undefined;
-
 		this.onPreprocessURL = null;
 
 		const lruCache = new LRUCache();

+ 6 - 41
src/three/TilesRenderer.js

@@ -10,7 +10,6 @@ import {
 	Sphere,
 	Vector3,
 	Vector2,
-	Quaternion,
 	Math as MathUtils,
 	Frustum,
 	LoadingManager,
@@ -88,6 +87,12 @@ export class TilesRenderer extends TilesRendererBase {
 	}
 
 	/* Public API */
+	getRootMatrix() {
+
+		return this.root.cached.boxTransform;
+
+	}
+
 	getBounds( box ) {
 
 		if ( ! this.root ) {
@@ -214,20 +219,6 @@ export class TilesRenderer extends TilesRendererBase {
 
 	}
 
-	rotationBetweenDirections( dir1, dir2 ) {
-
-		const rotation = new Quaternion();
-		const a = new Vector3().crossVectors( dir1, dir2 );
-		rotation.x = a.x;
-		rotation.y = a.y;
-		rotation.z = a.z;
-		rotation.w = 1 + dir1.clone().dot( dir2 );
-		rotation.normalize();
-
-		return rotation;
-
-	}
-
 	deleteCamera( camera ) {
 
 		const cameras = this.cameras;
@@ -262,32 +253,6 @@ export class TilesRenderer extends TilesRendererBase {
 				} );
 
 			}
-			Promise.resolve().then( () => {
-
-				if ( this.isGeoReferenced === undefined ) {
-
-					this.isGeoReferenced = new Vector3().setFromMatrixPosition( this.root.cached.boxTransform ).length() > 6360000; // approximate Earth radius
-
-				}
-
-				if ( this.isGeoReferenced ) {
-
-					const position = new Vector3().setFromMatrixPosition( this.root.cached.boxTransform );
-					const distanceToEarthCenter = position.length();
-
-					const surfaceDir = position.normalize();
-					const rotationToNorthPole = this.rotationBetweenDirections( surfaceDir, Y_AXIS );
-
-					this.group.quaternion.x = rotationToNorthPole.x;
-					this.group.quaternion.y = rotationToNorthPole.y;
-					this.group.quaternion.z = rotationToNorthPole.z;
-					this.group.quaternion.w = rotationToNorthPole.w;
-
-					this.group.position.y = - distanceToEarthCenter;
-
-				}
-
-			} );
 
 		} );
 		return pr;