1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- var createScene = function () {
- var scene = new BABYLON.Scene(engine);
- // Setup environment
- var light0 = new BABYLON.PointLight("Omni", new BABYLON.Vector3(0, 2, 8), scene);
- var camera = new BABYLON.ArcRotateCamera("ArcRotateCamera", 1, 0.8, 20, new BABYLON.Vector3(0, 0, 0), scene);
- camera.attachControl(canvas, true);
- // Fountain object
- var fountain = BABYLON.Mesh.CreateBox("foutain", 1.0, scene);
- // Ground
- var ground = BABYLON.Mesh.CreatePlane("ground", 50.0, scene);
- ground.position = new BABYLON.Vector3(0, -10, 0);
- ground.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);
- ground.material = new BABYLON.StandardMaterial("groundMat", scene);
- ground.material.backFaceCulling = false;
- ground.material.diffuseColor = new BABYLON.Color3(0.3, 0.3, 1);
- // Create a particle system
- var particleSystem = new BABYLON.ParticleSystem("particles", 2000, scene);
- //Texture of each particle
- particleSystem.particleTexture = new BABYLON.Texture("textures/flare.png", scene);
- // Where the particles come from
- particleSystem.emitter = fountain; // the starting object, the emitter
- particleSystem.minEmitBox = new BABYLON.Vector3(-1, 0, 0); // Starting all from
- particleSystem.maxEmitBox = new BABYLON.Vector3(1, 0, 0); // To...
- // Colors of all particles
- particleSystem.color1 = new BABYLON.Color4(0.7, 0.8, 1.0, 1.0);
- particleSystem.color2 = new BABYLON.Color4(0.2, 0.5, 1.0, 1.0);
- particleSystem.colorDead = new BABYLON.Color4(0, 0, 0.2, 0.0);
- // Size of each particle (random between...
- particleSystem.minSize = 0.1;
- particleSystem.maxSize = 0.5;
- // Life time of each particle (random between...
- particleSystem.minLifeTime = 0.3;
- particleSystem.maxLifeTime = 1.5;
- // Emission rate
- particleSystem.emitRate = 1500;
- // Blend mode : BLENDMODE_ONEONE, or BLENDMODE_STANDARD
- particleSystem.blendMode = BABYLON.ParticleSystem.BLENDMODE_ONEONE;
- // Set the gravity of all particles
- particleSystem.gravity = new BABYLON.Vector3(0, -9.81, 0);
- // Direction of each particle after it has been emitted
- particleSystem.direction1 = new BABYLON.Vector3(-7, 8, 3);
- particleSystem.direction2 = new BABYLON.Vector3(7, 8, -3);
- // Angular speed, in radians
- particleSystem.minAngularSpeed = 0;
- particleSystem.maxAngularSpeed = Math.PI;
- // Speed
- particleSystem.minEmitPower = 1;
- particleSystem.maxEmitPower = 3;
- particleSystem.updateSpeed = 0.005;
- // Start the particle system
- particleSystem.start();
- // Fountain's animation
- var keys = [];
- var animation = new BABYLON.Animation("animation", "rotation.x", 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT,
- BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
- // At the animation key 0, the value of scaling is "1"
- keys.push({
- frame: 0,
- value: 0
- });
- // At the animation key 50, the value of scaling is "0.2"
- keys.push({
- frame: 50,
- value: Math.PI
- });
- // At the animation key 100, the value of scaling is "1"
- keys.push({
- frame: 100,
- value: 0
- });
- // Launch animation
- animation.setKeys(keys);
- fountain.animations.push(animation);
- scene.beginAnimation(fountain, 0, 100, true);
- return scene;
- }
|