Collada Parser

What is a Collada file?

Collada is an XML-based schema designed to be a standard universal 3D asset file. It was created to make transporting 3d assets between applications easier. Collada files have a .DAE (digital asset exchange) extension

Feeling Software (www.feelingsoftware.com) offers plug-ins that allow you to export these ASCollada files from a couple different 3d applications to make your life a little bit easier.

I recommend using Collada files for scenes that have any complexities. Unlike ASE files, Collada files can include a number of objects that you can load and manipulate.

Collada Parsing Example

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

You might notice a lot of similarities between the ASE parser and the Collada parser. Almost all of the parsers have very similar ways for loading their respective objects.

In this example, I created the lighting just as I did in the previous (ASE) file. But this time instead of loading just the GouraudMaterial and applying that to the Collada object, it had to be added to a MaterialsList in order to be accepted by the parser.

  1. var knotMaterialsList:MaterialsList = new MaterialsList();
  2. var knotMaterial:GouraudMaterial = new GouraudMaterial(_light);
  3. knotMaterialsList.addMaterial(knotMaterial, "all");

Loading the Collada object involved passing the path to the file, the MaterialsList, and the scale for the model.

  1. _collada = new Collada("assets/knot.DAE", knotMaterialsList, 0.05);

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