package {
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.objects.DisplayObject3D;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;
import org.papervision3d.core.proto.DisplayObjectContainer3D;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.materials.VideoStreamMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.objects.parsers.Collada;
[SWF(width=700,height=700,frameRate=30,backgroundColor=0x0)]
public class SimpleVideo extends PV3DARApp {
private static const PATTERN_FILE:String = "resources/vni_marker.pat";
private static const CAMERA_FILE:String = "resources/camera_para.dat";
protected var plane:Plane;
protected var objectsContainer:DisplayObject3D;
protected var quality:uint = 16;
protected var netConnection:NetConnection;
protected var video:Video;
protected var netStream:NetStream;
protected var cube:Cube;
protected var imageMat:BitmapFileMaterial;
protected var video_cube:Cube;
protected var vni_logo_cube:Collada;
protected var videoMat:VideoStreamMaterial;
protected var fmat:FlatShadeMaterial;
protected var wmat:WireframeMaterial;
public function SimpleVideo()
{
addEventListener(Event.INIT, onInit);
init(CAMERA_FILE, PATTERN_FILE);
}
private function onInit(e:Event):void
{
removeEventListener(Event.INIT, onInit);
//Create light source for shade material
var light:PointLight3D = new PointLight3D();
light.x = 1000;
light.y = 1000;
light.z = 1000;
// create client for netStream object
var customClient:Object = new Object();
customClient.onMetaData = metaDataHandler;
netConnection = new NetConnection();
netConnection.connect(null);
netStream = new NetStream(netConnection);
netStream.client = customClient;
netStream.play("resources/minicoca.flv");
// add listener for net status to control video looping
netStream.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
video = new Video();
video.width = 500;
video.height = 500;
video.smoothing = true;
//video.deblocking = 5;
video.attachNetStream(netStream);
//Create Materials
videoMat = new VideoStreamMaterial(video, netStream, true, true);
fmat = new FlatShadeMaterial(light, 0x214fa1, 0x18347b);
wmat = new WireframeMaterial(0xff0000);
wmat.doubleSided = true;
//Create objects
objectsContainer = new DisplayObject3D();
plane = new Plane(wmat, 100, 100,1,1);
video_cube = new Cube(new MaterialsList( { front: videoMat } ), 250, 1, 250, quality, quality, quality, 0);
vni_logo_cube = new Collada("", new MaterialsList ( {all : fmat } ), .1, true);
//Position elements
vni_logo_cube.z = 0;
//vni_logo_cube.rotationZ = -90;
//video_cube.rotationZ = -90;
video_cube.x = -40;
video_cube.z += 30;
video_cube.y = -50;
objectsContainer.z = 0;
//Add objects to my container
objectsContainer.addChild(vni_logo_cube)
objectsContainer.addChild(video_cube)
//Add to base
//_baseNode.addChild(plane);
_baseNode.addChild(objectsContainer);
}
override protected function _onEnterFrame(e:Event = null):void
{
super._onEnterFrame(e);
}
private function metaDataHandler(infoObject:Object):void
{
trace('metaDataHandler= ',infoObject);
}
private function statusHandler(eventObject:Object):void
{
if(eventObject.info.code == "NetStream.Play.Stop")
{
// loop video
netStream.seek(0);
}
}
}
}