Parcourir la source

Merge branch 'dev' of https://github.com/arodic/three.js into dev

Conflicts:
	examples/js/controls/TransformControls.js
Mr.doob il y a 12 ans
Parent
commit
9ad3ba1dce
1 fichiers modifiés avec 171 ajouts et 165 suppressions
  1. 171 165
      examples/js/controls/TransformControls.js

+ 171 - 165
examples/js/controls/TransformControls.js

@@ -23,16 +23,16 @@ THREE.TransformGizmo = function () {
 
 	this.handleGizmos = {
 		X: [
-			new THREE.Mesh( new THREE.CylinderGeometry( 0.005, 0.005, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0xff0000 } ) ),
+			new THREE.Mesh( new THREE.CylinderGeometry( 0.005, 0.005, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: "red" } ) ),
 			new THREE.Vector3( 0.5, 0, 0 ),
 			new THREE.Vector3( 0, 0, -Math.PI/2 )
 		],
 		Y: [
-			new THREE.Mesh( new THREE.CylinderGeometry( 0.005, 0.005, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0x00ff00 } ) ),
+			new THREE.Mesh( new THREE.CylinderGeometry( 0.005, 0.005, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: "green" } ) ),
 			new THREE.Vector3( 0, 0.5, 0 )
 		],
 		Z: [
-			new THREE.Mesh( new THREE.CylinderGeometry( 0.005, 0.005, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0x0000ff } ) ),
+			new THREE.Mesh( new THREE.CylinderGeometry( 0.005, 0.005, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: "blue" } ) ),
 			new THREE.Vector3( 0, 0, 0.5 ),
 			new THREE.Vector3( Math.PI/2, 0, 0 )
 		]
@@ -40,6 +40,7 @@ THREE.TransformGizmo = function () {
 
 	var showPickers = false; //debug
 	var showActivePlane = false; //debug
+	this.activePlane = undefined;
 
 	this.init = function () {
 
@@ -144,7 +145,7 @@ THREE.TransformGizmo = function () {
 
 		}
 
-		if (this.activePlane) this.activePlane.visible = showActivePlane;
+		if ( this.activePlane !== undefined ) this.activePlane.visible = showActivePlane;
 
 	}
 
@@ -156,7 +157,7 @@ THREE.TransformGizmo = function () {
 
 			handle = this.handleGizmos[ i ][0];
 
-			if ( handle.material.oldColor ) {
+			if ( handle.material.oldColor !== undefined ) {
 
 				handle.material.color.copy( handle.material.oldColor );
 				handle.material.opacity = handle.material.oldOpacity;
@@ -165,7 +166,7 @@ THREE.TransformGizmo = function () {
 
 		}
 
-		if ( this.handleGizmos[ axis ] ) {
+		if ( this.handleGizmos[ axis ] !== undefined ) {
 		
 			handle = this.handleGizmos[ axis ][0];
 
@@ -225,33 +226,33 @@ THREE.TransformGizmoTranslate = function () {
 	this.handleGizmos = {
 
 		X: [
-			new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: 0xff0000 } ) ),
+			new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: "red" } ) ),
 			new THREE.Vector3( 0.5, 0, 0 ),
 			new THREE.Vector3( 0, 0, -Math.PI/2 )
 		],
 		Y: [
-			new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: 0x00ff00 } ) ),
+			new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: "green" } ) ),
 			new THREE.Vector3( 0, 0.5, 0 )
 		],
 		Z: [
-			new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: 0x0000ff } ) ),
+			new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: "blue" } ) ),
 			new THREE.Vector3( 0, 0, 0.5 ),
 			new THREE.Vector3( Math.PI/2, 0, 0 )
 		],
 		XYZ: [
-			new THREE.Mesh( new THREE.OctahedronGeometry( 0.1, 0 ), new THREE.TransformGizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) )
+			new THREE.Mesh( new THREE.OctahedronGeometry( 0.1, 0 ), new THREE.TransformGizmoMaterial( { color: "white", opacity: 0.25 } ) )
 		],
 		XY: [
-			new THREE.Mesh( new THREE.PlaneGeometry( 0.29, 0.29 ), new THREE.TransformGizmoMaterial( { color: 0xffff00, opacity: 0.25 } ) ),
+			new THREE.Mesh( new THREE.PlaneGeometry( 0.29, 0.29 ), new THREE.TransformGizmoMaterial( { color: "yellow", opacity: 0.25 } ) ),
 			new THREE.Vector3( 0.15, 0.15, 0 )
 		],
 		YZ: [
-			new THREE.Mesh( new THREE.PlaneGeometry( 0.29, 0.29 ), new THREE.TransformGizmoMaterial( { color: 0x00ffff, opacity: 0.25 } ) ),
+			new THREE.Mesh( new THREE.PlaneGeometry( 0.29, 0.29 ), new THREE.TransformGizmoMaterial( { color: "cyan", opacity: 0.25 } ) ),
 			new THREE.Vector3( 0, 0.15, 0.15 ),
 			new THREE.Vector3( 0, Math.PI/2, 0 )
 		],
 		XZ: [
-			new THREE.Mesh( new THREE.PlaneGeometry( 0.29, 0.29 ), new THREE.TransformGizmoMaterial( { color: 0xff00ff, opacity: 0.25 } ) ),
+			new THREE.Mesh( new THREE.PlaneGeometry( 0.29, 0.29 ), new THREE.TransformGizmoMaterial( { color: "magenta", opacity: 0.25 } ) ),
 			new THREE.Vector3( 0.15, 0, 0.15 ),
 			new THREE.Vector3( -Math.PI/2, 0, 0 )
 		]
