Browse Source

New TransformControls implementation.

Improved rotation interactions with radial and linear mode
depending on facing angle. Fixes #13806 and #7947.

Added auto-hiding for axis facing camera. Fixes #11340

Improved scaling interactions. Fixes #10916, #9312, #5489 and #5379
Aki Rodic 7 năm trước cách đây
mục cha
commit
63624bf63b

+ 377 - 917
examples/js/controls/TransformControls.js

@@ -2,1146 +2,606 @@
  * @author arodic / https://github.com/arodic
  */
 
-( function () {
+THREE.TransformControls = function ( camera, domElement ) {
+
+	// TODO: Make non-uniform scale and rotate play nice in hierarchies
+	// TODO: prevent infinite horizon translate
+
+	THREE.Object3D.call( this );
+
+	domElement = ( domElement !== undefined ) ? domElement : document;
+
+	this.visible = false;
+
+	var _gizmo = new THREE.TransformControlsGizmo();
+	this.add( _gizmo );
+
+	var _plane = new THREE.TransformControlsPlane();
+	this.add( _plane );
+
+	var scope = this;
+
+	defineProperty( "camera", camera );
+	defineProperty( "object", undefined );
+	defineProperty( "axis", null );
+	defineProperty( "mode", "translate" );
+	defineProperty( "translationSnap", null );
+	defineProperty( "rotationSnap", null );
+	defineProperty( "space", "world" );
+	defineProperty( "size", 1 );
+
+	scope.dragging = false;
+
+	var changeEvent = { type: "change" };
+	var mouseDownEvent = { type: "mouseDown" };
+	var mouseUpEvent = { type: "mouseUp", mode: scope.mode };
+	var objectChangeEvent = { type: "objectChange" };
+
+	var ray = new THREE.Raycaster();
+	var pointerVector = new THREE.Vector2();
+
+	var point = new THREE.Vector3();
+	var offset = new THREE.Vector3();
+
+	var rotation = new THREE.Vector3();
+	var offsetRotation = new THREE.Vector3();
+
+	var lookAtMatrix = new THREE.Matrix4();
+	var _eye = new THREE.Vector3();
+
+	var _tempMatrix = new THREE.Matrix4();
+	var _tempVector = new THREE.Vector3();
+	var _tempQuaternion = new THREE.Quaternion();
+	var _unitX = new THREE.Vector3( 1, 0, 0 );
+	var _unitY = new THREE.Vector3( 0, 1, 0 );
+	var _unitZ = new THREE.Vector3( 0, 0, 1 );
+	var _identityEuler = new THREE.Euler();
+
+	// var oldPosition = new THREE.Vector3();
+	// var oldScale = new THREE.Vector3();
+	// var oldRotationMatrix = new THREE.Matrix4();
+	var _worldRotationStart = new THREE.Quaternion();
+	var _worldPositionStart = new THREE.Vector3();
+	var _worldPointStart = new THREE.Vector3();
+	var _localPointStart = new THREE.Vector3();
+	var _localScale = new THREE.Vector3();
+	var _localPoint = new THREE.Vector3();
+	var _worldPoint = new THREE.Vector3();
+	var _worldShift = new THREE.Vector3();
+	var _localShift = new THREE.Vector3();
+	var _worldCross = new THREE.Vector3();
+	var _localCross = new THREE.Vector3();
+	var _worldQuaternion = new THREE.Quaternion();
+	var _localQuaternion = new THREE.Quaternion();
+
+	var _worldPosition = new THREE.Vector3();
+	var _worldRotation = new THREE.Euler();
+
+	var alignVector = new THREE.Vector3();
+	var _positionStart = new THREE.Vector3();
+	var _quaternionStart = new THREE.Quaternion();
+	var _scaleStart = new THREE.Vector3();
+
+	domElement.addEventListener( "mousedown", onPointerDown, false );
+	domElement.addEventListener( "touchstart", onPointerDown, false );
+	domElement.addEventListener( "mousemove", onPointerHover, false );
+	domElement.addEventListener( "touchmove", onPointerHover, false );
+	domElement.addEventListener( "mousemove", onPointerMove, false );
+	domElement.addEventListener( "touchmove", onPointerMove, false );
+	domElement.addEventListener( "mouseup", onPointerUp, false );
+	domElement.addEventListener( "mouseleave", onPointerUp, false );
+	domElement.addEventListener( "mouseout", onPointerUp, false );
+	domElement.addEventListener( "touchend", onPointerUp, false );
+	domElement.addEventListener( "touchcancel", onPointerUp, false );
+	domElement.addEventListener( "touchleave", onPointerUp, false );
+	domElement.addEventListener( "contextmenu", onContext, false );
+
+	this.dispose = function () {
+
+		domElement.removeEventListener( "mousedown", onPointerDown );
+		domElement.removeEventListener( "touchstart", onPointerDown );
+		domElement.removeEventListener( "mousemove", onPointerHover );
+		domElement.removeEventListener( "touchmove", onPointerHover );
+		domElement.removeEventListener( "mousemove", onPointerMove );
+		domElement.removeEventListener( "touchmove", onPointerMove );
+		domElement.removeEventListener( "mouseup", onPointerUp );
+		domElement.removeEventListener( "mouseleave", onPointerUp );
+		domElement.removeEventListener( "mouseout", onPointerUp );
+		domElement.removeEventListener( "touchend", onPointerUp );
+		domElement.removeEventListener( "touchcancel", onPointerUp );
+		domElement.removeEventListener( "touchleave", onPointerUp );
+		domElement.removeEventListener( "contextmenu", onContext );
 
-	'use strict';
-
-	var GizmoMaterial = function ( parameters ) {
-
-		THREE.MeshBasicMaterial.call( this );
-
-		this.depthTest = false;
-		this.depthWrite = false;
-		this.fog = false;
-		this.side = THREE.FrontSide;
-		this.transparent = true;
-
-		this.setValues( parameters );
-
-		this.oldColor = this.color.clone();
-		this.oldOpacity = this.opacity;
-
-		this.highlight = function ( highlighted ) {
+	};
 
-			if ( highlighted ) {
+	this.attach = function ( object ) {
 
-				this.color.setRGB( 1, 1, 0 );
-				this.opacity = 1;
+		this.object = object;
+		this.visible = true;
 
-			} else {
-
-				this.color.copy( this.oldColor );
-				this.opacity = this.oldOpacity;
+	};
 
-			}
+	this.detach = function () {
 
-		};
+		this.object = undefined;
+		this.visible = false;
+		this.axis = null;
 
 	};
 
-	GizmoMaterial.prototype = Object.create( THREE.MeshBasicMaterial.prototype );
-	GizmoMaterial.prototype.constructor = GizmoMaterial;
-
+	function defineProperty( propName, defaultValue ) {
 
-	var GizmoLineMaterial = function ( parameters ) {
+		var propValue = defaultValue;
 
-		THREE.LineBasicMaterial.call( this );
+		Object.defineProperty( scope, propName, {
 
-		this.depthTest = false;
-		this.depthWrite = false;
-		this.fog = false;
-		this.transparent = true;
-		this.linewidth = 1;
+			get: function() {
 
-		this.setValues( parameters );
+				return propValue !== undefined ? propValue : defaultValue;
 
-		this.oldColor = this.color.clone();
-		this.oldOpacity = this.opacity;
+			},
 
-		this.highlight = function ( highlighted ) {
+			set: function( value ) {
 
-			if ( highlighted ) {
+				if ( propValue !== value ) {
 
-				this.color.setRGB( 1, 1, 0 );
-				this.opacity = 1;
+					propValue = value;
 
-			} else {
+					scope.dispatchEvent( changeEvent );
 
-				this.color.copy( this.oldColor );
-				this.opacity = this.oldOpacity;
+				}
 
 			}
 
-		};
-
-	};
-
-	GizmoLineMaterial.prototype = Object.create( THREE.LineBasicMaterial.prototype );
-	GizmoLineMaterial.prototype.constructor = GizmoLineMaterial;
+		});
 
+		scope[ propName ] = defaultValue;
 
-	var pickerMaterial = new GizmoMaterial( { visible: false, transparent: false } );
+	}
 
+	this.updateMatrixWorld = function () {
 
-	THREE.TransformGizmo = function () {
+		if ( this.object === undefined ) return;
 
-		this.init = function () {
+		if ( this.mode === 'scale') this.space = 'local';
 
-			THREE.Object3D.call( this );
+		// camera.updateMatrixWorld();
+		// this.object.updateMatrixWorld();
 
-			this.handles = new THREE.Object3D();
-			this.pickers = new THREE.Object3D();
-			this.planes = new THREE.Object3D();
+		_worldPosition.setFromMatrixPosition( this.object.matrixWorld );
+		_worldRotation.setFromRotationMatrix( _tempMatrix.extractRotation( this.object.matrixWorld ) );
 
-			this.add( this.handles );
-			this.add( this.pickers );
-			this.add( this.planes );
+		this.position.copy( _worldPosition );
 
-			//// PLANES
+		if ( camera instanceof THREE.PerspectiveCamera ) {
 
-			var planeGeometry = new THREE.PlaneBufferGeometry( 50, 50, 2, 2 );
-			var planeMaterial = new THREE.MeshBasicMaterial( { visible: false, side: THREE.DoubleSide } );
+			_eye.setFromMatrixPosition( camera.matrixWorld ).sub( _worldPosition ).normalize();
 
-			var planes = {
-				"XY": new THREE.Mesh( planeGeometry, planeMaterial ),
-				"YZ": new THREE.Mesh( planeGeometry, planeMaterial ),
-				"XZ": new THREE.Mesh( planeGeometry, planeMaterial ),
-				"XYZE": new THREE.Mesh( planeGeometry, planeMaterial )
-			};
+		} else if ( camera instanceof THREE.OrthographicCamera ) {
 
-			this.activePlane = planes[ "XYZE" ];
+			_eye.setFromMatrixPosition( camera.matrixWorld ).normalize();
 
-			planes[ "YZ" ].rotation.set( 0, Math.PI / 2, 0 );
-			planes[ "XZ" ].rotation.set( - Math.PI / 2, 0, 0 );
-
-			for ( var i in planes ) {
+		}
 
-				planes[ i ].name = i;
-				this.planes.add( planes[ i ] );
-				this.planes[ i ] = planes[ i ];
+		// TODO
+		this._worldPosition = _worldPosition;
+		this._worldRotation = _worldRotation;
+		this._eye = _eye;
 
-			}
+		var scale = _worldPosition.distanceTo( _tempVector.setFromMatrixPosition( camera.matrixWorld ) ) / 6 * this.size;
+		this.scale.set( scale, scale, scale );
 
-			//// HANDLES AND PICKERS
+		THREE.Object3D.prototype.updateMatrixWorld.call( this );
 
-			var setupGizmos = function ( gizmoMap, parent ) {
+	};
 
-				for ( var name in gizmoMap ) {
+	function onContext( event ) {
 
-					for ( i = gizmoMap[ name ].length; i --; ) {
+		event.preventDefault();
 
-						var object = gizmoMap[ name ][ i ][ 0 ];
-						var position = gizmoMap[ name ][ i ][ 1 ];
-						var rotation = gizmoMap[ name ][ i ][ 2 ];
+	}
 
-						object.name = name;
+	function onPointerHover( event ) {
 
-						object.renderOrder = Infinity; // avoid being hidden by other transparent objects
+		if ( scope.object === undefined || scope.dragging === true || ( event.button !== undefined && event.button !== 0 ) ) return;
 
-						if ( position ) object.position.set( position[ 0 ], position[ 1 ], position[ 2 ] );
-						if ( rotation ) object.rotation.set( rotation[ 0 ], rotation[ 1 ], rotation[ 2 ] );
+		var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
 
-						parent.add( object );
+		var intersect = intersectObjects( pointer, _gizmo.picker[ scope.mode ].children );
 
-					}
+		if ( intersect ) {
 
-				}
+			scope.axis = intersect.object.name;
 
-			};
+			event.preventDefault();
 
-			setupGizmos( this.handleGizmos, this.handles );
-			setupGizmos( this.pickerGizmos, this.pickers );
+		} else {
 
-			// reset Transformations
+			scope.axis = null;
 
-			this.traverse( function ( child ) {
+		}
 
-				if ( child instanceof THREE.Mesh ) {
+	}
 
-					child.updateMatrix();
+	function onPointerDown( event ) {
 
-					var tempGeometry = child.geometry.clone();
-					tempGeometry.applyMatrix( child.matrix );
-					child.geometry = tempGeometry;
+		if ( scope.object === undefined || scope.dragging === true || ( event.button !== undefined && event.button !== 0 ) ) return;
 
-					child.position.set( 0, 0, 0 );
-					child.rotation.set( 0, 0, 0 );
-					child.scale.set( 1, 1, 1 );
+		var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
 
-				}
+		if ( pointer.button === 0 || pointer.button === undefined ) {
 
-			} );
+			var intersect = intersectObjects( pointer, _gizmo.picker[ scope.mode ].children );
 
-		};
+			if ( intersect ) {
 
-		this.highlight = function ( axis ) {
+				event.preventDefault();
+				event.stopPropagation();
 
-			this.traverse( function ( child ) {
+				scope.axis = intersect.object.name;
 
-				if ( child.material && child.material.highlight ) {
+				_plane.update( scope.space === "local" ? _worldRotation : _identityEuler, _eye );
 
-					if ( child.name === axis ) {
+				var planeIntersect = intersectObjects( pointer, [ _plane ] );
 
-						child.material.highlight( true );
+				if ( planeIntersect ) {
 
-					} else {
+					_positionStart.copy( scope.object.position );
+					_quaternionStart.copy( scope.object.quaternion );
+					_scaleStart.copy( scope.object.scale );
 
-						child.material.highlight( false );
+					_worldRotationStart.setFromRotationMatrix( scope.object.matrixWorld );
+					_worldPositionStart.setFromMatrixPosition( scope.object.matrixWorld );
 
-					}
+					_worldPointStart.copy( planeIntersect.point ).sub( _worldPositionStart );
+					_localPointStart.copy( _worldPointStart ).applyQuaternion( _worldRotationStart.clone().inverse() );
 
 				}
 
-			} );
-
-		};
-
-	};
-
-	THREE.TransformGizmo.prototype = Object.create( THREE.Object3D.prototype );
-	THREE.TransformGizmo.prototype.constructor = THREE.TransformGizmo;
-
-	THREE.TransformGizmo.prototype.update = function ( rotation, eye ) {
-
-		var vec1 = new THREE.Vector3( 0, 0, 0 );
-		var vec2 = new THREE.Vector3( 0, 1, 0 );
-		var lookAtMatrix = new THREE.Matrix4();
-
-		this.traverse( function ( child ) {
-
-			if ( child.name.search( "E" ) !== - 1 ) {
-
-				child.quaternion.setFromRotationMatrix( lookAtMatrix.lookAt( eye, vec1, vec2 ) );
-
-			} else if ( child.name.search( "X" ) !== - 1 || child.name.search( "Y" ) !== - 1 || child.name.search( "Z" ) !== - 1 ) {
+			} else {
 
-				child.quaternion.setFromEuler( rotation );
+				scope.axis = null;
 
 			}
 
-		} );
-
-	};
-
-	THREE.TransformGizmoTranslate = function () {
-
-		THREE.TransformGizmo.call( this );
-
-		var arrowGeometry = new THREE.ConeBufferGeometry( 0.05, 0.2, 12, 1, false );
-		arrowGeometry.translate( 0, 0.5, 0 );
-
-		var lineXGeometry = new THREE.BufferGeometry();
-		lineXGeometry.addAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 1, 0, 0 ], 3 ) );
-
-		var lineYGeometry = new THREE.BufferGeometry();
-		lineYGeometry.addAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
-
-		var lineZGeometry = new THREE.BufferGeometry();
-		lineZGeometry.addAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
-
-		this.handleGizmos = {
-
-			X: [
-				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0xff0000 } ) ), [ 0.5, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ],
-				[ new THREE.Line( lineXGeometry, new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
-			],
-
-			Y: [
-				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x00ff00 } ) ), [ 0, 0.5, 0 ] ],
-				[	new THREE.Line( lineYGeometry, new GizmoLineMaterial( { color: 0x00ff00 } ) ) ]
-			],
-
-			Z: [
-				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x0000ff } ) ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ] ],
-				[ new THREE.Line( lineZGeometry, new GizmoLineMaterial( { color: 0x0000ff } ) ) ]
-			],
-
-			XYZ: [
-				[ new THREE.Mesh( new THREE.OctahedronGeometry( 0.1, 0 ), new GizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) ), [ 0, 0, 0 ], [ 0, 0, 0 ] ]
-			],
-
-			XY: [
-				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0xffff00, opacity: 0.25 } ) ), [ 0.15, 0.15, 0 ] ]
-			],
-
-			YZ: [
-				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0x00ffff, opacity: 0.25 } ) ), [ 0, 0.15, 0.15 ], [ 0, Math.PI / 2, 0 ] ]
-			],
-
-			XZ: [
-				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0xff00ff, opacity: 0.25 } ) ), [ 0.15, 0, 0.15 ], [ - Math.PI / 2, 0, 0 ] ]
-			]
-
-		};
-
-		this.pickerGizmos = {
-
-			X: [
-				[ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0.6, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ]
-			],
+		}
 
