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

like Mountain

Get Adobe Flash player
by uly 07 Feb 2009
    Embed
package {
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.render.BasicRenderEngine;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.view.Viewport3D;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.materials.*;
    import org.papervision3d.materials.special.CompositeMaterial;

    public class FirstTest extends Sprite {
        private var _container:Sprite;
        private var _scene    :Scene3D;
        private var _viewport :Viewport3D;
        private var _camera   :Camera3D;
        private var _renderer :BasicRenderEngine;
        private var _floor    :Plane;
        private var _compoMat :CompositeMaterial;
        private var _txtCameraZ:TextField;
        private var _txtPlaneZ:TextField;
        private var _planeArray:Array=[];
        private var _planes:Array=[];
        [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="40")]   
        public function FirstTest () {
            // write as3 code here..
            init();
            
        }
        private function init():void{
            _renderer = new BasicRenderEngine();

            _scene = new Scene3D();
            _camera = new Camera3D();
            _camera.z =-300;
            _camera.focus = 1000;
            _camera.zoom = 0.8;
            _viewport = new Viewport3D(0,0,true);
            _viewport.viewportWidth = 60;
            _viewport.viewportHeight= 60;
            _viewport.y = 0;
            _viewport.opaqueBackground = 0x4bb0eb;

            addChild(_viewport);

               
            var colorMat:ColorMaterial = new ColorMaterial( 0x9ee94f, 1 );
            var wireMat:WireframeMaterial = new WireframeMaterial( 0x6eb718 );
            _compoMat= new CompositeMaterial();
            _compoMat.addMaterial(colorMat);
            _compoMat.addMaterial(wireMat);
            
            _floor = new Plane( _compoMat, 600, 600 , 6, 6);
            _scene.addChild(_floor);
            _floor.pitch(90);
            _floor.y = -stage.stageHeight/6;
            _planeArray.push(0);
            _planes.push(_floor);
            
            changeVertices(_floor);

            _txtCameraZ = new TextField();
            addChild(_txtCameraZ);
            _txtCameraZ.x = 15;
            _txtCameraZ.y = 15;

            _txtPlaneZ= new TextField();
            addChild(_txtPlaneZ);
            _txtPlaneZ.x = 15;
            _txtPlaneZ.y = 35;
            
            addEventListener(Event.ENTER_FRAME,update);
        }
        private function changeVertices(plane:Plane):void{
            var count:uint=0;
            for each(var obj_vartices:* in plane.geometry.vertices){
                
                if(count%2==0){
                    obj_vartices.x += (Math.random()-0.5)*20;
                    obj_vartices.y += (Math.random()-0.5)*50;
                    obj_vartices.z += (Math.random()-0.5)*100;
                }
                count++;
            }
        }
        private function update(e:Event):void{
            _camera.z +=2;
            if(_camera.z%250 == 0){
                //var cloneFloor:Plane = ;
                var f:Plane= new Plane( _compoMat, 600, 600 , 6, 6);
                f.z = _camera.z+700;
                _planeArray.push(f.z);
                f.pitch(90);
                f.y = -stage.stageHeight/6;
                 changeVertices(f);
                _scene.addChild(f);  
            }
           var res:* = inArray(_camera.z,_planeArray);
           if(res>0){
                _scene.removeChild(_planes[res]);  
           }
            
            _txtCameraZ.text = String(_camera.z);
            
            _renderer.renderScene(_scene,_camera,_viewport);
        }

    public function inArray ( val:* , ary:* ):int{
	var i:uint;
	for (i=0; i < ary.length; i++) {
		if (ary[i] === val) {
			return i;
		}
	}
	return -1;
    }

    
    }



}