11 flv作为材质

使用视频作为材质贴图,需要用到VideoStreamMaterial类。下面代码是使用VideoStreamMaterial类生成视频材质。

package  
{
	import flash.events.Event;
	import flash.media.Video;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	import org.papervision3d.materials.VideoStreamMaterial;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
	/**
	 * ...
	 * @author hellopv3d
	 */
	public class MyVideoDemo extends BasicView
	{
		
		private var plane:Plane;
		
		public function MyVideoDemo() 
		{
			//准备材质
			var video:Video = new Video(640, 480);//创建一台电视机
			
			var conn:NetConnection = new NetConnection();//创建连接
			conn.connect(null);//调用本地视频,因此设置为null
			
			//创建流(传输线路)
			var stream:NetStream = new NetStream(conn);
			
			stream.client = new Object();//设置流的回调方法
			
			stream.play("../assets/rabbit.flv");
			
			video.attachNetStream(stream);
			
			//依据视频创建材质
			var m:VideoStreamMaterial = new VideoStreamMaterial(video, stream);
			
			plane = new Plane(m);
			scene.addChild(plane);
			
			camera.z = -500;
			
			startRendering();			
		}
		
		override protected function onRenderTick(e:Event = null):void {
			super.onRenderTick();
			
		}
		
	}

}

其运行原理可参看下图:




你可能感兴趣的:(function,Stream,video,null,import,flv)