-			Y: [
-				[ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, 0.6, 0 ] ]
-			],
+		scope.dragging = true;
 
-			Z: [
-				[ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ] ]
-			],
+	}
 
-			XYZ: [
-				[ new THREE.Mesh( new THREE.OctahedronGeometry( 0.2, 0 ), pickerMaterial ) ]
-			],
+	function onPointerMove( event ) {
 
-			XY: [
-				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), pickerMaterial ), [ 0.2, 0.2, 0 ] ]
-			],
+		var axis = scope.axis;
+		var mode = scope.mode;
+		var object = scope.object;
+		var space = scope.space;
 
-			YZ: [
-				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), pickerMaterial ), [ 0, 0.2, 0.2 ], [ 0, Math.PI / 2, 0 ] ]
-			],
+		if ( object === undefined || axis === null || scope.dragging === false || ( event.button !== undefined && event.button !== 0 ) ) return;
 
-			XZ: [
-				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), pickerMaterial ), [ 0.2, 0, 0.2 ], [ - Math.PI / 2, 0, 0 ] ]
-			]
+		var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
 
-		};
+		var planeIntersect = intersectObjects( pointer, [ _plane ] );
 
-		this.setActivePlane = function ( axis, eye ) {
+		if ( planeIntersect === false ) return;
 
-			var tempMatrix = new THREE.Matrix4();
-			eye.applyMatrix4( tempMatrix.getInverse( tempMatrix.extractRotation( this.planes[ "XY" ].matrixWorld ) ) );
+		event.preventDefault();
+		event.stopPropagation();
 
-			if ( axis === "X" ) {
+		_worldPoint.copy( planeIntersect.point ).sub( _worldPositionStart );
+		_worldShift.subVectors( _worldPoint, _worldPointStart );
 
-				this.activePlane = this.planes[ "XY" ];
+		_localPoint.copy( _worldPoint );
+		_localPoint.applyQuaternion( _worldRotationStart.clone().inverse() );
+		_localShift.subVectors( _localPoint, _localPointStart );
+		_worldCross.copy( _worldPoint ).cross( _worldPointStart );
+		_localCross.copy( _localPoint ).cross( _localPointStart );
 
-				if ( Math.abs( eye.y ) > Math.abs( eye.z ) ) this.activePlane = this.planes[ "XZ" ];
+		if ( mode === 'translate' ) {
 
+			if ( axis.search( 'X' ) === -1 ) {
+				_worldShift.x = 0;
+				_localShift.x = 0;
 			}
-
-			if ( axis === "Y" ) {
-
-				this.activePlane = this.planes[ "XY" ];
-
-				if ( Math.abs( eye.x ) > Math.abs( eye.z ) ) this.activePlane = this.planes[ "YZ" ];
-
+			if ( axis.search( 'Y' ) === -1 ) {
+				_worldShift.y = 0;
+				_localShift.y = 0;
 			}
-
-			if ( axis === "Z" ) {
-
-				this.activePlane = this.planes[ "XZ" ];
-
-				if ( Math.abs( eye.x ) > Math.abs( eye.y ) ) this.activePlane = this.planes[ "YZ" ];
-
+			if ( axis.search( 'Z' ) === -1 ) {
+				_worldShift.z = 0;
+				_localShift.z = 0;
 			}
 
-			if ( axis === "XYZ" ) this.activePlane = this.planes[ "XYZE" ];
-
-			if ( axis === "XY" ) this.activePlane = this.planes[ "XY" ];
-
-			if ( axis === "YZ" ) this.activePlane = this.planes[ "YZ" ];
-
-			if ( axis === "XZ" ) this.activePlane = this.planes[ "XZ" ];
-
-		};
-
-		this.init();
-
-	};
-
-	THREE.TransformGizmoTranslate.prototype = Object.create( THREE.TransformGizmo.prototype );
-	THREE.TransformGizmoTranslate.prototype.constructor = THREE.TransformGizmoTranslate;
-
-	THREE.TransformGizmoRotate = function () {
-
-		THREE.TransformGizmo.call( this );
-
-		var CircleGeometry = function ( radius, facing, arc ) {
-
-			var geometry = new THREE.BufferGeometry();
-			var vertices = [];
-			arc = arc ? arc : 1;
-
-			for ( var i = 0; i <= 64 * arc; ++ i ) {
-
-				if ( facing === 'x' ) vertices.push( 0, Math.cos( i / 32 * Math.PI ) * radius, Math.sin( i / 32 * Math.PI ) * radius );
-				if ( facing === 'y' ) vertices.push( Math.cos( i / 32 * Math.PI ) * radius, 0, Math.sin( i / 32 * Math.PI ) * radius );
-				if ( facing === 'z' ) vertices.push( Math.sin( i / 32 * Math.PI ) * radius, Math.cos( i / 32 * Math.PI ) * radius, 0 );
+			// Apply translate
 
+			if ( space === 'local' ) {
+				object.position.copy(_localShift).applyQuaternion( _quaternionStart );
+			} else {
+				object.position.copy( _worldShift );
 			}
 
-			geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
-			return geometry;
-
-		};
-
-		this.handleGizmos = {
-
-			X: [
-				[ new THREE.Line( new CircleGeometry( 1, 'x', 0.5 ), new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
-			],
-
-			Y: [
-				[ new THREE.Line( new CircleGeometry( 1, 'y', 0.5 ), new GizmoLineMaterial( { color: 0x00ff00 } ) ) ]
-			],
-
-			Z: [
-				[ new THREE.Line( new CircleGeometry( 1, 'z', 0.5 ), new GizmoLineMaterial( { color: 0x0000ff } ) ) ]
-			],
-
-			E: [
-				[ new THREE.Line( new CircleGeometry( 1.25, 'z', 1 ), new GizmoLineMaterial( { color: 0xcccc00 } ) ) ]
-			],
-
-			XYZE: [
-				[ new THREE.Line( new CircleGeometry( 1, 'z', 1 ), new GizmoLineMaterial( { color: 0x787878 } ) ) ]
-			]
-
-		};
-
-		this.pickerGizmos = {
-
-			X: [
-				[ new THREE.Mesh( new THREE.TorusBufferGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ 0, - Math.PI / 2, - Math.PI / 2 ] ]
-			],
-
-			Y: [
-				[ new THREE.Mesh( new THREE.TorusBufferGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ Math.PI / 2, 0, 0 ] ]
-			],
-
-			Z: [
-				[ new THREE.Mesh( new THREE.TorusBufferGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ]
-			],
-
-			E: [
-				[ new THREE.Mesh( new THREE.TorusBufferGeometry( 1.25, 0.12, 2, 24 ), pickerMaterial ) ]
-			],
-
-			XYZE: [
-				[ new THREE.Mesh( new THREE.TorusBufferGeometry( 1, 0.12, 2, 24 ), pickerMaterial ) ]
-			]
-
-		};
-
-		this.pickerGizmos.XYZE[ 0 ][ 0 ].visible = false; // disable XYZE picker gizmo
-
-		this.setActivePlane = function ( axis ) {
-
-			if ( axis === "E" ) this.activePlane = this.planes[ "XYZE" ];
-
-			if ( axis === "X" ) this.activePlane = this.planes[ "YZ" ];
-
-			if ( axis === "Y" ) this.activePlane = this.planes[ "XZ" ];
-
-			if ( axis === "Z" ) this.activePlane = this.planes[ "XY" ];
-
-		};
-
-		this.update = function ( rotation, eye2 ) {
-
-			THREE.TransformGizmo.prototype.update.apply( this, arguments );
-
-			var tempMatrix = new THREE.Matrix4();
-			var worldRotation = new THREE.Euler( 0, 0, 1 );
-			var tempQuaternion = new THREE.Quaternion();
-			var unitX = new THREE.Vector3( 1, 0, 0 );
-			var unitY = new THREE.Vector3( 0, 1, 0 );
-			var unitZ = new THREE.Vector3( 0, 0, 1 );
-			var quaternionX = new THREE.Quaternion();
-			var quaternionY = new THREE.Quaternion();
-			var quaternionZ = new THREE.Quaternion();
-			var eye = eye2.clone();
-
-			worldRotation.copy( this.planes[ "XY" ].rotation );
-			tempQuaternion.setFromEuler( worldRotation );
-
-			tempMatrix.makeRotationFromQuaternion( tempQuaternion ).getInverse( tempMatrix );
-			eye.applyMatrix4( tempMatrix );
-
-			this.traverse( function( child ) {
-
-				tempQuaternion.setFromEuler( worldRotation );
-
-				if ( child.name === "X" ) {
+			object.position.add( _positionStart );
 
-					quaternionX.setFromAxisAngle( unitX, Math.atan2( - eye.y, eye.z ) );
-					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
-					child.quaternion.copy( tempQuaternion );
+			if ( scope.translationSnap ) {
 
-				}
+				if ( space === 'local' ) {
 
-				if ( child.name === "Y" ) {
+					object.position.applyQuaternion(_tempQuaternion.copy( _quaternionStart ).inverse() );
 
-					quaternionY.setFromAxisAngle( unitY, Math.atan2( eye.x, eye.z ) );
-					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionY );
-					child.quaternion.copy( tempQuaternion );
+					if ( axis.search( 'X' ) !== -1 ) {
+						object.position.x = Math.round( object.position.x / scope.translationSnap ) * scope.translationSnap;
+					}
 
-				}
+					if ( axis.search( 'Y' ) !== -1 ) {
+						object.position.y = Math.round( object.position.y / scope.translationSnap ) * scope.translationSnap;
+					}
 
-				if ( child.name === "Z" ) {
+					if ( axis.search( 'Z' ) !== -1 ) {
+						object.position.z = Math.round( object.position.z / scope.translationSnap ) * scope.translationSnap;
+					}
 
-					quaternionZ.setFromAxisAngle( unitZ, Math.atan2( eye.y, eye.x ) );
-					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionZ );
-					child.quaternion.copy( tempQuaternion );
+					object.position.applyQuaternion( _quaternionStart );
 
 				}
 
-			} );
-
-		};
-
-		this.init();
-
-	};
-
-	THREE.TransformGizmoRotate.prototype = Object.create( THREE.TransformGizmo.prototype );
-	THREE.TransformGizmoRotate.prototype.constructor = THREE.TransformGizmoRotate;
-
-	THREE.TransformGizmoScale = function () {
-
-		THREE.TransformGizmo.call( this );
-
-		var arrowGeometry = new THREE.BoxBufferGeometry( 0.125, 0.125, 0.125 );
-		arrowGeometry.translate( 0, 0.5, 0 );
-
-		var lineXGeometry = new THREE.BufferGeometry();
-		lineXGeometry.addAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0,  1, 0, 0 ], 3 ) );
-
-		var lineYGeometry = new THREE.BufferGeometry();
-		lineYGeometry.addAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0,  0, 1, 0 ], 3 ) );
-
-		var lineZGeometry = new THREE.BufferGeometry();
-		lineZGeometry.addAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0,  0, 0, 1 ], 3 ) );
-
-		this.handleGizmos = {
-
-			X: [
-				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0xff0000 } ) ), [ 0.5, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ],
-				[ new THREE.Line( lineXGeometry, new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
-			],
-
-			Y: [
-				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x00ff00 } ) ), [ 0, 0.5, 0 ] ],
-				[ new THREE.Line( lineYGeometry, new GizmoLineMaterial( { color: 0x00ff00 } ) ) ]
-			],
-
-			Z: [
-				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x0000ff } ) ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ] ],
-				[ new THREE.Line( lineZGeometry, new GizmoLineMaterial( { color: 0x0000ff } ) ) ]
-			],
+				if ( space === 'world' ) {
 
-			XYZ: [
-				[ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.125, 0.125, 0.125 ), new GizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) ) ]
-			]
-
-		};
-
-		this.pickerGizmos = {
-
-			X: [
-				[ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0.6, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ]
-			],
-
-			Y: [
-				[ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, 0.6, 0 ] ]
-			],
-
-			Z: [
-				[ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ] ]
-			],
-
-			XYZ: [
-				[ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.4, 0.4, 0.4 ), pickerMaterial ) ]
-			]
+					if ( object.parent ) {
+						object.position.add( _tempVector.setFromMatrixPosition( object.parent.matrixWorld ) );
+					}
 