@@ -261,18 +262,35 @@ THREE.TransformGizmoTranslate = function () {
 	this.pickerGizmos = {
 
 		X: [
-			new THREE.Mesh( new THREE.CylinderGeometry( 0.075, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ),
+			new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: "red", opacity: 0.25 } ) ),
 			new THREE.Vector3( 0.6, 0, 0 ),
 			new THREE.Vector3( 0, 0, -Math.PI/2 )
 		],
 		Y: [
-			new THREE.Mesh( new THREE.CylinderGeometry( 0.075, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0x00ff00, opacity: 0.25 } ) ),
+			new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: "green", opacity: 0.25 } ) ),
 			new THREE.Vector3( 0, 0.6, 0 )
 		],
 		Z: [
-			new THREE.Mesh( new THREE.CylinderGeometry( 0.075, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ),
+			new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: "blue", opacity: 0.25 } ) ),
 			new THREE.Vector3( 0, 0, 0.6 ),
 			new THREE.Vector3( Math.PI/2, 0, 0 )
+		],
+		XYZ: [
+			new THREE.Mesh( new THREE.OctahedronGeometry( 0.2, 0 ), new THREE.TransformGizmoMaterial( { color: "white", opacity: 0.25 } ) )
+		],
+		XY: [
+			new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), new THREE.TransformGizmoMaterial( { color: "yellow", opacity: 0.25 } ) ),
+			new THREE.Vector3( 0.2, 0.2, 0 )
+		],
+		YZ: [
+			new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), new THREE.TransformGizmoMaterial( { color: "cyan", opacity: 0.25 } ) ),
+			new THREE.Vector3( 0, 0.2, 0.2 ),
+			new THREE.Vector3( 0, Math.PI/2, 0 )
+		],
+		XZ: [
+			new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), new THREE.TransformGizmoMaterial( { color: "magenta", opacity: 0.25 } ) ),
+			new THREE.Vector3( 0.2, 0, 0.2 ),
+			new THREE.Vector3( -Math.PI/2, 0, 0 )
 		]
 
 	}
