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

[Alternativa3D] Change Material Demo

Get Adobe Flash player
by clockmaker 19 Oct 2010
/**
 * Copyright clockmaker ( http://wonderfl.net/user/clockmaker )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/eMM6
 */

package {
    import alternativ5.engine3d.controllers.*;
    import alternativ5.engine3d.core.*;
    import alternativ5.engine3d.display.*;
    import alternativ5.engine3d.loaders.*;
    import alternativ5.engine3d.materials.*;
    import alternativ5.engine3d.primitives.*;
    import alternativ5.types.*;
    import alternativ5.utils.*;

    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.net.*;
    import flash.utils.*;

    [SWF(width=465, height=465, frameRate=60)]
    public class Main extends Sprite {
        // 3d
        private var scene:Scene3D;
        private var view:View;
        private var camera:Camera3D;

        // myitem
        private var _material:TextureMaterial;
        private var _cube:Box;
        private var _bmpData:BitmapData;
        private const BMP_ARRAY:Array = [
            new BitmapData(100, 100, false, 0xFFFF0000),
            new BitmapData(100, 100, false, 0xFF0000FF),
            new BitmapData(100, 100, false, 0xFF00FF00),
            ];
        private var index:int = 0;


        public function Main() {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            stage.quality = StageQuality.HIGH;

            // Creating scene
            scene = new Scene3D();
            scene.splitAnalysis = false; // ポリゴン交差問題の分析のon/off設定
            scene.root = new Object3D();

            _material = new TextureMaterial(
                new Texture(BMP_ARRAY[index]),
                1, true, true, "normal", 1, 0x0, TextureMaterialPrecision.VERY_LOW);

            _cube = new Box(500, 500, 500, 4, 4, 4);
            _cube.cloneMaterialToAllSurfaces(_material);
            scene.root.addChild(_cube);

            // Adding camera
            camera = new Camera3D();
            camera.z = -1000;
            scene.root.addChild(camera);

            // set view
            view = new View();
            view.camera = camera;
            addChild(view);

            // FPS display launch
            FPS.init(stage);

            // mouse interactive
            addEventListener(Event.ENTER_FRAME, loop);

            // resize
            stage.addEventListener(Event.RESIZE, onResize);
            onResize(null);

            // clock
            stage.addEventListener(MouseEvent.CLICK, atClick);
        }


        private function loop(e:Event):void {
            _cube.rotationY += 1 * Math.PI / 180;
            _cube.rotationX += 1 * Math.PI / 180;
            singleRender(null);
        }

        private function singleRender(e:Event):void {
            // Scene calculating
            scene.calculate();
        }

        /**
         * Resize Handler
         */
        private function onResize(e:Event):void {
            view.width = stage.stageWidth;
            view.height = stage.stageHeight;
        }

        /**
         * Mouse Interactive
         */
        public function atClick(e:Event):void {
            index++;
            if (index == BMP_ARRAY.length)
                index = 0;

            _material.texture = new Texture(BMP_ARRAY[index]);
            _cube.cloneMaterialToAllSurfaces(_material);
        }
    }
}