Monday, 19 November 2012

VideoTexture with Away3D 4

I previously wrote a post on the VideoMaterial with Away3D 3.6 I will now write an update with Away3D 4. In Away3D 4, the creation of a Plane primitive is a little different to 3.6. The primitive objects are geometry creation tools rather than complete meshes like the 3.6 version.

package 
{

 import away3d.cameras.Camera3D;
 import away3d.containers.Scene3D;
 import away3d.containers.View3D;
 import away3d.entities.Mesh;
 import away3d.materials.ColorMaterial;
 import away3d.materials.TextureMaterial;
 import away3d.primitives.PlaneGeometry;
 import away3d.textures.VideoTexture;
 import flash.events.Event;
 import flash.text.TextField;
 import flash.display.*;
 
 [SWF(backgroundColor="#ffffff", frameRate="60", quality="HIGH", width="800", height="600")] 
  

 public class Main extends Sprite 
 {
  private static const VIDEO_URL:String = "vid.flv";
  
  private var scene:Scene3D;
  private var camera:Camera3D;
  private var view:View3D;

  private var planeMesh:Mesh; 
  
  public function Main():void 
  {
   stage.scaleMode = StageScaleMode.NO_SCALE;
   stage.align = StageAlign.TOP_LEFT;
   
   createView();
   createScene();
  }
  

  private function createView():void 
  {
   //setup away3D
   scene = new Scene3D();
   camera = new Camera3D();
   camera.z = -800;
  
   view = new View3D();
   view.scene = scene;
   view.camera = camera;
   view.backgroundColor = 0xffffff;
   view.antiAlias = 4; 
   addChild(view);
   
   addEventListener(Event.ENTER_FRAME, ef);
  }
  

  private function createScene():void 
  {
   //video texture
   var vt:VideoTexture = new VideoTexture(VIDEO_URL, 256, 256, true,true);
   var tm:TextureMaterial = new TextureMaterial(vt, true);
   
   //add plane
   var planeGeom:PlaneGeometry = new PlaneGeometry(640, 360, 1, 1, false, true);
   planeMesh = new Mesh(planeGeom, tm);
   scene.addChild(planeMesh);
  }
  

  private function ef(e:Event):void 
  {
   planeMesh.rotationY += 1;
   view.render();
  }

 }

}

0 comments:

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP