Explorar o código

Add start and end events triggered on mouse/wheel/touch down/up for trackball control

The start and end events can be used to start or stop an animation loop, for example, so that the animation loop does not have to run continuously.
Jason Grout %!s(int64=11) %!d(string=hai) anos
pai
achega
50186868ce
Modificáronse 1 ficheiros con 10 adicións e 0 borrados
  1. 10 0
      examples/js/controls/TrackballControls.js

+ 10 - 0
examples/js/controls/TrackballControls.js

@@ -65,6 +65,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 	// events
 
 	var changeEvent = { type: 'change' };
+	var startEvent = { type: 'start'};
+	var endEvent = { type: 'end'};
 
 
 	// methods
@@ -389,6 +391,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 		document.addEventListener( 'mousemove', mousemove, false );
 		document.addEventListener( 'mouseup', mouseup, false );
+		_this.dispatchEvent( startEvent );
+
 
 	}
 
@@ -426,6 +430,7 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 		document.removeEventListener( 'mousemove', mousemove );
 		document.removeEventListener( 'mouseup', mouseup );
+		_this.dispatchEvent( endEvent );
 
 	}
 
@@ -449,6 +454,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 		}
 
 		_zoomStart.y += delta * 0.01;
+		_this.dispatchEvent( startEvent );
+		_this.dispatchEvent( endEvent );
 
 	}
 
@@ -479,6 +486,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 				_state = STATE.NONE;
 
 		}
+		_this.dispatchEvent( startEvent );
+
 
 	}
 
@@ -533,6 +542,7 @@ THREE.TrackballControls = function ( object, domElement ) {
 		}
 
 		_state = STATE.NONE;
+		_this.dispatchEvent( endEvent );
 
 	}