소스 검색

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 11 년 전
부모
커밋
50186868ce
1개의 변경된 파일10개의 추가작업 그리고 0개의 파일을 삭제
  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 );
 
 	}