Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package examples {
- import away3d.animators.Animator;
- import away3d.animators.BonesAnimator;
- import away3d.containers.ObjectContainer3D;
- import away3d.containers.Scene3D;
- import away3d.containers.View3D;
- import away3d.core.utils.Cast;
- import away3d.events.Loader3DEvent;
- import away3d.lights.DirectionalLight3D;
- import away3d.loaders.AbstractParser;
- import away3d.loaders.Collada;
- import away3d.loaders.Loader3D;
- import away3d.loaders.utils.AnimationLibrary;
- import away3d.materials.BitmapMaterial;
- import com.transmote.flar.FLARManager;
- import com.transmote.flar.camera.FLARCamera_Away3D;
- import com.transmote.flar.camera.FLARCamera_PV3D;
- import com.transmote.flar.marker.FLARMarker;
- import com.transmote.flar.marker.FLARMarkerEvent;
- import com.transmote.flar.tracker.FLARToolkitManager;
- import com.transmote.flar.utils.geom.AwayGeomUtils;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.geom.Rectangle;
- import flash.geom.Vector3D;
- import flash.utils.getTimer;
- import flash.utils.Timer;
- import flash.events.TimerEvent;
- import com.greensock.TweenLite;
- /**
- * FLARManager_Tutorial3D demonstrates how to display a Collada-formatted model
- * using FLARManager, FLARToolkit, and Away3D.
- * see the accompanying tutorial writeup here:
- * http://words.transmote.com/wp/flarmanager/inside-flarmanager/loading-collada-models/
- *
- * the collada model used for this example, mario_testrun.dae, comes from Away3D's examples.
- *
- * @author Eric Socolofsky
- * @url http://transmote.com/flar
- */
- public class FLARManagerCollada extends Sprite {
- private var flarManager:FLARManager;
- private var view:View3D;
- private var camera3D:FLARCamera_Away3D;
- private var scene3D:Scene3D;
- private var light:DirectionalLight3D;
- private var activeMarker:FLARMarker;
- private var modelLoader:Loader3D;
- private var modelContainer:ObjectContainer3D
- private var model:ObjectContainer3D
- private var model1:ObjectContainer3D
- private var model2:ObjectContainer3D
- private var model3:ObjectContainer3D
- private var modelAnimator:BonesAnimator;
- private var modelAnimator1:BonesAnimator;
- private var modelAnimator2:BonesAnimator;
- private var modelAnimator3:BonesAnimator;
- // texture and collada file for mario
- //[Embed(source="/../resources/assets/mario_tex.jpg")]
- private var Charmap:Class;
- [Embed(source="//../resources/assets/KecoaLowPoly2.dae",mimeType="application/octet-stream")]
- private var Kecoa:Class;
- public function FLARManagerCollada () {
- this.addEventListener(Event.ADDED_TO_STAGE, this.onAdded);
- }
- private function onAdded (evt:Event) :void {
- this.removeEventListener(Event.ADDED_TO_STAGE, this.onAdded);
- // pass the path to the FLARManager xml config file into the FLARManager constructor.
- // FLARManager creates and uses a FLARCameraSource by default.
- // the image from the first detected camera will be used for marker detection.
- // also pass an IFLARTrackerManager instance to communicate with a tracking library,
- // and a reference to the Stage (required by some trackers).
- this.flarManager = new FLARManager("../resources/flar/flarConfig.xml", new FLARToolkitManager(), this.stage);
- // to switch tracking engines, pass a different IFLARTrackerManager into FLARManager.
- // refer to this page for information on using different tracking engines:
- // http://words.transmote.com/wp/inside-flarmanager-tracking-engines/
- // this.flarManager = new FLARManager("../resources/flar/flarConfig.xml", new FlareManager(), this.stage);
- // this.flarManager = new FLARManager("../resources/flar/flarConfig.xml", new FlareNFTManager(), this.stage);
- // add FLARManager.flarSource to the display list to display the video capture.
- this.addChild(Sprite(this.flarManager.flarSource));
- // begin listening for FLARMarkerEvents.
- this.flarManager.addEventListener(FLARMarkerEvent.MARKER_ADDED, this.onMarkerAdded);
- this.flarManager.addEventListener(FLARMarkerEvent.MARKER_UPDATED, this.onMarkerUpdated);
- this.flarManager.addEventListener(FLARMarkerEvent.MARKER_REMOVED, this.onMarkerRemoved);
- // wait for FLARManager to initialize before setting up Away3D environment.
- this.flarManager.addEventListener(Event.INIT, this.onFlarManagerInited);
- }
- private function onFlarManagerInited (evt:Event) :void {
- this.flarManager.removeEventListener(Event.INIT, this.onFlarManagerInited);
- this.scene3D = new Scene3D();
- this.camera3D = new FLARCamera_Away3D(this.flarManager, new Rectangle(0, 0, this.stage.stageWidth, this.stage.stageHeight));
- this.view = new View3D({x:0.5*this.stage.stageWidth, y:0.5*this.stage.stageHeight, scene:this.scene3D, camera:this.camera3D});
- this.addChild(this.view);
- this.light = new DirectionalLight3D();
- this.light.direction = new Vector3D(500, -300, 200);
- this.scene3D.addLight(light);
- var collada:Collada = new Collada();
- collada.scaling = 1;
- model = collada.parseGeometry(Kecoa) as ObjectContainer3D;
- //model.materialLibrary.getMaterial("FF_FF_FF_mario1").material = new BitmapMaterial(Cast.bitmap(Charmap));
- model.mouseEnabled = false;
- model.rotationY = 180;
- model.rotationX = -90;
- model.x = 0;
- model.y = 0;
- model.z = 0;
- //this.modelAnimator = model.animationLibrary.getAnimation("default").animator as BonesAnimator;
- // create a container for the model, that will accept matrix transformations.
- this.modelContainer = new ObjectContainer3D();
- this.modelContainer.addChild(model);
- this.modelContainer.visible = false;
- this.scene3D.addChild(this.modelContainer);
- var collada1:Collada = new Collada();
- collada1.scaling = 1;
- model1 = collada1.parseGeometry(Kecoa) as ObjectContainer3D;
- //model1.materialLibrary.getMaterial("FF_FF_FF_mario1").material = new BitmapMaterial(Cast.bitmap(Charmap));
- model1.mouseEnabled = false;
- model1.rotationY = 180;
- model1.x = 0;
- model1.y = 100;
- model1.z = 0;
- //this.modelAnimator1 = model1.animationLibrary.getAnimation("default").animator as BonesAnimator;
- // create a container for the model, that will accept matrix transformations.
- this.modelContainer.addChild(model1);
- this.modelContainer.visible = false;
- this.scene3D.addChild(this.modelContainer);
- var collada2:Collada = new Collada();
- collada2.scaling = 1;
- model2 = collada2.parseGeometry(Kecoa) as ObjectContainer3D;
- //model2.materialLibrary.getMaterial("FF_FF_FF_mario1").material = new BitmapMaterial(Cast.bitmap(Charmap));
- model2.mouseEnabled = false;
- model2.rotationY = 180;
- model2.x = 0;
- model2.y = 200;
- model2.z = 0;
- //this.modelAnimator2 = model2.animationLibrary.getAnimation("default").animator as BonesAnimator;
- // create a container for the model, that will accept matrix transformations.
- this.modelContainer.addChild(model2);
- this.modelContainer.visible = false;
- this.scene3D.addChild(this.modelContainer);
- var collada3:Collada = new Collada();
- collada3.scaling = 1;
- model3 = collada3.parseGeometry(Kecoa) as ObjectContainer3D;
- //model3.materialLibrary.getMaterial("FF_FF_FF_mario1").material = new BitmapMaterial(Cast.bitmap(Charmap));
- model3.mouseEnabled = false;
- model3.rotationY = 180;
- model3.x = 0;
- model3.y = 0;
- model3.z = 0;
- //this.modelAnimator3 = model3.animationLibrary.getAnimation("default").animator as BonesAnimator;
- // create a container for the model, that will accept matrix transformations.
- this.modelContainer.addChild(model3);
- this.modelContainer.visible = false;
- this.scene3D.addChild(this.modelContainer);
- this.addEventListener(Event.ENTER_FRAME, this.onEnterFrame);
- }
- private function onMarkerAdded (evt:FLARMarkerEvent) :void {
- trace("["+evt.marker.patternId+"] added");
- this.modelContainer.visible = true;
- this.activeMarker = evt.marker;
- }
- private function onMarkerUpdated (evt:FLARMarkerEvent) :void {
- trace("["+evt.marker.patternId+"] updated");
- this.modelContainer.visible = true;
- this.activeMarker = evt.marker;
- }
- private function onMarkerRemoved (evt:FLARMarkerEvent) :void {
- trace("["+evt.marker.patternId+"] removed");
- this.modelContainer.visible = false;
- this.activeMarker = null;
- }
- private function onEnterFrame (evt:Event) :void {
- // apply the FLARToolkit transformation matrix to the Cube.
- if (this.activeMarker) {
- this.modelContainer.transform = AwayGeomUtils.convertMatrixToAwayMatrix(this.activeMarker.transformMatrix);
- model.y -= 10;
- }
- // update the animation and Away3D view.
- if (this.modelAnimator) {
- this.modelAnimator.update(getTimer() * .0005);
- this.modelAnimator1.update(getTimer() * .005);
- this.modelAnimator2.update(getTimer() * .005);
- this.modelAnimator3.update(getTimer() * .005);
- }
- this.view.render();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement