Posted By

level09 on 04/08/09


Tagged

template Flex papervision


Versions (?)

Who likes this?

9 people have marked this snippet as a favorite

liamr
gudeidea
uselessdreamer
toxin20
volvis
Akuma99
quan
iamgowan
AndyCatch


Papervision Base Template


 / Published in: ActionScript 3
 

  1. /**
  2. * ...
  3. * @author Luke Mitchell
  4. * @version 1.8.0
  5. */
  6.  
  7. package {
  8. // These lines make different 'pieces' available in your code.
  9. import flash.display.Sprite; // To extend this class
  10. import flash.events.Event; // To work out when a frame is entered.
  11. import org.papervision3d.core.proto.CameraObject3D;
  12.  
  13. import org.papervision3d.view.Viewport3D; // We need a viewport
  14. import org.papervision3d.cameras.*; // Import all types of camera
  15. import org.papervision3d.scenes.Scene3D; // We'll need at least one scene
  16. import org.papervision3d.render.BasicRenderEngine; // And we need a renderer
  17.  
  18. public class PaperBase extends Sprite { //Must be "extends Sprite"
  19.  
  20. public var viewport:Viewport3D; // The Viewport
  21. public var renderer:BasicRenderEngine; // Rendering engine
  22.  
  23. public var current_scene:Scene3D;
  24. public var current_camera:CameraObject3D;
  25. public var current_viewport:Viewport3D;
  26. // -- Scenes -- //
  27. public var default_scene:Scene3D; // A Scene
  28. // -- Cameras --//
  29. public var default_camera:Camera3D; // A Camera
  30.  
  31. public function init(vpWidth:Number = 800, vpHeight:Number = 600):void {
  32. initPapervision(vpWidth, vpHeight); // Initialise papervision
  33. init3d(); // Initialise the 3d stuff..
  34. init2d(); // Initialise the interface..
  35. initEvents(); // Set up any event listeners..
  36. }
  37.  
  38. protected function initPapervision(vpWidth:Number, vpHeight:Number):void {
  39. // Here is where we initialise everything we need to
  40. // render a papervision scene.
  41. if (vpWidth == 0) {
  42. viewport = new Viewport3D(stage.width, stage.height, true, true);
  43. }else{
  44. viewport = new Viewport3D(vpWidth, vpHeight, false, true);
  45. }
  46. // The viewport is the object added to the flash scene.
  47. // You 'look at' the papervision scene through the viewport
  48. // window, which is placed on the flash stage.
  49. addChild(viewport); // Add the viewport to the stage.
  50. // Initialise the rendering engine.
  51. renderer = new BasicRenderEngine();
  52. // -- Initialise the Scenes -- //
  53. default_scene = new Scene3D();
  54. // -- Initialise the Cameras -- //
  55. default_camera = new Camera3D();
  56.  
  57. current_camera = default_camera;
  58. current_scene = default_scene;
  59. current_viewport = viewport;
  60.  
  61. }
  62.  
  63. protected function init3d():void {
  64. // This function should hold all of the stages needed
  65. // to initialise everything used for papervision.
  66. // Models, materials, cameras etc.
  67. }
  68.  
  69. protected function init2d():void {
  70. // This function should create all of the 2d items
  71. // that will be overlayed on your papervision project.
  72. // User interfaces, Heads up displays etc.
  73. }
  74.  
  75. protected function initEvents():void {
  76. // This function makes the onFrame function get called for
  77. // every frame.
  78. addEventListener(Event.ENTER_FRAME, onEnterFrame);
  79. // This line of code makes the onEnterFrame function get
  80. // called when every frame is entered.
  81. }
  82.  
  83. protected function processFrame():void {
  84. // Process any movement or animation here.
  85. }
  86.  
  87. protected function onEnterFrame( ThisEvent:Event ):void {
  88. //We need to render the scene and update anything here.
  89. processFrame();
  90. renderer.renderScene(current_scene, current_camera, current_viewport);
  91. }
  92.  
  93. }
  94.  
  95. }

Report this snippet  

You need to login to post a comment.