Beautifl - Flash Gallery

Thumbnail : Away3D [negimiku] + Tween24
Away3D [negimiku] + Tween24
ProjectNya 2012-09-26 MIT License

再生するにはFlash Playerが必要です。デスクトップのブラウザでご覧ください。

////////////////////////////////////////////////////////////////////////////////
// Away3D [negimiku] + Tween24
//
// [Away3D] モデル (3)
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1764
//
// Colladaデータとテキスチャ
// @rect先生 ( http://wonderfl.net/user/rect ) の
// http://blog.r3c7.net/as3-software-rendering/121/ からDLさせていただきました。
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.display.StageAlign;
    import flash.system.System;
    import flash.events.Event;
    import flash.geom.Vector3D;
    import flash.net.URLRequest;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import away3d.Away3D;
    import away3d.containers.View3D;
    import away3d.containers.Scene3D;
    import away3d.cameras.Camera3D;
    import away3d.lights.DirectionalLight;
    import away3d.containers.ObjectContainer3D;
    import away3d.materials.TextureMaterial;
    import away3d.materials.lightpickers.StaticLightPicker;
    import away3d.loaders.Loader3D;
    //import away3d.loaders.parsers.Parsers;
    import away3d.loaders.parsers.DAEParser;
    import away3d.events.LoaderEvent;
    import away3d.loaders.misc.AssetLoaderContext;
    import away3d.library.AssetLibrary;
    import away3d.library.assets.AssetType;
    import away3d.events.AssetEvent;
    import away3d.debug.AwayStats;
    import a24.tween.Tween24;
    import a24.tween.events.Tween24Event;

    [SWF(backgroundColor="#333333", width="465", height="465", frameRate="60")]

    public class Main extends Sprite {
        private var view:View3D;
        private var scene:Scene3D;
        private var camera:Camera3D;
        private var light:DirectionalLight;
        private var negimiku:ObjectContainer3D;
        private static var radius:uint = 500;
        private var angle:Number = - 90;
        private var degree:Number = 0;
        private static var depression:uint = 30;
        private static var radian:Number = Math.PI/180;
        private static var center:Vector3D = new Vector3D();
        private static var basePath:String = "http://www.project-nya.jp/images/wonderfl/";
        private static var colladaPath:String = "negimiku/negimiku.dae";
        private static var imagePath:String = "negimiku/negimiku.png";
        private var stats:AwayStats;
        //private var source:BitmapData = new BitmapData(465, 465, false, 0x000000);

        public function Main() {
            Wonderfl.disable_capture();
            //addChild(new Bitmap(source));
            //
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            System.pauseForGCIfCollectionImminent(1);
            init();
            stats = new AwayStats(view);
            addChild(stats);
            stats.x = 340;
        }

        private function init():void {
            view = new View3D();
            scene = view.scene;
            camera = view.camera;
            addChild(view);
            light = new DirectionalLight();
            scene.addChild(light);
            setup();
            initialize();
            //
            //addEventListener(Event.ENTER_FRAME, render, false, 0, true);
        }
        private function setup():void {
            view.backgroundColor = 0x333333;
            view.antiAlias = 4;
            //
            camera.x = 0;
            camera.y = 0;
            camera.z = - radius;
            //
            light.direction = new Vector3D(0, -1, 1);
            light.specular = 1;
            light.diffuse = 1;
            light.ambient = 0.3;
        }
        private function initialize():void {
            //Parsers.enableAllBundled();
            var context:AssetLoaderContext = new AssetLoaderContext();
            //context.mapUrlToData("negimiku.png", new ImageData());
            context.mapUrlToData(basePath + imagePath, "negimiku.png");
            AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, loaded, false, 0, true);
            var loader:Loader3D = new Loader3D();
            loader.addEventListener(LoaderEvent.RESOURCE_COMPLETE, complete, false, 0, true);
            //loader.loadData(new ColladaData(), context);
            //loader.loadData(new ColladaData(), context, null, new DAEParser());
            loader.load(new URLRequest(basePath + colladaPath), context, null, new DAEParser());
        }
        private function loaded(evt:AssetEvent):void {
            if (evt.asset.assetType == AssetType.CONTAINER) {
                negimiku = ObjectContainer3D(evt.asset);
                negimiku.rotationX = 90;
                negimiku.scale(16.8);
            }
            if (evt.asset.assetType == AssetType.MATERIAL) {
                var material:TextureMaterial = TextureMaterial(evt.asset);
                var lightPicker:StaticLightPicker = new StaticLightPicker([light]);
                material.lightPicker = lightPicker;
                material.ambientColor = 0xFFFFFF;
                //material.alpha = 0.99;
                material.alpha = 1;
                material.alphaThreshold = 0.5;
            }
        }
        private function complete(evt:LoaderEvent):void {
            AssetLibrary.removeEventListener(AssetEvent.ASSET_COMPLETE, loaded);
            evt.target.removeEventListener(LoaderEvent.RESOURCE_COMPLETE, complete);
            //
            scene.addChild(negimiku);
            addEventListener(Event.ENTER_FRAME, render, false, 0, true);
            negimiku.y = -50;
            jump();
        }
        private function jump():void {
            var atween:Tween24 = Tween24.serial(
                Tween24.tween(negimiku, 0.5, Tween24.ease.CubicOut).y(50), 
                Tween24.tween(negimiku, 0.5, Tween24.ease.CubicIn).y(-50)
            );
            atween.addEventListener(Tween24Event.COMPLETE, jumped, false, 0, true);
            atween.play();
        }
        private function jumped(evt:Tween24Event):void {
            evt.target.removeEventListener(Tween24Event.COMPLETE, jumped);
            jump();
        }
        private function render(evt:Event):void {
            angle += 0.5;
            degree += 1;
            var dip:Number = depression*Math.sin(degree*radian);
            camera.x = radius*Math.cos(angle*radian)*Math.cos(dip*radian);
            camera.y = radius*Math.sin(dip*radian);
            camera.z = radius*Math.sin(angle*radian)*Math.cos(dip*radian);
            camera.lookAt(center);
            view.render();
            //view.renderer.queueSnapshot(source);
        }
        
    }

}