mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-02-01 16:08:17 +00:00
选中物体和设置物体焦点事件。
This commit is contained in:
parent
6c9c62be9e
commit
e3ca37af8b
@ -47,7 +47,7 @@ function Viewport(app) {
|
||||
|
||||
//
|
||||
|
||||
var box = new THREE.Box3();
|
||||
|
||||
|
||||
var selectionBox = new THREE.BoxHelper();
|
||||
selectionBox.material.depthTest = false;
|
||||
@ -277,6 +277,8 @@ function Viewport(app) {
|
||||
// otherwise controls.enabled doesn't work.
|
||||
|
||||
var controls = new THREE.EditorControls(camera, container.dom);
|
||||
editor.controls = controls;
|
||||
|
||||
controls.addEventListener('change', function () {
|
||||
transformControls.update();
|
||||
_this.app.call('cameraChanged', _this, camera);
|
||||
@ -365,42 +367,6 @@ function Viewport(app) {
|
||||
_this.app.call('render');
|
||||
});
|
||||
|
||||
this.app.on('objectSelected.Viewport', function (object) {
|
||||
|
||||
selectionBox.visible = false;
|
||||
transformControls.detach();
|
||||
|
||||
if (object !== null && object !== scene) {
|
||||
|
||||
box.setFromObject(object);
|
||||
|
||||
if (box.isEmpty() === false) {
|
||||
|
||||
selectionBox.setFromObject(object);
|
||||
selectionBox.visible = true;
|
||||
|
||||
}
|
||||
|
||||
transformControls.attach(object);
|
||||
|
||||
}
|
||||
|
||||
_this.app.call('render');
|
||||
|
||||
});
|
||||
|
||||
this.app.on('objectFocused.Viewport', function (object) {
|
||||
controls.focus(object);
|
||||
});
|
||||
|
||||
this.app.on('geometryChanged.Viewport', function (object) {
|
||||
if (object !== undefined) {
|
||||
selectionBox.setFromObject(object);
|
||||
}
|
||||
|
||||
_this.app.call('render');
|
||||
});
|
||||
|
||||
this.app.call('animate');
|
||||
};
|
||||
|
||||
|
||||
@ -90,6 +90,7 @@ import SceneFogChangedEvent from './viewport/SceneFogChangedEvent';
|
||||
import SceneBackgroundChangedEvent from './viewport/SceneBackgroundChangedEvent';
|
||||
import HelperEvent from './viewport/HelperEvent';
|
||||
import ObjectEvent from './viewport/ObjectEvent';
|
||||
import GeometryEvent from './viewport/GeometryEvent';
|
||||
|
||||
import TransformModeChangedEvent from './statusBar/TransformModeChangedEvent';
|
||||
import GridChangeEvent from './statusBar/GridChangeEvent';
|
||||
@ -196,6 +197,7 @@ function EventDispatcher(app) {
|
||||
new SceneBackgroundChangedEvent(this.app),
|
||||
new HelperEvent(this.app),
|
||||
new ObjectEvent(this.app),
|
||||
new GeometryEvent(this.app),
|
||||
|
||||
// statusBar中的事件
|
||||
new TransformModeChangedEvent(this.app),
|
||||
|
||||
35
src/event/viewport/GeometryEvent.js
Normal file
35
src/event/viewport/GeometryEvent.js
Normal file
@ -0,0 +1,35 @@
|
||||
import BaseEvent from '../BaseEvent';
|
||||
|
||||
/**
|
||||
* 几何体改变事件
|
||||
* @param {*} app
|
||||
*/
|
||||
function GeometryEvent(app) {
|
||||
BaseEvent.call(this, app);
|
||||
}
|
||||
|
||||
GeometryEvent.prototype = Object.create(BaseEvent.prototype);
|
||||
GeometryEvent.prototype.constructor = GeometryEvent;
|
||||
|
||||
GeometryEvent.prototype.start = function () {
|
||||
var _this = this;
|
||||
this.app.on('geometryChanged.' + this.id, function (object) {
|
||||
_this.onGeometryChanged(object);
|
||||
});
|
||||
};
|
||||
|
||||
GeometryEvent.prototype.stop = function () {
|
||||
this.app.on('geometryChanged.' + this.id, null);
|
||||
};
|
||||
|
||||
GeometryEvent.prototype.onGeometryChanged = function (object) {
|
||||
var selectionBox = this.app.editor.selectionBox;
|
||||
|
||||
if (object !== undefined) {
|
||||
selectionBox.setFromObject(object);
|
||||
}
|
||||
|
||||
this.app.call('render');
|
||||
};
|
||||
|
||||
export default GeometryEvent;
|
||||
@ -6,6 +6,7 @@ import BaseEvent from '../BaseEvent';
|
||||
*/
|
||||
function ObjectEvent(app) {
|
||||
BaseEvent.call(this, app);
|
||||
this.box = new THREE.Box3();
|
||||
}
|
||||
|
||||
ObjectEvent.prototype = Object.create(BaseEvent.prototype);
|
||||
@ -22,12 +23,20 @@ ObjectEvent.prototype.start = function () {
|
||||
this.app.on('objectRemoved.' + this.id, function (object) {
|
||||
_this.onObjectRemoved(object);
|
||||
});
|
||||
this.app.on('objectSelected.' + this.id, function (object) {
|
||||
_this.onObjectSelected(object);
|
||||
});
|
||||
this.app.on('objectFocused.' + this.id, function (object) {
|
||||
_this.onObjectFocused(object);
|
||||
});
|
||||
};
|
||||
|
||||
ObjectEvent.prototype.stop = function () {
|
||||
this.app.on('objectAdded.' + this.id, null);
|
||||
this.app.on('objectChanged.' + this.id, null);
|
||||
this.app.on('objectRemoved.' + this.id, null);
|
||||
this.app.on('objectSelected.' + this.id, null);
|
||||
this.app.on('objectFocused.' + this.id, null);
|
||||
};
|
||||
|
||||
ObjectEvent.prototype.onObjectAdded = function (object) {
|
||||
@ -67,4 +76,32 @@ ObjectEvent.prototype.onObjectRemoved = function (object) {
|
||||
});
|
||||
};
|
||||
|
||||
ObjectEvent.prototype.onObjectSelected = function (object) {
|
||||
var editor = this.app.editor;
|
||||
var selectionBox = editor.selectionBox;
|
||||
var transformControls = editor.transformControls;
|
||||
var scene = editor.scene;
|
||||
var box = this.box;
|
||||
|
||||
selectionBox.visible = false;
|
||||
transformControls.detach();
|
||||
|
||||
if (object !== null && object !== scene) {
|
||||
box.setFromObject(object);
|
||||
if (box.isEmpty() === false) {
|
||||
selectionBox.setFromObject(object);
|
||||
selectionBox.visible = true;
|
||||
}
|
||||
transformControls.attach(object);
|
||||
}
|
||||
|
||||
this.app.call('render');
|
||||
};
|
||||
|
||||
ObjectEvent.prototype.onObjectFocused = function (object) {
|
||||
var controls = this.app.editor.controls;
|
||||
|
||||
controls.focus(object);
|
||||
};
|
||||
|
||||
export default ObjectEvent;
|
||||
Loading…
x
Reference in New Issue
Block a user