@@ -323,25 +341,25 @@ THREE.TransformGizmoRotate = function () {
 	this.handleGizmos = {
 
 		X: [
-			new THREE.Mesh( new THREE.TorusGeometry( 1, 0.005, 4, 32, Math.PI ), new THREE.TransformGizmoMaterial( { color: 0xff0000 } ) ),
+			new THREE.Mesh( new THREE.TorusGeometry( 1, 0.005, 4, 32, Math.PI ), new THREE.TransformGizmoMaterial( { color: "red" } ) ),
 			new THREE.Vector3( 0, 0, 0 ),
 			new THREE.Vector3( 0, -Math.PI/2, -Math.PI/2 )
 		],
 		Y: [
-			new THREE.Mesh( new THREE.TorusGeometry( 1, 0.005, 4, 32, Math.PI ), new THREE.TransformGizmoMaterial( { color: 0x00ff00 } ) ),
+			new THREE.Mesh( new THREE.TorusGeometry( 1, 0.005, 4, 32, Math.PI ), new THREE.TransformGizmoMaterial( { color: "green" } ) ),
 			new THREE.Vector3( 0, 0, 0 ),
 			new THREE.Vector3( Math.PI/2, 0, 0 )
 		],
 		Z: [
-			new THREE.Mesh( new THREE.TorusGeometry( 1, 0.005, 4, 32, Math.PI ), new THREE.TransformGizmoMaterial( { color: 0x0000ff } ) ),
+			new THREE.Mesh( new THREE.TorusGeometry( 1, 0.005, 4, 32, Math.PI ), new THREE.TransformGizmoMaterial( { color: "blue" } ) ),
 			new THREE.Vector3( 0, 0, 0 ),
 			new THREE.Vector3( 0, 0, -Math.PI/2 )
 		],
 		E: [
-			new THREE.Mesh( new THREE.TorusGeometry( 1.25, 0.005, 4, 64 ), new THREE.TransformGizmoMaterial( { color: 0xffff00, opacity: 0.25 } ) )
+			new THREE.Mesh( new THREE.TorusGeometry( 1.25, 0.005, 4, 64 ), new THREE.TransformGizmoMaterial( { color: "yellow", opacity: 0.25 } ) )
 		],
 		XYZE: [
-			new THREE.Mesh( new THREE.TorusGeometry( 1, 0.005, 4, 64 ), new THREE.TransformGizmoMaterial( { color: 0x787878 } ) )
+			new THREE.Mesh( new THREE.TorusGeometry( 1, 0.005, 4, 64 ), new THREE.TransformGizmoMaterial( { color: "gray" } ) )
 		]
 
 	}
@@ -349,22 +367,22 @@ THREE.TransformGizmoRotate = function () {
 	this.pickerGizmos = {
 
 		X: [
-			new THREE.Mesh( new THREE.TorusGeometry( 1, 0.05, 4, 12, Math.PI ), new THREE.TransformGizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ),
+			new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new THREE.TransformGizmoMaterial( { color: "red", opacity: 0.25 } ) ),
 			new THREE.Vector3( 0, 0, 0 ),
 			new THREE.Vector3( 0, -Math.PI/2, -Math.PI/2 )
 		],
 		Y: [
-			new THREE.Mesh( new THREE.TorusGeometry( 1, 0.05, 4, 12, Math.PI ), new THREE.TransformGizmoMaterial( { color: 0x00ff00, opacity: 0.25 } ) ),
+			new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new THREE.TransformGizmoMaterial( { color: "green", opacity: 0.25 } ) ),
 			new THREE.Vector3( 0, 0, 0 ),
 			new THREE.Vector3( Math.PI/2, 0, 0 )
 		],
 		Z: [
-			new THREE.Mesh( new THREE.TorusGeometry( 1, 0.05, 4, 12, Math.PI ), new THREE.TransformGizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ),
+			new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new THREE.TransformGizmoMaterial( { color: "blue", opacity: 0.25 } ) ),
 			new THREE.Vector3( 0, 0, 0 ),
 			new THREE.Vector3( 0, 0, -Math.PI/2 )
 		],
 		E: [
-			new THREE.Mesh( new THREE.TorusGeometry( 1.25, 0.05, 2, 24 ), new THREE.TransformGizmoMaterial( { color: 0xffff00, opacity: 0.25 } ) )
+			new THREE.Mesh( new THREE.TorusGeometry( 1.25, 0.12, 2, 24 ), new THREE.TransformGizmoMaterial( { color: "yellow", opacity: 0.25 } ) )
 		],
 		XYZE: [
 			new THREE.Mesh( new THREE.Geometry() ) // TODO
@@ -461,22 +479,22 @@ THREE.TransformGizmoScale = function () {
 
 	this.handleGizmos = {
 
-		XYZ: [
-			new THREE.Mesh( new THREE.CubeGeometry( 0.125, 0.125, 0.125 ), new THREE.TransformGizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) )
-		],
 		X: [
-			new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: 0xff0000 } ) ),
+			new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: "red" } ) ),
 			new THREE.Vector3( 0.5, 0, 0 ),
 			new THREE.Vector3( 0, 0, -Math.PI/2 )
 		],
 		Y: [
-			new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: 0x00ff00 } ) ),
+			new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: "green" } ) ),
 			new THREE.Vector3( 0, 0.5, 0 )
 		],
 		Z: [
-			new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: 0x0000ff } ) ),
+			new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: "blue" } ) ),
 			new THREE.Vector3( 0, 0, 0.5 ),
 			new THREE.Vector3( Math.PI/2, 0, 0 )