-		};
+					if ( axis.search( 'X' ) !== -1 ) {
+						object.position.x = Math.round( object.position.x / scope.translationSnap ) * scope.translationSnap;
+					}
 
-		this.setActivePlane = function ( axis, eye ) {
+					if ( axis.search( 'Y' ) !== -1 ) {
+						object.position.y = Math.round( object.position.y / scope.translationSnap ) * scope.translationSnap;
+					}
 
-			var tempMatrix = new THREE.Matrix4();
-			eye.applyMatrix4( tempMatrix.getInverse( tempMatrix.extractRotation( this.planes[ "XY" ].matrixWorld ) ) );
+					if ( axis.search( 'Z' ) !== -1 ) {
+						object.position.z = Math.round( object.position.z / scope.translationSnap ) * scope.translationSnap;
+					}
 
-			if ( axis === "X" ) {
+					if ( object.parent ) {
+						object.position.sub( _tempVector.setFromMatrixPosition( object.parent.matrixWorld ) );
+					}
 
-				this.activePlane = this.planes[ "XY" ];
-				if ( Math.abs( eye.y ) > Math.abs( eye.z ) ) this.activePlane = this.planes[ "XZ" ];
+				}
 
 			}
 
-			if ( axis === "Y" ) {
+		} else if ( mode === 'scale' ) {
 
-				this.activePlane = this.planes[ "XY" ];
-				if ( Math.abs( eye.x ) > Math.abs( eye.z ) ) this.activePlane = this.planes[ "YZ" ];
+			if ( axis === 'XYZ' ) {
 
-			}
+				_localScale.set( _worldShift.y / 50, _worldShift.y / 50, _worldShift.y / 50 ).addScalar( 1 );
 
-			if ( axis === "Z" ) {
+			} else {
 
-				this.activePlane = this.planes[ "XZ" ];
-				if ( Math.abs( eye.x ) > Math.abs( eye.y ) ) this.activePlane = this.planes[ "YZ" ];
+				_localScale.set(
+					axis.search( 'X' ) !== -1 ? _localShift.x / 100 : 0,
+					axis.search( 'Y' ) !== -1 ? _localShift.y / 100 : 0,
+					axis.search( 'Z' ) !== -1 ? _localShift.z / 100 : 0
+				).addScalar( 1 );
 
 			}
 
-			if ( axis === "XYZ" ) this.activePlane = this.planes[ "XYZE" ];
-
-		};
-
-		this.init();
-
-	};
-
-	THREE.TransformGizmoScale.prototype = Object.create( THREE.TransformGizmo.prototype );
-	THREE.TransformGizmoScale.prototype.constructor = THREE.TransformGizmoScale;
+			// Apply scale
 
