2008/07/01 | [papervision3d2] 粒子系统(扩展)
类别(做生活) | 评论(1) | 阅读(1325) | 发表于 03:42


使用了基于 zeuslabs  papervision3d 的 Particle System for Papervision3D
代码如下:
package ex{
	import flash.display.Bitmap;
	import flash.display.BlendMode;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.filters.GlowFilter;
	import flash.geom.ColorTransform;
	import org.papervision3d.core.effects.utils.BitmapDrawCommand;
	import org.papervision3d.core.math.Number3D;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.view.Viewport3D;	
	import zeuslabs.particles.ParticleEvent;
	import zeuslabs.particles.ParticleSystem3D;
	import zeuslabs.particles.SimpleParticle3D;
	import org.papervision3d.view.layer.BitmapEffectLayer;
	import org.papervision3d.core.effects.BitmapLayerEffect;
	import org.papervision3d.cameras.Camera3D;
	import flash.display.StageScaleMode;

	public class Ex4 extends Sprite{
		private var r:BasicRenderEngine ;
		private var s:Scene3D ;
		private var v:Viewport3D ;		
		private var c:Camera3D;		
		private var pS:ParticleSystem3D;		
		private var bfx:BitmapEffectLayer;
		private var a:uint=0;
		private var k:uint=0;
		public function Ex4(){
			stage.scaleMode=StageScaleMode.NO_SCALE;
			v=new Viewport3D(400,400);
			addChild(v);
			v.filters=[new GlowFilter(0xffff00,.5,3,3,3,8)];			
			r=new BasicRenderEngine();			
			s=new Scene3D();			
			c=new Camera3D();		
			stage.addEventListener(Event.ENTER_FRAME, enterFrameHandle);
			pS= new ParticleSystem3D( this.stage);			
			pS.spawnRate = 8;
			pS.particleClass = SimpleParticle3D ;			
			pS.start();
			s.addChild(pS);
			bfx = new BitmapEffectLayer(v,400, 400);
			v.containerSprite.addLayer(bfx);
			bfx.addDisplayObject3D(pS);
			bfx.addEffect(new BitmapLayerEffect(new BlurFilter(5, 5, 4)));
			bfx.drawLayer.blendMode = BlendMode.OVERLAY;
			bfx.setScroll(0,-0.5);
			pS.addEventListener( ParticleEvent.INITIALIZE_PARTICLE, initializeParticle);
			pS.addEventListener(ParticleEvent.UPDATE_PARTICLE, updateParticle);	
		}
		
		public function enterFrameHandle( e:Event ):void{
			if (k<100){k++;}else{k=0}			
			if (a<360){a=a+10;}else{a=0;}
			pS.rotationX = k/3*Math.sin(a*Math.PI/180)
			pS.rotationY=k*Math.cos(a*Math.PI/180)
			r.renderScene(s,c,v);
		}		
		private function initializeParticle(e:ParticleEvent):void{
			var p:SimpleParticle3D = SimpleParticle3D(e.particle);
			bfx.addDisplayObject3D(p);
			bfx.drawCommand = new BitmapDrawCommand(null,new ColorTransform(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1,1,1),BlendMode.HARDLIGHT);			
			p.size =1;
			p.lifetime =2000;			
			p.position = new Number3D(0, Math.random()*50-25,0);			
			p.velocity = new Number3D(Math.random()*4-2,50,Math.random()*4-2);
		}
		private function updateParticle(e:ParticleEvent):void{
			var p:SimpleParticle3D = SimpleParticle3D(e.particle);
			var age:Number = p.spawnTime%800;
			p.size +=0.05;	
			p.velocity = new Number3D(Math.sin(age/10)*age/10,Math.cos(age/10)*age/10,p.spawnVelocity.z*6); 			
		}
	}
}


13

评论Comments

日志分类
首页[67]
说故事[8]
看世界[15]
冶情操[9]
贴图片[15]
做生活[20]