DAE Parser

What is a DAE file?

Yes, I know I just explained that Collada uses DAE. Well the DAE parser also loads Collada files. Just a different version (v. 1.4.1). These are good files to use if you would like to import assets that include animations.

DAE Parsing Example

  1. package {
  2.  import flash.events.Event;
  3.  import org.papervision3d.lights.PointLight3D;
  4.  import org.papervision3d.materials.shadematerials.GouraudMaterial;
  5.  import org.papervision3d.materials.utils.MaterialsList;
  6.  import org.papervision3d.objects.parsers.DAE;
  7.  import org.papervision3d.view.BasicView;
  8.  
  9.  public class DaeParser_v1 extends BasicView {
  10.   // create a class-level var for the collada scene
  11.   private var _dae:DAE;
  12.   // create the light
  13.   private var _light:PointLight3D;
  14.  
  15.   public function DaeParser_v1() {
  16.    lights();
  17.    init3d();
  18.   }
  19.  
  20.   private function lights():void {
  21.    // create the light to the scene
  22.    _light = new PointLight3D(true, true);
  23.    // place it in the same position as the camera (0, 0, -1000);
  24.    _light.copyPosition(camera);
  25.   }
  26.  
  27.   private function init3d():void {
  28.    // create a materials list and add the wireframe material
  29.    var knotMaterialsList:MaterialsList = new MaterialsList();
  30.    // we are now going to use a gouraud material for shading
  31.    var knotMaterial:GouraudMaterial = new GouraudMaterial(_light);
  32.    knotMaterialsList.addMaterial(knotMaterial, "all");
  33.    // instantiate the DAE obj and load the knot object
  34.    // apply the material and scale to 0.05
  35.    _dae = new DAE();
  36.    _dae.load("assets/knot2.dae", knotMaterialsList);
  37.    _dae.scale = 5;
  38.    // add the DAE file to the scene
  39.    scene.addChild(_dae);
  40.    // start rendering (activated onRenderTick)
  41.    startRendering();
  42.   }
  43.  
  44.   override protected function onRenderTick(event:Event = null):void {
  45.    // rotate the object
  46.    _dae.yaw(1);
  47.    super.onRenderTick();
  48.   }
  49.  }
  50. }

Parsing a DAE file is much like parsing an Collada file. The only real difference is when certain properties have to be set. The constructor for the DAE file allows for different commands because this file is meant more for animated 3d objects (it takes autoplay, name, and loop).

To accommodate for this, I just left the constructor blank and set the scale. I also moved the loading until after the DAE parser object was instantiated.

  1. _dae = new DAE();
  2. _dae.load("assets/knot2.dae", knotMaterialsList);
  3. _dae.scale = 5;

Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Page 9