点光源优化。

This commit is contained in:
liteng 2018-09-19 20:49:43 +08:00
parent 92a1669858
commit b367eb477a
5 changed files with 56 additions and 15 deletions

View File

@ -15,7 +15,7 @@ function Options(options) {
// 帮助器配置
this.showGrid = true; // 是否显示网格
this.showCameraHelper = true; // 是否显示相机帮助器
this.showPointLightHelper = true; // 是否显示点光源帮助器
this.showPointLightHelper = false; // 是否显示点光源帮助器
this.showDirectionalLightHelper = true; // 是否显示平行光帮助器
this.showSpotLightHelper = true; // 是否显示聚光灯帮助器
this.showHemisphereLightHelper = true; // 是否显示半球光帮助器

View File

@ -278,6 +278,10 @@ LightComponent.prototype.updateUI = function () {
LightComponent.prototype.onChangeColor = function () {
var objectColor = UI.get('objectColor', this.id);
this.selected.color = new THREE.Color(objectColor.getHexValue());
var helper = this.selected.children.filter(n => n.userData.type === 'helper')[0];
if (helper) {
helper.material.color = this.selected.color;
}
};
LightComponent.prototype.onChangeIntensity = function () {

View File

@ -1,4 +1,6 @@
import UI from '../../ui/UI';
import AddObjectCommand from '../../command/AddObjectCommand';
import PointLight from '../../object/light/PointLight';
/**
* 添加菜单
@ -156,9 +158,7 @@ AddMenu.prototype.render = function () {
id: 'mAddPointLight',
html: '点光源',
cls: 'option',
onClick: function () {
_this.app.call('mAddPointLight');
}
onClick: this.addPointLight.bind(this)
}, {
xtype: 'div',
id: 'mAddSpotLight',
@ -183,16 +183,6 @@ AddMenu.prototype.render = function () {
onClick: function () {
_this.app.call('mAddRectAreaLight');
}
}, {
xtype: 'hr'
}, {
xtype: 'div',
id: 'mAddPerspectiveCamera',
html: '透视相机',
cls: 'option',
onClick: function () {
_this.app.call('mAddPerspectiveCamera');
}
}]
}]
});
@ -200,4 +190,31 @@ AddMenu.prototype.render = function () {
container.render();
}
// ------------------------- 环境光 ------------------------------
// ------------------------- 平行光 ------------------------------
// ------------------------- 点光源 ------------------------------
AddMenu.prototype.addPointLight = function () {
var editor = this.app.editor;
var color = 0xffffff;
var intensity = 1;
var distance = 0;
var light = new PointLight(color, intensity, distance);
light.name = '点光源';
light.position.y = 5;
light.castShadow = true;
editor.execute(new AddObjectCommand(light));
};
// ------------------------- 聚光灯 ------------------------------
// ------------------------- 半球光 ------------------------------
// ------------------------- 矩形光 ------------------------------
export default AddMenu;

View File

@ -1,5 +1,6 @@
import MenuEvent from '../MenuEvent';
import AddObjectCommand from '../../../command/AddObjectCommand';
import PointLight from '../../../object/light/PointLight';
var ID = 1;
@ -33,7 +34,7 @@ AddPointLightEvent.prototype.onAddPointLight = function () {
var intensity = 1;
var distance = 0;
var light = new THREE.PointLight(color, intensity, distance);
var light = new PointLight(color, intensity, distance);
light.name = '点光源' + ID++;
light.position.y = 5;
light.castShadow = true;

View File

@ -0,0 +1,19 @@
/**
* 点光源
*/
function PointLight(color, intensity, distance, decay) {
THREE.PointLight.call(this, color, intensity, distance, decay);
var geometry = new THREE.SphereBufferGeometry(0.2, 16, 8);
var material = new THREE.MeshBasicMaterial({ color: color });
var mesh = new THREE.Mesh(geometry, material);
mesh.userData.type = 'helper';
this.add(mesh);
}
PointLight.prototype = Object.create(THREE.PointLight.prototype);
PointLight.prototype.constructor = PointLight;
export default PointLight;