浏览代码

Box3: preserves emptiness on `getBoundingSphere()` (#25489)

* empty box's bsphere is empty

* use `sphere.makeEmpty`

* use `sphere.isEmpty`
ycw 2 年之前
父节点
当前提交
8670f97427
共有 2 个文件被更改,包括 13 次插入2 次删除
  1. 10 2
      src/math/Box3.js
  2. 3 0
      test/unit/src/math/Box3.tests.js

+ 10 - 2
src/math/Box3.js

@@ -404,9 +404,17 @@ class Box3 {
 
 	getBoundingSphere( target ) {
 
-		this.getCenter( target.center );
+		if ( this.isEmpty() ) {
+
+			target.makeEmpty();
+
+		} else {
 
-		target.radius = this.getSize( _vector ).length() * 0.5;
+			this.getCenter( target.center );
+
+			target.radius = this.getSize( _vector ).length() * 0.5;
+
+		}
 
 		return target;
 

+ 3 - 0
test/unit/src/math/Box3.tests.js

@@ -550,6 +550,9 @@ export default QUnit.module( 'Maths', () => {
 			assert.ok( b.getBoundingSphere( sphere ).equals( new Sphere( one3.clone().multiplyScalar( 0.5 ), Math.sqrt( 3 ) * 0.5 ) ), 'Passed!' );
 			assert.ok( c.getBoundingSphere( sphere ).equals( new Sphere( zero3, Math.sqrt( 12 ) * 0.5 ) ), 'Passed!' );
 
+			const d = new Box3().makeEmpty();
+			assert.ok( d.getBoundingSphere( sphere ).isEmpty(), 'Empty box\'s bounding sphere is empty' );
+
 		} );
 
 		QUnit.test( 'intersect', ( assert ) => {