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

Away3D [slime]

////////////////////////////////////////////////////////////////////////////////
// Away3D [slime]
//
// [Away3D] モデル (1)
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1762
//
// Colladaデータとテキスチャ
// @itoz師匠 ( http://wonderfl.net/user/romatica ) からいただきました。
////////////////////////////////////////////////////////////////////////////////
Get Adobe Flash player
by ProjectNya 26 Sep 2012
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/q4wf
 */

////////////////////////////////////////////////////////////////////////////////
// Away3D [slime]
//
// [Away3D] モデル (1)
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1762
//
// Colladaデータとテキスチャ
// @itoz師匠 ( http://wonderfl.net/user/romatica ) からいただきました。
////////////////////////////////////////////////////////////////////////////////

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.loaders.misc.AssetLoaderContext;
    import away3d.library.AssetLibrary;
    import away3d.library.assets.AssetType;
    import away3d.events.AssetEvent;
    import away3d.debug.AwayStats;

    [SWF(backgroundColor="#000000", 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 slime: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 = "slime/slime.dae";
        private static var imagePath:String = "slime/slime.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 = 0x000000;
            view.antiAlias = 4;
            //
            camera.x = 0;
            camera.y = 0;
            camera.z = - radius;
            //
            light.direction = new Vector3D(1, -1, 1);
            light.specular = 0.1;
            light.diffuse = 0.9;
            light.ambient = 0.3;
        }
        private function initialize():void {
            //Parsers.enableAllBundled();
            var context:AssetLoaderContext = new AssetLoaderContext();
            //context.mapUrlToData("slime.png", new ImageData());
            context.mapUrlToData(basePath + imagePath, "slime.png");
            AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, loaded, false, 0, true);
            var loader:Loader3D = new Loader3D();
            //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) {
                slime = ObjectContainer3D(evt.asset);
                slime.rotationX = 90;
                slime.rotationY = 90;
                slime.scale(84);
                slime.y = - 40;
                scene.addChild(slime);
            }
            if (evt.asset.assetType == AssetType.MATERIAL) {
                var material:TextureMaterial = TextureMaterial(evt.asset);
                var lightPicker:StaticLightPicker = new StaticLightPicker([light]);
                material.lightPicker = lightPicker;
                material.ambientColor = 0xFFFFFF;
            }
        }
        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);
        }
        
    }

}