daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.rimv.PV3DUtils
  2. {
  3.     import flash.display.*;
  4.     import flash.events.*;
  5.     import flash.utils.Timer;
  6.     import org.papervision3d.cameras.*;
  7.     import org.papervision3d.scenes.Scene3D;
  8.     import org.papervision3d.render.BasicRenderEngine;
  9.     import org.papervision3d.view.Viewport3D;
  10.     import org.papervision3d.objects.DisplayObject3D;
  11.    
  12.     public class PV3DEnvironment extends Sprite
  13.     {
  14.        
  15.         // pv3d parameters
  16.         private var _scene:Scene3D;
  17.         private var _viewport:Viewport3D;
  18.         private var _renderer:BasicRenderEngine;
  19.         private var _camera:Camera3D;
  20.        
  21.         // render manager
  22.         private var rManager:Timer;
  23.        
  24.         // get function
  25.         public function get scene():Scene3D
  26.         {
  27.             return _scene;
  28.         }
  29.        
  30.         public function get viewport():Viewport3D
  31.         {
  32.             return _viewport;
  33.         }
  34.        
  35.         public function get renderer():BasicRenderEngine
  36.         {
  37.             return _renderer;
  38.         }
  39.        
  40.         public function get camera():Camera3D
  41.         {
  42.             return _camera;
  43.         }
  44.        
  45.         // main
  46.         public function PV3DEnvironment(vWidth:Number = 640, vHeight:Number = 480, scaleToStage:Boolean = false, interactive:Boolean = true)
  47.         {
  48.             // initialize 3d parameters
  49.             _viewport = new Viewport3D(vWidth, vHeight, scaleToStage, interactive);
  50.             _scene = new Scene3D();
  51.             _renderer = new BasicRenderEngine();
  52.             _camera = new Camera3D(60);
  53.             _camera.target = DisplayObject3D.ZERO;
  54.             _camera.z = -(_camera.zoom * _camera.focus);
  55.            
  56.             // setup render manager
  57.             rManager = new Timer(1000, 1);
  58.             rManager.addEventListener(TimerEvent.TIMER_COMPLETE, stopRendering, false, 0, true);
  59.         }
  60.        
  61.         // render manager function
  62.        
  63.         public function renderManager(duration:Number):void
  64.         {
  65.             rManager.stop();
  66.             rManager.reset();
  67.             rManager.delay = duration * 1000;
  68.             startRendering();
  69.             rManager.start();
  70.         }
  71.                
  72.         public function startRendering():void
  73.         {
  74.             addEventListener(Event.ENTER_FRAME, rendering, false, 0, true);
  75.         }
  76.        
  77.         public function stopRendering(e:TimerEvent):void
  78.         {
  79.             removeEventListener(Event.ENTER_FRAME, rendering);
  80.         }
  81.        
  82.         private function rendering(e:Event):void
  83.         {
  84.             _renderer.renderScene(_scene, _camera, _viewport);
  85.         }
  86.        
  87.        
  88.        
  89.     }
  90.    
  91. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top