Browse Source

Added hovered boolean to TransformControls. Improved Editor mouse behaviour.

Mr.doob 12 years ago
parent
commit
3080578f45
2 changed files with 18 additions and 10 deletions
  1. 5 10
      editor/js/Viewport.js
  2. 13 0
      examples/js/controls/TransformControls.js

+ 5 - 10
editor/js/Viewport.js

@@ -99,16 +99,12 @@ var Viewport = function ( signals ) {
 
 		onMouseDownPosition.set( event.layerX, event.layerY );
 
-		controls.enabled = true;
+		if ( transformControls.hovered === false ) {
 
-		document.addEventListener( 'mousemove', onMouseMove, false );
-		document.addEventListener( 'mouseup', onMouseUp, false );
-
-	};
-
-	var onMouseMove = function ( event ) {
+			controls.enabled = true;
+			document.addEventListener( 'mouseup', onMouseUp, false );
 
-		controls.enabled = transformControls.active === false;
+		}
 
 	};
 
@@ -146,7 +142,6 @@ var Viewport = function ( signals ) {
 
 		controls.enabled = false;
 
-		document.removeEventListener( 'mousemove', onMouseMove );
 		document.removeEventListener( 'mouseup', onMouseUp );
 
 	};
@@ -158,7 +153,6 @@ var Viewport = function ( signals ) {
 		if ( intersects.length > 0 && intersects[ 0 ].object === selected ) {
 
 			controls.focus( selected );
-			controls.enabled = true;
 
 		}
 
@@ -177,6 +171,7 @@ var Viewport = function ( signals ) {
 		transformControls.update();
 
 	} );
+	controls.enabled = false;
 
 	// signals
 

+ 13 - 0
examples/js/controls/TransformControls.js

@@ -8,11 +8,16 @@ THREE.TransformControls = function ( camera, domElement, doc ) {
 
 	// TODO: Make non-uniform scale and rotate play nice in hierarchies
 	// TODO: ADD RXYZ contol
+
 	this.camera = camera;
 	this.domElement = ( domElement !== undefined ) ? domElement : document;
 	this.document = ( doc !== undefined ) ? doc : document;
 
+	this.object = undefined;
+
 	this.active = false;
+	this.hovered = false;
+
 	this.mode = 'translate';
 	this.space = 'local';
 	this.scale = 1;
@@ -358,6 +363,8 @@ THREE.TransformControls = function ( camera, domElement, doc ) {
 
 	this.detatch = function ( object ) {
 
+		this.object = undefined;
+
 	 	this.hide();
 
 		this.domElement.removeEventListener( 'mousedown', onMouseDown, false );
@@ -368,6 +375,8 @@ THREE.TransformControls = function ( camera, domElement, doc ) {
 
 	this.update = function () {
 
+		if ( this.object === undefined ) return;
+
 		this.object.updateMatrixWorld();
 		worldPosition.getPositionFromMatrix( this.object.matrixWorld );
 		worldRotation.setEulerFromRotationMatrix( tempMatrix.extractRotation(this.object.matrixWorld ));
@@ -613,6 +622,8 @@ THREE.TransformControls = function ( camera, domElement, doc ) {
 
 				}
 
+				scope.hovered = true;
+
 			} else if ( hovered !== null ) {
 
 				hovered.material.color.copy( hoveredColor );
@@ -622,6 +633,8 @@ THREE.TransformControls = function ( camera, domElement, doc ) {
 
 				scope.dispatchEvent( changeEvent );
 
+				scope.hovered = false;
+
 			}
 
 		}