亮度在z值上排序的三维粒子图片

三维粒子 everyinch 3101℃ 0评论
package{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.events.MouseEvent;

	import org.papervision3d.core.effects.utils.BitmapClearMode;
	import org.papervision3d.core.geom.Pixels;
	import org.papervision3d.core.geom.renderables.Pixel3D;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.view.layer.BitmapEffectLayer;
	import org.papervision3d.view.layer.util.ViewportLayerSortMode;

	[SWF(width="800", height="600", frameRate="31",backgroundColor="0x000000")]
	public class Pixel3DTest4 extends BasicView{
		[Embed(source="assets/xuanya.jpg")]
		private var image:Class;

		private var pic:Bitmap;
		private var sampling:Number=1;
		private var spread:Number=1.33;
		private var originX:Number;
		private var originY:Number;
		private var sampleFuzzX:Number=0; 
		private var sampleFuzzY:Number=0;

		private var pixels:Pixels;
		private var isDown:Boolean;
		private var container:DisplayObject3D;

		public function Pixel3DTest4(){
			super(800, 600, true, true);
			var s:Bitmap = new image();
			addChild(s);
			init3D();
			startRendering();
		}

		private function init3D():void{
			camera.z=-200;

			var bfx:BitmapEffectLayer=new BitmapEffectLayer(viewport, 800, 600, true, 0, BitmapClearMode.CLEAR_POST, true, true);
			viewport.containerSprite.addLayer(bfx);
			bfx.sortMode=ViewportLayerSortMode.Z_SORT;
			pixels=new Pixels(bfx);
			createPixels();

			stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
		}

		private function createPixels():void{
			var bmp:Bitmap=new image();
			var bmpd:BitmapData=bmp.bitmapData;
			var width:Number=bmpd.width;
			var height:Number=bmpd.height;
			var originX:Number=width>>1;
			var originY:Number=height>>1;

			for(var i:int=0;i> 16 & 0xff;
					var green:uint=color >> 8 & 0xff;
					var blue:uint=color & 0xff;
					var zpos:Number=0.2126*red + 0.7152*green + 0.0722*blue;
					zpos = (zpos-128);
					var pixel:Pixel3D=new Pixel3D(0xFF000000|bmpd.getPixel32(i, j), spread*(xpos - originX), spread*(originY - ypos), zpos/2);
					pixels.addPixel3D(pixel);
				}
			}
			container=new DisplayObject3D();
			container.addChild(pixels)
			scene.addChild(container);
		}

		private function onMouseUp(event:MouseEvent):void{
			isDown=false;
		}

		private function onMouseDown(event:MouseEvent):void{
			isDown=true;
		}

		protected override function onRenderTick(event:Event=null):void{
			if(isDown){
				container.localRotationY=viewport.containerSprite.mouseX / 2;
				container.localRotationX=viewport.containerSprite.mouseY / 2;
			}
			super.onRenderTick(event);
		}
	}
}

分享&收藏

转载请注明:陈童的博客 » 亮度在z值上排序的三维粒子图片

喜欢 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
'; } if( dopt('d_footcode_b') ) echo dopt('d_footcode'); ?>