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

PV3DText3DFogEffect

package
{		
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;	
	import flash.events.MouseEvent;
	import flash.filters.BlurFilter;
	import flash.filters.ColorMatrixFilter;
	import caurina.transitions.Tweener;	
	import org.papervision3d.objects.DisplayObject3D;		
	import org.papervision3d.cameras.CameraType;	
	import org.papervision3d.materials.special.Letter3DMaterial;	
	import org.papervision3d.typography.fonts.HelveticaMedium;
	import org.papervision3d.typography.Text3D;	
	import org.papervision3d.view.BasicView;
        [SWF(width = "500", height = "500", frameRate = "41", backgroundColor = "#ffffff", pageTitle = "milkmidi.com")]
	public class Text3DDemo2 extends MovieClip
	{			
		private var view:BasicView
		private var demoString	:String = " milkmidi.com";
		private var _letterArray:Array = demoString.split("");
		
		public function Text3DDemo2() {
			
			init3DEngine();			
			init3DObject();
			initObject();		
			randomLetter();
		}	
		
		private function init3DEngine():void{
			view = new BasicView(0, 0, true, true, CameraType.TARGET);								
			view.camera.focus     = 550;
			view.camera.zoom      = 1;
			view.camera.x         = 0;
			view.camera.y         = 0;
			view.camera.z         = -1000;
			this.addChild(view);
			this.addEventListener(Event.ENTER_FRAME, onRender3D);
		}
		private function initObject():void {			
			stage.addEventListener(MouseEvent.CLICK, stageClickHandler);			
		}		
		private function stageClickHandler(e:MouseEvent):void {			
			randomLetter();
		}
		private function init3DObject():void {			
			var _letterMat : Letter3DMaterial = new Letter3DMaterial(0x00, 1 );
			//Text3D文字物件, 需要的材質為Letter3DMaterial
			//new Letter3DMaterial(色碼:uint,alpha值:Number);			
			
			for (var i:int = 0; i < _letterArray.length; i++) {				
				//var _text3D:Text3D = new  Text3D(String.fromCharCode(i + 65), new HelveticaMedium(), _letterMat);
				var _text3D:Text3D = new  Text3D(_letterArray[i], new HelveticaMedium(), _letterMat);
				//new Text3D(文字:String ,  字型   , 材質  )
				//Text3D是繼承DisplayObject3D, 所以擁有其全的的屬性和方法。
				_text3D.name = "letter" + i;		
				_text3D.useOwnContainer = true;
				view.scene.addChild(_text3D);				
			}			
		}		
		private function randomLetter():void {
			for (var i:int = 0; i < _letterArray.length; i++) {	
				var _text3D:Text3D = view.scene.getChildByName("letter" + i) as Text3D;
				Tweener.addTween(_text3D, 
				{
						time	:1.5,
						delay	:i*0.01,
						x		: randomNumber( -400, 400),
						y		: randomNumber( -400, 400),
						z		: randomNumber( -400, 400),
						rotationX : randomNumber( -360, 360),
						rotationY : randomNumber( -360, 360),
						rotationZ : randomNumber( -360, 360),
						onComplete		: onTweenerComplete,
						onCompleteParams: [_text3D,i]
				} );
			}
		}
		private function onTweenerComplete(pTxt3D:Text3D, pIndex:int):void {
			var _offsetX:int = 60;
			Tweener.addTween(pTxt3D, 
			{
				x	:pIndex * _offsetX - (_letterArray.length * _offsetX/2),
				y	:0,
				z	:0,				
				rotationX:0,
				rotationY:0,
				rotationZ:0,
				time:1,
				transition:"easeOutExpo"				
			});
		}
		private function randomNumber(pMin:Number, pMax:Number):int	{				
			return Math.random() * (pMax - pMin) + pMin ;			
		}	
		private function calcPointDistanceFromCamera(obj:DisplayObject3D):Number {
			var vecX:Number = obj.sceneX - view.camera.x;
			var vecY:Number = obj.sceneY - view.camera.y;
			var vecZ:Number = obj.sceneZ - view.camera.z;
			return Math.sqrt((vecX * vecX) + (vecY * vecY) + (vecZ * vecZ));
		}
		private function onRender3D(e:Event):void {			
			for (var i:int = 0; i < _letterArray.length; i++) {	
				var _text3D		:Text3D = view.scene.getChildByName("letter" + i) as Text3D;
				var _deg		:Number = Math.abs(calcPointDistanceFromCamera(_text3D) -view. camera.focus);					
				var _blurVal	:int = Math.min(16, _deg * .008 );								
				var _blurFilter	:BlurFilter = new BlurFilter(_blurVal, _blurVal, 1);								
				
				var _blightness		:Number = _deg / 6;
				var _blightnessArr	:Array =
				[
					1, 0, 0, 0, _blightness,
					0, 1, 0, 0, _blightness,
					0, 0, 1, 0, _blightness,
					0, 0, 0, 1, 0
				];
				var _blightnessFilter:ColorMatrixFilter = new ColorMatrixFilter(_blightnessArr);				
				_text3D.filters = [_blurFilter, _blightnessFilter];				
			}
			view.camera.x = stage.mouseX - stage.stageWidth/2;
			view.camera.y = stage.mouseY - stage.stageHeight / 2;
			view.singleRender();
		} 
		
	}
}