新增选中帮助器。

This commit is contained in:
tengge1 2019-02-21 21:56:06 +08:00
parent c62faecf63
commit 784ecfafe0
2 changed files with 29 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import BaseHelper from './BaseHelper';
import GridHelper from './GridHelper';
import ViewHelper from './ViewHelper';
import SelectHelper from './SelectHelper';
import SplineHelper from './line/SplineHelper';
/**
@ -13,6 +14,7 @@ function Helpers(app) {
this.helpers = [
new GridHelper(app),
new ViewHelper(app),
new SelectHelper(app),
new SplineHelper(app),
];
}

View File

@ -12,11 +12,37 @@ SelectHelper.prototype = Object.create(BaseHelper.prototype);
SelectHelper.prototype.constructor = SelectHelper;
SelectHelper.prototype.start = function () {
this.app.on(`objectSelected.${this.id}`, this.onObjectSelected.bind(this));
this.app.on(`objectChanged.${this.id}`, this.onObjectChanged.bind(this));
};
SelectHelper.prototype.stop = function () {
this.app.on(`objectSelected.${this.id}`, null);
this.app.on(`objectChanged.${this.id}`, null);
};
SelectHelper.prototype.onObjectSelected = function (obj) {
if (this.helper === undefined) {
this.helper = new THREE.BoxHelper();
this.helper.visible = false;
this.app.editor.sceneHelpers.add(this.helper);
}
if (obj) {
this.object = obj;
this.helper.setFromObject(obj);
this.helper.visible = true;
} else {
delete this.object;
this.helper.setFromObject(undefined);
this.helper.visible = false;
}
};
SelectHelper.prototype.onObjectChanged = function (obj) {
if (this.object && this.helper && this.object === obj) {
this.helper.update();
}
};
export default SelectHelper;