Guest
Public paste!

Hype/Papervision - ApplicationView class

By: a guest | Mar 29th, 2010 | Syntax: ActionScript 3 | Size: 3.35 KB | Hits: 914 | Expires: Never
Copy text to clipboard
  1. package com.almerblanklabs.view
  2. {
  3.         import __AS3__.vec.Vector;
  4.        
  5.         import com.greensock.OverwriteManager;
  6.         import com.greensock.TweenMax;
  7.         import com.greensock.easing.Elastic;
  8.         import com.greensock.plugins.MotionBlurPlugin;
  9.         import com.greensock.plugins.TweenPlugin;
  10.        
  11.         import flash.events.Event;
  12.        
  13.         import org.papervision3d.core.geom.Particles;
  14.         import org.papervision3d.core.geom.renderables.Particle;
  15.         import org.papervision3d.core.geom.renderables.Vertex3D;
  16.         import org.papervision3d.materials.special.ParticleMaterial;
  17.         import org.papervision3d.objects.DisplayObject3D;
  18.         import org.papervision3d.objects.primitives.Sphere;
  19.         import org.papervision3d.view.BasicView;
  20.        
  21.         //import com.greensock.plugins.
  22.  
  23.         public class ApplicationView extends BasicView
  24.         {
  25.                 private var _object3D : DisplayObject3D;
  26.                 private var _origVertices : Vector.<Object>;
  27.                 private var _displayObj : DisplayObject3D;
  28.                 private var _satellites : Vector.<Particle>;
  29.                 private var _particles : Particles;
  30.                
  31.                 public function ApplicationView()
  32.                 {
  33.                         super(580, 580);       
  34.                         //TweenPlugin.activate([MotionBlurPlugin]);            
  35.                 }
  36.                
  37.                 override protected function onRenderTick(event:Event=null):void
  38.                 {
  39.                         super.onRenderTick();
  40.                 }
  41.                
  42.                 public function set object3D(aValue : DisplayObject3D):void
  43.                 {
  44.                         _object3D = aValue;
  45.                         _setObjectVertices();
  46.                 }
  47.                
  48.                 private function _setObjectVertices():void
  49.                 {
  50.                         _origVertices = new Vector.<Object>;
  51.                         for each(var vert : Vertex3D in _object3D.geometry.vertices)
  52.                         {
  53.                                 var vertObj : Object = {x:vert.x, y:vert.y, z:vert.z};
  54.                                 _origVertices.push(vertObj);
  55.                         }
  56.                        
  57.                         _initParticles();
  58.                 }
  59.                
  60.                 private function _initParticles():void
  61.                 {                      
  62.                         var material : ParticleMaterial = new ParticleMaterial(0xff0000, 1, ParticleMaterial.SHAPE_CIRCLE, 10);
  63.                        
  64.                         _satellites = new Vector.<Particle>();                 
  65.                         _particles = new Particles();                  
  66.                         _displayObj = new DisplayObject3D();
  67.                        
  68.                         scene.addChild(_particles);
  69.                         scene.addChild(_displayObj);
  70.                        
  71.                         _displayObj.addChild(_particles);
  72.                        
  73.                         for each(var vert : Vertex3D in _object3D.geometry.vertices)
  74.                         {                                      
  75.                                 var particle : Particle = new Particle(material);
  76.                                         particle.x = vert.x;
  77.                                         particle.y = vert.y;
  78.                                         particle.z = vert.z;
  79.                                        
  80.                                 _particles.addParticle(particle);
  81.                                
  82.                                 _satellites.push(particle);
  83.                         }
  84.                 }
  85.                
  86.                 public function moveParticles(aValue:Vector.<Number>):void
  87.                 {
  88.                                 var i : int = 0;
  89.                                 var j : int = 0;
  90.                                 var t : int = 0;
  91.                                
  92.                                 // This ensures even distribution among all vertices.
  93.                                 var divisor : Number = Math.floor(_satellites.length / 256);
  94.                                
  95.                                 for each (var sat : Particle in _satellites)
  96.                                 {
  97.                                         // The values used in the x,y,z calculations were achieved through trial and error...
  98.                                         TweenMax.to(_satellites[i], .2, {
  99.                                                                                                                 x: _origVertices[i].x * ((400 / aValue[i]) * 1.2),
  100.                                                                                                                 y: _origVertices[i].y * ((400 / aValue[i]) * 1.2),
  101.                                                                                                                 z: _origVertices[i].z * ((400 / aValue[i]) * 1.2),
  102.                                                                                                                 overwrite: OverwriteManager.PREEXISTING
  103.                                                                                                         } );
  104.                                        
  105.                                        
  106.                                         if (i < (_satellites.length - (divisor - 1))) {
  107.                                                 i += divisor;
  108.                                         }
  109.                                        
  110.                                        
  111.                                 }
  112.                                
  113.                        
  114.                         _displayObj.localRotationZ += .3;
  115.                         _displayObj.localRotationY += .1;                      
  116.                 }
  117.                
  118.                 private function _renderScene():void
  119.                 {
  120.                         renderer.renderScene(scene, camera, viewport);
  121.                 }
  122.         }
  123. }