Переглянути джерело

getBoundsTransform changes

Petter 4 роки тому
батько
коміт
8c3d9e92d0
3 змінених файлів з 29 додано та 9 видалено
  1. 5 2
      example/ionExample.js
  2. 3 1
      src/three/TilesRenderer.d.ts
  3. 21 6
      src/three/TilesRenderer.js

+ 5 - 2
example/ionExample.js

@@ -27,7 +27,8 @@ import {
 	Group,
 	TorusBufferGeometry,
 	OrthographicCamera,
-	sRGBEncoding
+	sRGBEncoding,
+	Matrix4
 } from 'three';
 import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
 import { BufferGeometryUtils } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
@@ -181,7 +182,9 @@ function reinstantiateTiles() {
 
 				tiles.onLoadTileSet = () => {
 
-					const position = new Vector3().setFromMatrixPosition( tiles.getRootMatrix() );
+					const matrix = new Matrix4();
+					tiles.getBoundsTransform( matrix );
+					const position = new Vector3().setFromMatrixPosition( matrix );
 					const distanceToEllipsoidCenter = position.length();
 
 					const surfaceDirection = position.normalize();

+ 3 - 1
src/three/TilesRenderer.d.ts

@@ -1,4 +1,4 @@
-import { Box3, Camera, Vector2, WebGLRenderer, Object3D, LoadingManager } from 'three';
+import { Box3, Camera, Vector2, Matrix4, WebGLRenderer, Object3D, LoadingManager } from 'three';
 import { TilesRendererBase } from '../base/TilesRendererBase';
 import { TilesGroup } from './TilesGroup';
 
@@ -10,6 +10,8 @@ export class TilesRenderer extends TilesRendererBase {
 
 	group : TilesGroup;
 
+	getBoundsTransform(target: Matrix4) : Boolean;
+
 	getBounds( box : Box3 ) : Boolean;
 
 	hasCamera( camera : Camera ) : Boolean;

+ 21 - 6
src/three/TilesRenderer.js

@@ -87,12 +87,6 @@ export class TilesRenderer extends TilesRendererBase {
 	}
 
 	/* Public API */
-	getRootMatrix() {
-
-		return this.root.cached.boxTransform;
-
-	}
-
 	getBounds( box ) {
 
 		if ( ! this.root ) {
@@ -120,6 +114,27 @@ export class TilesRenderer extends TilesRendererBase {
 
 	}
 
+	getBoundsTransform( target ) {
+
+		if ( ! this.root ) {
+
+			return false;
+
+		}
+
+		if ( this.root.cached.boxTransform ) {
+
+			target.copy( this.root.cached.boxTransform );
+			return true;
+
+		} else {
+
+			return false;
+
+		}
+
+	}
+
 	forEachLoadedModel( callback ) {
 
 		this.traverse( tile => {