-	THREE.TransformControls = function ( camera, domElement ) {
+			object.scale.copy( _scaleStart ).multiply( _localScale );
 
-		// TODO: Make non-uniform scale and rotate play nice in hierarchies
-		// TODO: ADD RXYZ contol
+		} else if ( mode === 'rotate' ) {
 
-		THREE.Object3D.call( this );
+			if ( axis === 'E' ) {
 
-		domElement = ( domElement !== undefined ) ? domElement : document;
+				_localCross.applyQuaternion( _worldRotationStart ).normalize();
+				direction = _localCross.dot( _eye ) < 0 ? 1 : -1;
+				_worldQuaternion.setFromAxisAngle( _eye, _localPoint.angleTo( _localPointStart ) * direction );
 
-		this.object = undefined;
-		this.visible = false;
-		this.translationSnap = null;
-		this.rotationSnap = null;
-		this.space = "world";
-		this.size = 1;
-		this.axis = null;
-
-		var scope = this;
-
-		var _mode = "translate";
-		var _dragging = false;
-		var _gizmo = {
-
-			"translate": new THREE.TransformGizmoTranslate(),
-			"rotate": new THREE.TransformGizmoRotate(),
-			"scale": new THREE.TransformGizmoScale()
-		};
-
-		for ( var type in _gizmo ) {
-
-			var gizmoObj = _gizmo[ type ];
-
-			gizmoObj.visible = ( type === _mode );
-			this.add( gizmoObj );
-
-		}
-
-		var changeEvent = { type: "change" };
-		var mouseDownEvent = { type: "mouseDown" };
-		var mouseUpEvent = { type: "mouseUp", mode: _mode };
-		var objectChangeEvent = { type: "objectChange" };
-
-		var ray = new THREE.Raycaster();
-		var pointerVector = new THREE.Vector2();
-
-		var point = new THREE.Vector3();
-		var offset = new THREE.Vector3();
-
-		var rotation = new THREE.Vector3();
-		var offsetRotation = new THREE.Vector3();
-		var scale = 1;
-
-		var lookAtMatrix = new THREE.Matrix4();
-		var eye = new THREE.Vector3();
-
-		var tempMatrix = new THREE.Matrix4();
-		var tempVector = new THREE.Vector3();
-		var tempQuaternion = new THREE.Quaternion();
-		var unitX = new THREE.Vector3( 1, 0, 0 );
-		var unitY = new THREE.Vector3( 0, 1, 0 );
-		var unitZ = new THREE.Vector3( 0, 0, 1 );
-
-		var quaternionXYZ = new THREE.Quaternion();
-		var quaternionX = new THREE.Quaternion();
-		var quaternionY = new THREE.Quaternion();
-		var quaternionZ = new THREE.Quaternion();
-		var quaternionE = new THREE.Quaternion();
-
-		var oldPosition = new THREE.Vector3();
-		var oldScale = new THREE.Vector3();
-		var oldRotationMatrix = new THREE.Matrix4();
-
-		var parentRotationMatrix = new THREE.Matrix4();
-		var parentScale = new THREE.Vector3();
-
-		var worldPosition = new THREE.Vector3();
-		var worldRotation = new THREE.Euler();
-		var worldRotationMatrix = new THREE.Matrix4();
-		var camPosition = new THREE.Vector3();
-		var camRotation = new THREE.Euler();
-
-		domElement.addEventListener( "mousedown", onPointerDown, false );
-		domElement.addEventListener( "touchstart", onPointerDown, false );
-
-		domElement.addEventListener( "mousemove", onPointerHover, false );
-		domElement.addEventListener( "touchmove", onPointerHover, false );
-
-		domElement.addEventListener( "mousemove", onPointerMove, false );
-		domElement.addEventListener( "touchmove", onPointerMove, false );
-
-		domElement.addEventListener( "mouseup", onPointerUp, false );
-		domElement.addEventListener( "mouseout", onPointerUp, false );
-		domElement.addEventListener( "touchend", onPointerUp, false );
-		domElement.addEventListener( "touchcancel", onPointerUp, false );
-		domElement.addEventListener( "touchleave", onPointerUp, false );
-
-		this.dispose = function () {
-
-			domElement.removeEventListener( "mousedown", onPointerDown );
-			domElement.removeEventListener( "touchstart", onPointerDown );
-
-			domElement.removeEventListener( "mousemove", onPointerHover );
-			domElement.removeEventListener( "touchmove", onPointerHover );
-
-			domElement.removeEventListener( "mousemove", onPointerMove );
-			domElement.removeEventListener( "touchmove", onPointerMove );
-
-			domElement.removeEventListener( "mouseup", onPointerUp );
-			domElement.removeEventListener( "mouseout", onPointerUp );
-			domElement.removeEventListener( "touchend", onPointerUp );
-			domElement.removeEventListener( "touchcancel", onPointerUp );
-			domElement.removeEventListener( "touchleave", onPointerUp );
-
-		};
-
-		this.attach = function ( object ) {
-
-			this.object = object;
-			this.visible = true;
-			this.update();
-
-		};
-
-		this.detach = function () {
-
-			this.object = undefined;
-			this.visible = false;
-			this.axis = null;
-
-		};
-
-		this.getMode = function () {
-
-			return _mode;
+			} else if ( axis === 'XYZE' ) {
 
-		};
+				// TODO: not working
+				// _tempVector.copy( _worldShift ).cross( _eye ).normalize();
+				// _worldQuaternion.setFromAxisAngle( _tempVector, -2 * offset.length() );
 
-		this.setMode = function ( mode ) {
-
-			_mode = mode ? mode : _mode;
-
-			if ( _mode === "scale" ) scope.space = "local";
+			} else {
 
-			for ( var type in _gizmo ) _gizmo[ type ].visible = ( type === _mode );
+				var rotation = scope.space === "local" ? _worldRotation : _identityEuler;
 
-			this.update();
-			scope.dispatchEvent( changeEvent );
+				// TODO: make rotation speed relative to pointer movement in view space.
+				var LINEAR_ROTATION_SPEED = 0.005;
 
-		};
+				if ( axis === 'X' ) {
 
-		this.setTranslationSnap = function ( translationSnap ) {
+					alignVector.set( 1, 0, 0 ).applyEuler( rotation );
 
-			scope.translationSnap = translationSnap;
+					if ( Math.abs( alignVector.dot( _eye ) ) > 0.3 ) {
 
-		};
+						_localQuaternion.setFromAxisAngle( _unitX, _localPoint.angleTo( _localPointStart ) * ( _localCross.x > 0 ? -1 : 1 ) );
+						_worldQuaternion.setFromAxisAngle( _unitX, _worldPoint.angleTo( _worldPointStart ) * ( _worldCross.x > 0 ? -1 : 1 ) );
 
-		this.setRotationSnap = function ( rotationSnap ) {
+          } else {
 
-			scope.rotationSnap = rotationSnap;
+						_localQuaternion.setFromAxisAngle( _unitX, _worldPoint.sub( _worldPointStart ).dot( _unitX.clone().applyQuaternion( _worldRotationStart ).cross( _eye ) ) * LINEAR_ROTATION_SPEED );
+						_worldQuaternion.setFromAxisAngle( _unitX, _worldPoint.sub( _worldPointStart ).dot( _unitX.clone().cross( _eye ) ) * LINEAR_ROTATION_SPEED );
 
-		};
+          }
 
-		this.setSize = function ( size ) {
+				} else if ( axis === 'Y' ) {
 
-			scope.size = size;
-			this.update();
-			scope.dispatchEvent( changeEvent );
+					alignVector.set( 0, 1, 0 ).applyEuler( rotation );
 
-		};
+					if ( Math.abs( alignVector.dot( _eye ) ) > 0.3 ) {
 
-		this.setSpace = function ( space ) {
+						_localQuaternion.setFromAxisAngle( _unitY, _localPoint.angleTo( _localPointStart ) * ( _localCross.y > 0 ? -1 : 1 ) );
+						_worldQuaternion.setFromAxisAngle( _unitY, _worldPoint.angleTo( _worldPointStart ) * ( _worldCross.y > 0 ? -1 : 1 ) );
 
-			scope.space = space;
-			this.update();
-			scope.dispatchEvent( changeEvent );
+          } else {
 
-		};
+						_localQuaternion.setFromAxisAngle( _unitY, _worldPoint.sub( _worldPointStart ).dot( _unitY.clone().applyEuler( rotation ).cross( _eye ) ) * LINEAR_ROTATION_SPEED );
+						_worldQuaternion.setFromAxisAngle( _unitY, _worldPoint.sub( _worldPointStart ).dot( _unitY.clone().cross( _eye ) ) * LINEAR_ROTATION_SPEED );
 
-		this.update = function () {
+          }
 
-			if ( scope.object === undefined ) return;
+				} else if ( axis === 'Z' ) {
 
-			scope.object.updateMatrixWorld();
-			worldPosition.setFromMatrixPosition( scope.object.matrixWorld );
-			worldRotation.setFromRotationMatrix( tempMatrix.extractRotation( scope.object.matrixWorld ) );
+					alignVector.set( 0, 0, 1 ).applyEuler( rotation );
 
-			camera.updateMatrixWorld();
-			camPosition.setFromMatrixPosition( camera.matrixWorld );
-			camRotation.setFromRotationMatrix( tempMatrix.extractRotation( camera.matrixWorld ) );
+					if ( Math.abs( alignVector.dot( _eye ) ) > 0.3 ) {
 
-			scale = worldPosition.distanceTo( camPosition ) / 6 * scope.size;
-			this.position.copy( worldPosition );
-			this.scale.set( scale, scale, scale );
+						_localQuaternion.setFromAxisAngle( _unitZ, _localPoint.angleTo( _localPointStart ) * ( _localCross.z > 0 ? -1 : 1 ) );
+						_worldQuaternion.setFromAxisAngle( _unitZ, _worldPoint.angleTo( _worldPointStart ) * ( _worldCross.z > 0 ? -1 : 1 ) );
 
-			if ( camera instanceof THREE.PerspectiveCamera ) {
+          } else {
 
-				eye.copy( camPosition ).sub( worldPosition ).normalize();
+						_localQuaternion.setFromAxisAngle( _unitZ, _worldPoint.sub( _worldPointStart ).dot( _unitZ.clone().applyEuler( rotation ).cross( _eye ) ) * LINEAR_ROTATION_SPEED );
+						_worldQuaternion.setFromAxisAngle( _unitZ, _worldPoint.sub( _worldPointStart ).dot( _unitZ.clone().cross( _eye ) ) * LINEAR_ROTATION_SPEED );
 
-			} else if ( camera instanceof THREE.OrthographicCamera ) {
+					}
 
-				eye.copy( camPosition ).normalize();
+				}
 
 			}
 
-			if ( scope.space === "local" ) {
+			// Apply rotate
 
-				_gizmo[ _mode ].update( worldRotation, eye );
+			if ( axis === 'E' ||  axis === 'XYZE' ) {
 
-			} else if ( scope.space === "world" ) {
-
-				_gizmo[ _mode ].update( new THREE.Euler(), eye );
+			  space = 'world';
 
 			}
 
-			_gizmo[ _mode ].highlight( scope.axis );
-
-		};
-
-		function onPointerHover( event ) {
-
-			if ( scope.object === undefined || _dragging === true || ( event.button !== undefined && event.button !== 0 ) ) return;
-
-			var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
+			if ( space === 'local' ) {
 
-			var intersect = intersectObjects( pointer, _gizmo[ _mode ].pickers.children );
+				object.quaternion.copy( _quaternionStart );
+				object.quaternion.multiply( _localQuaternion );
 
-			var axis = null;
-
-			if ( intersect ) {
-
-				axis = intersect.object.name;
+			} else {
 
-				event.preventDefault();
+				object.quaternion.copy( _worldQuaternion );
+				object.quaternion.multiply( _quaternionStart );
 
 			}
 
-			if ( scope.axis !== axis ) {
+			if ( scope.snapAngle) {
 
-				scope.axis = axis;
-				scope.update();
-				scope.dispatchEvent( changeEvent );
+				// TODO: implement rotation snap
 
 			}
 
 		}
 
-		function onPointerDown( event ) {
-
-			if ( scope.object === undefined || _dragging === true || ( event.button !== undefined && event.button !== 0 ) ) return;
-
-			var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
-
-			if ( pointer.button === 0 || pointer.button === undefined ) {
-
-				var intersect = intersectObjects( pointer, _gizmo[ _mode ].pickers.children );
-
-				if ( intersect ) {
+		scope.dispatchEvent( changeEvent );
+		scope.dispatchEvent( objectChangeEvent );
 
-					event.preventDefault();
-					event.stopPropagation();
+	}
 
-					scope.axis = intersect.object.name;
+	function onPointerUp( event ) {
 
-					scope.dispatchEvent( mouseDownEvent );
+		event.preventDefault(); // Prevent MouseEvent on mobile
 
-					scope.update();
+		if ( event.button !== undefined && event.button !== 0 ) return;
 
-					eye.copy( camPosition ).sub( worldPosition ).normalize();
+		if ( scope.dragging && ( scope.axis !== null ) ) {
 
-					_gizmo[ _mode ].setActivePlane( scope.axis, eye );
-
-					var planeIntersect = intersectObjects( pointer, [ _gizmo[ _mode ].activePlane ] );
-
-					if ( planeIntersect ) {
-
-						oldPosition.copy( scope.object.position );
-						oldScale.copy( scope.object.scale );
-
-						oldRotationMatrix.extractRotation( scope.object.matrix );
-						worldRotationMatrix.extractRotation( scope.object.matrixWorld );
-
-						parentRotationMatrix.extractRotation( scope.object.parent.matrixWorld );
-						parentScale.setFromMatrixScale( tempMatrix.getInverse( scope.object.parent.matrixWorld ) );
-
-						offset.copy( planeIntersect.point );
-
-					}
-
-				}
-
-			}
-
-			_dragging = true;
+			mouseUpEvent.mode = scope.mode;
+			scope.dispatchEvent( mouseUpEvent );
 
 		}
 
-		function onPointerMove( event ) {
-
-			if ( scope.object === undefined || scope.axis === null || _dragging === false || ( event.button !== undefined && event.button !== 0 ) ) return;
-
-			var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
-
-			var planeIntersect = intersectObjects( pointer, [ _gizmo[ _mode ].activePlane ] );
-
-			if ( planeIntersect === false ) return;
-
-			event.preventDefault();
-			event.stopPropagation();
-
-			point.copy( planeIntersect.point );
-
-			if ( _mode === "translate" ) {
-
-				point.sub( offset );
-				point.multiply( parentScale );
-
-				if ( scope.space === "local" ) {
-
-					point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
-
-					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( 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;
-
-					point.applyMatrix4( tempMatrix.getInverse( parentRotationMatrix ) );
-
-					scope.object.position.copy( oldPosition );
-					scope.object.position.add( point );
-
-				}
-
-				if ( scope.translationSnap !== null ) {
-
-					if ( scope.space === "local" ) {
-
-						scope.object.position.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
-
-					}
-
-					if ( scope.axis.search( "X" ) !== - 1 ) scope.object.position.x = Math.round( scope.object.position.x / scope.translationSnap ) * scope.translationSnap;
-					if ( scope.axis.search( "Y" ) !== - 1 ) scope.object.position.y = Math.round( scope.object.position.y / scope.translationSnap ) * scope.translationSnap;
-					if ( scope.axis.search( "Z" ) !== - 1 ) scope.object.position.z = Math.round( scope.object.position.z / scope.translationSnap ) * scope.translationSnap;
-
-					if ( scope.space === "local" ) {
-
-						scope.object.position.applyMatrix4( worldRotationMatrix );
-
-					}
-
-				}
-
-			} else if ( _mode === "scale" ) {
-
-				point.sub( offset );
-				point.multiply( parentScale );
-
-				if ( scope.space === "local" ) {
-
-					if ( scope.axis === "XYZ" ) {
-
-						scale = 1 + ( ( point.y ) / Math.max( oldScale.x, oldScale.y, oldScale.z ) );
-
-						scope.object.scale.x = oldScale.x * scale;
-						scope.object.scale.y = oldScale.y * scale;
-						scope.object.scale.z = oldScale.z * scale;
-
-					} else {
-
-						point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
-
-						if ( scope.axis === "X" ) scope.object.scale.x = oldScale.x * ( 1 + point.x / oldScale.x );
-						if ( scope.axis === "Y" ) scope.object.scale.y = oldScale.y * ( 1 + point.y / oldScale.y );
-						if ( scope.axis === "Z" ) scope.object.scale.z = oldScale.z * ( 1 + point.z / oldScale.z );
-
-					}
-
-				}
-
-			} else if ( _mode === "rotate" ) {
-
-				point.sub( worldPosition );
-				point.multiply( parentScale );
-				tempVector.copy( offset ).sub( worldPosition );
-				tempVector.multiply( parentScale );
-
-				if ( scope.axis === "E" ) {
-
-					point.applyMatrix4( tempMatrix.getInverse( lookAtMatrix ) );
-					tempVector.applyMatrix4( tempMatrix.getInverse( lookAtMatrix ) );
-
-					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 ) );
-
-					tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
-
-					quaternionE.setFromAxisAngle( eye, rotation.z - offsetRotation.z );
-					quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
-
-					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionE );
-					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
-
-					scope.object.quaternion.copy( tempQuaternion );
-
-				} else if ( scope.axis === "XYZE" ) {
-
-					quaternionE.setFromEuler( point.clone().cross( tempVector ).normalize() ); // rotation axis
-
-					tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
-					quaternionX.setFromAxisAngle( quaternionE, - point.clone().angleTo( tempVector ) );
-					quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
-
-					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
-					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
-
-					scope.object.quaternion.copy( tempQuaternion );
-
-				} else if ( scope.space === "local" ) {
-
-					point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
-
-					tempVector.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 ) );
+		scope.dragging = false;
 
-					quaternionXYZ.setFromRotationMatrix( oldRotationMatrix );
+		if ( 'TouchEvent' in window && event instanceof TouchEvent ) {
 
-					if ( scope.rotationSnap !== null ) {
+			// Force "rollover"
 
-						quaternionX.setFromAxisAngle( unitX, Math.round( ( rotation.x - offsetRotation.x ) / scope.rotationSnap ) * scope.rotationSnap );
-						quaternionY.setFromAxisAngle( unitY, Math.round( ( rotation.y - offsetRotation.y ) / scope.rotationSnap ) * scope.rotationSnap );
-						quaternionZ.setFromAxisAngle( unitZ, Math.round( ( rotation.z - offsetRotation.z ) / scope.rotationSnap ) * scope.rotationSnap );
+			scope.axis = null;
 
-					} else {
+		} else {
 
-						quaternionX.setFromAxisAngle( unitX, rotation.x - offsetRotation.x );
-						quaternionY.setFromAxisAngle( unitY, rotation.y - offsetRotation.y );
-						quaternionZ.setFromAxisAngle( unitZ, rotation.z - offsetRotation.z );
+			onPointerHover( event );
 
-					}
+		}
 
-					if ( scope.axis === "X" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionX );
-					if ( scope.axis === "Y" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionY );
-					if ( scope.axis === "Z" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionZ );
+	}
 
-					scope.object.quaternion.copy( quaternionXYZ );
+	function intersectObjects( pointer, objects ) {
 
-				} else if ( scope.space === "world" ) {
+		var rect = domElement.getBoundingClientRect();
+		var x = ( pointer.clientX - rect.left ) / rect.width;
+		var y = ( pointer.clientY - rect.top ) / rect.height;
 
-					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 ) );
+		pointerVector.set( ( x * 2 ) - 1, - ( y * 2 ) + 1 );
+		ray.setFromCamera( pointerVector, camera );
 
-					tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
+		var intersections = ray.intersectObjects( objects, true );
 
-					if ( scope.rotationSnap !== null ) {
+		return intersections[ 0 ] ? intersections[ 0 ] : false;
 
-						quaternionX.setFromAxisAngle( unitX, Math.round( ( rotation.x - offsetRotation.x ) / scope.rotationSnap ) * scope.rotationSnap );
-						quaternionY.setFromAxisAngle( unitY, Math.round( ( rotation.y - offsetRotation.y ) / scope.rotationSnap ) * scope.rotationSnap );
-						quaternionZ.setFromAxisAngle( unitZ, Math.round( ( rotation.z - offsetRotation.z ) / scope.rotationSnap ) * scope.rotationSnap );
+	}
 
-					} else {
+	// TODO: depricate
 
-						quaternionX.setFromAxisAngle( unitX, rotation.x - offsetRotation.x );
-						quaternionY.setFromAxisAngle( unitY, rotation.y - offsetRotation.y );
-						quaternionZ.setFromAxisAngle( unitZ, rotation.z - offsetRotation.z );
+	this.getMode = function () {
 
-					}
+		return scope.mode;
 
-					quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
+		console.warn( 'THREE.TransformControls: getMode function has been depricated.' );
 
-					if ( scope.axis === "X" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
-					if ( scope.axis === "Y" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionY );
-					if ( scope.axis === "Z" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionZ );
+	};
 
-					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
+	this.setMode = function ( mode ) {
 
-					scope.object.quaternion.copy( tempQuaternion );
+		scope.mode = mode;
 
-				}
+		console.warn( 'THREE.TransformControls: setMode function has been depricated.' );
 
-			}
+	};
 
-			scope.update();
-			scope.dispatchEvent( changeEvent );
-			scope.dispatchEvent( objectChangeEvent );
+	this.setTranslationSnap = function ( translationSnap ) {
 
-		}
+		scope.translationSnap = translationSnap;
 
-		function onPointerUp( event ) {
+		console.warn( 'THREE.TransformControls: setTranslationSnap function has been depricated.' );
 
-			event.preventDefault(); // Prevent MouseEvent on mobile
+	};
 
-			if ( event.button !== undefined && event.button !== 0 ) return;
+	this.setRotationSnap = function ( rotationSnap ) {
 
-			if ( _dragging && ( scope.axis !== null ) ) {
+		scope.rotationSnap = rotationSnap;
 
-				mouseUpEvent.mode = _mode;
-				scope.dispatchEvent( mouseUpEvent );
+		console.warn( 'THREE.TransformControls: setRotationSnap function has been depricated.' );
 
-			}
+	};
 
-			_dragging = false;
+	this.setSize = function ( size ) {
 
-			if ( 'TouchEvent' in window && event instanceof TouchEvent ) {
+		scope.size = size;
 
-				// Force "rollover"
+		console.warn( 'THREE.TransformControls: setSize function has been depricated.' );
 
-				scope.axis = null;
-				scope.update();
-				scope.dispatchEvent( changeEvent );
+	};
 
-			} else {
+	this.setSpace = function ( space ) {
 
-				onPointerHover( event );
+		scope.space = space;
 
-			}
+		console.warn( 'THREE.TransformControls: setSpace function has been depricated.' );
 
-		}
+	};
 
