In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Gallery [PV3D] (2)

Gallery [PV3D] (2)

[PV3D]ギャラリーもどき (4)
http://www.project-nya.jp/modules/weblog/details.php?blog_id=1315
Get Adobe Flash player
by ProjectNya 04 Jan 2011
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/toT5s
 */

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

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 layer:uint = n%4;
                var plane:Plane = new Plane(material, 80, 60, 0, 0);
                plane.x = 90*uint(n/4);
                plane.y = 105 - 70*layer;
                plane.z = 0;
                wall1.addChild(plane);
                if (layer == 3) {
                    var reflection:ReflectionPlane = new ReflectionPlane(material, 80, 60, 0, 0, 0.2);
                    reflection.x = 90*uint(n/4);
                    reflection.y = 105 - 70*3 - 60;
                    reflection.z = 0;
                    wall1.addChild(reflection);
                }
            }
        }
        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 layer:uint = n%4;
                var plane:Plane = new Plane(material, 80, 60, 0, 0);
                plane.x = - 90*uint(n/4);
                plane.y = 105 - 70*layer;
                plane.z = 0;
                wall2.addChild(plane);
                if (layer == 3) {
                    var reflection:ReflectionPlane = new ReflectionPlane(material, 80, 60, 0, 0, 0.2);
                    reflection.x = -90*uint(n/4);
                    reflection.y = 105 - 70*3 - 60;
                    reflection.z = 0;
                    wall2.addChild(reflection);
                }
            }
        }
        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);
        }
        
    }

}


//////////////////////////////////////////////////
// ReflectionPlaneクラス
//////////////////////////////////////////////////

import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Matrix;
import flash.geom.ColorTransform;
import flash.display.Shape;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.InterpolationMethod;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.objects.primitives.Plane;

class ReflectionPlane extends DisplayObject3D {
    private var _material:BitmapFileMaterial;
    private var _width:Number = 0;
    private var _height:Number = 0;
    private var _segmentsW:Number = 0;
    private var _segmentsH:Number = 0;
    private var _alpha:Number = 1;
    private var plane:Plane;
    private var bitmapData:BitmapData;
    private var bitmap:Bitmap;

    public function ReflectionPlane(material:BitmapFileMaterial = null, width:Number = 0, height:Number = 0, segmentsW:Number = 0, segmentsH:Number = 0, alpha:Number = 1) {
        _material = material;
        _width = width;
        _height = height;
        _segmentsW = segmentsW;
        _segmentsH = segmentsH;
        _alpha = alpha;
        init();
    }

    private function init():void {
        _material.addEventListener(FileLoadEvent.LOAD_COMPLETE, loaded, false, 0, true);
    }
    private function loaded(evt:FileLoadEvent):void {
        draw();
        reflect();
        var material:BitmapMaterial = new BitmapMaterial(bitmapData, false);
        material.smooth = true;
        plane = new Plane(material, _width, _height, _segmentsW, _segmentsH);
        addChild(plane);
    }
    private function draw():void {
        var bd:BitmapData = _material.bitmap.clone();
        bitmapData = new BitmapData(bd.width, bd.height, false, 0xFFFFFFFF);
        var matrix:Matrix = new Matrix();
        matrix.scale(1, -1);
        matrix.translate(0, bd.height);
        var colorTrans:ColorTransform = new ColorTransform();
        colorTrans.alphaMultiplier = _alpha;
        bitmapData.lock();
        bitmapData.draw(bd, matrix, colorTrans);
        bitmapData.unlock();
        bd.dispose();
    }
    private function reflect():void {
        var overlay:Shape = new Shape();
        var colors:Array = [0xFFFFFF, 0xFFFFFF];
        var alphas:Array = [0, 1];
        var ratios:Array = [0, 204];
        var matrix:Matrix = new Matrix();
        matrix.createGradientBox(bitmapData.width, bitmapData.height, Math.PI/2, 0, 0);
        overlay.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
        overlay.graphics.drawRect(0, 0, bitmapData.width, bitmapData.height);
        overlay.graphics.endFill();
        bitmapData.lock();
        bitmapData.draw(overlay);
        bitmapData.unlock();
    }

}