Hi,
sorry no complete example code but at least I cleaned the two necessary classes. (see the zip file below)
It is not completely done yet. I only tested PerspectiveLens & DirectionalLight ... anything else maybe later if it is possible to detect Objects between camera and lightsource. Otherwise it would not make sense anyway.
btw: Is there a possibility to create layers or prevent clipping for specified objects/materials or anything like that? Right now I try to set the position as near as possible to the frustrum - could cause display errors. How are you guys handling stuff like that? Layers would be really great, e. g. for HUDs.
>> live example (fp ~5MB / 11.2 beta)
use the mouseWheel to change the fieldOfView
3 simple steps:
embed some bitmaps:
[Embed(source="embedded_assets/lensFlares/sunSphere.png")]
private var matSunSpehereBitmap:Class;
[Embed(source="embedded_assets/lensFlares/flare1.png")]
private var matSunFlare1Bitmap:Class;
[Embed(source="embedded_assets/lensFlares/flare2.png")]
private var matSunFlare2Bitmap:Class;
[Embed(source="embedded_assets/lensFlares/flare3.png")]
private var matSunFlare3Bitmap:Class;
[Embed(source="embedded_assets/lensFlares/flare4.png")]
private var matSunFlare4Bitmap:Class;
[Embed(source="embedded_assets/lensFlares/flareRing.png")]
private var matSunFlareRingBitmap:Class;
[Embed(source="embedded_assets/lensFlares/sunGlow.png")]
private var matSunGlowBitmap:Class;
[Embed(source="embedded_assets/lensFlares/sunStar.png")]
private var matSunStarBitmap:Class;
[Embed(source="embedded_assets/lensFlares/flareStreak.png")]
private var matSunFlareStreakBitmap:Class;
initiate the controller (I use about 40 flares):
import de.flintfabrik.away3d4.fx.LensFlares.LensFlare3DManager;
import de.flintfabrik.away3d4.fx.LensFlares.LensFlare;
...
lensFlare3DManager = new LensFlare3DManager(view, sun, directionalLight1.direction);
//lens flares
lensFlare3DManager.addChild(new LensFlare(new matSunFlare1Bitmap().bitmapData, -0.3 , 1.0));
lensFlare3DManager.addChild(new LensFlare(new matSunFlare2Bitmap().bitmapData, 0.7 , 1.0 ));
lensFlare3DManager.addChild(new LensFlare(new matSunFlare3Bitmap().bitmapData, -1.5 , 1.0 ));
lensFlare3DManager.addChild(new LensFlare(new matSunFlare4Bitmap().bitmapData, 0.2 , 1.0 ));
lensFlare3DManager.addChild(new LensFlare(new matSunFlare1Bitmap().bitmapData, 1.3 , 1.0 ));
lensFlare3DManager.addChild(new LensFlare(new matSunFlare2Bitmap().bitmapData, 1.2 , 1.0 ));
lensFlare3DManager.addChild(new LensFlare(new matSunFlare3Bitmap().bitmapData, 0.65, 1.0));
lensFlare3DManager.addChild(new LensFlare(new matSunFlare4Bitmap().bitmapData, 0.8 , 1.0 ));
lensFlare3DManager.addChild(new LensFlare(new matSunFlareRingBitmap().bitmapData, 1.7 , 1.0 ));
//sun
lensFlare3DManager.addChild(new LensFlare(new matSunGlowBitmap().bitmapData, 0.0 , 1.0 ));
lensFlare3DManager.addChild(new LensFlare(new matSunFlareStreakBitmap().bitmapData, 0.0 , 2.0, .5 ));
lensFlare3DManager.addChild(new LensFlare(new matSunStarBitmap().bitmapData, 0.0 , 2.0 ));
//extreme
lensFlare3DManager.addChild(new LensFlare(new matSunFlare1Bitmap().bitmapData, -50.0 , 10.0));
lensFlare3DManager.addChild(new LensFlare(new matSunGlowBitmap().bitmapData, 50.0 , 10.0));
//additional random lens flares
var flareMaps:Array = [ new matSunFlare1Bitmap().bitmapData,
new matSunFlare2Bitmap().bitmapData,
new matSunFlare3Bitmap().bitmapData,
new matSunFlare4Bitmap().bitmapData
];
for (var i:int = 0; i < 20; i++ ) {
lensFlare3DManager.addChild(
new LensFlare(
flareMaps[ Math.floor( Math.random() * flareMaps.length) ],
Math.random() * 10 - 2 ,
Math.random() * 1 + 0.5,
Math.random() *.25 + .25
)
);
}
for (i = 0; i < 10; i++ ) {
lensFlare3DManager.addChild(
new LensFlare(
flareMaps[ Math.floor( Math.random() * flareMaps.length) ],
Math.random() * 5 + 5 ,
Math.random() * 3 + 1.5,
Math.random() *.25 + .25
)
);
}
onEnterFrame:
LensFlare3DManager.updateAll();
That is all
Regards
Michael
ps: I killed my apostorphe key - just in case somebody has been wondering.
edit: dispose method error fixed