Browse Source

Rotates tiles by angle to sphere

Petter Gåsström 4 years ago
parent
commit
52902de3c0
1 changed files with 17 additions and 3 deletions
  1. 17 3
      example/ionExample.js

+ 17 - 3
example/ionExample.js

@@ -29,6 +29,7 @@ import {
 	sRGBEncoding,
 	Matrix4,
 	Box3,
+	Sphere,
 } from 'three';
 import { FlyOrbitControls } from './FlyOrbitControls.js';
 import { BufferGeometryUtils } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
@@ -176,10 +177,23 @@ function reinstantiateTiles() {
 				tiles.onLoadTileSet = () => {
 
 					const box = new Box3();
+					const sphere = new Sphere();
 					const matrix = new Matrix4();
-					tiles.getOrientedBounds( box, matrix );
-					const position = new Vector3().setFromMatrixPosition( matrix );
-					const distanceToEllipsoidCenter = position.length();
+
+					let position;
+					let distanceToEllipsoidCenter;
+
+					if ( tiles.getOrientedBounds( box, matrix ) ) {
+
+						position = new Vector3().setFromMatrixPosition( matrix );
+						distanceToEllipsoidCenter = position.length();
+		
+					} else if ( tiles.getBoundingSphere( sphere ) ) {
+				
+						position = sphere.center.clone();
+						distanceToEllipsoidCenter = position.length();
+				
+					}
 
 					const surfaceDirection = position.normalize();
 					const up = new Vector3( 0, 1, 0 );