Test
...
@author ish-xxxx
package {
import flash.display.Sprite;
import flash.events.Event;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.lights.PointLight3D;
import net.hires.debug.Stats;
/**
* ...
* @author ish-xxxx
*/
[SWF(backgroundColor="0x121212")]
public class App extends Sprite {
private var v:Viewport3D, r:BasicRenderEngine, s:Scene3D, l:PointLight3D, world:DisplayObject3D, camera:Camera3D;
private var container:Sprite;
private var arr:Array = [];
public function App() {
container = addChild( new Sprite ) as Sprite;
v = container.addChild( new Viewport3D( 0, 0, true, true ) ) as Viewport3D;
l = new PointLight3D;
r = new BasicRenderEngine;
s = new Scene3D;
world = s.addChild( new DisplayObject3D ) as DisplayObject3D;
camera = new Camera3D;
var __len:uint = 100;
while ( __len-- ) {
var p:Particle = world.addChild( new Particle( l ) ) as Particle;
p.name = "p" + String( __len );
arr.push(p);
}
addEventListener( Event.ENTER_FRAME, render );
addChild( new Stats );
}
private function render( ev:Event ) : void {
var __len:uint = arr.length;
while ( __len-- ) {
var p:Particle = arr[__len] as Particle;
p.fall();
}
world.rotationY += ( ( mouseX - 225 ) - world.rotationY ) / 8;
r.renderScene( s, camera, v );
}
}
}
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Sphere;
internal class Particle extends DisplayObject3D {
private var s:Sphere;
private var _sp:Number = Math.max( 2, Math.random() * 10 );
private var m:FlatShadeMaterial;
public function Particle( __light:PointLight3D ) {
m = new FlatShadeMaterial( __light, 0xFFFFFF | 0, 0x121212 | 0 );
s = addChild( new Sphere( m, Math.max( 5, Math.random() * 50 ), 6, 6 ) ) as Sphere;
s.y = Math.max( 1000, Math.random() * 1300 );
s.x = Math.random() * 1000 - Math.random() * 1000;
s.z = Math.random() * 1000 - Math.random() * 1000;
}
public function fall() : void {
s.y -= _sp;
s.rotationX += _sp / 3;
s.rotationY += _sp / 5;
if ( s.y < -1000 ) {
s.y = 1000;
_sp = Math.max( 2, Math.random() * 10 );
}
}
}