Here it is :

package
        {
        import away3d.containers.ObjectContainer3D;
        import away3d.containers.View3D;
        import away3d.core.base.Vertex;
        import away3d.core.math.Number3D;
        import away3d.geom.Explode;
        import away3d.primitives.Plane;
        import away3d.primitives.Sphere;
        import flash.display.BlendMode;
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.filters.BitmapFilterQuality;
        import flash.filters.BlurFilter;
        import flash.text.TextField;

        /**
         * ...
         * @author Ghislain Flandin
         */
        public class Main extends View3D
                {


                private var exploded:ObjectContainer3D;
                private var nbVertices:int;
                private var containerExploded:ObjectContainer3D;
                private var rayon:int = 100;

                private var t:TextField;
                private var amountRate:int = 12;

                public function Main():void
                        {
                        if (stage) init();
                        else addEventListener(Event.ADDED_TO_STAGE,init);
                        }

                private function init(e:Event = null):void
                        {
                        removeEventListener(Event.ADDED_TO_STAGE, init);

                        x = this.stage.stageWidth / 2;
                        y = this.stage.stageHeight / 2;

                        camera.z = -900;
                        camera.y = 0;

                        var plane:Plane = new Plane( { width:256, height:91, 
segmentsW:8,
segmentsH:7 ,rotationX:90} );
                        //scene.addChild(plane);

                        var exploder:Explode = new Explode(true,true);
                        exploded = exploder.apply(plane) as ObjectContainer3D;

                        containerExploded = new ObjectContainer3D();
                        scene.addChild(containerExploded);
                        containerExploded.addChild(exploded);
                        //containerExploded.rotationX = 90;

                        //use a sphere to position my triangles
                        var sphere:Sphere = new Sphere( {segmentsW:11, 
segmentsH:11,
radius: rayon} );
                        //scene.addChild(sphere);

                        nbVertices = sphere.vertices.length;

                        for (var i:int = 0; i < nbVertices; i+=1)
                                {
                                var vertex:Vertex = sphere.vertices[i];

                                exploded.children[i].x = sphere.vertices[i].x;
                                exploded.children[i].bothsides = true;
                                exploded.children[i].y = sphere.vertices[i].y;
                                exploded.children[i].z = sphere.vertices[i].z;
                                exploded.children[i].ownCanvas=true;
                                exploded.children[i].lookAt(new Number3D());
                                exploded.children[i].rotationX += 90;
                                }

                        this.stage.addChild(t);
                        addEventListener(Event.ENTER_FRAME, enterFrame, false, 
0, true);
                        }

                private function enterFrame(e:Event):void
                        {
                        containerExploded.rotationY += 2;

                        var min:Number = 0;

                        var filtre:Array = new Array();
                        var blur:BlurFilter = new BlurFilter();
                        blur.quality = BitmapFilterQuality.LOW;
                        filtre.push(blur);

                        for (var i:int = 0; i < nbVertices; i+=1)
                                {
                                var diff:Number = 
containerExploded.distanceTo(camera) -
exploded.children[i].distanceTo(camera);

                                if (diff < -5)
                                        {
                                        var amount:Number = Math.abs(diff / 
rayon) *amountRate;
                                        blur.blurX = amount*amountRate;
                                        blur.blurY = amount*amountRate;
                                        exploded.children[i].filters = filtre;
                                        exploded.children[i].alpha = .6
                                        //exploded.children[i].blendMode = 
BlendMode.MULTIPLY;
                                        }
                                else
                                        {
                                        exploded.children[i].filters = null;
                                        exploded.children[i].alpha = 1;
                                        }
                                }
                        render();
                        }
                }
        }

Maybe it will be useful for somebody else !!!

Thanks again and sorry for my english level !!!


On 10 déc, 23:16, Peter Kapelyan <[email protected]> wrote:
> You can try to add a blur to each object.
>
> Something like this:http://away3d.com/examples.php?example=32
>
> And use
>
> myObject.distanceTo(camera.position)
>
> for a number, to see how far away you are and how much blur to apply.
>
> Hope it makes sense.
>
> -Pete
>
> On Thu, Dec 10, 2009 at 5:11 PM, Ghislain Flandin <[email protected]>wrote:
>
>
>
> > Do you think i can easyly add depth of field on this piece of code or
> > do i have to change everything and use DOFSprite ?
>
> > Thanks a lot again !!
>
> > On 10 déc, 23:09, Peter Kapelyan <[email protected]> wrote:
> > > Hooray!
>
> > > You are welcome :)
>
> > > Happy Away3d'ing! :)
>
> > > -Peter
>
> > > ___________________
>
> > > Actionscript 3.0 Flash 3D Graphics Engine
>
> > > HTTP://AWAY3D.COM
>
> --
> ___________________
>
> Actionscript 3.0 Flash 3D Graphics Engine
>
> HTTP://AWAY3D.COM

Reply via email to