-		function intersectObjects( pointer, objects ) {
+	this.update = function () {
 
-			var rect = domElement.getBoundingClientRect();
-			var x = ( pointer.clientX - rect.left ) / rect.width;
-			var y = ( pointer.clientY - rect.top ) / rect.height;
+		console.warn( 'THREE.TransformControls: update function has been depricated.' );
 
-			pointerVector.set( ( x * 2 ) - 1, - ( y * 2 ) + 1 );
-			ray.setFromCamera( pointerVector, camera );
+	}
 
-			var intersections = ray.intersectObjects( objects, true );
-			return intersections[ 0 ] ? intersections[ 0 ] : false;
+};
 
-		}
+THREE.TransformControls.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
 
-	};
+  constructor: THREE.TransformControls,
 
-	THREE.TransformControls.prototype = Object.create( THREE.Object3D.prototype );
-	THREE.TransformControls.prototype.constructor = THREE.TransformControls;
+  isTransformControls: true
 
-}() );
+} );

+ 587 - 0
examples/js/controls/TransformControlsGizmo.js

@@ -0,0 +1,587 @@
+/**
+ * @author arodic / https://github.com/arodic
+ */
+
+THREE.TransformControlsGizmo = function () {
+
+  'use strict';
+
+  THREE.Object3D.call( this );
+
+	this.type = 'TransformControlsGizmo';
+
+  // shared materials
+
+  var gizmoMaterial = new THREE.MeshBasicMaterial({
+    depthTest: false,
+    depthWrite: false,
+    transparent: true,
+    side: THREE.DoubleSide,
+    fog: false
+  });
+
+  var gizmoLineMaterial = new THREE.LineBasicMaterial({
+    depthTest: false,
+    depthWrite: false,
+    transparent: true,
+    linewidth: 1,
+    fog: false
+  });
+
+  var matInvisible = gizmoMaterial.clone();
+  matInvisible.opacity = 0.15;
+
+  var matRed = gizmoMaterial.clone();
+  matRed.color.set(0xff0000);
+
+  var matGreen = gizmoMaterial.clone();
+  matGreen.color.set(0x00ff00);
+
+  var matBlue = gizmoMaterial.clone();
+  matBlue.color.set(0x0000ff);
+
+  var matWhiteTransperent = gizmoMaterial.clone();
+  matWhiteTransperent.opacity = 0.25;
+
+  var matYellowTransparent = matWhiteTransperent.clone();
+  matYellowTransparent.color.set(0xffff00);
+
+  var matCyanTransparent = matWhiteTransperent.clone();
+  matCyanTransparent.color.set(0x00ffff);
+
+  var matMagentaTransparent = matWhiteTransperent.clone();
+  matMagentaTransparent.color.set(0xff00ff);
+
+  var matYellow = gizmoMaterial.clone();
+  matYellow.color.set(0xffff00);
+
+  var matLineRed = gizmoLineMaterial.clone();
+  matLineRed.color.set(0xff0000);
+
+  var matLineGreen = gizmoLineMaterial.clone();
+  matLineGreen.color.set(0x00ff00);
+
+  var matLineBlue = gizmoLineMaterial.clone();
+  matLineBlue.color.set(0x0000ff);
+
+  var matLineCyan = gizmoLineMaterial.clone();
+  matLineCyan.color.set(0x00ffff);
+
+  var matLineMagenta = gizmoLineMaterial.clone();
+  matLineMagenta.color.set(0xff00ff);
+
+  var matLineBlue = gizmoLineMaterial.clone();
+  matLineBlue.color.set(0x0000ff);
+
+  var matLineYellow = gizmoLineMaterial.clone();
+  matLineYellow.color.set(0xffff00);
+
+  var matLineGray = gizmoLineMaterial.clone();
+  matLineGray.color.set(0x787878);
+
+  var matLineYellowTransparent = matLineYellow.clone();
+  matLineYellowTransparent.opacity = 0.25;
+
+  // shared objects
+
+  var arrowGeometry = new THREE.CylinderGeometry( 0, 0.05, 0.2, 12, 1, false);
+
+  var scaleHandleGeometry = new THREE.BoxGeometry( 0.125, 0.125, 0.125);
+
+  var lineGeometry = new THREE.BufferGeometry( );
+  lineGeometry.addAttribute('position', new THREE.Float32BufferAttribute([ 0, 0, 0,  1, 0, 0 ], 3));
+
+  var CircleGeometry = function(radius, arc) {
+    var geometry = new THREE.BufferGeometry( );
+    var vertices = [];
+    for (var i = 0; i <= 64 * arc; ++i) {
+      vertices.push(0, Math.cos(i / 32 * Math.PI) * radius, Math.sin(i / 32 * Math.PI) * radius);
+    }
+    geometry.addAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));
+    return geometry;
+  };
+
+  // gizmos
+
+  var gizmoTranslate = {
+    X: [
+      [ new THREE.Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, -Math.PI / 2 ], null, 'fwd' ],
+      [ new THREE.Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, Math.PI / 2 ], null, 'bwd' ],
+      [ new THREE.Line( lineGeometry, matLineRed ) ]
+    ],
+    Y: [
+      [ new THREE.Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], null, null, 'fwd' ],
+      [ new THREE.Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], [ Math.PI, 0, 0 ], null, 'bwd' ],
+      [ new THREE.Line( lineGeometry, matLineGreen ), null, [ 0, 0, Math.PI / 2 ] ]
+    ],
+    Z: [
+      [ new THREE.Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ Math.PI / 2, 0, 0 ], null, 'fwd' ],
+      [ new THREE.Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ -Math.PI / 2, 0, 0 ], null, 'bwd' ],
+      [ new THREE.Line( lineGeometry, matLineBlue ), null, [ 0, -Math.PI / 2, 0 ] ]
+    ],
+    XYZ: [
+      [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.1, 0 ), matWhiteTransperent ), [ 0, 0, 0 ], [ 0, 0, 0 ] ]
+    ],
+    XY: [
+      [ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.295, 0.295 ), matYellowTransparent ), [ 0.15, 0.15, 0 ] ],
+      [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.18, 0.3, 0 ], null, [ 0.125, 1, 1 ] ],
+      [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.3, 0.18, 0 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ] ]
+    ],
+    YZ: [
+      [ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.295, 0.295 ), matCyanTransparent ), [ 0, 0.15, 0.15 ], [ 0, Math.PI / 2, 0 ] ],
+      [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.18, 0.3 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ] ],
+      [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.3, 0.18 ], [ 0, -Math.PI / 2, 0 ], [ 0.125, 1, 1 ] ]
+    ],
+    XZ: [
+      [ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.295, 0.295 ), matMagentaTransparent ), [ 0.15, 0, 0.15 ], [ -Math.PI / 2, 0, 0 ] ],
+      [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.18, 0, 0.3 ], null, [ 0.125, 1, 1 ] ],
+      [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.3, 0, 0.18 ], [ 0, -Math.PI / 2, 0 ], [ 0.125, 1, 1 ] ]
+    ]
+  };
+
+  var pickerTranslate = {
+    X: [
+      [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0.6, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ]
+    ],
+    Y: [
+      [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0, 0.6, 0 ] ]
+    ],
+    Z: [
+      [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ] ]
+    ],
+    XYZ: [
+      [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.2, 0 ), matInvisible ) ]
+    ],
+    XY: [
+      [ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0.2, 0.2, 0 ] ]
+    ],
+    YZ: [
+      [ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0, 0.2, 0.2 ], [ 0, Math.PI / 2, 0 ] ]
+    ],
+    XZ: [
+      [ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0.2, 0, 0.2 ], [ -Math.PI / 2, 0, 0 ] ]
+    ]
+  };
+
+  var gizmoRotate = {
+    X: [
+      [ new THREE.Line( new CircleGeometry( 1, 0.5 ), matLineRed ) ],
+      [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.04, 0 ), matRed ), [ 0, 0, 0.99 ], null, [ 1, 3, 1 ], 'linear' ],
+      [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.03, 0 ), matRed ), [ 0, 0, 1 ], null, [ 4, 1, 4 ], 'radial' ],
+    ],
+    Y: [
+      [ new THREE.Line( new CircleGeometry( 1, 0.5 ), matLineGreen ), null, [ 0, 0, -Math.PI / 2 ] ],
+      [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.04, 0 ), matGreen ), [ 0, 0, 0.99 ], null, [ 3, 1, 1 ], 'linear' ],
+      [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.03, 0 ), matGreen ), [ 0, 0, 1 ], null, [ 1, 4, 4 ], 'radial' ],
+    ],
+    Z: [
+      [ new THREE.Line( new CircleGeometry( 1, 0.5 ), matLineBlue ), null, [ 0, Math.PI / 2, 0 ] ],
+      [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.04, 0 ), matBlue ), [ 0.99, 0, 0 ], null, [ 1, 3, 1 ], 'linear' ],
+      [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.03, 0 ), matBlue ), [ 1, 0, 0 ], null, [ 4, 1, 4 ], 'radial' ],
+    ],
+    E: [
+      [ new THREE.Line( new CircleGeometry( 1.25, 1 ), matLineYellowTransparent ), null, [ 0, Math.PI / 2, 0 ] ],
+      [ new THREE.Mesh( new THREE.CylinderGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 1.17, 0, 0 ], [ 0, 0, -Math.PI / 2 ], [ 1, 1, 0.001 ]],
+      [ new THREE.Mesh( new THREE.CylinderGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ -1.17, 0, 0 ], [ 0, 0, Math.PI / 2 ], [ 1, 1, 0.001 ]],
+      [ new THREE.Mesh( new THREE.CylinderGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 0, -1.17, 0 ], [ Math.PI, 0, 0 ], [ 1, 1, 0.001 ]],
+      [ new THREE.Mesh( new THREE.CylinderGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 0, 1.17, 0 ], [ 0, 0, 0 ], [ 1, 1, 0.001 ]],
+    ],
+    XYZE: [
+      [ new THREE.Line( new CircleGeometry( 0.99, 1 ), matLineGray ), null, [ 0, Math.PI / 2, 0 ] ]
+    ]
+  };
+
+  var pickerRotate = {
+    X: [
+      [ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ 0, -Math.PI / 2, -Math.PI / 2 ] ],
+    ],
+    Y: [
+      [ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ Math.PI / 2, 0, 0 ] ],
+    ],
+    Z: [
+      [ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ],
+    ],
+    E: [
+      [ new THREE.Mesh( new THREE.TorusGeometry( 1.25, 0.1, 2, 24 ), matInvisible ) ]
+    ],
+    XYZE: [
+      [ new THREE.Mesh( new THREE.SphereGeometry( 0.7, 10, 8 ), matInvisible ) ]
+    ]
+  };
+
+  var gizmoScale = {
+    X: [
+      [ new THREE.Mesh( scaleHandleGeometry, matRed ), [ 0.8, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ],
+      [ new THREE.Line( lineGeometry, matLineRed ), null, null, [ 0.8, 1, 1 ] ]
+    ],
+    Y: [
+      [ new THREE.Mesh( scaleHandleGeometry, matGreen ), [ 0, 0.8, 0 ] ],
+      [ new THREE.Line( lineGeometry, matLineGreen ), null, [ 0, 0, Math.PI / 2 ], [ 0.8, 1, 1 ] ]
+    ],
+    Z: [
+      [ new THREE.Mesh( scaleHandleGeometry, matBlue ), [ 0, 0, 0.8 ], [ Math.PI / 2, 0, 0 ] ],
+      [ new THREE.Line( lineGeometry, matLineBlue ), null, [ 0, -Math.PI / 2, 0 ], [ 0.8, 1, 1 ] ]
+    ],
+    XY: [
+      [ new THREE.Mesh( scaleHandleGeometry, matYellowTransparent ), [ 0.85, 0.85, 0 ], null, [ 2, 2, 0.2 ] ],
+      [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.855, 0.98, 0 ], null, [ 0.125, 1, 1 ] ],
+      [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.98, 0.855, 0 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ] ]
+    ],
+    YZ: [
+      [ new THREE.Mesh( scaleHandleGeometry, matCyanTransparent ), [ 0, 0.85, 0.85 ], null, [ 0.2, 2, 2 ] ],
+      [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.855, 0.98 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ] ],
+      [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.98, 0.855 ], [ 0, -Math.PI / 2, 0 ], [ 0.125, 1, 1 ] ]
+    ],
+    XZ: [
+      [ new THREE.Mesh( scaleHandleGeometry, matMagentaTransparent ), [ 0.85, 0, 0.85 ], null, [ 2, 0.2, 2 ] ],
+      [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.855, 0, 0.98 ], null, [ 0.125, 1, 1 ] ],
+      [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.98, 0, 0.855 ], [ 0, -Math.PI / 2, 0 ], [ 0.125, 1, 1 ] ]
+    ],
+    XYZX: [
+      [ new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ), matWhiteTransperent ), [ 1.1, 0, 0 ] ],
+    ],
+    XYZY: [
+      [ new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ), matWhiteTransperent ), [ 0, 1.1, 0 ] ],
+    ],
+    XYZZ: [
+      [ new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ), matWhiteTransperent ), [ 0, 0, 1.1 ] ],
+    ]
+  };
+
+  var pickerScale = {
+    X: [
+      [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0.5, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ]
+    ],
+    Y: [
+      [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0, 0.5, 0 ] ]
+    ],
+    Z: [
+      [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ] ]
+    ],
+    XY: [
+      [ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0.85, 0 ], null, [ 3, 3, 0.2 ] ],
+    ],
+    YZ: [
+      [ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0, 0.85, 0.85 ], null, [ 0.2, 3, 3 ] ],
+    ],
+    XZ: [
+      [ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0, 0.85 ], null, [ 3, 0.2, 3 ] ],
+    ],
+    XYZX: [
+      [ new THREE.Mesh( new THREE.BoxGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 1.1, 0, 0 ] ],
+    ],
+    XYZY: [
+      [ new THREE.Mesh( new THREE.BoxGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 1.1, 0 ] ],
+    ],
+    XYZZ: [
+      [ new THREE.Mesh( new THREE.BoxGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 0, 1.1 ] ],
+    ]
+  };
+
+  var setupGizmo = function( gizmoMap ) {
+
+    var gizmo = new THREE.Object3D();
+
+    for ( var name in gizmoMap ) {
+
+      for ( var i = gizmoMap[ name ].length; i --; ) {
+
+        var object = gizmoMap[ name ][ i ][ 0 ].clone();
+        var position = gizmoMap[ name ][ i ][ 1 ];
+        var rotation = gizmoMap[ name ][ i ][ 2 ];
+        var scale = gizmoMap[ name ][ i ][ 3 ];
+        var tag = gizmoMap[ name ][ i ][ 4 ];
+
+        object.name = name;
+        object.tag = tag;
+
+        if (position) {
+          object.position.set(position[ 0 ], position[ 1 ], position[ 2 ]);
+        }
+        if (rotation) {
+          object.rotation.set(rotation[ 0 ], rotation[ 1 ], rotation[ 2 ]);
+        }
+        if (scale) {
+          object.scale.set(scale[ 0 ], scale[ 1 ], scale[ 2 ]);
+        }
+
+        object.updateMatrix();
+
+        var tempGeometry = object.geometry.clone();
+        tempGeometry.applyMatrix(object.matrix);
+        object.geometry = tempGeometry;
+
+        object.position.set(0, 0, 0);
+        object.rotation.set(0, 0, 0);
+        object.scale.set(1, 1, 1);
+
+        gizmo.add(object);
+
+      }
+
+    }
+
+    return gizmo;
+
+  };
+
+  var vec1 = new THREE.Vector3( 0, 0, 0 );
+  var tempVector = new THREE.Vector3();
+  var alignVector = new THREE.Vector3( 0, 1, 0 );
+  var lookAtMatrix = new THREE.Matrix4();
+  var tempQuaternion = new THREE.Quaternion();
+  var tempQuaternion2 = new THREE.Quaternion();
+  var identityEuler = new THREE.Euler();
+
+  var unitX = new THREE.Vector3( 1, 0, 0 );
+  var unitY = new THREE.Vector3( 0, 1, 0 );
+  var unitZ = new THREE.Vector3( 0, 0, 1 );
+
+  this.gizmo = {};
+	this.picker = {};
+
+  this.add( this.gizmo[ "translate" ] = setupGizmo( gizmoTranslate ) );
+  this.add( this.gizmo[ "rotate" ] = setupGizmo( gizmoRotate ) );
+  this.add( this.gizmo[ "scale" ] = setupGizmo( gizmoScale ) );
+  this.add( this.picker[ "translate" ] = setupGizmo( pickerTranslate ) );
+  this.add( this.picker[ "rotate" ] = setupGizmo( pickerRotate ) );
+  this.add( this.picker[ "scale" ] = setupGizmo( pickerScale ) );
+
+  this.picker[ "translate" ].visible = false;
+  this.picker[ "rotate" ].visible = false;
+  this.picker[ "scale" ].visible = false;
+
+  this.updateMatrixWorld = function () {
+
+    var rotation = this.parent.space === "local" ? this.parent._worldRotation : identityEuler;
+    var eye = this.parent._eye
+    var mode = this.parent.mode;
+    var axis = this.parent.axis;
+
+    this.gizmo[ "translate" ].visible = mode === "translate";
+    this.gizmo[ "rotate" ].visible = mode === "rotate";
+    this.gizmo[ "scale" ].visible = mode === "scale";
+
+    this.picker[ "translate" ].visible = false; // mode === "translate";
+    this.picker[ "rotate" ].visible = false; // mode === "rotate";
+    this.picker[ "scale" ].visible = false; // mode === "scale";
+
+    var handles = [];
+    handles = handles.concat( this.picker[ mode ].children );
+    handles = handles.concat( this.gizmo[ mode ].children );
+
+    for ( var i = 0; i < handles.length; i++ ) {
+
+      var handle = handles[i];
+
+      // hide aligned to camera
+
+      handle.visible = true;
+      handle.scale.set( 1, 1, 1 );
+      handle.position.set( 0, 0, 0 );
+      handle.rotation.set( 0, 0, 0 );
+
+      if ( mode === 'translate' || mode === 'scale' ) {
+
+        // Hide translate and scale axis facing the camera
+
+        if ( handle.name === 'X' || handle.name === 'XYZX' ) {
+          if ( Math.abs( alignVector.set( 1, 0, 0 ).applyEuler( rotation ).dot( eye ) ) > 0.99 ) {
+            handle.scale.set( 1e-3, 1e-3, 1e-3 );
+            handle.visible = false;
+          }
+        }
+        if ( handle.name === 'Y' || handle.name === 'XYZY' ) {
+          if ( Math.abs( alignVector.set( 0, 1, 0 ).applyEuler( rotation ).dot( eye ) ) > 0.99 ) {
+            handle.scale.set( 1e-3, 1e-3, 1e-3 );
+            handle.visible = false;
+          }
+        }
+        if ( handle.name === 'Z' || handle.name === 'XYZZ' ) {
+          if ( Math.abs( alignVector.set( 0, 0, 1 ).applyEuler( rotation ).dot( eye ) ) > 0.99 ) {
+            handle.scale.set( 1e-3, 1e-3, 1e-3 );
+            handle.visible = false;
+          }
+        }
+        if ( handle.name === 'XY' ) {
+          if ( Math.abs( alignVector.set( 0, 0, 1 ).applyEuler( rotation ).dot( eye ) ) < 0.2 ) {
+            handle.scale.set( 1e-3, 1e-3, 1e-3 );
+            handle.visible = false;
+          }
+        }
+        if ( handle.name === 'YZ' ) {
+          if ( Math.abs( alignVector.set( 1, 0, 0 ).applyEuler( rotation ).dot( eye ) ) < 0.2 ) {
+            handle.scale.set( 1e-3, 1e-3, 1e-3 );
+            handle.visible = false;
+          }
+        }
+        if ( handle.name === 'XZ' ) {
+          if ( Math.abs( alignVector.set( 0, 1, 0 ).applyEuler( rotation ).dot( eye ) ) < 0.2 ) {
+            handle.scale.set( 1e-3, 1e-3, 1e-3 );
+            handle.visible = false;
+          }
+        }
+
+        // Flip translate and scale axis ocluded behind another axis
+
+        if ( handle.name.search( 'X' ) !== -1 ) {
+          if ( alignVector.set( 1, 0, 0 ).applyEuler( rotation ).dot( eye ) < -0.4 ) {
+            if ( handle.tag === 'fwd' ) {
+              handle.visible = false;
+            } else {
+              handle.scale.x = -1;
+            }
+          } else if ( handle.tag === 'bwd' ) {
+            handle.visible = false;
+          }
+        }
+
+        if ( handle.name.search( 'Y' ) !== -1 ) {
+          if ( alignVector.set( 0, 1, 0 ).applyEuler( rotation ).dot( eye ) < -0.4 ) {
+            if ( handle.tag === 'fwd' ) {
+              handle.visible = false;
+            } else {
+              handle.scale.y = -1;
+            }
+          } else if ( handle.tag === 'bwd' ) {
+            handle.visible = false;
+          }
+        }
+
+        if ( handle.name.search( 'Z' ) !== -1 ) {
+          if ( alignVector.set( 0, 0, 1 ).applyEuler( rotation ).dot( eye ) < -0.4 ) {
+            if ( handle.tag === 'fwd' ) {
+              handle.visible = false;
+            } else {
+              handle.scale.z = -1;
+            }
+          } else if ( handle.tag === 'bwd' ) {
+            handle.visible = false;
+          }
+        }
+
+        // Align handles to current local or world rotation
+
+        handle.quaternion.setFromEuler( rotation );
+
+      } else if (mode === 'rotate') {
+
+        // switch between liner/radial rotation handle affordances
+
+        if ( handle.name === 'X' ) {
+          if ( Math.abs( alignVector.set( 1, 0, 0 ).applyEuler( rotation ).dot( eye ) ) > 0.3 ) {
+            if ( handle.tag === 'linear' ) {
+              handle.visible = false;
+            }
+          } else if ( handle.tag === 'radial' ) {
+            handle.visible = false;
+          }
+        }
+
+        if ( handle.name === 'Y' ) {
+          if ( Math.abs( alignVector.set( 0, 1, 0 ).applyEuler( rotation ).dot( eye ) ) > 0.3 ) {
+            if ( handle.tag === 'linear' ) {
+              handle.visible = false;
+            }
+          } else if ( handle.tag === 'radial' ) {
+            handle.visible = false;
+          }
+        }
+
+        if ( handle.name === 'Z' ) {
+          if ( Math.abs( alignVector.set( 0, 0, 1 ).applyEuler( rotation ).dot( eye ) ) > 0.3 ) {
+            if ( handle.tag === 'linear' ) {
+              handle.visible = false;
+            }
+          } else if ( handle.tag === 'radial' ) {
+            handle.visible = false;
+          }
+        }
+
+        // Align handles to current local or world rotation
+
+        tempQuaternion2.setFromEuler( rotation );
+        alignVector.copy( eye ).applyQuaternion( tempQuaternion.setFromEuler( rotation ).inverse());
+
+        if ( handle.name.search( "E" ) !== - 1 ) {
+
+          alignVector.set( 0, 1, 0 );
+          handle.quaternion.setFromRotationMatrix( lookAtMatrix.lookAt( eye, vec1, alignVector ) );
+
+        }
+
+        if ( handle.name === 'X' ) {
+
+          tempQuaternion.setFromAxisAngle( unitX, Math.atan2( -alignVector.y, alignVector.z ) );
+          tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
+          handle.quaternion.copy( tempQuaternion );
+
+        }
+
+        if ( handle.name === 'Y' ) {
+
+          tempQuaternion.setFromAxisAngle( unitY, Math.atan2( alignVector.x, alignVector.z ) );
+          tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
+          handle.quaternion.copy( tempQuaternion );
+
+        }
+
+        if ( handle.name === 'Z' ) {
+
+          tempQuaternion.setFromAxisAngle( unitZ, Math.atan2( alignVector.y, alignVector.x ) );
+          tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
+          handle.quaternion.copy( tempQuaternion );
+
+        }
+
+      }
+
+      // highlight selected axis
+
+      handle.material._opacity = handle.material._opacity || handle.material.opacity;
+      handle.material._color = handle.material._color || handle.material.color.clone();
+
+      handle.material.color.copy( handle.material._color );
+      handle.material.opacity = handle.material._opacity;
+
+      if ( axis ) {
+
+        if ( handle.name === axis ) {
+
+          handle.material.opacity *= 2.0;
+          handle.material.color.lerp( new THREE.Color( 1, 1, 1 ), 0.5 );
+
+        } else if ( axis.split('').some( function( a ) { return handle.name === a; } ) ) {
+
+          handle.material.opacity *= 2.0;
+          handle.material.color.lerp( new THREE.Color( 1, 1, 1 ), 0.5 );
+
+        } else {
+
+          handle.material.opacity *= 0.15;
+
+        }
+
+      }
+
+    }
+
+		THREE.Object3D.prototype.updateMatrixWorld.call( this );
+
+	};
+
+  this.setMode = function() {
+
+    console.warn( 'THREE.TransformControlsGizmo: setMode function has been depricated.' );
+
+  };
+
+};
+
+THREE.TransformControlsGizmo.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
+
+  constructor: THREE.TransformControlsGizmo,
+
+  isTransformControlsGizmo: true
+
+} );

