package
{
/**
* ...
* @author Ikarus / triple tecnologia
*/
// *** Declaracion de Librerias a Ser Utilizadas ***
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 com.transmote.utils.time.FramerateDisplay;
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;
// *** Parametros de Tamano, Altura, Fondo y Refrescamiento del Flash File a Desplegar ***
[SWF(width="640", height="480", backgroundColor="#000000", frameRate="40")]
// *** Clase Principal *** //
public class ChooseVideoAR extends Sprite
{
// *** Declaracion de Variables de Objetos Tipo Globales *** //
private var fm : FLARManager;
private var scene : Scene3D;
private var view : Viewport3D;
private var camera : FLARCamera3D;
private var lre : LazyRenderEngine;
private var p : Plane;
private var con : DisplayObject3D;
private var marker : FLARMarker;
private var v : Vid;
// *** Cuerpo Principal el Programa *** //
public function ChooseVideoAR()
{
// Inicializacion de Parametros del FLARManager
initFLAR();
// Instanciando el Objeto con la Libreria Externa Vid.swc
v = new Vid();
// Parametro de Ubicacion del Archivo de Video
//v.vid.source = "../mov/test.flv";
// Indicacion para que No Empiece a Reproducirse el Video Hasta que Este Totalmente Parametrizado
v.vid.stop();
}
// *** Inicializacion de Parametros del FLARManager ***
private function initFLAR() : void
{
// Invocacion del Archivo de Configuracion del FLARManager
fm = new FLARManager("../xml/flarConfig.xml");
// Comportamiento del Ambiente AR a Invocar el Pattern
fm.addEventListener(FLARMarkerEvent.MARKER_ADDED, onAdded);
// Comportamiento del Ambiente AR a Remover el Pattern
fm.addEventListener(FLARMarkerEvent.MARKER_REMOVED, onRemoved);
// Invocacion del Ambiente 3D a Efectuarse al Mover el Pattern Desde Cualquier Perspectiva
addChild(Sprite(fm.flarSource));
fm.addEventListener(Event.INIT, init3D);
}
// *** Comportamiento del Ambiente AR a Invocar el Pattern ***
private function onAdded(e:FLARMarkerEvent) : void
{
// Determinar el PatterID actual para evaluar y ejecutar la logica deseada en base a su seleccion con la estructura de control switch.
var patternID:String;
patternID = e.marker.patternId.toString();
trace(patternID);
switch(patternID)
{
case "0":
{
v.vid.source = "../mov/test.flv";
break;
}
case "1":
{
v.vid.source = "../mov/phone.flv";
break;
}
}
marker = e.marker;
p.visible = true;
v.vid.play();
}
// *** Comportamiento del Ambiente AR al Remover el Pattern ***
private function onRemoved(e:FLARMarkerEvent) : void
{
var patternID:String;
patternID = e.marker.patternId.toString();
trace(patternID);
marker = null;
p.visible = false;
v.vid.stop();
}
// *** Invocacion del Ambiente 3D a Efectuarse al Mover el Pattern Desde Cualquier Perspectiva ***
private function init3D(e:Event) : void
{
// Parametros para la Scene3D
scene = new Scene3D();
// Parametros para la Camera
camera = new FLARCamera3D(fm.cameraParams);
camera.z = -30;
// Parametros para el Point of View
view = new Viewport3D(640, 480, true);
// Parametros para el LazyRenderEngine
lre = new LazyRenderEngine(scene, camera, view);
// Parametros que Recubriran al Pattern con Respecto al Movie/Pelicula
var mat:MovieMaterial = new MovieMaterial(v, true, true);
p = new Plane(mat, 240, 320, 3, 3);
p.scaleY = -1;
p.rotationZ = 0;
p.visible = false;
// Despliegue en Consola o Pantalla del Video
con = new DisplayObject3D();
con.addChild(p);
scene.addChild(con);
addChild(view);
addChild(new FramerateDisplay());
// Mantenerse en un Loop Hasta que se Retire el Pattern
addEventListener(Event.ENTER_FRAME, loop);
}
// *** Proceso de Loop del Movie/Pelicula Mientras el Pattern Este Visible ***
private function loop(e:Event) : void
{
// Si el Marker/Pattern es Diferente de Nullo
if (marker != null)
{
con.transform = FLARPVGeomUtils.convertFLARMatrixToPVMatrix(marker.transformMatrix);
}
lre.render();
}
}
}