PV3D ParticleMaterial

by hacker_szoe51ih
♥0 | Line 52 | Modified 2010-08-30 21:41:36 | MIT License
play

ActionScript3 source code

/**
 * Copyright hacker_szoe51ih ( http://wonderfl.net/user/hacker_szoe51ih )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/qfwv
 */

package {
    
    import flash.display.*;
    import flash.events.*;
    import flash.filters.GlowFilter;
    import org.papervision3d.materials.*;
    import org.papervision3d.objects.primitives.*;

    import org.papervision3d.cameras.CameraType;
    import org.papervision3d.core.geom.Particles;
    import org.papervision3d.core.geom.renderables.Particle;
    import org.papervision3d.materials.special.ParticleMaterial;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.view.BasicView;
    
    import caurina.transitions.*;
    import caurina.transitions.properties.*

    

    [SWF (width=500, height=500, backgroundColor=0x0, frameRate=60)]

    
    public class Main extends BasicView {
        
        public var rot:Number=0;
        public var particleArray:Array;
        public var particleNum:Number=200;
        

        public function Main() {
            
            particleArray=new Array();
            
            //床を作る
            var floor:WireframeMaterial = new WireframeMaterial(0xffffffff);
            floor.doubleSided = true;

            var floorObj:Plane = new Plane(floor,500,500,5,5);
            floorObj.rotationX = 90;
            floorObj.y = -250;
            scene.addChild(floorObj);


            //パーティクルを作る
            var particles:Particles = new Particles();//パーティクルを追加するコンテナ
            scene.addChild(particles);


            for (var i:int=0; i<particleNum; i++) {

                var pMaterial:ParticleMaterial=new ParticleMaterial(Math.random()*0xffffff,1);//パーティクルの色
                var p:Particle=new Particle(pMaterial,10,Math.ceil(Math.random()*500)-250,Math.ceil(Math.random()*500)-250,Math.ceil(Math.random()*500)-250);// マテリアル、サイズ、x座標、y座標、z座標を引数で指定
                particles.addParticle(p);
                particleArray.push(p);

            }



            startRendering();
            addEventListener("enterFrame", loop);
            stage.addEventListener(MouseEvent.CLICK,changePos);

        }

        public function loop(e:Event):void {
            rot+=0.8;            
            camera.x=600*Math.sin(rot*Math.PI/180);
            camera.z=600*Math.cos(rot*Math.PI/180);
            camera.y=800*Math.cos(rot*Math.PI/180);
            
        }
        
        public function changePos(e:MouseEvent):void{
            
            for (var i:int=0; i<particleArray.length; i++) {
                    
                    Tweener.addTween(particleArray[i], {x:Math.ceil(Math.random()*500)-250,y:Math.ceil(Math.random()*500)-250,z:Math.ceil(Math.random()*500)-250,time:2,transition:"easeOutElastic"});
                
            }
            
        }



    }
}