whs
Version:
Super-fast 3D framework for Web Applications & Games. Based on Three.js
42 lines (39 loc) • 1.04 kB
JavaScript
import {
FogExp2,
Fog
} from 'three';
/**
* @class FogModule
* @category modules/app
* @param {Object} [params={color: 0xefd1b5, density: 0.020, near: 10, far: 1000}] - The parameters object.
* @param {String} [type=exp2] - The type of fog - exp2 or linear
* @memberof module:modules/app
* @example <caption>How to create and apply a FogModule</caption>
* const fogModule = new FogModule({
* color: 0xffffff,
* density: 0.03,
* near: 20,
* far: 200
* }, 'exp2');
*
* new App([
* ...,
* fogModule
* ]);
*/
export class FogModule {
constructor(params = {}, type) {
this.params = Object.assign({
color: 0xefd1b5,
density: 0.020,
near: 10,
far: 1000
}, params);
if (!type || type === 'exp2') this.fog = new FogExp2(this.params.color, this.params.density);
else if (type === 'linear') this.fog = new Fog(this.params.color, this.params.near, this.params.far);
}
manager(manager) {
manager.set('fog', this.fog);
manager.get('scene').fog = this.fog;
}
}