+ 113 - 0
examples/js/controls/TransformControlsPlane.js

@@ -0,0 +1,113 @@
+/**
+ * @author arodic / https://github.com/arodic
+ */
+
+THREE.TransformControlsPlane = function () {
+
+  'use strict';
+
+  THREE.Mesh.call( this,
+    new THREE.PlaneBufferGeometry( 1000, 1000, 2, 2 ),
+    new THREE.MeshBasicMaterial( { visible: false, wireframe: true, side: THREE.DoubleSide, transparent: true, opacity: 0.1 } )
+  );
+
+	this.type = 'TransformControlsPlane';
+
+  var unitX = new THREE.Vector3( 1, 0, 0 );
+  var unitY = new THREE.Vector3( 0, 1, 0 );
+  var unitZ = new THREE.Vector3( 0, 0, 1 );
+
+	var dirVector = new THREE.Vector3();
+	var alignVector = new THREE.Vector3();
+  var tempMatrix = new THREE.Matrix4();
+  var camRotation = new THREE.Euler();
+
+  this.update = function( rotation, eye ) {
+
+    var axis = this.parent.axis;
+    var mode = this.parent.mode;
+
+    unitX.set( 1, 0, 0 ).applyEuler( rotation );
+    unitY.set( 0, 1, 0 ).applyEuler( rotation );
+    unitZ.set( 0, 0, 1 ).applyEuler( rotation );
+
+    alignVector.copy( unitY );
+
+    switch ( mode ) {
+      case 'translate':
+      case 'scale':
+      switch ( axis ) {
+        case 'X':
+          alignVector.copy( eye ).cross( unitX );
+          dirVector.copy( unitX ).cross( alignVector );
+          break;
+        case 'Y':
+          alignVector.copy( eye ).cross( unitY );
+          dirVector.copy( unitY ).cross( alignVector );
+          break;
+        case 'Z':
+          alignVector.copy( eye ).cross( unitZ );
+          dirVector.copy( unitZ ).cross( alignVector );
+          break;
+        case 'XY':
+          dirVector.copy( unitZ );
+          break;
+        case 'YZ':
+          dirVector.copy( unitX );
+          break;
+        case 'XZ':
+          dirVector.copy( unitY );
+          break;
+        case 'XYZ':
+        case 'E':
+          dirVector.set( 0,0,0 );
+          break;
+        }
+        break;
+      case 'rotate':
+      default:
+        switch ( axis ) {
+          // case 'X':
+          //   dirVector.copy( unitX );
+          //   break;
+          // case 'Y':
+          //   dirVector.copy( unitY );
+          //   break;
+          // case 'Z':
+          //   dirVector.copy( unitZ );
+          //   break;
+          default:
+            dirVector.set( 0,0,0 );
+            break;
+        }
+        break;
+    }
+
+    if ( dirVector.length() === 0 ) {
+
+      var camRotation = new THREE.Euler();
+    	// camRotation.setFromRotationMatrix( _tempMatrix.extractRotation( camera.matrixWorld ) );
+    	camRotation.setFromRotationMatrix( this.parent.camera.matrixWorld );
+      this.quaternion.setFromEuler( camRotation );
+
+    } else {
+
+      tempMatrix.lookAt( this.position, dirVector, alignVector );
+
+      this.quaternion.setFromRotationMatrix( tempMatrix );
+
+    }
+
+    this.updateMatrixWorld();
+
+  };
+
+};
+
+THREE.TransformControlsPlane.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), {
+
+  constructor: THREE.TransformControlsPlane,
+
+  isTransformControlsPlane: true
+
+} );

