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

Ginny Effect 3D - DisplayObject3D Editionを火狐にしてみた。

Ginny Effect 3D
* 
* Photo by 
* http://www.flickr.com/photos/28791486@N03/2762581747/
/**
 * Copyright paq ( http://wonderfl.net/user/paq )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/r2ej
 */

// forked from AtuyL's forked from: Ginny Effect 3D - DisplayObject3D Edition
// forked from clockmaker's Ginny Effect 3D
/**
 * Ginny Effect 3D
 * 
 * Photo by 
 * http://www.flickr.com/photos/28791486@N03/2762581747/
 */
package {
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
	import flash.utils.*;
	import org.libspark.betweenas3.BetweenAS3;
	import org.libspark.betweenas3.easing.*;
	import org.libspark.betweenas3.tweens.ITween;
	import org.papervision3d.core.geom.renderables.Vertex3D;
	import org.papervision3d.core.utils.Mouse3D;
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.render.QuadrantRenderEngine;
	import org.papervision3d.view.BasicView;
	import com.bit101.components.*;
	
	[SWF(frameRate = 60)]
	public class Main extends BasicView {
			
		private const IMAGE_URL:String = "http://farm4.static.flickr.com/3134/2762581747_f58aa3dcff_b.jpg";
		private const RADIUS:Number = 200;
		private const SEGMENTSW:int = 8;
		private const SEGMENTSH:int = 8;
		private var loader:Loader;
		private var isHide:Boolean = false;
		private var isShift:Boolean = false;
		private var obj3d:DisplayObject3D;
        private var floorPlane:Plane;
		
		public function Main():void {
			// init
			super(0, 0, true, true);
			stage.quality = StageQuality.MEDIUM;
			viewport.opaqueBackground = 0x0;
			Mouse3D.enabled = true;
			
			Wonderfl.capture_delay( 10 );
			new Label(this, 360, 440, "PLEASE CLICK STAGE")

			//renderer = new QuadrantRenderEngine(QuadrantRenderEngine.CORRECT_Z_FILTER);
			
			// load
			var context:LoaderContext = new LoaderContext(true);
			loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, compHandler);
			loader.load(new URLRequest(IMAGE_URL), context);
		}
		
		public var planePosition:Vector.<Number>;
		public var planeNormal:Vector.<Number>;
		public var defaultVertices:Array;
		private function compHandler(e:Event):void {
            var material:BitmapMaterial = new BitmapMaterial(Bitmap(loader.content).bitmapData);
			obj3d = new Sphere(material, RADIUS, SEGMENTSW, SEGMENTSH);
			obj3d.y = RADIUS;
			scene.addChild(obj3d);
			
			//デフォルトの頂点位置を記録
			defaultVertices = [];
			var length:uint = obj3d.geometry.vertices.length;
			for (var i:int = 0; i < length; i++) {
				var v:Vertex3D = obj3d.geometry.vertices[i];
				defaultVertices[i] = {
					x:v.x,
					y:v.y,
					z:v.z
				}
			}
			
            // タイルの作り方はrectさんのを参考
            var bmd:BitmapData = new BitmapData(2, 2, false);
            bmd.setPixel(0, 0, 0xDDDDDD);
            bmd.setPixel(0, 1, 0x333333);
            bmd.setPixel(1, 0, 0x333333);
            bmd.setPixel(1, 1, 0xDDDDDD);
            
            var floorMat:BitmapMaterial = new BitmapMaterial(bmd, true);
            floorMat.tiled = true;
            floorMat.maxU = 10, floorMat.maxV = 10;
            floorMat.interactive = true;
			
            floorPlane = new Plane(floorMat, 1000, 1000, 5, 5);
            scene.addChild(floorPlane);
            floorPlane.rotationX = 90;
            floorPlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, clickHandler);
			
			addEventListener(Event.ENTER_FRAME, draw);
			stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
			startRendering();
		}
		
        private function clickHandler(e:InteractiveScene3DEvent):void {
            var mx:Number = viewport.interactiveSceneManager.mouse3D.x;
            var my:Number = viewport.interactiveSceneManager.mouse3D.y - RADIUS;//SphereをRADIUS分浮かしているため。
            var mz:Number = viewport.interactiveSceneManager.mouse3D.z;
			
			var tweens:Array = [];
			var distance:Number;
			
			var length:uint = defaultVertices.length;
			for (var i:int = 0; i < length; i++) {
				var v:Object = defaultVertices[i];//記憶しておいた初期位置を取得
				
				//初期位置とクリック位置の距離を算出
				distance = Math.sqrt((mx - v.x) * (mx - v.x) + (my - v.y) * (my - v.y) + (mz - v.z) * (mz - v.z));
				
				tweens.push(
					BetweenAS3.delay(
						BetweenAS3.tween(obj3d.geometry.vertices[i], {
							x : mx,
							y : my,
							z : mz
						},{
							x : v.x,
							y : v.y,
							z : v.z
						}, 1, Cubic.easeIn),
						distance / RADIUS
					)
				);
			}
			
			var itw:ITween = BetweenAS3.parallelTweens(tweens);
			if (isHide) itw = BetweenAS3.reverse(itw);
			if (isShift) itw = BetweenAS3.scale(itw, 5);
			itw.play();
			
			isHide = !isHide;
		}
		
		private function draw(e:Event = null):void {
			// 角度に応じてカメラの位置を設定
			camera.x = 1000 * Math.sin(getTimer() / 3000);
			camera.y = 500 * Math.sin(getTimer() / 2500) + 800;
			camera.z = 500;
		}
		
		/**
		 * Shiftキーを押してるとスローモーションになる
		 * macの挙動と同じように
		 */
		private function keyUpHandler(e:KeyboardEvent):void {
			if(e.keyCode == 16) isShift = false;
		}
		
		private function keyDownHandler(e:KeyboardEvent):void {
			if(e.keyCode == 16) isShift = true;
		}
	}
}