Selaa lähdekoodia

Revert "OrbitControls: Removed update condition code (#26061)"

This reverts commit a7c9a2056de7e89f6dc73f3e6d67e68eca1332d1.
Mr.doob 2 vuotta sitten
vanhempi
commit
d1e85b099b
1 muutettua tiedostoa jossa 25 lisäystä ja 2 poistoa
  1. 25 2
      examples/jsm/controls/OrbitControls.js

+ 25 - 2
examples/jsm/controls/OrbitControls.js

@@ -163,6 +163,9 @@ class OrbitControls extends EventDispatcher {
 			const quat = new Quaternion().setFromUnitVectors( object.up, new Vector3( 0, 1, 0 ) );
 			const quatInverse = quat.clone().invert();
 
+			const lastPosition = new Vector3();
+			const lastQuaternion = new Quaternion();
+
 			const twoPI = 2 * Math.PI;
 
 			return function update() {
@@ -268,8 +271,26 @@ class OrbitControls extends EventDispatcher {
 				}
 
 				scale = 1;
-				
-				scope.dispatchEvent( _changeEvent );
+
+				// update condition is:
+				// min(camera displacement, camera rotation in radians)^2 > EPS
+				// using small-angle approximation cos(x/2) = 1 - x^2 / 8
+
+				if ( zoomChanged ||
+					lastPosition.distanceToSquared( scope.object.position ) > EPS ||
+					8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ) {
+
+					scope.dispatchEvent( _changeEvent );
+
+					lastPosition.copy( scope.object.position );
+					lastQuaternion.copy( scope.object.quaternion );
+					zoomChanged = false;
+
+					return true;
+
+				}
+
+				return false;
 
 			};
 
@@ -317,6 +338,8 @@ class OrbitControls extends EventDispatcher {
 
 		let state = STATE.NONE;
 
+		const EPS = 0.000001;
+
 		// current position in spherical coordinates
 		const spherical = new Spherical();
 		const sphericalDelta = new Spherical();