Advertisement
Mackan90096

Fireworks!

Dec 5th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var createScene = function () {
  2.     var scene = new BABYLON.Scene(engine);
  3.  
  4.     // Setup environment
  5.     var light0 = new BABYLON.PointLight("Omni", new BABYLON.Vector3(0, 2, 8), scene);
  6.     var camera = new BABYLON.ArcRotateCamera("ArcRotateCamera", 1, 0.8, 20, new BABYLON.Vector3(0, 0, 0), scene);
  7.     camera.attachControl(canvas, true);
  8.  
  9.     // Fountain object
  10.     var fountain = BABYLON.Mesh.CreateBox("foutain", .1, scene);
  11.  
  12.     // Ground
  13.     var ground = BABYLON.Mesh.CreatePlane("ground", 50.0, scene);
  14.     ground.position = new BABYLON.Vector3(0, -10, 0);
  15.     ground.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);
  16.  
  17.     ground.material = new BABYLON.StandardMaterial("groundMat", scene);
  18.     ground.material.backFaceCulling = false;
  19.     ground.material.diffuseColor = new BABYLON.Color3(0.3, 0.3, 0.3);
  20.  
  21.     // Create a particle system
  22.     var particleSystem = new BABYLON.ParticleSystem("particles", 2000, scene);
  23.  
  24.     //Texture of each particle
  25.     particleSystem.particleTexture = new BABYLON.Texture("textures/flare.png", scene);
  26.  
  27.     // Where the particles come from
  28.     particleSystem.emitter = fountain; // the starting object, the emitter
  29.     particleSystem.minEmitBox = new BABYLON.Vector3(-1, 0, 0); // Starting all from
  30.     particleSystem.maxEmitBox = new BABYLON.Vector3(1, 0, 0); // To...
  31.  
  32.     // Colors of all particles
  33.     particleSystem.color1 = new BABYLON.Color3(0, 255, 0);
  34.     particleSystem.color2 = new BABYLON.Color3(255, 0, 255);
  35.     particleSystem.colorDead = new BABYLON.Color3(0, 0, 255);
  36.  
  37.     // Size of each particle (random between...
  38.     particleSystem.minSize = 0.1;
  39.     particleSystem.maxSize = 0.5;
  40.  
  41.     // Life time of each particle (random between...
  42.     particleSystem.minLifeTime = 0.3;
  43.     particleSystem.maxLifeTime = 1.5;
  44.  
  45.     // Emission rate
  46.     particleSystem.emitRate = 150000;
  47.  
  48.     // Blend mode : BLENDMODE_ONEONE, or BLENDMODE_STANDARD
  49.     particleSystem.blendMode = BABYLON.ParticleSystem.BLENDMODE_ONEONE;
  50.  
  51.     // Set the gravity of all particles
  52.     particleSystem.gravity = new BABYLON.Vector3(0, -9.81, 0);
  53.  
  54.     // Direction of each particle after it has been emitted
  55.     particleSystem.direction1 = new BABYLON.Vector3(-7, 8, 3);
  56.     particleSystem.direction2 = new BABYLON.Vector3(7, 8, -3);
  57.  
  58.     // Angular speed, in radians
  59.     particleSystem.minAngularSpeed = 0;
  60.     particleSystem.maxAngularSpeed = Math.PI;
  61.  
  62.     // Speed
  63.     particleSystem.minEmitPower = 1;
  64.     particleSystem.maxEmitPower = 3;
  65.     particleSystem.updateSpeed = 0.005;
  66.  
  67.     // Start the particle system
  68.     particleSystem.start();
  69.  
  70.     // Fountain's animation
  71.    
  72.     window.setInterval(function(){
  73.         fountain.rotation.x += 1;  
  74.     },10);
  75.    
  76.     return scene;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement