新增菜单完善。

This commit is contained in:
liteng 2018-06-22 12:18:15 +08:00
parent d270f4648f
commit bc75ec8ef0
9 changed files with 358 additions and 0 deletions

View File

@ -55,6 +55,14 @@ import AddIcosahedronEvent from './menu/add/AddIcosahedronEvent';
import AddTorusEvent from './menu/add/AddTorusEvent';
import AddTorusKnotEvent from './menu/add/AddTorusKnotEvent';
import AddTeaportEvent from './menu/add/AddTeaportEvent';
import AddLatheEvent from './menu/add/AddLatheEvent';
import AddSpriteEvent from './menu/add/AddSpriteEvent';
import AddPointLightEvent from './menu/add/AddPointLightEvent';
import AddSpotLightEvent from './menu/add/AddSpotLightEvent';
import AddDirectionalLightEvent from './menu/add/AddDirectionalLightEvent';
import AddHemisphereLightEvent from './menu/add/AddHemisphereLightEvent';
import AddAmbientLightEvent from './menu/add/AddAmbientLightEvent';
import AddPerspectiveCameraEvent from './menu/add/AddPerspectiveCameraEvent';
/**
* 事件执行器
@ -120,6 +128,14 @@ function EventDispatcher(app) {
new AddTorusEvent(this.app),
new AddTorusKnotEvent(this.app),
new AddTeaportEvent(this.app),
new AddLatheEvent(this.app),
new AddSpriteEvent(this.app),
new AddPointLightEvent(this.app),
new AddSpotLightEvent(this.app),
new AddDirectionalLightEvent(this.app),
new AddHemisphereLightEvent(this.app),
new AddAmbientLightEvent(this.app),
new AddPerspectiveCameraEvent(this.app),
];
}

View File

@ -0,0 +1,39 @@
import MenuEvent from '../MenuEvent';
import AddObjectCommand from '../../../command/AddObjectCommand';
var ID = 1;
/**
* 添加环境光事件
* @param {*} app
*/
function AddAmbientLightEvent(app) {
MenuEvent.call(this, app);
}
AddAmbientLightEvent.prototype = Object.create(MenuEvent.prototype);
AddAmbientLightEvent.prototype.constructor = AddAmbientLightEvent;
AddAmbientLightEvent.prototype.start = function () {
var _this = this;
this.app.on('mAddAmbientLight.' + this.id, function () {
_this.onAddAmbientLightEvent();
});
};
AddAmbientLightEvent.prototype.stop = function () {
this.app.on('mAddAmbientLight.' + this.id, null);
};
AddAmbientLightEvent.prototype.onAddAmbientLightEvent = function () {
var editor = this.app.editor;
var color = 0x222222;
var light = new THREE.AmbientLight(color);
light.name = 'AmbientLight ' + ID++;
editor.execute(new AddObjectCommand(light));
};
export default AddAmbientLightEvent;

View File

@ -0,0 +1,43 @@
import MenuEvent from '../MenuEvent';
import AddObjectCommand from '../../../command/AddObjectCommand';
var ID = 1;
/**
* 添加平行光源事件
* @param {*} app
*/
function AddDirectionalLightEvent(app) {
MenuEvent.call(this, app);
}
AddDirectionalLightEvent.prototype = Object.create(MenuEvent.prototype);
AddDirectionalLightEvent.prototype.constructor = AddDirectionalLightEvent;
AddDirectionalLightEvent.prototype.start = function () {
var _this = this;
this.app.on('mAddDirectionalLight.' + this.id, function () {
_this.onAddDirectionalLight();
});
};
AddDirectionalLightEvent.prototype.stop = function () {
this.app.on('mAddDirectionalLight.' + this.id, null);
};
AddDirectionalLightEvent.prototype.onAddDirectionalLight = function () {
var editor = this.app.editor;
var color = 0xffffff;
var intensity = 1;
var light = new THREE.DirectionalLight(color, intensity);
light.name = 'DirectionalLight ' + ID;
light.target.name = 'DirectionalLight ' + (ID++) + ' Target';
light.position.set(5, 10, 7.5);
editor.execute(new AddObjectCommand(light));
};
export default AddDirectionalLightEvent;

View File

@ -0,0 +1,43 @@
import MenuEvent from '../MenuEvent';
import AddObjectCommand from '../../../command/AddObjectCommand';
var ID = 1;
/**
* 添加半球光事件
* @param {*} app
*/
function AddHemisphereLightEvent(app) {
MenuEvent.call(this, app);
}
AddHemisphereLightEvent.prototype = Object.create(MenuEvent.prototype);
AddHemisphereLightEvent.prototype.constructor = AddHemisphereLightEvent;
AddHemisphereLightEvent.prototype.start = function () {
var _this = this;
this.app.on('mAddHemisphereLight.' + this.id, function () {
_this.onAddHemisphereLight();
});
};
AddHemisphereLightEvent.prototype.stop = function () {
this.app.on('mAddHemisphereLight.' + this.id, null);
};
AddHemisphereLightEvent.prototype.onAddHemisphereLight = function () {
var editor = this.app.editor;
var skyColor = 0x00aaff;
var groundColor = 0xffaa00;
var intensity = 1;
var light = new THREE.HemisphereLight(skyColor, groundColor, intensity);
light.name = 'HemisphereLight ' + ID++;
light.position.set(0, 10, 0);
editor.execute(new AddObjectCommand(light));
};
export default AddHemisphereLightEvent;

View File

