Gallery [PV3D] (1)

by ProjectNya
////////////////////////////////////////////////////////////////////////////////
// Gallery [PV3D] (1)
//
// [PV3D]ギャラリーもどき (1)
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1312
////////////////////////////////////////////////////////////////////////////////
♥2 | Line 110 | Modified 2011-01-04 18:57:00 | MIT License
play

ActionScript3 source code

/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/XfNH
 */

////////////////////////////////////////////////////////////////////////////////
// Gallery [PV3D] (1)
//
// [PV3D]ギャラリーもどき (1)
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1312
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.events.Event;
    import flash.system.Security;
    import org.papervision3d.Papervision3D;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.view.Viewport3D;
    import org.papervision3d.render.BasicRenderEngine;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.materials.BitmapFileMaterial;
    import org.papervision3d.events.FileLoadEvent;

    [SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]

    public class Main extends Sprite {
        private var scene:Scene3D;
        private var camera:Camera3D;
        private var viewport:Viewport3D;
        private var renderer:BasicRenderEngine;
        private static var radius:uint = 400;
        private static var cameraHeight:uint = 0;
        private var angle:Number = 90;
        private static var radian:Number = Math.PI/180;
        private static var max:uint = 20*2;
        private var wall1:DisplayObject3D;
        private var wall2:DisplayObject3D;
        private static var basePath:String = "http://www.project-nya.jp/images/flash/gallery/";
        private var completed:uint = 0;

        public function Main() {
            //Wonderfl.capture_delay(1);
            init();
        }

        private function init():void {
            Security.allowDomain("www.project-nya.jp");
            Security.loadPolicyFile("http://www.project-nya.jp/crossdomain.xml");
            scene = new Scene3D();
            camera =new Camera3D();
            viewport = new Viewport3D(0, 0, true, false);
            renderer = new BasicRenderEngine();
            setup();
            initialize();
            addChild(viewport);
        }
        private function setup():void {
            camera.x = 0;
            camera.y = 0;
            camera.z = radius;
            camera.zoom = 25;
            camera.focus = 20;
            camera.target = DisplayObject3D.ZERO;
        }
        private function initialize():void {
            wall1 = new DisplayObject3D();
            wall1.x = 200;
            wall1.y = 0;
            wall1.z = - 40;
            wall1.rotationY = 90 + 20;
            scene.addChild(wall1);
            wall2 = new DisplayObject3D();
            wall2.x = -200;
            wall2.y = 0;
            wall2.z = - 40;
            wall2.rotationY = - 90 - 20;
            scene.addChild(wall2);
            initialize1();
            initialize2();
            //start();
        }
        private function initialize1():void {
            for (var n:uint = 0; n < 20; n++) {
                var filePath:String = basePath + "photo" + (n + 1) + ".jpg";
                var material:BitmapFileMaterial = new BitmapFileMaterial(filePath, false);
                material.doubleSided = true;
                material.smooth = true;
                material.addEventListener(FileLoadEvent.LOAD_COMPLETE, loaded, false, 0, true);
                var plane:Plane = new Plane(material, 80, 60, 0, 0);
                plane.x = 90*uint(n/4);
                plane.y = 105 - 70*(n%4);
                plane.z = 0;
                wall1.addChild(plane);
            }
        }
        private function initialize2():void {
            for (var n:uint = 0; n < 20; n++) {
                var filePath:String = basePath + "photo" + (n + 1) + ".jpg";
                var material:BitmapFileMaterial = new BitmapFileMaterial(filePath, false);
                material.doubleSided = true;
                material.smooth = true;
                material.addEventListener(FileLoadEvent.LOAD_COMPLETE, loaded, false, 0, true);
                var plane:Plane = new Plane(material, 80, 60, 0, 0);
                plane.x = - 90*uint(n/4);
                plane.y = 105 - 70*(n%4);
                plane.z = 0;
                wall2.addChild(plane);
            }
        }
        private function loaded(evt:FileLoadEvent):void {
            completed ++;
            if (completed > max - 1) start();
        }
        private function start():void {
            addEventListener(Event.ENTER_FRAME, render, false, 0, true);
        }
        private function render(evt:Event):void {
            angle ++;
            camera.x = 200*Math.cos(angle*radian);
            camera.y = cameraHeight;
            camera.z = radius;
            //
            renderer.renderScene(scene, camera, viewport);
        }
        
    }

}