+		],
+		XYZ: [
+			new THREE.Mesh( new THREE.CubeGeometry( 0.125, 0.125, 0.125 ), new THREE.TransformGizmoMaterial( { color: "white", opacity: 0.25 } ) )
 		]
 
 	}
@@ -484,21 +502,22 @@ THREE.TransformGizmoScale = function () {
 	this.pickerGizmos = {
 
 		X: [
-			new THREE.Mesh( new THREE.CylinderGeometry( 0.125, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ),
+			new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: "red", opacity: 0.25 } ) ),
 			new THREE.Vector3( 0.6, 0, 0 ),
-			new THREE.Vector3( Math.PI/4, 0, -Math.PI/2 )
+			new THREE.Vector3( 0, 0, -Math.PI/2 )
 		],
 		Y: [
-			new THREE.Mesh( new THREE.CylinderGeometry( 0.125, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0x00ff00, opacity: 0.25 } ) ),
-			new THREE.Vector3( 0, 0.6, 0 ),
-			new THREE.Vector3( 0, Math.PI/4, 0 )
+			new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: "green", opacity: 0.25 } ) ),
+			new THREE.Vector3( 0, 0.6, 0 )
 		],
 		Z: [
-			new THREE.Mesh( new THREE.CylinderGeometry( 0.125, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ),
+			new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: "blue", opacity: 0.25 } ) ),
 			new THREE.Vector3( 0, 0, 0.6 ),
-			new THREE.Vector3( Math.PI/2, Math.PI/4, 0 )
+			new THREE.Vector3( Math.PI/2, 0, 0 )
+		],
+		XYZ: [
+			new THREE.Mesh( new THREE.CubeGeometry( 0.4, 0.4, 0.4 ), new THREE.TransformGizmoMaterial( { color: "white", opacity: 0.25 } ) )
 		]