@ -0,0 +1,55 @@
import MenuEvent from '../MenuEvent';
import AddObjectCommand from '../../../command/AddObjectCommand';
var ID = 1;
/**
* 添加花瓶事件
* @param {*} app
*/
function AddLatheEvent(app) {
MenuEvent.call(this, app);
}
AddLatheEvent.prototype = Object.create(MenuEvent.prototype);
AddLatheEvent.prototype.constructor = AddLatheEvent;
AddLatheEvent.prototype.start = function () {
var _this = this;
this.app.on('mAddLathe.' + this.id, function () {
_this.onAddLathe();
});
};
AddLatheEvent.prototype.stop = function () {
this.app.on('mAddLathe.' + this.id, null);
};
AddLatheEvent.prototype.onAddLathe = function () {
var editor = this.app.editor;
var points = [
new THREE.Vector2(0, 0),
new THREE.Vector2(4, 0),
new THREE.Vector2(3.5, 0.5),
new THREE.Vector2(1, 0.75),
new THREE.Vector2(0.8, 1),
new THREE.Vector2(0.8, 4),
new THREE.Vector2(1, 4.2),
new THREE.Vector2(1.4, 4.8),
new THREE.Vector2(2, 5),
new THREE.Vector2(2.5, 5.4),
new THREE.Vector2(3, 12)
];
var segments = 20;
var phiStart = 0;
var phiLength = 2 * Math.PI;
var geometry = new THREE.LatheBufferGeometry(points, segments, phiStart, phiLength);
var mesh = new THREE.Mesh(geometry, new THREE.MeshStandardMaterial({ side: THREE.DoubleSide }));
mesh.name = 'Lathe ' + ID++;
editor.execute(new AddObjectCommand(mesh));
};
export default AddLatheEvent;

View File

@ -0,0 +1,37 @@
import MenuEvent from '../MenuEvent';
import AddObjectCommand from '../../../command/AddObjectCommand';
var ID = 1;
/**
* 添加透视相机事件
* @param {*} app
*/
function AddPerspectiveCameraEvent(app) {
MenuEvent.call(this, app);
}
AddPerspectiveCameraEvent.prototype = Object.create(MenuEvent.prototype);
AddPerspectiveCameraEvent.prototype.constructor = AddPerspectiveCameraEvent;
AddPerspectiveCameraEvent.prototype.start = function () {
var _this = this;
this.app.on('mAddPerspectiveCamera.' + this.id, function () {
_this.onAddPerspectiveCamera();
});
};
AddPerspectiveCameraEvent.prototype.stop = function () {
this.app.on('mAddPerspectiveCamera.' + this.id, null);
};
AddPerspectiveCameraEvent.prototype.onAddPerspectiveCamera = function () {
var editor = this.app.editor;
var camera = new THREE.PerspectiveCamera(50, 1, 1, 10000);
camera.name = 'PerspectiveCamera ' + ID++;
editor.execute(new AddObjectCommand(camera));
};
export default AddPerspectiveCameraEvent;

View File

@ -0,0 +1,41 @@
import MenuEvent from '../MenuEvent';
import AddObjectCommand from '../../../command/AddObjectCommand';
var ID = 1;
/**
* 添加点光源事件
* @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 THREE.PointLight(color, intensity, distance);
light.name = 'PointLight ' + ID++;
editor.execute(new AddObjectCommand(light));
};
export default AddPointLightEvent;

View File

@ -0,0 +1,47 @@
import MenuEvent from '../MenuEvent';
import AddObjectCommand from '../../../command/AddObjectCommand';
var ID = 1;
/**
* 添加聚光灯事件
* @param {*} app
*/
function AddSpotLightEvent(app) {
MenuEvent.call(this, app);
}
AddSpotLightEvent.prototype = Object.create(MenuEvent.prototype);
AddSpotLightEvent.prototype.constructor = AddSpotLightEvent;
AddSpotLightEvent.prototype.start = function () {
var _this = this;
this.app.on('mAddSpotLight.' + this.id, function () {
_this.onAddSpotLight();
});
};
AddSpotLightEvent.prototype.stop = function () {
this.app.on('mAddSpotLight.' + this.id, null);
};
AddSpotLightEvent.prototype.onAddSpotLight = function () {
var editor = this.app.editor;
var color = 0xffffff;
var intensity = 1;
var distance = 0;
var angle = Math.PI * 0.1;
var penumbra = 0;
var light = new THREE.SpotLight(color, intensity, distance, angle, penumbra);
light.name = 'SpotLight ' + ID;
light.target.name = 'SpotLight ' + (ID++) + ' Target';
light.position.set(5, 10, 7.5);
editor.execute(new AddObjectCommand(light));
};
export default AddSpotLightEvent;

View File

@ -0,0 +1,37 @@
import MenuEvent from '../MenuEvent';
import AddObjectCommand from '../../../command/AddObjectCommand';
var ID = 1;
/**
* 添加精灵事件
* @param {*} app
*/
function AddSpriteEvent(app) {
MenuEvent.call(this, app);
}
AddSpriteEvent.prototype = Object.create(MenuEvent.prototype);
AddSpriteEvent.prototype.constructor = AddSpriteEvent;
AddSpriteEvent.prototype.start = function () {
var _this = this;
this.app.on('mAddSprite.' + this.id, function () {
_this.onAddSprite();
});
};
AddSpriteEvent.prototype.stop = function () {
this.app.on('mAddSprite.' + this.id, null);
};
AddSpriteEvent.prototype.onAddSprite = function () {
var editor = this.app.editor;
var sprite = new THREE.Sprite(new THREE.SpriteMaterial());
sprite.name = 'Sprite ' + ID++;
editor.execute(new AddObjectCommand(sprite));
};
export default AddSpriteEvent;