雾效和背景改变事件。

This commit is contained in:
liteng 2018-06-25 21:38:47 +08:00
parent 2407fd0b2a
commit f48498cb36
4 changed files with 93 additions and 48 deletions

View File

@ -444,54 +444,6 @@ function Viewport(app) {
_this.app.call('render');
});
// fog
this.app.on('sceneBackgroundChanged.Viewport', function (backgroundColor) {
scene.background.setHex(backgroundColor);
_this.app.call('render');
});
var currentFogType = null;
this.app.on('sceneFogChanged.Viewport', function (fogType, fogColor, fogNear, fogFar, fogDensity) {
if (currentFogType !== fogType) {
switch (fogType) {
case 'None':
scene.fog = null;
break;
case 'Fog':
scene.fog = new THREE.Fog();
break;
case 'FogExp2':
scene.fog = new THREE.FogExp2();
break;
}
currentFogType = fogType;
}
if (scene.fog instanceof THREE.Fog) {
scene.fog.color.setHex(fogColor);
scene.fog.near = fogNear;
scene.fog.far = fogFar;
} else if (scene.fog instanceof THREE.FogExp2) {
scene.fog.color.setHex(fogColor);
scene.fog.density = fogDensity;
}
_this.app.call('render');
});
this.app.call('animate');
};

View File

@ -86,6 +86,8 @@ import RenderEvent from './viewport/RenderEvent';
import AnimateEvent from './viewport/AnimateEvent';
import ShowGridChangedEvent from './viewport/ShowGridChangedEvent';
import WindowResizeEvent from './viewport/WindowResizeEvent';
import SceneFogChangedEvent from './viewport/SceneFogChangedEvent';
import SceneBackgroundChangedEvent from './viewport/SceneBackgroundChangedEvent';
import TransformModeChangedEvent from './statusBar/TransformModeChangedEvent';
import GridChangeEvent from './statusBar/GridChangeEvent';
@ -188,6 +190,8 @@ function EventDispatcher(app) {
new AnimateEvent(this.app),
new ShowGridChangedEvent(this.app),
new WindowResizeEvent(this.app),
new SceneFogChangedEvent(this.app),
new SceneBackgroundChangedEvent(this.app),
// statusBar中的事件
new TransformModeChangedEvent(this.app),

View File

@ -0,0 +1,32 @@
import BaseEvent from '../BaseEvent';
/**
* 场景背景改变改变事件
* @param {*} app
*/
function SceneBackgroundChangedEvent(app) {
BaseEvent.call(this, app);
}
SceneBackgroundChangedEvent.prototype = Object.create(BaseEvent.prototype);
SceneBackgroundChangedEvent.prototype.constructor = SceneBackgroundChangedEvent;
SceneBackgroundChangedEvent.prototype.start = function () {
var _this = this;
this.app.on('sceneBackgroundChanged.' + this.id, function (backgroundColor) {
_this.onSceneBackgroundChanged(backgroundColor);
});
};
SceneBackgroundChangedEvent.prototype.stop = function () {
this.app.on('sceneBackgroundChanged.' + this.id, null);
};
SceneBackgroundChangedEvent.prototype.onSceneBackgroundChanged = function (backgroundColor) {
var scene = this.app.editor.scene;
scene.background.setHex(backgroundColor);
this.app.call('render');
};
export default SceneBackgroundChangedEvent;

View File

@ -0,0 +1,57 @@
import BaseEvent from '../BaseEvent';
/**
* 雾效改变事件
* @param {*} app
*/
function SceneFogChangedEvent(app) {
BaseEvent.call(this, app);
this.currentFogType = null;
}
SceneFogChangedEvent.prototype = Object.create(BaseEvent.prototype);
SceneFogChangedEvent.prototype.constructor = SceneFogChangedEvent;
SceneFogChangedEvent.prototype.start = function () {
var _this = this;
this.app.on('sceneFogChanged.' + this.id, function (fogType, fogColor, fogNear, fogFar, fogDensity) {
_this.onSceneFogChanged(fogType, fogColor, fogNear, fogFar, fogDensity);
});
};
SceneFogChangedEvent.prototype.stop = function () {
this.app.on('sceneFogChanged.' + this.id, null);
};
SceneFogChangedEvent.prototype.onSceneFogChanged = function (fogType, fogColor, fogNear, fogFar, fogDensity) {
var scene = this.app.editor.scene;
if (this.currentFogType !== fogType) {
switch (fogType) {
case 'None':
scene.fog = null;
break;
case 'Fog':
scene.fog = new THREE.Fog();
break;
case 'FogExp2':
scene.fog = new THREE.FogExp2();
break;
}
this.currentFogType = fogType;
}
if (scene.fog instanceof THREE.Fog) {
scene.fog.color.setHex(fogColor);
scene.fog.near = fogNear;
scene.fog.far = fogFar;
} else if (scene.fog instanceof THREE.FogExp2) {
scene.fog.color.setHex(fogColor);
scene.fog.density = fogDensity;
}
this.app.call('render');
};
export default SceneFogChangedEvent;