+ 30 - 19
examples/misc_controls_transform.html

@@ -27,11 +27,14 @@
 
 		<div id="info">
 		"W" translate | "E" rotate | "R" scale | "+" increase size | "-" decrease size<br />
-		Press "Q" to toggle world/local space, keep "Ctrl" down to snap to grid
+		Press "Q" to toggle world/local space, keep "Shift" down to snap to grid
 		</div>
 
 		<script src="../build/three.js"></script>
+		<script src="js/controls/EditorControls.js"></script>
 		<script src="js/controls/TransformControls.js"></script>
+		<script src="js/controls/TransformControlsPlane.js"></script>
+		<script src="js/controls/TransformControlsGizmo.js"></script>
 
 		<script>
 
@@ -49,9 +52,9 @@
 
 				//
 
-				camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 3000 );
+				camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 100000 );
 				camera.position.set( 1000, 500, 1000 );
-				camera.lookAt( new THREE.Vector3( 0, 200, 0 ) );
+				camera.lookAt( new THREE.Vector3( 0, 0, 0 ) );
 
 				scene = new THREE.Scene();
 				scene.add( new THREE.GridHelper( 1000, 10 ) );
@@ -67,12 +70,22 @@
 				var geometry = new THREE.BoxBufferGeometry( 200, 200, 200 );
 				var material = new THREE.MeshLambertMaterial( { map: texture } );
 
