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

Papervision3D Cube

...
@author pixelDevil
/**
 * Copyright PixelDevil ( http://wonderfl.net/user/PixelDevil )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/bfkm
 */

package {
            /**
            * ...
            * @author pixelDevil
            */
        import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import org.papervision3d.cameras.Camera3D;
	import org.papervision3d.objects.*;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.scenes.Scene3D
	import org.papervision3d.view.Viewport3D;
	import org.papervision3d.objects.primitives.*;
	import org.papervision3d.materials.*;
	import org.papervision3d.events.*;
	import caurina.transitions.Tweener;
        import org.papervision3d.objects.primitives.Cube;
        import org.papervision3d.materials.*;
	 import org.papervision3d.materials.utils.MaterialsList;
        import flash.filters.BlurFilter;
        import flash.filters.ColorMatrixFilter;
        import flash.geom.Point;
        import flash.display.Bitmap;
        import flash.display.BitmapData;
        
        [SWF(width="500", height="500", backgroundColor= 0x000000, frameRate="24")]
        
    public class FlashTest extends Sprite {
        // item
	private var viewport:Viewport3D;
	private var scene:Scene3D;
	private var camera:Camera3D;
	private var renderer:BasicRenderEngine;
        private var cube:Cube;
	var matList:MaterialsList;

        //filters
        private var bmd:BitmapData = new BitmapData(550, 400, true, 0x00000);
        private var bm:Bitmap = new Bitmap (bmd);
        var bf:BlurFilter = new BlurFilter (8, 8, 1);
        var cmf:ColorMatrixFilter = new ColorMatrixFilter ([1, 0, 0, 0, 0,            // red
                                                            0, 1, 0, 0, 0,            // green
                                                            0, 0, 1, 0, 0,            // blue
                                                            0, 0, 0, 0.8, 0,]);       // alpha
        
        
// CONSTRUCTOR
        public function FlashTest() {
            init();
            stage.addEventListener( MouseEvent.MOUSE_WHEEL, mouseWheel ); 
        }
        private function init():void {
	
			initPapervision();
			initMaterials();
			initObjects();
			initListener();
                        addChild(bm);
		}

       private function initPapervision():void{

// CREAT VIEWPORT
			viewport = new Viewport3D(500, 500, false, true);
			addChild( viewport );

// CREAT 3D SCENE
			scene = new Scene3D();
			camera = new Camera3D();

// CREAT RENDER ENGINE
			renderer = new BasicRenderEngine();
		}
        private function initMaterials():void{
            
// CREAT ALL THE MATERIAL
		matList = new MaterialsList();
		matList.addMaterial (new ColorMaterial(0xd7084c), "all");
                matList.addMaterial (new ColorMaterial(0x880000), "right");
                matList.addMaterial (new ColorMaterial(0x880000), "left");
                matList.addMaterial (new ColorMaterial(0xbf0067), "top");
                matList.addMaterial (new ColorMaterial(0xbf0067), "bottom");
        }

// FUNCTION CREAT CUBE AND CAMERA
	private function initObjects():void {
		camera.zoom = 80;
		cube = new Cube(matList, 200, 200, 200, 8, 8, 8, 0, 0);
		scene.addChild(cube);
	}
// LISTENER ENTER_FRAME
        private function initListener():void {
                addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
// FUCTION MOUSE_WHEEL
		private function mouseWheel(e:MouseEvent):void {
			if (camera.zoom <= 120 && camera.zoom >= 15) {
				camera.zoom += e.delta / 2;
			}
			else if (camera.zoom <= 16) {
				camera.zoom += 1;
				
			}
			else if (camera.zoom >= 119) {
				camera.zoom -= 1;
				
			}
		}
// FUNCTION ENTER_FRAME TO MOVE CUBE AND APPLY FILTERS
        private function onEnterFrame(e:Event):void {
		renderer.renderScene( scene, camera, viewport );
		
                // rotation with mouseX and mouseY
		cube.yaw(-(mouseX - stage.stageWidth / 2) / 50);
		cube.pitch(-(mouseY - stage.stageHeight/2) / 50);
    
                // apply filters
                bmd.draw(this);
                bmd.applyFilter(bmd, bmd.rect, new Point (0, 0), bf);
                bmd.applyFilter(bmd, bmd.rect, new Point (0, 0), cmf);
                bmd.scroll(0, -5); // effect goes to top
	}
    }
}