Using Papervision Object Parsers

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

package {
	import flash.events.Event;

	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.materials.shadematerials.GouraudMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.parsers.Collada;
	import org.papervision3d.view.BasicView;

	public class ColladaParser_v1 extends BasicView {
		// create a class-level var for the collada scene
		private var _collada:Collada;
		// create the light
		private var _light:PointLight3D;

		public function ColladaParser_v1() {
			lights();
			init3d();
		}

		private function lights():void {
			// create the light to the scene
			_light = new PointLight3D(true, true);
			// place it in the same position as the camera (0, 0, -1000);
			_light.copyPosition(camera);
		}

		private function init3d():void {
			// create a materials list and add the wireframe material
			var knotMaterialsList:MaterialsList = new MaterialsList();
			// we are now going to use a gouraud material for shading
			var knotMaterial:GouraudMaterial = new GouraudMaterial(_light);
			knotMaterialsList.addMaterial(knotMaterial, "all");
			// instantiate the collada obj and load the knot object
			// apply the material and scale to 0.05
			_collada = new Collada("assets/knot.DAE", knotMaterialsList, 0.05);
			// add the collada file to the scene
			scene.addChild(_collada);
			// start rendering (activated onRenderTick)
			startRendering();
		}

		override protected function onRenderTick(event:Event = null):void {
			// rotate the object
			_collada.yaw(2);
			super.onRenderTick();
		}
	}
}

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.

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

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *