平移旋转缩放事件优化。

This commit is contained in:
liteng 2018-06-27 12:07:14 +08:00
parent 021bdaa895
commit fd38570df7
2 changed files with 15 additions and 27 deletions

View File

@ -8,6 +8,9 @@ import UI2 from '../ui2/UI';
function Viewport(app) {
this.app = app;
var editor = this.app.editor;
var _this = this;
// 用户界面
var container = new UI2.Div({
parent: this.app.container,
@ -18,10 +21,9 @@ function Viewport(app) {
container.render();
this.viewportInfo = new ViewportInfo(app, container);
this.viewportInfo = new ViewportInfo(this.app, this.container);
//
var _this = this;
var renderer = null;
@ -55,19 +57,8 @@ function Viewport(app) {
// 平移旋转缩放控件
var transformControls = new THREE.TransformControls(camera, container.dom);
editor.transformControls = transformControls;
transformControls.addEventListener('change', function () {
_this.app.call('transformControlsChange', _this);
});
transformControls.addEventListener('mouseDown', function () {
_this.app.call('transformControlsMouseDown', _this);
});
transformControls.addEventListener('mouseUp', function () {
_this.app.call('transformControlsMouseUp', _this);
});
sceneHelpers.add(transformControls);
editor.transformControls = transformControls;
// 编辑器控件

View File

@ -19,22 +19,19 @@ TransformControlsEvent.prototype = Object.create(BaseEvent.prototype);
TransformControlsEvent.prototype.constructor = TransformControlsEvent;
TransformControlsEvent.prototype.start = function () {
var _this = this;
this.app.on('transformControlsChange.' + this.id, function () {
_this.onChange();
});
this.app.on('transformControlsMouseDown.' + this.id, function () {
_this.onMouseDown();
});
this.app.on('transformControlsMouseUp.' + this.id, function () {
_this.onMouseUp();
});
var transformControls = this.app.editor.transformControls;
transformControls.addEventListener('change', this.onChange.bind(this));
transformControls.addEventListener('mouseDown', this.onMouseDown.bind(this));
transformControls.addEventListener('mouseUp', this.onMouseUp.bind(this));
};
TransformControlsEvent.prototype.stop = function () {
this.app.on('transformControlsChange.' + this.id, null);
this.app.on('transformControlsMouseDown.' + this.id, null);
this.app.on('transformControlsMouseUp.' + this.id, null);
var transformControls = this.app.editor.transformControls;
transformControls.removeEventListener('change', this.onChange);
transformControls.removeEventListener('mouseDown', this.onMouseDown);
transformControls.removeEventListener('mouseUp', this.onMouseUp);
};
TransformControlsEvent.prototype.onChange = function () {