소스 검색

Editor: Add SelectionHelper for Viewport. (#23902)

* wip(editor): Add SelectPlugin for Editor.

* fix(editor): Fixed SelectionHelper priority to minimum priority.

* Remove useless code.

* fix(editor): Remove SelectionHelper priority.

* Clean up.

* Clean up.

* Clean up.

* Fix error.

* Rename intersects -> intersectionsDetected

* Add SelectionHelper for sw.js
linbingquan 3 년 전
부모
커밋
eb59abbdee
4개의 변경된 파일79개의 추가작업 그리고 39개의 파일을 삭제
  1. 8 17
      editor/js/Editor.js
  2. 69 0
      editor/js/Viewport.SelectionHelper.js
  3. 1 22
      editor/js/Viewport.js
  4. 1 0
      editor/sw.js

+ 8 - 17
editor/js/Editor.js

@@ -5,6 +5,7 @@ import { Loader } from './Loader.js';
 import { History as _History } from './History.js';
 import { Strings } from './Strings.js';
 import { Storage as _Storage } from './Storage.js';
+import { SelectionHelper } from './Viewport.SelectionHelper.js';
 
 var _DEFAULT_CAMERA = new THREE.PerspectiveCamera( 50, 1, 0.01, 1000 );
 _DEFAULT_CAMERA.name = 'Camera';
@@ -13,7 +14,7 @@ _DEFAULT_CAMERA.lookAt( new THREE.Vector3() );
 
 function Editor() {
 
-	var Signal = signals.Signal;
+	const Signal = signals.Signal; // eslint-disable-line no-undef
 
 	this.signals = {
 
@@ -84,7 +85,9 @@ function Editor() {
 		refreshSidebarObject3D: new Signal(),
 		historyChanged: new Signal(),
 
-		viewportCameraChanged: new Signal()
+		viewportCameraChanged: new Signal(),
+
+		intersectionsDetected: new Signal(),
 
 	};
 
@@ -92,6 +95,7 @@ function Editor() {
 	this.history = new _History( this );
 	this.storage = new _Storage();
 	this.strings = new Strings( this.config );
+	this.selectionHelper = new SelectionHelper( this );
 
 	this.loader = new Loader( this );
 
@@ -535,20 +539,7 @@ Editor.prototype = {
 
 	select: function ( object ) {
 
-		if ( this.selected === object ) return;
-
-		var uuid = null;
-
-		if ( object !== null ) {
-
-			uuid = object.uuid;
-
-		}
-
-		this.selected = object;
-
-		this.config.setKey( 'selected', uuid );
-		this.signals.objectSelected.dispatch( object );
+		this.selectionHelper.select( object );
 
 	},
 
@@ -583,7 +574,7 @@ Editor.prototype = {
 
 	deselect: function () {
 
-		this.select( null );
+		this.selectionHelper.deselect();
 
 	},
 

+ 69 - 0
editor/js/Viewport.SelectionHelper.js

@@ -0,0 +1,69 @@
+class SelectionHelper {
+
+	constructor( editor ) {
+
+		const signals = editor.signals;
+
+		this.editor = editor;
+		this.config = editor.config;
+		this.signals = signals;
+		this.selected = null;
+
+		// signals
+
+		signals.intersectionsDetected.add( ( intersects ) => {
+
+			if ( intersects.length > 0 ) {
+
+				const object = intersects[ 0 ].object;
+
+				if ( object.userData.object !== undefined ) {
+
+					// helper
+
+					this.select( object.userData.object );
+
+				} else {
+
+					this.select( object );
+
+				}
+
+			} else {
+
+				this.select( null );
+
+			}
+
+		} );
+
+	}
+
+	select( object ) {
+
+		if ( this.selected === object ) return;
+
+		let uuid = null;
+
+		if ( object !== null ) {
+
+			uuid = object.uuid;
+
+		}
+
+		this.selected = object;
+
+		this.config.setKey( 'selected', uuid );
+		this.signals.objectSelected.dispatch( object );
+
+	}
+
+	deselect() {
+
+		this.select( null );
+
+	}
+
+}
+
+export { SelectionHelper };

+ 1 - 22
editor/js/Viewport.js

@@ -207,28 +207,7 @@ function Viewport( editor ) {
 		if ( onDownPosition.distanceTo( onUpPosition ) === 0 ) {
 
 			const intersects = getIntersects( onUpPosition );
-
-			if ( intersects.length > 0 ) {
-
-				const object = intersects[ 0 ].object;
-
-				if ( object.userData.object !== undefined ) {
-
-					// helper
-
-					editor.select( object.userData.object );
-
-				} else {
-
-					editor.select( object );
-
-				}
-
-			} else {
-
-				editor.select( null );
-
-			}
+			signals.intersectionsDetected.dispatch( intersects );
 
 			render();
 

+ 1 - 0
editor/sw.js

@@ -190,6 +190,7 @@ const assets = [
 	'./js/Viewport.js',
 	'./js/Viewport.Camera.js',
 	'./js/Viewport.Info.js',
+	'./js/Viewport.SelectionHelper.js',
 	'./js/Viewport.ViewHelper.js',
 	'./js/Viewport.VR.js',