Papervision3D Collada Parser Example


/ Published in: ActionScript 3
Save to your folder(s)

Easy little Collada parser I found online somewhere.


Copy this code and paste it in your HTML
  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. }

URL: http://www.destroyyourcomputer.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.