mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
import MenuEvent from '../MenuEvent';
|
|
import AddObjectCommand from '../../../command/AddObjectCommand';
|
|
import PointLight from '../../../object/light/PointLight';
|
|
|
|
var ID = 1;
|
|
|
|
/**
|
|
* 添加点光源事件
|
|
* @author tengge / https://github.com/tengge1
|
|
* @param {*} app
|
|
*/
|
|
function AddPointLightEvent(app) {
|
|
MenuEvent.call(this, app);
|
|
}
|
|
|
|
AddPointLightEvent.prototype = Object.create(MenuEvent.prototype);
|
|
AddPointLightEvent.prototype.constructor = AddPointLightEvent;
|
|
|
|
AddPointLightEvent.prototype.start = function () {
|
|
var _this = this;
|
|
this.app.on('mAddPointLight.' + this.id, function () {
|
|
_this.onAddPointLight();
|
|
});
|
|
};
|
|
|
|
AddPointLightEvent.prototype.stop = function () {
|
|
this.app.on('mAddPointLight.' + this.id, null);
|
|
};
|
|
|
|
AddPointLightEvent.prototype.onAddPointLight = function () {
|
|
var editor = this.app.editor;
|
|
|
|
var color = 0xffffff;
|
|
var intensity = 1;
|
|
var distance = 0;
|
|
|
|
var light = new PointLight(color, intensity, distance);
|
|
light.name = '点光源' + ID++;
|
|
light.position.y = 5;
|
|
light.castShadow = true;
|
|
|
|
editor.execute(new AddObjectCommand(light));
|
|
};
|
|
|
|
export default AddPointLightEvent; |