添加矩形光

This commit is contained in:
liteng 2018-08-11 09:56:16 +08:00
parent 87c75a496f
commit 6ba19e18dd
5 changed files with 50 additions and 2 deletions

View File

@ -180,7 +180,7 @@ AddMenu.prototype.render = function () {
html: '矩形光',
cls: 'option',
onClick: function () {
// _this.app.call('mAddHemisphereLight');
_this.app.call('mAddRectAreaLight');
}
}, {
xtype: 'hr'

View File

@ -76,6 +76,7 @@ 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 AddRectAreaLightEvent from './menu/add/AddRectAreaLightEvent';
import AddTextEvent from './menu/add/AddTextEvent';
import AddPerspectiveCameraEvent from './menu/add/AddPerspectiveCameraEvent';
@ -226,6 +227,7 @@ function EventDispatcher(app) {
new AddDirectionalLightEvent(this.app),
new AddHemisphereLightEvent(this.app),
new AddAmbientLightEvent(this.app),
new AddRectAreaLightEvent(this.app),
new AddTextEvent(this.app),
new AddPerspectiveCameraEvent(this.app),

View File

@ -55,6 +55,7 @@ var EventList = [
'mAddDirectionalLight', // 添加平行光源
'mAddHemisphereLight', // 添加半球光
'mAddAmbientLight', // 添加环境光
'mAddRectAreaLight', // 添加矩形光
'mAddText', // 添加文本
'mAddPerspectiveCamera', // 添加透视相机

View File

@ -28,10 +28,11 @@ AddPlaneEvent.prototype.stop = function () {
AddPlaneEvent.prototype.onAddPlane = function () {
var editor = this.app.editor;
var geometry = new THREE.PlaneBufferGeometry(2, 2);
var geometry = new THREE.PlaneBufferGeometry(50, 50);
var material = new THREE.MeshStandardMaterial();
var mesh = new THREE.Mesh(geometry, material);
mesh.name = '平板' + ID++;
mesh.rotation.x = -Math.PI / 2;
editor.execute(new AddObjectCommand(mesh));
};

View File

@ -0,0 +1,44 @@
import MenuEvent from '../MenuEvent';
import AddObjectCommand from '../../../command/AddObjectCommand';
var ID = 1;
/**
* 添加矩形光事件
* @param {*} app
*/
function AddRectAreaLightEvent(app) {
MenuEvent.call(this, app);
}
AddRectAreaLightEvent.prototype = Object.create(MenuEvent.prototype);
AddRectAreaLightEvent.prototype.constructor = AddRectAreaLightEvent;
AddRectAreaLightEvent.prototype.start = function () {
var _this = this;
this.app.on('mAddRectAreaLight.' + this.id, function () {
_this.onAddHemisphereLight();
});
};
AddRectAreaLightEvent.prototype.stop = function () {
this.app.on('mAddRectAreaLight.' + this.id, null);
};
AddRectAreaLightEvent.prototype.onAddHemisphereLight = function () {
var editor = this.app.editor;
var color = 0xffffff;
var intensity = 1;
var width = 40;
var height = 30;
var light = new THREE.RectAreaLight(color, intensity, width, height);
light.name = '矩形光' + ID++;
light.position.set(0, 50, 0);
editor.execute(new AddObjectCommand(light));
};
export default AddRectAreaLightEvent;