initial commit
This commit is contained in:
26
lib/lights/AmbientLight.js
Normal file
26
lib/lights/AmbientLight.js
Normal file
@ -0,0 +1,26 @@
|
||||
import { Light } from './Light.js';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function AmbientLight( color, intensity ) {
|
||||
|
||||
Light.call( this, color, intensity );
|
||||
|
||||
this.type = 'AmbientLight';
|
||||
|
||||
this.castShadow = undefined;
|
||||
|
||||
}
|
||||
|
||||
AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
|
||||
|
||||
constructor: AmbientLight,
|
||||
|
||||
isAmbientLight: true
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { AmbientLight };
|
46
lib/lights/DirectionalLight.js
Normal file
46
lib/lights/DirectionalLight.js
Normal file
@ -0,0 +1,46 @@
|
||||
import { Light } from './Light.js';
|
||||
import { DirectionalLightShadow } from './DirectionalLightShadow.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
|
||||
function DirectionalLight( color, intensity ) {
|
||||
|
||||
Light.call( this, color, intensity );
|
||||
|
||||
this.type = 'DirectionalLight';
|
||||
|
||||
this.position.copy( Object3D.DefaultUp );
|
||||
this.updateMatrix();
|
||||
|
||||
this.target = new Object3D();
|
||||
|
||||
this.shadow = new DirectionalLightShadow();
|
||||
|
||||
}
|
||||
|
||||
DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
|
||||
|
||||
constructor: DirectionalLight,
|
||||
|
||||
isDirectionalLight: true,
|
||||
|
||||
copy: function ( source ) {
|
||||
|
||||
Light.prototype.copy.call( this, source );
|
||||
|
||||
this.target = source.target.clone();
|
||||
|
||||
this.shadow = source.shadow.clone();
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { DirectionalLight };
|
21
lib/lights/DirectionalLightShadow.js
Normal file
21
lib/lights/DirectionalLightShadow.js
Normal file
@ -0,0 +1,21 @@
|
||||
import { LightShadow } from './LightShadow.js';
|
||||
import { OrthographicCamera } from '../cameras/OrthographicCamera.js';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function DirectionalLightShadow( ) {
|
||||
|
||||
LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
|
||||
|
||||
}
|
||||
|
||||
DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
|
||||
|
||||
constructor: DirectionalLightShadow
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { DirectionalLightShadow };
|
43
lib/lights/HemisphereLight.js
Normal file
43
lib/lights/HemisphereLight.js
Normal file
@ -0,0 +1,43 @@
|
||||
import { Light } from './Light.js';
|
||||
import { Color } from '../math/Color.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
|
||||
function HemisphereLight( skyColor, groundColor, intensity ) {
|
||||
|
||||
Light.call( this, skyColor, intensity );
|
||||
|
||||
this.type = 'HemisphereLight';
|
||||
|
||||
this.castShadow = undefined;
|
||||
|
||||
this.position.copy( Object3D.DefaultUp );
|
||||
this.updateMatrix();
|
||||
|
||||
this.groundColor = new Color( groundColor );
|
||||
|
||||
}
|
||||
|
||||
HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
|
||||
|
||||
constructor: HemisphereLight,
|
||||
|
||||
isHemisphereLight: true,
|
||||
|
||||
copy: function ( source ) {
|
||||
|
||||
Light.prototype.copy.call( this, source );
|
||||
|
||||
this.groundColor.copy( source.groundColor );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { HemisphereLight };
|
62
lib/lights/Light.js
Normal file
62
lib/lights/Light.js
Normal file
@ -0,0 +1,62 @@
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
import { Color } from '../math/Color.js';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
|
||||
function Light( color, intensity ) {
|
||||
|
||||
Object3D.call( this );
|
||||
|
||||
this.type = 'Light';
|
||||
|
||||
this.color = new Color( color );
|
||||
this.intensity = intensity !== undefined ? intensity : 1;
|
||||
|
||||
this.receiveShadow = undefined;
|
||||
|
||||
}
|
||||
|
||||
Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
||||
|
||||
constructor: Light,
|
||||
|
||||
isLight: true,
|
||||
|
||||
copy: function ( source ) {
|
||||
|
||||
Object3D.prototype.copy.call( this, source );
|
||||
|
||||
this.color.copy( source.color );
|
||||
this.intensity = source.intensity;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
toJSON: function ( meta ) {
|
||||
|
||||
var data = Object3D.prototype.toJSON.call( this, meta );
|
||||
|
||||
data.object.color = this.color.getHex();
|
||||
data.object.intensity = this.intensity;
|
||||
|
||||
if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
|
||||
|
||||
if ( this.distance !== undefined ) data.object.distance = this.distance;
|
||||
if ( this.angle !== undefined ) data.object.angle = this.angle;
|
||||
if ( this.decay !== undefined ) data.object.decay = this.decay;
|
||||
if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
|
||||
|
||||
if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { Light };
|
61
lib/lights/LightShadow.js
Normal file
61
lib/lights/LightShadow.js
Normal file
@ -0,0 +1,61 @@
|
||||
import { Matrix4 } from '../math/Matrix4.js';
|
||||
import { Vector2 } from '../math/Vector2.js';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function LightShadow( camera ) {
|
||||
|
||||
this.camera = camera;
|
||||
|
||||
this.bias = 0;
|
||||
this.radius = 1;
|
||||
|
||||
this.mapSize = new Vector2( 512, 512 );
|
||||
|
||||
this.map = null;
|
||||
this.matrix = new Matrix4();
|
||||
|
||||
}
|
||||
|
||||
Object.assign( LightShadow.prototype, {
|
||||
|
||||
copy: function ( source ) {
|
||||
|
||||
this.camera = source.camera.clone();
|
||||
|
||||
this.bias = source.bias;
|
||||
this.radius = source.radius;
|
||||
|
||||
this.mapSize.copy( source.mapSize );
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
|
||||
return new this.constructor().copy( this );
|
||||
|
||||
},
|
||||
|
||||
toJSON: function () {
|
||||
|
||||
var object = {};
|
||||
|
||||
if ( this.bias !== 0 ) object.bias = this.bias;
|
||||
if ( this.radius !== 1 ) object.radius = this.radius;
|
||||
if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
|
||||
|
||||
object.camera = this.camera.toJSON( false ).object;
|
||||
delete object.camera.matrix;
|
||||
|
||||
return object;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { LightShadow };
|
62
lib/lights/PointLight.js
Normal file
62
lib/lights/PointLight.js
Normal file
@ -0,0 +1,62 @@
|
||||
import { Light } from './Light.js';
|
||||
import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
|
||||
import { LightShadow } from './LightShadow.js';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
|
||||
function PointLight( color, intensity, distance, decay ) {
|
||||
|
||||
Light.call( this, color, intensity );
|
||||
|
||||
this.type = 'PointLight';
|
||||
|
||||
Object.defineProperty( this, 'power', {
|
||||
get: function () {
|
||||
|
||||
// intensity = power per solid angle.
|
||||
// ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
|
||||
return this.intensity * 4 * Math.PI;
|
||||
|
||||
},
|
||||
set: function ( power ) {
|
||||
|
||||
// intensity = power per solid angle.
|
||||
// ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
|
||||
this.intensity = power / ( 4 * Math.PI );
|
||||
|
||||
}
|
||||
} );
|
||||
|
||||
this.distance = ( distance !== undefined ) ? distance : 0;
|
||||
this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
|
||||
|
||||
this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
|
||||
|
||||
}
|
||||
|
||||
PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
|
||||
|
||||
constructor: PointLight,
|
||||
|
||||
isPointLight: true,
|
||||
|
||||
copy: function ( source ) {
|
||||
|
||||
Light.prototype.copy.call( this, source );
|
||||
|
||||
this.distance = source.distance;
|
||||
this.decay = source.decay;
|
||||
|
||||
this.shadow = source.shadow.clone();
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { PointLight };
|
48
lib/lights/RectAreaLight.js
Normal file
48
lib/lights/RectAreaLight.js
Normal file
@ -0,0 +1,48 @@
|
||||
import { Light } from './Light.js';
|
||||
|
||||
/**
|
||||
* @author abelnation / http://github.com/abelnation
|
||||
*/
|
||||
|
||||
function RectAreaLight( color, intensity, width, height ) {
|
||||
|
||||
Light.call( this, color, intensity );
|
||||
|
||||
this.type = 'RectAreaLight';
|
||||
|
||||
this.width = ( width !== undefined ) ? width : 10;
|
||||
this.height = ( height !== undefined ) ? height : 10;
|
||||
|
||||
}
|
||||
|
||||
RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
|
||||
|
||||
constructor: RectAreaLight,
|
||||
|
||||
isRectAreaLight: true,
|
||||
|
||||
copy: function ( source ) {
|
||||
|
||||
Light.prototype.copy.call( this, source );
|
||||
|
||||
this.width = source.width;
|
||||
this.height = source.height;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
toJSON: function ( meta ) {
|
||||
|
||||
var data = Light.prototype.toJSON.call( this, meta );
|
||||
|
||||
data.object.width = this.width;
|
||||
data.object.height = this.height;
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
export { RectAreaLight };
|
72
lib/lights/SpotLight.js
Normal file
72
lib/lights/SpotLight.js
Normal file
@ -0,0 +1,72 @@
|
||||
import { Light } from './Light.js';
|
||||
import { SpotLightShadow } from './SpotLightShadow.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
|
||||
function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
|
||||
|
||||
Light.call( this, color, intensity );
|
||||
|
||||
this.type = 'SpotLight';
|
||||
|
||||
this.position.copy( Object3D.DefaultUp );
|
||||
this.updateMatrix();
|
||||
|
||||
this.target = new Object3D();
|
||||
|
||||
Object.defineProperty( this, 'power', {
|
||||
get: function () {
|
||||
|
||||
// intensity = power per solid angle.
|
||||
// ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
|
||||
return this.intensity * Math.PI;
|
||||
|
||||
},
|
||||
set: function ( power ) {
|
||||
|
||||
// intensity = power per solid angle.
|
||||
// ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
|
||||
this.intensity = power / Math.PI;
|
||||
|
||||
}
|
||||
} );
|
||||
|
||||
this.distance = ( distance !== undefined ) ? distance : 0;
|
||||
this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
|
||||
this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
|
||||
this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
|
||||
|
||||
this.shadow = new SpotLightShadow();
|
||||
|
||||
}
|
||||
|
||||
SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
|
||||
|
||||
constructor: SpotLight,
|
||||
|
||||
isSpotLight: true,
|
||||
|
||||
copy: function ( source ) {
|
||||
|
||||
Light.prototype.copy.call( this, source );
|
||||
|
||||
this.distance = source.distance;
|
||||
this.angle = source.angle;
|
||||
this.penumbra = source.penumbra;
|
||||
this.decay = source.decay;
|
||||
|
||||
this.target = source.target.clone();
|
||||
|
||||
this.shadow = source.shadow.clone();
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { SpotLight };
|
43
lib/lights/SpotLightShadow.js
Normal file
43
lib/lights/SpotLightShadow.js
Normal file
@ -0,0 +1,43 @@
|
||||
import { LightShadow } from './LightShadow.js';
|
||||
import { _Math } from '../math/Math.js';
|
||||
import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function SpotLightShadow() {
|
||||
|
||||
LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
|
||||
|
||||
}
|
||||
|
||||
SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
|
||||
|
||||
constructor: SpotLightShadow,
|
||||
|
||||
isSpotLightShadow: true,
|
||||
|
||||
update: function ( light ) {
|
||||
|
||||
var camera = this.camera;
|
||||
|
||||
var fov = _Math.RAD2DEG * 2 * light.angle;
|
||||
var aspect = this.mapSize.width / this.mapSize.height;
|
||||
var far = light.distance || camera.far;
|
||||
|
||||
if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
|
||||
|
||||
camera.fov = fov;
|
||||
camera.aspect = aspect;
|
||||
camera.far = far;
|
||||
camera.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { SpotLightShadow };
|
Reference in New Issue
Block a user