mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-02-01 16:08:17 +00:00
雾效和背景改变事件。
This commit is contained in:
parent
2407fd0b2a
commit
f48498cb36
@ -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');
|
||||
};
|
||||
|
||||
|
||||
@ -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),
|
||||
|
||||
32
src/event/viewport/SceneBackgroundChangedEvent.js
Normal file
32
src/event/viewport/SceneBackgroundChangedEvent.js
Normal 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;
|
||||
57
src/event/viewport/SceneFogChangedEvent.js
Normal file
57
src/event/viewport/SceneFogChangedEvent.js
Normal 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;
|
||||
Loading…
x
Reference in New Issue
Block a user