LABS | VIZAR

Vizar Laboratorien

Papergrid - Get more into PV3D and Flex

Ok, not that new but i think why not share that experiment. Again it`s based by a PV3D-Flash App coded by Lee Brimelow

It show how to integrate a bitmap into the Flex Framework - I like it more to code AS3 in Flex because it`s so intuitive to extend the built in Flex-Classes. How said it Doug McCune :

Flex changed my life ;-)

PaperGrid in action
PaperGrid’s code

PaperGrid.as

package net.borishorn.flex.pv3d
{
    import caurina.transitions.*;

    import flash.display.Sprite;
    import flash.display.Stage;
    import flash.events.*;
    import flash.geom.Point;

    import net.borishorn.assets.images.Images;
    import net.borishorn.flex.pv3d.utils.BitmapUtils;

    import mx.core.UIComponent;

    import org.papervision3d.cameras.*;
    import org.papervision3d.materials.*;
    import org.papervision3d.objects.*;
    import org.papervision3d.scenes.*;

    public class PaperGrid extends UIComponent
    {
        public var con:Sprite;
        private var cam:Camera3D;
        private var scene:Scene3D;
        private var pa:Array;
        private var cm:BitmapMaterial;
        private var p:Plane;

        public function PaperGrid()
        {
            con = new Sprite();
            addChild(con);

            scene = new Scene3D(con);
            cam = new Camera3D();
            cam.zoom = 11;

            pa = new Array();

            for(var i:uint=0; i < 10; i++)
            {
                for(var j:uint=0; j < 10; j++)
                {

                    cm = BitmapUtils.createBitmapMaterial(Images.flexIcon);
                    cm.oneSide = false;

                    p = new Plane(cm, 50, 50);
                    p.x = j * 50 + 25;
                    p.y = i * 50 + 25;

                    scene.addChild(p);

                    pa.push({pl:p, rotY:Math.random() * 360, rotZ:Math.random() * 360, z:Math.random() * 30000});
                    p.rotationY = pa[i].rotY;
                    p.rotationZ = pa[i].rotZ;
                    p.z = pa[i].z;

                }

            }

            addEventListener(Event.ENTER_FRAME, render);

        }

        private function render(e:Event):void
        {
            for(var i:uint; i
           {
               if(checkDist(pa[i].pl))
                {

                    Tweener.addTween(pa[i].pl, {rotationY:0, rotationZ:0, z:0, time:0.3});

                }
                else
                {

                    Tweener.addTween(pa[i].pl, {rotationY:pa[i].rotY, rotationZ:pa[i].rotZ, z:pa[i].z, time:3});

                }

            }

            scene.renderCamera(cam);

        }

        private function checkDist(p:Plane):Boolean
        {
            var p1:Point = new Point(p.x, p.y);
            var p2:Point = new Point(con.mouseX, -con.mouseY);

            if(Point.distance(p1, p2)> 150)
            {
                    return true;

            }

            else return false;

        }

    }    

}

No comments yet. Be the first.

Leave a reply