VideoStreamMaterial: http://www.sandy1219.com/3d/test1/TestVideoMat.html (视频文件较大,请等会)
但是有一个问题,旋转的时候视频好像是变形了。发生了扭曲.
<textarea cols="79" rows="15" name="code" class="c-sharp">package { import flash.events.Event; import flash.events.MouseEvent; import flash.geom.Point; import flash.media.SoundTransform; import flash.media.Video; import flash.net.NetConnection; import flash.net.NetStream; import org.papervision3d.events.InteractiveScene3DEvent; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.MovieMaterial; import org.papervision3d.materials.VideoStreamMaterial; import org.papervision3d.materials.shadematerials.FlatShadeMaterial; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.primitives.Cube; import org.papervision3d.view.BasicView; public class TestVideoMat extends BasicView { public function TestVideoMat() { super(800,800,true,true); init3D(); } private var video:Video; private var light:PointLight3D; private var objGroup:DisplayObject3D; private var stream:NetStream; private var cb:Cube ; private var prevPoint:Point = new Point(0,0); private var _yaw : Number; private var _pitch : Number; private var aim:DisplayObject3D; private function init3D():void { createVideo() createLight(); camera.zoom = 2; camera.focus = 500; // camera.fov = 20 stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); //stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler); //stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler); /* aim = DisplayObject3D.ZERO; camera.lookAt(aim) */ startRendering(); } override protected function onRenderTick(event:Event=null):void { cb.rotationY += 1; super.onRenderTick(event) } private function mouseDownHandler(evt:MouseEvent):void { prevPoint = new Point(evt.stageX, evt.stageY); stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler); } private function createVideo():void { var nc:NetConnection = new NetConnection(); nc.connect(null); stream = new NetStream(nc); stream.client = new Object(); video = new Video(); stream.play('dae/cg.flv'); video.attachNetStream(stream); var stf:SoundTransform = this.soundTransform; stf.volume = 0; } private function createLight():void { light = new PointLight3D(); light.x = 400 ; light.y = 1000 ; light.z = -400 ; objGroup = new DisplayObject3D(); var _videoMat:VideoStreamMaterial = new VideoStreamMaterial(video,stream,true,true); addProjector(_videoMat); } private function addProjector(_mat:MovieMaterial ):void { /* mat.tiled = true; _mat.maxU = 2; _mat.maxV = 2; */ //_mat.doubleSided = true; //_mat.allowAutoResize = false; _mat.smooth = true; _mat.interactive = true; /* _mat.allowAutoResize = true; _mat.opposite = true */ var _flat:FlatShadeMaterial = new FlatShadeMaterial(light); _flat.interactive = true; var _matList:MaterialsList = new MaterialsList(); _matList.addMaterial(_flat,'all'); _matList.addMaterial(_mat,'front'); _matList.addMaterial(_mat,'back'); cb = new Cube(_matList,320,20,200) cb.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK , clickHandle); //cb.flipLightDirection = true; //objGroup.addChild(cb); scene.addChild(cb); scene.addChild(light); /* var angle:Number = 0 * 120 - 180; var angleRadians:Number = angle * 2 * Math.PI / 360.; // position of projector var x:Number = Math.sin(angleRadians) * 300; var z:Number = Math.cos(angleRadians) * 300; // create tween to position, rotate and scale projector smoothly over 1 second Tweener.addTween( cb, {x:x, y:-150, z:z, rotationY:angle, scale:0.8, time:1, transition:"linear" } ); */ } private function clickHandle(e:InteractiveScene3DEvent):void { //trace( viewport.interactiveSceneManager.virtualMouse.x , viewport.interactiveSceneManager.virtualMouse.y ) } /* override protected function onRenderTick(event:Event = null):void { */ //camera.orbit(100, 100); //cb.rotationY ++; //camera.orbit(,lastMouseY) // camera.moveBackward(1) //camera.orbit(100,100, true); /* super.onRenderTick(event); } */ private function mouseUpHandler(evt : MouseEvent) : void { stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler); } private var cameraPitch:Number = 0; private var cameraYaw:Number = 0; private function mouseMoveHandler(evt : MouseEvent) : void { var dPitch:Number = (evt.stageY - prevPoint.y) / 2; var dYaw:Number = (evt.stageX - prevPoint.x) / 2; if(cameraPitch == 0 ) cameraPitch = evt.stageY; if(cameraYaw == 0 ) cameraYaw = evt.stageX ; cameraPitch -= dPitch; cameraYaw -= dYaw; /* if(cameraPitch <= 0) { cameraPitch = 0.1; } else if(cameraPitch >= 360) { cameraPitch = 359.9; } */ prevPoint.x = evt.stageX ; prevPoint.y = evt.stageY ; trace(cameraPitch,cameraYaw); camera.orbit(cameraPitch, cameraYaw); } } }</textarea>