-				control = new THREE.TransformControls( camera, renderer.domElement );
-				control.addEventListener( 'change', render );
 
 				var mesh = new THREE.Mesh( geometry, material );
 				scene.add( mesh );
 
+				var control2 = new THREE.EditorControls( camera, renderer.domElement );
+				control2.addEventListener( 'change', render );
+
+				control = new THREE.TransformControls( camera, renderer.domElement );
+				control.addEventListener( 'change', function () {
+					control2.enabled = !control.dragging;
+					render();
+				} );
+				control.mode = "scale";
+				// control.space = "local";
+				mesh.rotation.set( 1, -2, -2 );
+
 				control.attach( mesh );
 				scene.add( control );
 
@@ -83,34 +96,34 @@
 					switch ( event.keyCode ) {
 
 						case 81: // Q
-							control.setSpace( control.space === "local" ? "world" : "local" );
+							control.space = control.space === "local" ? "world" : "local";
 							break;
 
-						case 17: // Ctrl
-							control.setTranslationSnap( 100 );
-							control.setRotationSnap( THREE.Math.degToRad( 15 ) );
+						case 16: // Shift
+							control.translationSnap = 100;
+							control.rotationSnap = THREE.Math.degToRad( 15 );
 							break;
 
 						case 87: // W
-							control.setMode( "translate" );
+							control.mode = "translate";
 							break;
 
 						case 69: // E
-							control.setMode( "rotate" );
+							control.mode = "rotate";
 							break;
 
 						case 82: // R
-							control.setMode( "scale" );
+							control.mode = "scale";
 							break;
 
 						case 187:
 						case 107: // +, =, num+
-							control.setSize( control.size + 0.1 );
+							control.size = control.size + 0.1;
 							break;
 
 						case 189:
 						case 109: // -, _, num-
-							control.setSize( Math.max( control.size - 0.1, 0.1 ) );
+							control.size = Math.max( control.size - 0.1, 0.1 );
 							break;
 
 					}
@@ -121,9 +134,9 @@
 
 					switch ( event.keyCode ) {
 
-						case 17: // Ctrl
-							control.setTranslationSnap( null );
-							control.setRotationSnap( null );
+						case 16: // Shift
+							control.translationSnap = null;
+							control.rotationSnap = null;
 							break;
 
 					}
@@ -145,8 +158,6 @@
 
 			function render() {
 
-				control.update();
-
 				renderer.render( scene, camera );
 
 			}