mirror of
https://github.com/wahyd4/three.js.git
synced 2026-08-09 04:56:01 +10:00
Still a bit dirty but less than it was before. Maybe also sprites could be pluginized.
92 lines
2.3 KiB
JavaScript
92 lines
2.3 KiB
JavaScript
/**
|
|
* @author mikael emtinger / http://gomo.se/
|
|
* @author alteredq / http://alteredqualia.com/
|
|
*/
|
|
|
|
THREE.LensFlare = function ( texture, size, distance, blending, color ) {
|
|
|
|
THREE.Object3D.call( this );
|
|
|
|
this.lensFlares = [];
|
|
|
|
this.positionScreen = new THREE.Vector3();
|
|
this.customUpdateCallback = undefined;
|
|
|
|
if( texture !== undefined ) {
|
|
|
|
this.add( texture, size, distance, blending, color );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
THREE.LensFlare.prototype = new THREE.Object3D();
|
|
THREE.LensFlare.prototype.constructor = THREE.LensFlare;
|
|
THREE.LensFlare.prototype.supr = THREE.Object3D.prototype;
|
|
|
|
|
|
/*
|
|
* Add: adds another flare
|
|
*/
|
|
|
|
THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
|
|
|
|
if( size === undefined ) size = -1;
|
|
if( distance === undefined ) distance = 0;
|
|
if( opacity === undefined ) opacity = 1;
|
|
if( color === undefined ) color = new THREE.Color( 0xffffff );
|
|
if( blending === undefined ) blending = THREE.BillboardBlending;
|
|
|
|
distance = Math.min( distance, Math.max( 0, distance ) );
|
|
|
|
this.lensFlares.push( { texture: texture, // THREE.Texture
|
|
size: size, // size in pixels (-1 = use texture.width)
|
|
distance: distance, // distance (0-1) from light source (0=at light source)
|
|
x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is ontop z = 1 is back
|
|
scale: 1, // scale
|
|
rotation: 1, // rotation
|
|
opacity: opacity, // opacity
|
|
color: color, // color
|
|
blending: blending } ); // blending
|
|
|
|
};
|
|
|
|
|
|
/*
|
|
* Update lens flares update positions on all flares based on the screen position
|
|
* Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
|
|
*/
|
|
|
|
THREE.LensFlare.prototype.updateLensFlares = function () {
|
|
|
|
var f, fl = this.lensFlares.length;
|
|
var flare;
|
|
var vecX = -this.positionScreen.x * 2;
|
|
var vecY = -this.positionScreen.y * 2;
|
|
|
|
for( f = 0; f < fl; f ++ ) {
|
|
|
|
flare = this.lensFlares[ f ];
|
|
|
|
flare.x = this.positionScreen.x + vecX * flare.distance;
|
|
flare.y = this.positionScreen.y + vecY * flare.distance;
|
|
|
|
flare.wantedRotation = flare.x * Math.PI * 0.25;
|
|
flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|