摄像头视频的粒子化

三维粒子 everyinch 1756℃ 0评论
package{
	import flash.events.Event;
	import flash.media.Camera;
	import flash.media.Video;
	import flash.net.NetConnection;
	import flash.net.NetStream;

	import org.papervision3d.core.effects.utils.BitmapClearMode;
	import org.papervision3d.core.geom.Pixels;
	import org.papervision3d.core.geom.renderables.Pixel3D;
	import org.papervision3d.materials.VideoStreamMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.view.layer.BitmapEffectLayer;
	import org.papervision3d.cameras.CameraType;

	[SWF(width="800", height="600", frameRate="31",backgroundColor="0x000000")]
	public class Pixel3DWebCam extends BasicView{
		private var video:Video;
		private var stream:NetStream
		private var pixels:Pixels;
		private var pixelArray:Array=new Array();
		private var material:VideoStreamMaterial;
		private var container:DisplayObject3D=new DisplayObject3D();

		public function Pixel3DWebCam(){
			super(800, 600, true, true,CameraType.FREE);
			init3D();
			startRendering();
		}

		private function init3D():void{
			camera.z=-300;
			camera.x=50;

			var nc:NetConnection = new NetConnection();
			nc.connect(null);
			stream = new NetStream(nc);
			stream.client=new Object();

			video=new Video(320,240);
			var cam:Camera=Camera.getCamera();
			cam.setMode(320,240,15);
			video.attachCamera(cam);

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

		private function createPixels():void{
			material=new VideoStreamMaterial(video,stream);
			material.animated=true;
			material.allowAutoResize=true;
			material.interactive=true;
			material.smooth=true;
			material.doubleSided=true;

			for(var w:int=0;w> 16 & 0xff;
					var green:uint=color >> 8 & 0xff;
					var blue:uint=color & 0xff;
					var zpos:Number=red+blue-green;

					var pixel:Pixel3D=new Pixel3D(color,(160-w),(120-h),zpos);
					pixels.addPixel3D(pixel);
					pixelArray.push(pixel);
				}
			}
			pixels.localRotationY=180;
			container.addChild(pixels);
			scene.addChild(container);

			var plane:Plane = new Plane(material,160,120,2,4);
			plane.x=pixels.x+280;
			plane.y=pixels.y;
			plane.z=pixels.z;
			scene.addChild(plane);
		}

		protected override function onRenderTick(event:Event=null):void{
			for(var i:int=0;i> 16 & 0xff;
				var green:uint=color >> 8 & 0xff;
				var blue:uint=color & 0xff;
				var distance:Number=Math.sqrt(red*red+green*green+blue*blue);
				pixel.color=color;
				pixel.z=distance*0.1;
			}
			//container.localRotationY=viewport.containerSprite.mouseX / 2;
			super.onRenderTick(event);
		}
	}
}



转载请注明:陈童的博客 » 摄像头视频的粒子化

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

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

无觅相关文章插件,快速提升流量