소스 검색

Editor: Some more touch work.

Mr.doob 11 년 전
부모
커밋
50cfd87e2e
3개의 변경된 파일70개의 추가작업 그리고 29개의 파일을 삭제
  1. 2 3
      build/three.js
  2. 66 23
      editor/js/Viewport.js
  3. 2 3
      src/extras/helpers/DirectionalLightHelper.js

+ 2 - 3
build/three.js

@@ -31682,7 +31682,7 @@ THREE.DirectionalLightHelper = function ( light, size ) {
 THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
 
 THREE.DirectionalLightHelper.prototype.dispose = function () {
-	
+
 	this.lightPlane.geometry.dispose();
 	this.lightPlane.material.dispose();
 	this.targetLine.geometry.dispose();
@@ -31708,11 +31708,10 @@ THREE.DirectionalLightHelper.prototype.update = function () {
 		this.targetLine.geometry.verticesNeedUpdate = true;
 		this.targetLine.material.color.copy( this.lightPlane.material.color );
 
-	}
+	};
 
 }();
 
-
 // File:src/extras/helpers/EdgesHelper.js
 
 /**

+ 66 - 23
editor/js/Viewport.js

@@ -34,6 +34,18 @@ var Viewport = function ( editor ) {
 	var transformControls = new THREE.TransformControls( camera, container.dom );
 	transformControls.addEventListener( 'change', function () {
 
+		var object = transformControls.object;
+
+		if ( object !== undefined ) {
+
+			if ( editor.helpers[ object.id ] !== undefined ) {
+
+				editor.helpers[ object.id ].update();
+
+			}
+
+		}
+
 		render();
 
 	} );
@@ -84,9 +96,9 @@ var Viewport = function ( editor ) {
 
 	};
 
-	var onMouseDownPosition = new THREE.Vector2();
-	var onMouseUpPosition = new THREE.Vector2();
-	var onMouseDoubleClickPosition = new THREE.Vector2();
+	var onDownPosition = new THREE.Vector2();
+	var onUpPosition = new THREE.Vector2();
+	var onDoubleClickPosition = new THREE.Vector2();
 
 	var getMousePosition = function ( dom, x, y ) {
 
@@ -95,25 +107,11 @@ var Viewport = function ( editor ) {
 
 	};
 
-	var onMouseDown = function ( event ) {
+	var handleClick = function () {
 
-		event.preventDefault();
+		if ( onDownPosition.distanceTo( onUpPosition ) == 0 ) {
 
-		var array = getMousePosition( container.dom, event.clientX, event.clientY );
-		onMouseDownPosition.fromArray( array );
-
-		document.addEventListener( 'mouseup', onMouseUp, false );
-
-	};
-
-	var onMouseUp = function ( event ) {
-
-		var array = getMousePosition( container.dom, event.clientX, event.clientY );
-		onMouseUpPosition.fromArray( array );
-
-		if ( onMouseDownPosition.distanceTo( onMouseUpPosition ) == 0 ) {
-
-			var intersects = getIntersects( onMouseUpPosition, objects );
+			var intersects = getIntersects( onUpPosition, objects );
 
 			if ( intersects.length > 0 ) {
 
@@ -141,16 +139,60 @@ var Viewport = function ( editor ) {
 
 		}
 
-		document.removeEventListener( 'mouseup', onMouseUp );
+	};
+
+	var onMouseDown = function ( event ) {
+
+		event.preventDefault();
+
+		var array = getMousePosition( container.dom, event.clientX, event.clientY );
+		onDownPosition.fromArray( array );
+
+		document.addEventListener( 'mouseup', onMouseUp, false );
+
+	};
+
+	var onMouseUp = function ( event ) {
+
+		var array = getMousePosition( container.dom, event.clientX, event.clientY );
+		onUpPosition.fromArray( array );
+
+		handleClick();
+
+		document.removeEventListener( 'mouseup', onMouseUp, false );
+
+	};
+
+	var onTouchStart = function ( event ) {
+
+		var touch = event.changedTouches[ 0 ];
+
+		var array = getMousePosition( container.dom, touch.clientX, touch.clientY );
+		onDownPosition.fromArray( array );
+
+		document.addEventListener( 'touchend', onTouchEnd, false );
+
+	};
+
+	var onTouchEnd = function ( event ) {
+
+		var touch = event.changedTouches[ 0 ];
+
+		var array = getMousePosition( container.dom, touch.clientX, touch.clientY );
+		onUpPosition.fromArray( array );
+
+		handleClick();
+
+		document.removeEventListener( 'touchend', onTouchEnd, false );
 
 	};
 
 	var onDoubleClick = function ( event ) {
 
 		var array = getMousePosition( container.dom, event.clientX, event.clientY );
-		onMouseDoubleClickPosition.fromArray( array );
+		onDoubleClickPosition.fromArray( array );
 
-		var intersects = getIntersects( onMouseDoubleClickPosition, objects );
+		var intersects = getIntersects( onDoubleClickPosition, objects );
 
 		if ( intersects.length > 0 ) {
 
@@ -163,6 +205,7 @@ var Viewport = function ( editor ) {
 	};
 
 	container.dom.addEventListener( 'mousedown', onMouseDown, false );
+	container.dom.addEventListener( 'touchstart', onTouchStart, false );
 	container.dom.addEventListener( 'dblclick', onDoubleClick, false );
 
 	// controls need to be added *after* main logic,

+ 2 - 3
src/extras/helpers/DirectionalLightHelper.js

@@ -50,7 +50,7 @@ THREE.DirectionalLightHelper = function ( light, size ) {
 THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
 
 THREE.DirectionalLightHelper.prototype.dispose = function () {
-	
+
 	this.lightPlane.geometry.dispose();
 	this.lightPlane.material.dispose();
 	this.targetLine.geometry.dispose();
@@ -76,7 +76,6 @@ THREE.DirectionalLightHelper.prototype.update = function () {
 		this.targetLine.geometry.verticesNeedUpdate = true;
 		this.targetLine.material.color.copy( this.lightPlane.material.color );
 
-	}
+	};
 
 }();
-