-
 	}
 
 	this.setActivePlane = function ( axis, eye ) {
@@ -556,11 +575,11 @@ THREE.TransformControls = function ( camera, domElement ) {
 	this.gizmo["rotate"].hide();
 	this.gizmo["scale"].hide();
 
-	this.object = false;
+	this.object = undefined;
 	this.snap = false;
 	this.space = "world";
 	this.size = 1;
-	this.axis = false;
+	this.axis = undefined;
 
 	var scope = this;
 	
@@ -634,15 +653,14 @@ THREE.TransformControls = function ( camera, domElement ) {
 	 	this.gizmo["scale"].hide();
 	 	this.gizmo[_mode].show();
 
-	 	scope.dispatchEvent( changeEvent );
 	 	scope.update();
 
 	}
 
 	this.detach = function ( object ) {
 
-		scope.object = false;
-		this.axis = false;
+		scope.object = undefined;
+		this.axis = undefined;
 
 	 	this.gizmo["translate"].hide();
 	 	this.gizmo["rotate"].hide();
@@ -661,7 +679,6 @@ THREE.TransformControls = function ( camera, domElement ) {
 	 	this.gizmo["scale"].hide();	
 	 	this.gizmo[_mode].show();
 
-	 	scope.dispatchEvent( changeEvent );
 		this.update();
 
 	}
@@ -675,7 +692,6 @@ THREE.TransformControls = function ( camera, domElement ) {
 	this.setSize = function ( size ) {
 
 		scope.size = size;
-	 	scope.dispatchEvent( changeEvent );
 		this.update();
 	 	
 	}
@@ -684,14 +700,13 @@ THREE.TransformControls = function ( camera, domElement ) {
 
 		scope.space = space;
 
-	 	scope.dispatchEvent( changeEvent );
 		this.update();
 
 	}
 
 	this.update = function () {
 
-		if ( !scope.object ) return;
+		if ( scope.object === undefined ) return;
 
 		scope.object.updateMatrixWorld();
 		worldPosition.getPositionFromMatrix( scope.object.matrixWorld );
@@ -719,7 +734,7 @@ THREE.TransformControls = function ( camera, domElement ) {
 
 	function onPointerHover( event ) {
 
-		if ( !scope.object || _dragging ) return;
+		if ( scope.object === undefined || _dragging == true ) return;
 
 		event.preventDefault();
 		event.stopPropagation();
@@ -731,14 +746,14 @@ THREE.TransformControls = function ( camera, domElement ) {
 		if ( intersect ) {
 
 			scope.axis = intersect.object.name;
-			scope.dispatchEvent( changeEvent );
 			scope.update();
+			scope.dispatchEvent( changeEvent );
 
-		} else {
+		} else if ( scope.axis !== undefined ) {
 
-			scope.axis = false;
-			scope.dispatchEvent( changeEvent );
+			scope.axis = undefined;
 			scope.update();
+			scope.dispatchEvent( changeEvent );
 
 		}
 
@@ -746,14 +761,14 @@ THREE.TransformControls = function ( camera, domElement ) {
 
 	function onPointerDown( event ) {
 
-		if ( !scope.object || _dragging ) return;
+		if ( scope.object === undefined || _dragging == true ) return;
 
 		event.preventDefault();
 		event.stopPropagation();
 
 		var pointer = event.touches? event.touches[0] : event;
 
-		if ( pointer.button === 0 || pointer.button == undefined ) {
+		if ( pointer.button === 0 || pointer.button === undefined ) {
 
 			var intersect = intersectObjects( pointer, scope.gizmo[_mode].pickers.children );
 
@@ -769,20 +784,16 @@ THREE.TransformControls = function ( camera, domElement ) {
 
 				var planeIntersect = intersectObjects( pointer, [scope.gizmo[_mode].activePlane] );
 
-				if ( planeIntersect ) {
-
-					oldPosition.copy( scope.object.position );
-					oldScale.copy( scope.object.scale );
+				oldPosition.copy( scope.object.position );
+				oldScale.copy( scope.object.scale );
 
-					oldRotationMatrix.extractRotation( scope.object.matrix );
-					worldRotationMatrix.extractRotation( scope.object.matrixWorld );
+				oldRotationMatrix.extractRotation( scope.object.matrix );
+				worldRotationMatrix.extractRotation( scope.object.matrixWorld );
 
-					parentRotationMatrix.extractRotation( scope.object.parent.matrixWorld );
-					parentScale.getScaleFromMatrix( tempMatrix.getInverse( scope.object.parent.matrixWorld ) );
+				parentRotationMatrix.extractRotation( scope.object.parent.matrixWorld );
+				parentScale.getScaleFromMatrix( tempMatrix.getInverse( scope.object.parent.matrixWorld ) );
 
-					offset.copy( planeIntersect.point );
-
-				}
+				offset.copy( planeIntersect.point );
 
 			}
 
@@ -794,7 +805,7 @@ THREE.TransformControls = function ( camera, domElement ) {
 
 	function onPointerMove( event ) {
 
-		if ( !scope.object || !scope.axis || !_dragging ) return;
+		if ( scope.object === undefined || scope.axis === undefined || _dragging == false ) return;
 
 		event.preventDefault();
 		event.stopPropagation();
@@ -803,172 +814,167 @@ THREE.TransformControls = function ( camera, domElement ) {
 
 		var planeIntersect = intersectObjects( pointer, [scope.gizmo[_mode].activePlane] );
 
-		if ( planeIntersect ) {
-
-			point.copy( planeIntersect.point );
+		point.copy( planeIntersect.point );
 
-			if ( _mode == "translate" ) {
+		if ( _mode == "translate" ) {
 
-				point.sub( offset );
-				point.multiply(parentScale);
+			point.sub( offset );
+			point.multiply(parentScale);
 
-				if ( scope.space == "local" ) {
-
-					point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
+			if ( scope.space == "local" ) {
 
-					if ( scope.axis.search("X") == -1 ) point.x = 0;
-					if ( scope.axis.search("Y") == -1 ) point.y = 0;
-					if ( scope.axis.search("Z") == -1 ) point.z = 0;
+				point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
 
-					point.applyMatrix4( oldRotationMatrix );
+				if ( scope.axis.search("X") == -1 ) point.x = 0;
+				if ( scope.axis.search("Y") == -1 ) point.y = 0;
+				if ( scope.axis.search("Z") == -1 ) point.z = 0;
 
-					scope.object.position.copy( oldPosition );
-					scope.object.position.add( point );
+				point.applyMatrix4( oldRotationMatrix );
 
-				} 
+				scope.object.position.copy( oldPosition );
+				scope.object.position.add( point );
 
-				if ( scope.space == "world" || scope.axis.search("XYZ") != -1 ) {
+			} 
 
-					if ( scope.axis.search("X") == -1 ) point.x = 0;
-					if ( scope.axis.search("Y") == -1 ) point.y = 0;
-					if ( scope.axis.search("Z") == -1 ) point.z = 0;
+			if ( scope.space == "world" || scope.axis.search("XYZ") != -1 ) {
 
-					point.applyMatrix4( tempMatrix.getInverse( parentRotationMatrix ) );
+				if ( scope.axis.search("X") == -1 ) point.x = 0;
+				if ( scope.axis.search("Y") == -1 ) point.y = 0;
+				if ( scope.axis.search("Z") == -1 ) point.z = 0;
 
-					scope.object.position.copy( oldPosition );
-					scope.object.position.add( point );
+				point.applyMatrix4( tempMatrix.getInverse( parentRotationMatrix ) );
 
-					if ( scope.snap ) {
+				scope.object.position.copy( oldPosition );
+				scope.object.position.add( point );
 
-						if ( scope.axis.search("X") != -1 ) scope.object.position.x = Math.round( scope.object.position.x / scope.snap ) * scope.snap;
-						if ( scope.axis.search("Y") != -1 ) scope.object.position.y = Math.round( scope.object.position.y / scope.snap ) * scope.snap;
-						if ( scope.axis.search("Z") != -1 ) scope.object.position.z = Math.round( scope.object.position.z / scope.snap ) * scope.snap;
-					
-					}
+				if ( scope.snap == true ) {
 
+					if ( scope.axis.search("X") != -1 ) scope.object.position.x = Math.round( scope.object.position.x / scope.snap ) * scope.snap;
+					if ( scope.axis.search("Y") != -1 ) scope.object.position.y = Math.round( scope.object.position.y / scope.snap ) * scope.snap;
+					if ( scope.axis.search("Z") != -1 ) scope.object.position.z = Math.round( scope.object.position.z / scope.snap ) * scope.snap;
+				
 				}
 
-			} else if ( _mode == "scale" ) {
+			}
 
-				point.sub( offset );
-				point.multiply(parentScale);
+		} else if ( _mode == "scale" ) {
 
-				if ( scope.space == "local" ) {
+			point.sub( offset );
+			point.multiply(parentScale);
 
-					if ( scope.axis == "XYZ") {
+			if ( scope.space == "local" ) {
 
-						scale = 1 + ( ( point.y ) / 50 );
+				if ( scope.axis == "XYZ") {
 
-						scope.object.scale.x = oldScale.x * scale;
-						scope.object.scale.y = oldScale.y * scale;
-						scope.object.scale.z = oldScale.z * scale;
+					scale = 1 + ( ( point.y ) / 50 );
 
-					} else {
+					scope.object.scale.x = oldScale.x * scale;
+					scope.object.scale.y = oldScale.y * scale;
+					scope.object.scale.z = oldScale.z * scale;
 
-						point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
+				} else {
 
-						if ( scope.axis == "X" ) scope.object.scale.x = oldScale.x * ( 1 + point.x / 50 );
-						if ( scope.axis == "Y" ) scope.object.scale.y = oldScale.y * ( 1 + point.y / 50 );
-						if ( scope.axis == "Z" ) scope.object.scale.z = oldScale.z * ( 1 + point.z / 50 );
+					point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
 
-					}
+					if ( scope.axis == "X" ) scope.object.scale.x = oldScale.x * ( 1 + point.x / 50 );
+					if ( scope.axis == "Y" ) scope.object.scale.y = oldScale.y * ( 1 + point.y / 50 );
+					if ( scope.axis == "Z" ) scope.object.scale.z = oldScale.z * ( 1 + point.z / 50 );
 
 				}
 
-			} else if ( _mode == "rotate" ) {
+			}
 
-				point.sub( worldPosition );
-				point.multiply(parentScale);
-				tempVector.copy(offset).sub( worldPosition );
-				tempVector.multiply(parentScale);
+		} else if ( _mode == "rotate" ) {
 
-				if ( scope.axis == "E" ) {
+			point.sub( worldPosition );
+			point.multiply(parentScale);
+			tempVector.copy(offset).sub( worldPosition );
+			tempVector.multiply(parentScale);
 
-					point.applyMatrix4( tempMatrix.getInverse( lookAtMatrix ) );
-					tempVector.applyMatrix4( tempMatrix.getInverse( lookAtMatrix ) );
+			if ( scope.axis == "E" ) {
 
-					rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
-					offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
+				point.applyMatrix4( tempMatrix.getInverse( lookAtMatrix ) );
+				tempVector.applyMatrix4( tempMatrix.getInverse( lookAtMatrix ) );
 
-					tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
+				rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
+				offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
 
-					quaternionE.setFromAxisAngle( eye, rotation.z - offsetRotation.z );
-					quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
+				tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
 
-					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionE );
-					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
+				quaternionE.setFromAxisAngle( eye, rotation.z - offsetRotation.z );
+				quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
 
-					scope.object.quaternion.copy( tempQuaternion );
+				tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionE );
+				tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
 
-				} else if ( scope.axis == "XYZE" ) {
+				scope.object.quaternion.copy( tempQuaternion );
 
-					quaternionE.setFromEuler( point.clone().cross(tempVector).normalize() ); // rotation axis
+			} else if ( scope.axis == "XYZE" ) {
 
-					tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
-					quaternionX.setFromAxisAngle( quaternionE, - point.clone().angleTo(tempVector) );
-					quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
+				quaternionE.setFromEuler( point.clone().cross(tempVector).normalize() ); // rotation axis
 
-					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
-					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
+				tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
+				quaternionX.setFromAxisAngle( quaternionE, - point.clone().angleTo(tempVector) );
+				quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
 
-					scope.object.quaternion.copy( tempQuaternion );
+				tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
+				tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
 
-				} else if ( scope.space == "local" ) {
+				scope.object.quaternion.copy( tempQuaternion );
 
-					point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
+			} else if ( scope.space == "local" ) {
 
-					tempVector.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
+				point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
 
-					rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
-					offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
+				tempVector.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
 
-					quaternionXYZ.setFromRotationMatrix( oldRotationMatrix );
-					quaternionX.setFromAxisAngle( unitX, rotation.x - offsetRotation.x );
-					quaternionY.setFromAxisAngle( unitY, rotation.y - offsetRotation.y );
-					quaternionZ.setFromAxisAngle( unitZ, rotation.z - offsetRotation.z );
+				rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
+				offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
 
-					if ( scope.axis == "X" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionX );
-					if ( scope.axis == "Y" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionY );
-					if ( scope.axis == "Z" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionZ );
+				quaternionXYZ.setFromRotationMatrix( oldRotationMatrix );
+				quaternionX.setFromAxisAngle( unitX, rotation.x - offsetRotation.x );
+				quaternionY.setFromAxisAngle( unitY, rotation.y - offsetRotation.y );
+				quaternionZ.setFromAxisAngle( unitZ, rotation.z - offsetRotation.z );
 
-					scope.object.quaternion.copy( quaternionXYZ );
+				if ( scope.axis == "X" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionX );
+				if ( scope.axis == "Y" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionY );
+				if ( scope.axis == "Z" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionZ );
 
-				} else if ( scope.space == "world" ) {
+				scope.object.quaternion.copy( quaternionXYZ );
 
-					rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
-					offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
+			} else if ( scope.space == "world" ) {
 
-					tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
+				rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
+				offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
 
-					quaternionX.setFromAxisAngle( unitX, rotation.x - offsetRotation.x );
-					quaternionY.setFromAxisAngle( unitY, rotation.y - offsetRotation.y );
-					quaternionZ.setFromAxisAngle( unitZ, rotation.z - offsetRotation.z );
-					quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
+				tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
 
-					if ( scope.axis == "X" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
-					if ( scope.axis == "Y" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionY );
-					if ( scope.axis == "Z" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionZ );
+				quaternionX.setFromAxisAngle( unitX, rotation.x - offsetRotation.x );
+				quaternionY.setFromAxisAngle( unitY, rotation.y - offsetRotation.y );
+				quaternionZ.setFromAxisAngle( unitZ, rotation.z - offsetRotation.z );
+				quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
 
-					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
+				if ( scope.axis == "X" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
+				if ( scope.axis == "Y" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionY );
+				if ( scope.axis == "Z" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionZ );
 
-					scope.object.quaternion.copy( tempQuaternion );
+				tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
 
-				}
+				scope.object.quaternion.copy( tempQuaternion );
 
 			}
 
 		}
 
-		scope.dispatchEvent( changeEvent );
 		scope.update();
+		scope.dispatchEvent( changeEvent );
 
 	}
 
 	function onPointerUp( event ) {
 
-		scope.axis = false;
+		scope.axis = undefined;
 		_dragging = false;
-		scope.dispatchEvent( changeEvent );
 		scope.update();
 
 	}