package
{
import com.transmote.flar.FLARManager;
import com.transmote.flar.marker.FLARMarker;
import com.transmote.flar.marker.FLARMarkerEvent;
import com.transmote.flar.utils.geom.FLARPVGeomUtils;
import flash.display.Sprite;
import flash.events.Event;
import org.libspark.flartoolkit.support.pv3d.FLARCamera3D;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.render.LazyRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
public class multimarkervideo extends Sprite
{
private var fm:FLARManager;
private var vid1:Vid;
private var vid2:Vid;
private var container1:DisplayObject3D;
private var container2:DisplayObject3D;
private var activemarker1:FLARMarker;
private var scene:Scene3D;
private var viewport:Viewport3D;
private var p1:Plane;
private var p2:Plane;
private var lre:LazyRenderEngine;
private var camera:FLARCamera3D;
private var activemarker2:FLARMarker;
private var markerid:int;
public function multimarkervideo()
{
initflar();
vid2= new Vid();
vid2.vid.source="first_2.flv";
vid1= new Vid();
vid1.vid.source="kramer.m4v";
vid1.vid.stop();
vid2.vid.stop();
}
private function initflar():void
{
fm= new FLARManager("../resources/flar/flarConfig.xml");
fm.addEventListener(FLARMarkerEvent.MARKER_ADDED, onadd);
fm.addEventListener(FLARMarkerEvent.MARKER_REMOVED, onremove);
fm.addEventListener(Event.INIT, init3d);
}
private function onadd(e:FLARMarkerEvent):void
{
//trace("add");
if(e.marker.patternId==0)
{
markerAdded(0);
activemarker1=e.marker;
vid1.vid.play();
p1.visible=true;
}
if(e.marker.patternId==1)
{
markerAdded(1);
activemarker2=e.marker;
vid2.vid.play();
p2.visible=true;
}
}
private function onremove(e:FLARMarkerEvent):void
{
// trace("remove");
if(e.marker.patternId==0){
markerRemoved(0);
vid1.vid.stop();
p1.visible= false;
}
if(e.marker.patternId==1){
markerRemoved(1);
vid2.vid.stop();
p2.visible=false;
}
activemarker1=null;
activemarker2=null;
}
private function init3d(e:Event):void
{
//smua ini komponen kcuali mat
scene= new Scene3D();
//melewatkan parameter camera,jadi di attach flarmanagaer instance
camera= new FLARCamera3D(fm.cameraParams);
camera.z= -30;
viewport= new Viewport3D(640, 480, true);
lre= new LazyRenderEngine(scene, camera, viewport);
//video 1
var mat:MovieMaterial= new MovieMaterial(vid1, false, true);
p1= new Plane(mat, 320, 240, 2, 2);
p1.scaleY= -1;
p1.rotationZ=90;
p1.visible= false;
container1 = new DisplayObject3D();
container1.addChild(p1)
container1.visible=false;
scene.addChild(container1);
addChild(viewport);
//video 2
var mat1:MovieMaterial= new MovieMaterial(vid2, false, true);
p2= new Plane(mat, 320, 240, 2, 2);
p2.scaleY= -1;
p2.rotationZ=90;
p2.visible= false;
container2 = new DisplayObject3D();
container2.addChild(p2)
container2.visible=false;
scene.addChild(container2);
addChild(viewport);
addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(e:Event):void
{
if(activemarker1){
container1.transform=
FLARPVGeomUtils.convertFLARMatrixToPVMatrix(activemarker1.transformMatrix);
}
if(activemarker2) {
container2.transform=
FLARPVGeomUtils.convertFLARMatrixToPVMatrix(activemarker2.transformMatrix);
}
lre.render();
}
private function markerRemoved(markerid:int):void
{
var x:int = markerid;
switch(x)
{
case 1:
{
if(container1.visible==true)
{
container1.visible=false;
break;
}
else
break;
}
case 2:
{
if(container2.visible==true)
{
container2.visible=false;
break;
}
else
{
break;
}
}
}
}
private function markerAdded(markerid:int):void
{
trace(markerid);
var x:int = markerid;
switch(x)
{
case 1:
{
if(container1.visible==false)
{
container1.visible=true;
break;
}
else
break;
}
case 2:
{
if(container2.visible==false)
{
container2.visible=true;
break;
}
else
break;
}
}
}
} |