From 8b07bd00f8bfb8af8960a6802c1d12b11dad211c Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 11:05:02 -0800 Subject: [PATCH 01/25] basic firework --- .../fireworksLaunchButtonEntityScript.js | 120 ++++++++++++++++++ .../fireworks/fireworksLaunchButtonSpawner.js | 48 +++++++ 2 files changed, 168 insertions(+) create mode 100644 examples/playa/fireworks/fireworksLaunchButtonEntityScript.js create mode 100644 examples/playa/fireworks/fireworksLaunchButtonSpawner.js diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js new file mode 100644 index 0000000000..27c19f140f --- /dev/null +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -0,0 +1,120 @@ + // + // fireworksLaunchEntityScript.js + // examples/playa/fireworks + // + // Created by Eric Levina on 2/24/16. + // Copyright 2015 High Fidelity, Inc. + // + // Run this script to spawn a big fireworks launch button that a user can press + // + // Distributed under the Apache License, Version 2.0. + // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + + (function() { + var _this; + Fireworks = function() { + _this = this; + + }; + + Fireworks.prototype = { + + startNearTrigger: function() { + print("EBL NEAR TRIGGER") + _this.shootFirework(); + }, + + clickReleaseOnEntity: function() { + _this.shootFirework(); + }, + + shootFirework: function() { + var fireworkSettings = { + name: "fireworks emitter", + position: _this.position, + type: "ParticleEffect", + color: { + red: 205, + green: 84, + blue: 84 + }, + maxParticles: 1000, + lifetime: 20, + lifespan: 4, + emitRate: 1000, + emitSpeed: 1.5, + speedSpread: 1.0, + emitOrientation: { + x: -0.2, + y: 0, + z: 0, + w: 0.7 + }, + emitDimensions: { + x: 0, + y: 0, + z: 0 + }, + emitRadiusStart: 0.5, + polarStart: 1, + polarFinish: 1.2, + azimuthStart: -Math.PI, + azimuthFinish: Math.PI, + emitAcceleration: { + x: 0, + y: -0.7, + z: 0 + }, + accelerationSpread: { + x: 0, + y: 0, + z: 0 + }, + particleRadius: 0.04, + radiusSpread: 0, + radiusStart: 0.14, + radiusFinish: 0.14, + colorSpread: { + red: 0, + green: 0, + blue: 0 + }, + colorStart: { + red: 255, + green: 255, + blue: 255 + }, + colorFinish: { + red: 255, + green: 255, + blue: 255 + }, + alpha: 1, + alphaSpread: 0, + alphaStart: 0, + alphaFinish: 1, + textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/spark_2.png", + }; + + _this.firework = Entities.addEntity(fireworkSettings); + }, + + preload: function(entityID) { + _this.entityID = entityID; + _this.position = Entities.getEntityProperties(_this.entityID, "position").position; + print("EBL RELOAD ENTITY SCRIPT!!!"); + + }, + + unload: function() { + if (_this.firework) { + Entities.deleteEntity(_this.firework); + } + } + + + }; + + // entity scripts always need to return a newly constructed object of our type + return new Fireworks(); + }); \ No newline at end of file diff --git a/examples/playa/fireworks/fireworksLaunchButtonSpawner.js b/examples/playa/fireworks/fireworksLaunchButtonSpawner.js new file mode 100644 index 0000000000..b21aad6d08 --- /dev/null +++ b/examples/playa/fireworks/fireworksLaunchButtonSpawner.js @@ -0,0 +1,48 @@ + // + // fireworksLaunchButtonSpawner.js + // examples/playa/fireworks + // + // Created by Eric Levina on 2/24/16. + // Copyright 2015 High Fidelity, Inc. + // + // Run this script to spawn a big fireworks launch button that a user can press + // + // Distributed under the Apache License, Version 2.0. + // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + + var orientation = Camera.getOrientation(); + orientation = Quat.safeEulerAngles(orientation); + orientation.x = 0; + orientation = Quat.fromVec3Degrees(orientation); + var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientation))); + + // Math.random ensures no caching of script + var SCRIPT_URL = Script.resolvePath("fireworksLaunchButtonEntityScript.js?v1" + Math.random()) + + var myEntity = Entities.addEntity({ + type: "Box", + color: { + red: 200, + green: 10, + blue: 10 + }, + position: center, + dimensions: { + x: 0.1, + y: 0.1, + z: 0.1 + }, + script: SCRIPT_URL, + userData: JSON.stringify({ + grabbableKey: { + wantsTrigger: true + } + }) + }) + + + function cleanup() { + Entities.deleteEntity(myEntity); + } + + Script.scriptEnding.connect(cleanup); \ No newline at end of file From 5520094baca6c2d5bfc3a0bb0fc3ea1b93d944a1 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 12:29:54 -0800 Subject: [PATCH 02/25] exploding fireworks --- .../particle_explorer/particleExplorer.js | 4 +- .../fireworksLaunchButtonEntityScript.js | 87 ++++++++++++++++--- 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/examples/particle_explorer/particleExplorer.js b/examples/particle_explorer/particleExplorer.js index a3cfd32676..307e361ff1 100644 --- a/examples/particle_explorer/particleExplorer.js +++ b/examples/particle_explorer/particleExplorer.js @@ -43,10 +43,10 @@ var keysToAllow = [ 'emitSpeed', 'speedSpread', 'emitOrientation', - 'emitDimensios', - 'emitRadiusStart', + 'emitDimensions', 'polarStart', 'polarFinish', + 'azimuthStart', 'azimuthFinish', 'emitAcceleration', 'accelerationSpread', diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index 27c19f140f..a40327d7f5 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -29,9 +29,72 @@ }, shootFirework: function() { + var position = Vec3.sum(_this.position, {x: 0, y: 0.5, z: 0}); + _this.missle = Entities.addEntity({ + type: "Sphere", + position: position, + color: {red: 200, green : 10, blue: 200}, + dimensions: {x: 0.2, y: 0.4, z: 0.2}, + damping: 0, + dynamic: true, + velocity: {x: 0.0, y: 0.1, z: 0}, + gravity: {x: 0, y: 0.7, z: 0} + }); + + var smokeSettings = { + type: "ParticleEffect", + position: position, + name: "Smoke Trail", + maxParticles: 1000, + emitRate: 20, + emitSpeed: 0, + speedSpread: 0, + dimensions: {x: 1000, y: 1000, z: 1000}, + polarStart: 0, + polarFinish: 0, + azimuthStart: -3.14, + azimuthFinish: 3.14, + emitAcceleration: { + x: 0, + y: -0.5, + z: 0 + }, + accelerationSpread: { + x: 0.2, + y: 0, + z: 0.2 + }, + radiusSpread: 0.04, + particleRadius: 0.07, + radiusStart: 0.07, + radiusFinish: 0.07, + alpha: 0.7, + alphaSpread: 0, + alphaStart: 0, + alphaFinish: 0, + additiveBlending: 0, + textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", + emitterShouldTrail: true, + parentID: _this.missle + }; + + _this.smoke = Entities.addEntity(smokeSettings); + + + Script.setTimeout(function() { + var explodePosition = Entities.getEntityProperties(_this.missle, "position").position; + Entities.deleteEntity(_this.missle); + Entities.deleteEntity(_this.smoke); + _this.explodeFirework(explodePosition); + }, 2500) + + + }, + + explodeFirework: function(explodePosition) { var fireworkSettings = { name: "fireworks emitter", - position: _this.position, + position: explodePosition, type: "ParticleEffect", color: { red: 205, @@ -50,12 +113,6 @@ z: 0, w: 0.7 }, - emitDimensions: { - x: 0, - y: 0, - z: 0 - }, - emitRadiusStart: 0.5, polarStart: 1, polarFinish: 1.2, azimuthStart: -Math.PI, @@ -72,8 +129,8 @@ }, particleRadius: 0.04, radiusSpread: 0, - radiusStart: 0.14, - radiusFinish: 0.14, + radiusStart: 0.06, + radiusFinish: 0.05, colorSpread: { red: 0, green: 0, @@ -92,11 +149,16 @@ alpha: 1, alphaSpread: 0, alphaStart: 0, - alphaFinish: 1, + alphaFinish: 0, textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/spark_2.png", }; _this.firework = Entities.addEntity(fireworkSettings); + + Script.setTimeout(function() { + Entities.editEntity(_this.firework, {isEmitting: false}); + }, 1000) + }, preload: function(entityID) { @@ -107,9 +169,8 @@ }, unload: function() { - if (_this.firework) { - Entities.deleteEntity(_this.firework); - } + Entities.deleteEntity(_this.smoke); + Entities.deleteEntity(_this.missle); } From e245ad93d6c165b47c6f792ac4a901e9a1fe6235 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 15:58:09 -0800 Subject: [PATCH 03/25] smoke and fire --- .../fireworksLaunchButtonEntityScript.js | 75 +++++++++++-------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index a40327d7f5..f96d39fc33 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -11,10 +11,13 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html (function() { + Script.include("../../libraries/utils.js"); var _this; Fireworks = function() { _this = this; - + _this.launchSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/missle+launch.wav"); + _this.explosionSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/fireworksExplosion.wav"); + _this.timeToExplosionRange = {min: 1000, max: 2000}; }; Fireworks.prototype = { @@ -29,24 +32,30 @@ }, shootFirework: function() { - var position = Vec3.sum(_this.position, {x: 0, y: 0.5, z: 0}); + var rocketPosition = Vec3.sum(_this.position, {x: 0, y: 0.1, z: 0}); + Audio.playSound(_this.launchSound, {position: rocketPosition}); + + var MODEL_URL = "file:///C:/Users/Eric/Desktop/Rocket-2.fbx" _this.missle = Entities.addEntity({ - type: "Sphere", - position: position, + type: "Model", + modelURL: MODEL_URL, + position: rocketPosition, color: {red: 200, green : 10, blue: 200}, dimensions: {x: 0.2, y: 0.4, z: 0.2}, damping: 0, dynamic: true, velocity: {x: 0.0, y: 0.1, z: 0}, - gravity: {x: 0, y: 0.7, z: 0} + acceleration: {x: 0, y: 1, z: 0} }); + var smokeTrailPosition = Vec3.sum(rocketPosition, {x: 0, y: -0.15, z: 0}); var smokeSettings = { type: "ParticleEffect", - position: position, + position: smokeTrailPosition, + lifespan: 2, name: "Smoke Trail", - maxParticles: 1000, - emitRate: 20, + maxParticles: 3000, + emitRate: 50, emitSpeed: 0, speedSpread: 0, dimensions: {x: 1000, y: 1000, z: 1000}, @@ -56,23 +65,22 @@ azimuthFinish: 3.14, emitAcceleration: { x: 0, - y: -0.5, + y: 0.1, z: 0 }, accelerationSpread: { - x: 0.2, + x: 0.1, y: 0, - z: 0.2 + z: 0.1 }, - radiusSpread: 0.04, - particleRadius: 0.07, - radiusStart: 0.07, - radiusFinish: 0.07, - alpha: 0.7, + radiusSpread: 0.001, + particleRadius: 0.06, + radiusStart: 0.06, + radiusFinish: 0.2, + alpha: 0.1, alphaSpread: 0, alphaStart: 0, alphaFinish: 0, - additiveBlending: 0, textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", emitterShouldTrail: true, parentID: _this.missle @@ -80,18 +88,31 @@ _this.smoke = Entities.addEntity(smokeSettings); + smokeSettings.colorStart = {red: 75, green: 193, blue: 254}; + smokeSettings.color = {red: 202, green: 132, blue: 151}; + smokeSettings.colorFinish = {red: 250, green: 132, blue: 21}; + smokeSettings.lifespan = 0.7; + smokeSettings.emitAcceleration.y= -1;; + smokeSettings.alphaStart = 0.7; + smokeSettings.alphaFinish = 0.2; + smokeSettings.radiusFinish = 0.06; + smokeSettings.particleRadius = 0.06; + smokeSettings.emitRate = 200; + smokeSettings.emitterShouldTrail = false; + _this.fire = Entities.addEntity(smokeSettings); - Script.setTimeout(function() { - var explodePosition = Entities.getEntityProperties(_this.missle, "position").position; - Entities.deleteEntity(_this.missle); - Entities.deleteEntity(_this.smoke); - _this.explodeFirework(explodePosition); - }, 2500) + // Script.setTimeout(function() { + // var explodePosition = Entities.getEntityProperties(_this.missle, "position").position; + // Entities.deleteEntity(_this.missle); + // Entities.deleteEntity(_this.smoke); + // _this.explodeFirework(explodePosition); + // }, randFloat(_this.timeToExplosionRange.min, _this.timeToExplosionRange.max)); }, explodeFirework: function(explodePosition) { + Audio.playSound(_this.explosionSound, {position: explodePosition}); var fireworkSettings = { name: "fireworks emitter", position: explodePosition, @@ -150,7 +171,7 @@ alphaSpread: 0, alphaStart: 0, alphaFinish: 0, - textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/spark_2.png", + textures: "http://ericrius1.github.io/PlatosCave/assets/star.png", }; _this.firework = Entities.addEntity(fireworkSettings); @@ -166,14 +187,8 @@ _this.position = Entities.getEntityProperties(_this.entityID, "position").position; print("EBL RELOAD ENTITY SCRIPT!!!"); - }, - - unload: function() { - Entities.deleteEntity(_this.smoke); - Entities.deleteEntity(_this.missle); } - }; // entity scripts always need to return a newly constructed object of our type From dea41edf9c9966099f270dc1f0b543e1b7fd2502 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 16:01:38 -0800 Subject: [PATCH 04/25] tweaks --- .../fireworksLaunchButtonEntityScript.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index f96d39fc33..7a2c77ff6b 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -53,6 +53,7 @@ type: "ParticleEffect", position: smokeTrailPosition, lifespan: 2, + lifetime: 20, name: "Smoke Trail", maxParticles: 3000, emitRate: 50, @@ -94,24 +95,26 @@ smokeSettings.lifespan = 0.7; smokeSettings.emitAcceleration.y= -1;; smokeSettings.alphaStart = 0.7; - smokeSettings.alphaFinish = 0.2; + smokeSettings.alphaFinish = 0.1; smokeSettings.radiusFinish = 0.06; smokeSettings.particleRadius = 0.06; smokeSettings.emitRate = 200; smokeSettings.emitterShouldTrail = false; _this.fire = Entities.addEntity(smokeSettings); - // Script.setTimeout(function() { - // var explodePosition = Entities.getEntityProperties(_this.missle, "position").position; - // Entities.deleteEntity(_this.missle); - // Entities.deleteEntity(_this.smoke); - // _this.explodeFirework(explodePosition); - // }, randFloat(_this.timeToExplosionRange.min, _this.timeToExplosionRange.max)); + Script.setTimeout(function() { + var explodePosition = Entities.getEntityProperties(_this.missle, "position").position; + _this.explodeFirework(explodePosition); + }, randFloat(_this.timeToExplosionRange.min, _this.timeToExplosionRange.max)); }, explodeFirework: function(explodePosition) { + // We just exploded firework, so stop emitting its fire and smoke + Entities.editEntity(_this.smoke, {parentID: null, isEmitting: false}); + Entities.editEntity(_this.fire, {parentID: null, isEmitting: false}); + Entities.deleteEntity(_this.missle); Audio.playSound(_this.explosionSound, {position: explodePosition}); var fireworkSettings = { name: "fireworks emitter", From 04993349382b1ce7fdfb892e1c1f43818448053b Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 16:14:46 -0800 Subject: [PATCH 05/25] toadd: different colors for fireworks --- .../fireworksLaunchButtonEntityScript.js | 198 +++++++++++------- .../fireworks/fireworksLaunchButtonSpawner.js | 20 +- 2 files changed, 133 insertions(+), 85 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index 7a2c77ff6b..cfb81674cb 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -17,7 +17,10 @@ _this = this; _this.launchSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/missle+launch.wav"); _this.explosionSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/fireworksExplosion.wav"); - _this.timeToExplosionRange = {min: 1000, max: 2000}; + _this.timeToExplosionRange = { + min: 2000, + max: 3000 + }; }; Fireworks.prototype = { @@ -32,90 +35,137 @@ }, shootFirework: function() { - var rocketPosition = Vec3.sum(_this.position, {x: 0, y: 0.1, z: 0}); - Audio.playSound(_this.launchSound, {position: rocketPosition}); - - var MODEL_URL = "file:///C:/Users/Eric/Desktop/Rocket-2.fbx" - _this.missle = Entities.addEntity({ - type: "Model", - modelURL: MODEL_URL, - position: rocketPosition, - color: {red: 200, green : 10, blue: 200}, - dimensions: {x: 0.2, y: 0.4, z: 0.2}, - damping: 0, - dynamic: true, - velocity: {x: 0.0, y: 0.1, z: 0}, - acceleration: {x: 0, y: 1, z: 0} + var rocketPosition = Vec3.sum(_this.position, { + x: 0, + y: 0.1, + z: 0 + }); + Audio.playSound(_this.launchSound, { + position: rocketPosition }); - var smokeTrailPosition = Vec3.sum(rocketPosition, {x: 0, y: -0.15, z: 0}); - var smokeSettings = { - type: "ParticleEffect", - position: smokeTrailPosition, - lifespan: 2, - lifetime: 20, - name: "Smoke Trail", - maxParticles: 3000, - emitRate: 50, - emitSpeed: 0, - speedSpread: 0, - dimensions: {x: 1000, y: 1000, z: 1000}, - polarStart: 0, - polarFinish: 0, - azimuthStart: -3.14, - azimuthFinish: 3.14, - emitAcceleration: { - x: 0, - y: 0.1, - z: 0 - }, - accelerationSpread: { - x: 0.1, - y: 0, - z: 0.1 - }, - radiusSpread: 0.001, - particleRadius: 0.06, - radiusStart: 0.06, - radiusFinish: 0.2, - alpha: 0.1, - alphaSpread: 0, - alphaStart: 0, - alphaFinish: 0, - textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", - emitterShouldTrail: true, - parentID: _this.missle + var MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/Rocket-2.fbx"; + var missleDimensions = { + x: 0.24, + y: 0.7, + z: 0.24 }; + _this.missle = Entities.addEntity({ + type: "Model", + modelURL: MODEL_URL, + position: rocketPosition, + dimensions: missleDimensions, + damping: 0, + dynamic: true, + velocity: { + x: 0.0, + y: 0.1, + z: 0 + }, + acceleration: { + x: 0, + y: 1, + z: 0 + } + }); - _this.smoke = Entities.addEntity(smokeSettings); + var smokeTrailPosition = Vec3.sum(rocketPosition, { + x: 0, + y: -missleDimensions.y/2 + 0.08, + z: 0 + }); + var smokeSettings = { + type: "ParticleEffect", + position: smokeTrailPosition, + lifespan: 1.6, + lifetime: 20, + name: "Smoke Trail", + maxParticles: 3000, + emitRate: 50, + emitSpeed: 0, + speedSpread: 0, + dimensions: { + x: 1000, + y: 1000, + z: 1000 + }, + polarStart: 0, + polarFinish: 0, + azimuthStart: -3.14, + azimuthFinish: 3.14, + emitAcceleration: { + x: 0, + y: 0.1, + z: 0 + }, + accelerationSpread: { + x: 0.1, + y: 0, + z: 0.1 + }, + radiusSpread: 0.001, + particleRadius: 0.06, + radiusStart: 0.06, + radiusFinish: 0.2, + alpha: 0.1, + alphaSpread: 0, + alphaStart: 0, + alphaFinish: 0, + textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", + emitterShouldTrail: true, + parentID: _this.missle + }; - smokeSettings.colorStart = {red: 75, green: 193, blue: 254}; - smokeSettings.color = {red: 202, green: 132, blue: 151}; - smokeSettings.colorFinish = {red: 250, green: 132, blue: 21}; - smokeSettings.lifespan = 0.7; - smokeSettings.emitAcceleration.y= -1;; - smokeSettings.alphaStart = 0.7; - smokeSettings.alphaFinish = 0.1; - smokeSettings.radiusFinish = 0.06; - smokeSettings.particleRadius = 0.06; - smokeSettings.emitRate = 200; - smokeSettings.emitterShouldTrail = false; - _this.fire = Entities.addEntity(smokeSettings); + _this.smoke = Entities.addEntity(smokeSettings); - Script.setTimeout(function() { - var explodePosition = Entities.getEntityProperties(_this.missle, "position").position; - _this.explodeFirework(explodePosition); - }, randFloat(_this.timeToExplosionRange.min, _this.timeToExplosionRange.max)); + smokeSettings.colorStart = { + red: 75, + green: 193, + blue: 254 + }; + smokeSettings.color = { + red: 202, + green: 132, + blue: 151 + }; + smokeSettings.colorFinish = { + red: 250, + green: 132, + blue: 21 + }; + smokeSettings.lifespan = 0.7; + smokeSettings.emitAcceleration.y = -1;; + smokeSettings.alphaStart = 0.7; + smokeSettings.alphaFinish = 0.1; + smokeSettings.radiusFinish = 0.06; + smokeSettings.particleRadius = 0.06; + smokeSettings.emitRate = 200; + smokeSettings.emitterShouldTrail = false; + smokeSettings.name = "fire emitter"; + _this.fire = Entities.addEntity(smokeSettings); + + Script.setTimeout(function() { + var explodePosition = Entities.getEntityProperties(_this.missle, "position").position; + _this.explodeFirework(explodePosition); + }, randFloat(_this.timeToExplosionRange.min, _this.timeToExplosionRange.max)); }, explodeFirework: function(explodePosition) { // We just exploded firework, so stop emitting its fire and smoke - Entities.editEntity(_this.smoke, {parentID: null, isEmitting: false}); - Entities.editEntity(_this.fire, {parentID: null, isEmitting: false}); + Entities.editEntity(_this.smoke, { + parentID: null, + isEmitting: false + }); + Entities.editEntity(_this.fire, { + parentID: null, + isEmitting: false + }); Entities.deleteEntity(_this.missle); - Audio.playSound(_this.explosionSound, {position: explodePosition}); + Audio.playSound(_this.explosionSound, { + position: explodePosition + }); var fireworkSettings = { name: "fireworks emitter", position: explodePosition, @@ -180,7 +230,9 @@ _this.firework = Entities.addEntity(fireworkSettings); Script.setTimeout(function() { - Entities.editEntity(_this.firework, {isEmitting: false}); + Entities.editEntity(_this.firework, { + isEmitting: false + }); }, 1000) }, diff --git a/examples/playa/fireworks/fireworksLaunchButtonSpawner.js b/examples/playa/fireworks/fireworksLaunchButtonSpawner.js index b21aad6d08..831afc18f1 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonSpawner.js +++ b/examples/playa/fireworks/fireworksLaunchButtonSpawner.js @@ -18,19 +18,15 @@ // Math.random ensures no caching of script var SCRIPT_URL = Script.resolvePath("fireworksLaunchButtonEntityScript.js?v1" + Math.random()) - - var myEntity = Entities.addEntity({ - type: "Box", - color: { - red: 200, - green: 10, - blue: 10 - }, + var MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/Launch-Button.fbx"; + var launchButton = Entities.addEntity({ + type: "Model", + modelURL: MODEL_URL, position: center, dimensions: { - x: 0.1, - y: 0.1, - z: 0.1 + x: 0.98, + y: 1.16, + z: 0.98 }, script: SCRIPT_URL, userData: JSON.stringify({ @@ -42,7 +38,7 @@ function cleanup() { - Entities.deleteEntity(myEntity); + Entities.deleteEntity(launchButton); } Script.scriptEnding.connect(cleanup); \ No newline at end of file From 0a6a35ddd807ad7aae19cffa33ae9e04347348d2 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 16:30:29 -0800 Subject: [PATCH 06/25] need multiple explosions at once --- examples/libraries/utils.js | 2 +- .../fireworksLaunchButtonEntityScript.js | 44 +++++-------------- 2 files changed, 12 insertions(+), 34 deletions(-) diff --git a/examples/libraries/utils.js b/examples/libraries/utils.js index b2b2902cb0..f4a431a657 100644 --- a/examples/libraries/utils.js +++ b/examples/libraries/utils.js @@ -199,7 +199,7 @@ pointInExtents = function(point, minPoint, maxPoint) { * @param Number l The lightness * @return Array The RGB representation */ -hslToRgb = function(hsl, hueOffset) { +hslToRgb = function(hsl) { var r, g, b; if (hsl.s == 0) { r = g = b = hsl.l; // achromatic diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index cfb81674cb..2abf96a86d 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -21,12 +21,12 @@ min: 2000, max: 3000 }; + _this.explodeTime = 500; }; Fireworks.prototype = { startNearTrigger: function() { - print("EBL NEAR TRIGGER") _this.shootFirework(); }, @@ -170,25 +170,18 @@ name: "fireworks emitter", position: explodePosition, type: "ParticleEffect", - color: { - red: 205, - green: 84, - blue: 84 - }, - maxParticles: 1000, + colorStart: hslToRgb({h: Math.random(), s: 0.5, l: 0.7}), + color: hslToRgb({h: Math.random(), s: 0.5, l: 0.5}), + colorFinish: hslToRgb({h: Math.random(), s: 0.5, l: 0.7}), + maxParticles: 10000, lifetime: 20, - lifespan: 4, - emitRate: 1000, - emitSpeed: 1.5, + lifespan: randFloat(1.5, 3), + emitRate: randInt(500, 3000), + emitSpeed: randFloat(0.5, 2), speedSpread: 1.0, - emitOrientation: { - x: -0.2, - y: 0, - z: 0, - w: 0.7 - }, + emitOrientation: Quat.fromPitchYawRollDegrees(randInt(0, 360), randInt(0, 360), randInt(0, 360)), polarStart: 1, - polarFinish: 1.2, + polarFinish: randFloat(1.2, 3), azimuthStart: -Math.PI, azimuthFinish: Math.PI, emitAcceleration: { @@ -205,21 +198,6 @@ radiusSpread: 0, radiusStart: 0.06, radiusFinish: 0.05, - colorSpread: { - red: 0, - green: 0, - blue: 0 - }, - colorStart: { - red: 255, - green: 255, - blue: 255 - }, - colorFinish: { - red: 255, - green: 255, - blue: 255 - }, alpha: 1, alphaSpread: 0, alphaStart: 0, @@ -233,7 +211,7 @@ Entities.editEntity(_this.firework, { isEmitting: false }); - }, 1000) + }, _this.explodeTime); }, From 769a5ecca9ef07465e5f55a50fb1731f16abf05e Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 16:33:28 -0800 Subject: [PATCH 07/25] tweaks --- .../fireworksLaunchButtonEntityScript.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index 2abf96a86d..55df20cfda 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -176,9 +176,9 @@ maxParticles: 10000, lifetime: 20, lifespan: randFloat(1.5, 3), - emitRate: randInt(500, 3000), + emitRate: randInt(500, 10000), emitSpeed: randFloat(0.5, 2), - speedSpread: 1.0, + speedSpread: 0.2, emitOrientation: Quat.fromPitchYawRollDegrees(randInt(0, 360), randInt(0, 360), randInt(0, 360)), polarStart: 1, polarFinish: randFloat(1.2, 3), @@ -186,22 +186,22 @@ azimuthFinish: Math.PI, emitAcceleration: { x: 0, - y: -0.7, + y: randFloat(-1, -0.2), z: 0 }, accelerationSpread: { - x: 0, + x: Math.random(), y: 0, - z: 0 + z: Math.random() }, - particleRadius: 0.04, - radiusSpread: 0, - radiusStart: 0.06, - radiusFinish: 0.05, - alpha: 1, - alphaSpread: 0, - alphaStart: 0, - alphaFinish: 0, + particleRadius: randFloat(0.001, 0.1), + radiusSpread: Math.random() * 0.1, + radiusStart: randFloat(0.001, 0.1), + radiusFinish: randFloat(0.001, 0.1), + alpha: Math.random(), + alphaSpread: Math.random(), + alphaStart: Math.random(), + alphaFinish: Math.random(), textures: "http://ericrius1.github.io/PlatosCave/assets/star.png", }; From 208096f2e01d5c1c52cbc3f0f133f140b929587e Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 16:36:54 -0800 Subject: [PATCH 08/25] fireworks but no smoke --- .../fireworksLaunchButtonEntityScript.js | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index 55df20cfda..286dbf0375 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -50,7 +50,7 @@ y: 0.7, z: 0.24 }; - _this.missle = Entities.addEntity({ + var missle = Entities.addEntity({ type: "Model", modelURL: MODEL_URL, position: rocketPosition, @@ -71,7 +71,7 @@ var smokeTrailPosition = Vec3.sum(rocketPosition, { x: 0, - y: -missleDimensions.y/2 + 0.08, + y: -missleDimensions.y/2 + 0.1, z: 0 }); var smokeSettings = { @@ -116,7 +116,7 @@ parentID: _this.missle }; - _this.smoke = Entities.addEntity(smokeSettings); + var smoke = Entities.addEntity(smokeSettings); smokeSettings.colorStart = { red: 75, @@ -142,31 +142,31 @@ smokeSettings.emitRate = 200; smokeSettings.emitterShouldTrail = false; smokeSettings.name = "fire emitter"; - _this.fire = Entities.addEntity(smokeSettings); + var fire = Entities.addEntity(smokeSettings); Script.setTimeout(function() { - var explodePosition = Entities.getEntityProperties(_this.missle, "position").position; - _this.explodeFirework(explodePosition); + var explodePosition = Entities.getEntityProperties(missle, "position").position; + _this.explodeFirework(smoke, fire, missle, explodePosition); }, randFloat(_this.timeToExplosionRange.min, _this.timeToExplosionRange.max)); }, - explodeFirework: function(explodePosition) { + explodeFirework: function(smoke, fire, missle, explodePosition) { // We just exploded firework, so stop emitting its fire and smoke - Entities.editEntity(_this.smoke, { + Entities.editEntity(smoke, { parentID: null, isEmitting: false }); - Entities.editEntity(_this.fire, { + Entities.editEntity(fire, { parentID: null, isEmitting: false }); - Entities.deleteEntity(_this.missle); + Entities.deleteEntity(missle); Audio.playSound(_this.explosionSound, { position: explodePosition }); - var fireworkSettings = { + var firework = Entities.addEntity({ name: "fireworks emitter", position: explodePosition, type: "ParticleEffect", @@ -203,12 +203,11 @@ alphaStart: Math.random(), alphaFinish: Math.random(), textures: "http://ericrius1.github.io/PlatosCave/assets/star.png", - }; + }); - _this.firework = Entities.addEntity(fireworkSettings); Script.setTimeout(function() { - Entities.editEntity(_this.firework, { + Entities.editEntity(firework, { isEmitting: false }); }, _this.explodeTime); From fdb5d33866266426a0125e3d580fbf75b85c9730 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 16:42:24 -0800 Subject: [PATCH 09/25] MORE RANDOM YAHH --- .../fireworksLaunchButtonEntityScript.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index 286dbf0375..deb67e5e83 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -19,9 +19,9 @@ _this.explosionSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/fireworksExplosion.wav"); _this.timeToExplosionRange = { min: 2000, - max: 3000 + max: 4000 }; - _this.explodeTime = 500; + _this.explodeTime = randInt(500, 1000); }; Fireworks.prototype = { @@ -59,14 +59,16 @@ dynamic: true, velocity: { x: 0.0, - y: 0.1, + y: randFloat(0.4, 1.0), z: 0 }, acceleration: { x: 0, - y: 1, + y: randFloat(1.0, 2.0), z: 0 - } + }, + angularVelocity: {x: 0, y: randInt(0, 10), z: 0}, + angularDamping: 0 }); var smokeTrailPosition = Vec3.sum(rocketPosition, { @@ -113,7 +115,7 @@ alphaFinish: 0, textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", emitterShouldTrail: true, - parentID: _this.missle + parentID: missle }; var smoke = Entities.addEntity(smokeSettings); @@ -133,7 +135,7 @@ green: 132, blue: 21 }; - smokeSettings.lifespan = 0.7; + smokeSettings.lifespan = 1; smokeSettings.emitAcceleration.y = -1;; smokeSettings.alphaStart = 0.7; smokeSettings.alphaFinish = 0.1; From c26ad2b9d0d182b088ec84074024a54feaecf604 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 16:52:02 -0800 Subject: [PATCH 10/25] relative smoke trail --- .../fireworksLaunchButtonEntityScript.js | 70 +++++++++++-------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index deb67e5e83..646f63cc91 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -45,35 +45,35 @@ }); var MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/Rocket-2.fbx"; - var missleDimensions = { - x: 0.24, - y: 0.7, - z: 0.24 - }; - var missle = Entities.addEntity({ - type: "Model", - modelURL: MODEL_URL, - position: rocketPosition, - dimensions: missleDimensions, - damping: 0, - dynamic: true, - velocity: { - x: 0.0, - y: randFloat(0.4, 1.0), - z: 0 - }, - acceleration: { - x: 0, - y: randFloat(1.0, 2.0), - z: 0 - }, - angularVelocity: {x: 0, y: randInt(0, 10), z: 0}, - angularDamping: 0 - }); + var missleDimensions = Vec3.multiply({ + x: 0.24, + y: 0.7, + z: 0.24 + }, randFloat(0.2, 1.5)); + var missleRotation = Quat.fromPitchYawRollDegrees(randInt(-30, 30), 0, randInt(-30, 30)); + var missleVelocity = Vec3.multiply(Quat.getUp(missleRotation), randFloat(1, 3)); + var missleAcceleration = Vec3.multiply(Quat.getUp(missleRotation), randFloat(0.7, 3)); + var missle = Entities.addEntity({ + type: "Model", + modelURL: MODEL_URL, + position: rocketPosition, + rotation: missleRotation, + dimensions: missleDimensions, + damping: 0, + dynamic: true, + velocity: missleVelocity, + acceleration: missleAcceleration, + angularVelocity: { + x: 0, + y: randInt(-5, 5), + z: 0 + }, + angularDamping: 0 + }); var smokeTrailPosition = Vec3.sum(rocketPosition, { x: 0, - y: -missleDimensions.y/2 + 0.1, + y: -missleDimensions.y / 2 + 0.1, z: 0 }); var smokeSettings = { @@ -172,9 +172,21 @@ name: "fireworks emitter", position: explodePosition, type: "ParticleEffect", - colorStart: hslToRgb({h: Math.random(), s: 0.5, l: 0.7}), - color: hslToRgb({h: Math.random(), s: 0.5, l: 0.5}), - colorFinish: hslToRgb({h: Math.random(), s: 0.5, l: 0.7}), + colorStart: hslToRgb({ + h: Math.random(), + s: 0.5, + l: 0.7 + }), + color: hslToRgb({ + h: Math.random(), + s: 0.5, + l: 0.5 + }), + colorFinish: hslToRgb({ + h: Math.random(), + s: 0.5, + l: 0.7 + }), maxParticles: 10000, lifetime: 20, lifespan: randFloat(1.5, 3), From 45e8287d1d926ad1a571c4e41ef7e8a28135a2e1 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 16:55:31 -0800 Subject: [PATCH 11/25] particle trail in right spot --- .../playa/fireworks/fireworksLaunchButtonEntityScript.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index 646f63cc91..f8ba98f3c6 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -71,11 +71,7 @@ angularDamping: 0 }); - var smokeTrailPosition = Vec3.sum(rocketPosition, { - x: 0, - y: -missleDimensions.y / 2 + 0.1, - z: 0 - }); + var smokeTrailPosition = Vec3.sum(rocketPosition, Vec3.multiply(-missleDimensions.y/2 + 0.1, Quat.getUp(missleRotation))); var smokeSettings = { type: "ParticleEffect", position: smokeTrailPosition, From 08e7adc5186bbf0fecdb8c5776bee2cd01bf67da Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 17:08:12 -0800 Subject: [PATCH 12/25] tweaks --- .../fireworksLaunchButtonEntityScript.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index f8ba98f3c6..35c68fd488 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -27,10 +27,14 @@ Fireworks.prototype = { startNearTrigger: function() { - _this.shootFirework(); + _this.shootFireworks(); }, clickReleaseOnEntity: function() { + _this.shootFireworks(); + }, + + shootFireworks: function() { _this.shootFirework(); }, @@ -68,7 +72,8 @@ y: randInt(-5, 5), z: 0 }, - angularDamping: 0 + angularDamping: 0, + visible: false }); var smokeTrailPosition = Vec3.sum(rocketPosition, Vec3.multiply(-missleDimensions.y/2 + 0.1, Quat.getUp(missleRotation))); @@ -131,14 +136,9 @@ green: 132, blue: 21 }; - smokeSettings.lifespan = 1; - smokeSettings.emitAcceleration.y = -1;; - smokeSettings.alphaStart = 0.7; + smokeSettings.alphaStart = 0.1; smokeSettings.alphaFinish = 0.1; - smokeSettings.radiusFinish = 0.06; - smokeSettings.particleRadius = 0.06; - smokeSettings.emitRate = 200; - smokeSettings.emitterShouldTrail = false; + smokeSettings.name = "fire emitter"; var fire = Entities.addEntity(smokeSettings); From 857ccc7409826df89e7ae0b321a1a91490f9ece0 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 17:53:46 -0800 Subject: [PATCH 13/25] move sound with thing --- .../fireworksLaunchButtonEntityScript.js | 69 +++++++++++-------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index 35c68fd488..ac609418fd 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -21,7 +21,6 @@ min: 2000, max: 4000 }; - _this.explodeTime = randInt(500, 1000); }; Fireworks.prototype = { @@ -35,17 +34,21 @@ }, shootFireworks: function() { - _this.shootFirework(); + var numMissles = randInt(1, 5); + for(var i = 0; i < numMissles; i++) { + _this.shootMissle(); + } }, - shootFirework: function() { + shootMissle: function() { var rocketPosition = Vec3.sum(_this.position, { x: 0, y: 0.1, z: 0 }); Audio.playSound(_this.launchSound, { - position: rocketPosition + position: rocketPosition, + volume: 0.5 }); var MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/Rocket-2.fbx"; @@ -54,7 +57,7 @@ y: 0.7, z: 0.24 }, randFloat(0.2, 1.5)); - var missleRotation = Quat.fromPitchYawRollDegrees(randInt(-30, 30), 0, randInt(-30, 30)); + var missleRotation = Quat.fromPitchYawRollDegrees(randInt(-60, 60), 0, randInt(-60, 60)); var missleVelocity = Vec3.multiply(Quat.getUp(missleRotation), randFloat(1, 3)); var missleAcceleration = Vec3.multiply(Quat.getUp(missleRotation), randFloat(0.7, 3)); var missle = Entities.addEntity({ @@ -65,18 +68,19 @@ dimensions: missleDimensions, damping: 0, dynamic: true, + lifetime: 20, // Just in case velocity: missleVelocity, acceleration: missleAcceleration, angularVelocity: { x: 0, - y: randInt(-5, 5), + y: randInt(-1, 1), z: 0 }, angularDamping: 0, visible: false }); - var smokeTrailPosition = Vec3.sum(rocketPosition, Vec3.multiply(-missleDimensions.y/2 + 0.1, Quat.getUp(missleRotation))); + var smokeTrailPosition = Vec3.sum(rocketPosition, Vec3.multiply(-missleDimensions.y / 2 + 0.1, Quat.getUp(missleRotation))); var smokeSettings = { type: "ParticleEffect", position: smokeTrailPosition, @@ -110,7 +114,7 @@ particleRadius: 0.06, radiusStart: 0.06, radiusFinish: 0.2, - alpha: 0.1, + alpha: 0.7, alphaSpread: 0, alphaStart: 0, alphaFinish: 0, @@ -136,31 +140,42 @@ green: 132, blue: 21 }; - smokeSettings.alphaStart = 0.1; + smokeSettings.alphaStart = 0.6; smokeSettings.alphaFinish = 0.1; smokeSettings.name = "fire emitter"; var fire = Entities.addEntity(smokeSettings); Script.setTimeout(function() { - var explodePosition = Entities.getEntityProperties(missle, "position").position; - _this.explodeFirework(smoke, fire, missle, explodePosition); + Entities.editEntity(smoke, { + parentID: null, + isEmitting: false + }); + Entities.editEntity(fire, { + parentID: null, + isEmitting: false + }); + + var explodeBasePosition = Entities.getEntityProperties(missle, "position").position; + + Entities.deleteEntity(missle); + // Explode 1 firework immediately + _this.explodeFirework(explodeBasePosition); + var numAdditionalFireworks = randInt(4, 10); + for (var i = 0; i < numAdditionalFireworks; i++) { + Script.setTimeout(function() { + var explodePosition = Vec3.sum(explodeBasePosition, {x: randFloat(-3, 3), y: randFloat(-3, 3), z: randFloat(-3, 3)}); + _this.explodeFirework(explodePosition); + }, randInt(0, 1000)) + } }, randFloat(_this.timeToExplosionRange.min, _this.timeToExplosionRange.max)); }, - explodeFirework: function(smoke, fire, missle, explodePosition) { + explodeFirework: function(explodePosition) { // We just exploded firework, so stop emitting its fire and smoke - Entities.editEntity(smoke, { - parentID: null, - isEmitting: false - }); - Entities.editEntity(fire, { - parentID: null, - isEmitting: false - }); - Entities.deleteEntity(missle); + Audio.playSound(_this.explosionSound, { position: explodePosition }); @@ -186,7 +201,7 @@ maxParticles: 10000, lifetime: 20, lifespan: randFloat(1.5, 3), - emitRate: randInt(500, 10000), + emitRate: randInt(500, 5000), emitSpeed: randFloat(0.5, 2), speedSpread: 0.2, emitOrientation: Quat.fromPitchYawRollDegrees(randInt(0, 360), randInt(0, 360), randInt(0, 360)), @@ -208,10 +223,10 @@ radiusSpread: Math.random() * 0.1, radiusStart: randFloat(0.001, 0.1), radiusFinish: randFloat(0.001, 0.1), - alpha: Math.random(), - alphaSpread: Math.random(), - alphaStart: Math.random(), - alphaFinish: Math.random(), + alpha: randFloat(0.5, 1.0), + alphaSpread: randFloat(0.5, 1.0), + alphaStart: randFloat(0.5, 1.0), + alphaFinish: randFloat(0.5, 1.0), textures: "http://ericrius1.github.io/PlatosCave/assets/star.png", }); @@ -220,7 +235,7 @@ Entities.editEntity(firework, { isEmitting: false }); - }, _this.explodeTime); + }, randInt(500, 1000)); }, From 29c4ac83c0b7d503f0402c32a52db1d55550f455 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 18:00:57 -0800 Subject: [PATCH 14/25] can set launch position in userdata --- .../fireworksLaunchButtonEntityScript.js | 18 ++++++++---------- .../fireworks/fireworksLaunchButtonSpawner.js | 1 + 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index ac609418fd..15d9b7d4bd 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -34,20 +34,18 @@ }, shootFireworks: function() { + // Get launch position + var launchPosition = getEntityUserData(_this.entityID).launchPosition || _this.position; + var numMissles = randInt(1, 5); for(var i = 0; i < numMissles; i++) { - _this.shootMissle(); + _this.shootMissle(launchPosition); } }, - shootMissle: function() { - var rocketPosition = Vec3.sum(_this.position, { - x: 0, - y: 0.1, - z: 0 - }); + shootMissle: function(launchPosition) { Audio.playSound(_this.launchSound, { - position: rocketPosition, + position: launchPosition, volume: 0.5 }); @@ -63,7 +61,7 @@ var missle = Entities.addEntity({ type: "Model", modelURL: MODEL_URL, - position: rocketPosition, + position: launchPosition, rotation: missleRotation, dimensions: missleDimensions, damping: 0, @@ -80,7 +78,7 @@ visible: false }); - var smokeTrailPosition = Vec3.sum(rocketPosition, Vec3.multiply(-missleDimensions.y / 2 + 0.1, Quat.getUp(missleRotation))); + var smokeTrailPosition = Vec3.sum(launchPosition, Vec3.multiply(-missleDimensions.y / 2 + 0.1, Quat.getUp(missleRotation))); var smokeSettings = { type: "ParticleEffect", position: smokeTrailPosition, diff --git a/examples/playa/fireworks/fireworksLaunchButtonSpawner.js b/examples/playa/fireworks/fireworksLaunchButtonSpawner.js index 831afc18f1..9e0bca8a8d 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonSpawner.js +++ b/examples/playa/fireworks/fireworksLaunchButtonSpawner.js @@ -30,6 +30,7 @@ }, script: SCRIPT_URL, userData: JSON.stringify({ + launchPosition: {x: 1, y: 1.8, z: -20.9}, grabbableKey: { wantsTrigger: true } From a1eab365ced574ba11b5a042ffb03e3036fe04d6 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 18:11:08 -0800 Subject: [PATCH 15/25] added name to launch pad --- examples/playa/fireworks/fireworksLaunchButtonSpawner.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/playa/fireworks/fireworksLaunchButtonSpawner.js b/examples/playa/fireworks/fireworksLaunchButtonSpawner.js index 9e0bca8a8d..dd82922aed 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonSpawner.js +++ b/examples/playa/fireworks/fireworksLaunchButtonSpawner.js @@ -21,6 +21,7 @@ var MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/Launch-Button.fbx"; var launchButton = Entities.addEntity({ type: "Model", + name: "launch pad", modelURL: MODEL_URL, position: center, dimensions: { From 7cb57aa067bcf410f865224493aa15ed1bec13db Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 18:15:34 -0800 Subject: [PATCH 16/25] alpha tweaks --- .../playa/fireworks/fireworksLaunchButtonEntityScript.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index 15d9b7d4bd..4e6309de41 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -221,10 +221,10 @@ radiusSpread: Math.random() * 0.1, radiusStart: randFloat(0.001, 0.1), radiusFinish: randFloat(0.001, 0.1), - alpha: randFloat(0.5, 1.0), - alphaSpread: randFloat(0.5, 1.0), - alphaStart: randFloat(0.5, 1.0), - alphaFinish: randFloat(0.5, 1.0), + alpha: randFloat(0.8, 1.0), + alphaSpread: randFloat(0.1, 0.2), + alphaStart: randFloat(0.7, 1.0), + alphaFinish: randFloat(0.7, 1.0), textures: "http://ericrius1.github.io/PlatosCave/assets/star.png", }); From ad49bcda72cd97df7049d923fb9a9413f5ff6524 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 18:29:44 -0800 Subject: [PATCH 17/25] lowered num fireworks --- examples/playa/fireworks/fireworksLaunchButtonEntityScript.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index 4e6309de41..acfbce099e 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -37,7 +37,7 @@ // Get launch position var launchPosition = getEntityUserData(_this.entityID).launchPosition || _this.position; - var numMissles = randInt(1, 5); + var numMissles = randInt(1, 3); for(var i = 0; i < numMissles; i++) { _this.shootMissle(launchPosition); } @@ -159,7 +159,7 @@ Entities.deleteEntity(missle); // Explode 1 firework immediately _this.explodeFirework(explodeBasePosition); - var numAdditionalFireworks = randInt(4, 10); + var numAdditionalFireworks = randInt(1, 5); for (var i = 0; i < numAdditionalFireworks; i++) { Script.setTimeout(function() { var explodePosition = Vec3.sum(explodeBasePosition, {x: randFloat(-3, 3), y: randFloat(-3, 3), z: randFloat(-3, 3)}); From 8f914c6673ed105339aadb9f3fecdeaf30a2bb5b Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 24 Feb 2016 20:08:35 -0800 Subject: [PATCH 18/25] removed query string on entity script --- examples/playa/fireworks/fireworksLaunchButtonSpawner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonSpawner.js b/examples/playa/fireworks/fireworksLaunchButtonSpawner.js index dd82922aed..20527a7e3a 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonSpawner.js +++ b/examples/playa/fireworks/fireworksLaunchButtonSpawner.js @@ -17,7 +17,7 @@ var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientation))); // Math.random ensures no caching of script - var SCRIPT_URL = Script.resolvePath("fireworksLaunchButtonEntityScript.js?v1" + Math.random()) + var SCRIPT_URL = Script.resolvePath("fireworksLaunchButtonEntityScript.js"); var MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/Launch-Button.fbx"; var launchButton = Entities.addEntity({ type: "Model", From 728612f9a7892b3e8e70333a52200ef940123f19 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 25 Feb 2016 09:26:37 -0800 Subject: [PATCH 19/25] far trigger launches fireworks --- examples/playa/fireworks/fireworksLaunchButtonEntityScript.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index acfbce099e..8c4480e24f 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -29,6 +29,10 @@ _this.shootFireworks(); }, + startFarTrigger: function() { + _this.shootFireworks(); + }, + clickReleaseOnEntity: function() { _this.shootFireworks(); }, From 9a108c298fb77e687f77860785cfac18287572c0 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 25 Feb 2016 09:34:22 -0800 Subject: [PATCH 20/25] smoke tweaks --- .../playa/fireworks/fireworksLaunchButtonEntityScript.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index 8c4480e24f..560c55681d 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -86,11 +86,11 @@ var smokeSettings = { type: "ParticleEffect", position: smokeTrailPosition, - lifespan: 1.6, + lifespan: 4, lifetime: 20, name: "Smoke Trail", maxParticles: 3000, - emitRate: 50, + emitRate: 80, emitSpeed: 0, speedSpread: 0, dimensions: { @@ -115,8 +115,8 @@ radiusSpread: 0.001, particleRadius: 0.06, radiusStart: 0.06, - radiusFinish: 0.2, - alpha: 0.7, + radiusFinish: 0.6, + alpha: 0.5, alphaSpread: 0, alphaStart: 0, alphaFinish: 0, From d4d5aed51867f7b6cee3a60a3ff495774043211e Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 25 Feb 2016 09:44:48 -0800 Subject: [PATCH 21/25] smoke tweaks --- .../fireworksLaunchButtonEntityScript.js | 44 +++++-------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index 560c55681d..7b82fbdada 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -86,7 +86,7 @@ var smokeSettings = { type: "ParticleEffect", position: smokeTrailPosition, - lifespan: 4, + lifespan: 10, lifetime: 20, name: "Smoke Trail", maxParticles: 3000, @@ -104,21 +104,21 @@ azimuthFinish: 3.14, emitAcceleration: { x: 0, - y: 0.1, + y: 0.01, z: 0 }, accelerationSpread: { - x: 0.1, + x: 0.01, y: 0, - z: 0.1 + z: 0.01 }, - radiusSpread: 0.001, - particleRadius: 0.06, + radiusSpread: 0.03, + particleRadius: 0.3, radiusStart: 0.06, - radiusFinish: 0.6, - alpha: 0.5, + radiusFinish: 0.9, + alpha: 0.4, alphaSpread: 0, - alphaStart: 0, + alphaStart: 0.7, alphaFinish: 0, textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", emitterShouldTrail: true, @@ -127,36 +127,12 @@ var smoke = Entities.addEntity(smokeSettings); - smokeSettings.colorStart = { - red: 75, - green: 193, - blue: 254 - }; - smokeSettings.color = { - red: 202, - green: 132, - blue: 151 - }; - smokeSettings.colorFinish = { - red: 250, - green: 132, - blue: 21 - }; - smokeSettings.alphaStart = 0.6; - smokeSettings.alphaFinish = 0.1; - - smokeSettings.name = "fire emitter"; - var fire = Entities.addEntity(smokeSettings); - Script.setTimeout(function() { Entities.editEntity(smoke, { parentID: null, isEmitting: false }); - Entities.editEntity(fire, { - parentID: null, - isEmitting: false - }); + var explodeBasePosition = Entities.getEntityProperties(missle, "position").position; From f12acfb7f3e64a1741eab47579ce44b49c4c587e Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 25 Feb 2016 09:49:44 -0800 Subject: [PATCH 22/25] simplfied --- .../playa/fireworks/fireworksLaunchButtonEntityScript.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index 7b82fbdada..a97e334dec 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -83,7 +83,7 @@ }); var smokeTrailPosition = Vec3.sum(launchPosition, Vec3.multiply(-missleDimensions.y / 2 + 0.1, Quat.getUp(missleRotation))); - var smokeSettings = { + var smoke = Entities.addEntity({ type: "ParticleEffect", position: smokeTrailPosition, lifespan: 10, @@ -122,17 +122,15 @@ alphaFinish: 0, textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", emitterShouldTrail: true, - parentID: missle - }; + parentID: missle, + }); - var smoke = Entities.addEntity(smokeSettings); Script.setTimeout(function() { Entities.editEntity(smoke, { parentID: null, isEmitting: false }); - var explodeBasePosition = Entities.getEntityProperties(missle, "position").position; From 54ee3d347c2098237146e4086e52727523eadc6d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 25 Feb 2016 09:53:17 -0800 Subject: [PATCH 23/25] more velocity --- .../playa/fireworks/fireworksLaunchButtonEntityScript.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index a97e334dec..380bbec009 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -18,8 +18,8 @@ _this.launchSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/missle+launch.wav"); _this.explosionSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/fireworksExplosion.wav"); _this.timeToExplosionRange = { - min: 2000, - max: 4000 + min: 2500, + max: 4500 }; }; @@ -60,8 +60,8 @@ z: 0.24 }, randFloat(0.2, 1.5)); var missleRotation = Quat.fromPitchYawRollDegrees(randInt(-60, 60), 0, randInt(-60, 60)); - var missleVelocity = Vec3.multiply(Quat.getUp(missleRotation), randFloat(1, 3)); - var missleAcceleration = Vec3.multiply(Quat.getUp(missleRotation), randFloat(0.7, 3)); + var missleVelocity = Vec3.multiply(Quat.getUp(missleRotation), randFloat(2, 4)); + var missleAcceleration = Vec3.multiply(Quat.getUp(missleRotation), randFloat(1, 3)); var missle = Entities.addEntity({ type: "Model", modelURL: MODEL_URL, From 98cf784c6f2aba50a4a44819c923846652da7dfd Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 25 Feb 2016 10:32:21 -0800 Subject: [PATCH 24/25] more smoke fading --- examples/playa/fireworks/fireworksLaunchButtonEntityScript.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index 380bbec009..7e85f5695f 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -116,7 +116,7 @@ particleRadius: 0.3, radiusStart: 0.06, radiusFinish: 0.9, - alpha: 0.4, + alpha: 0.1, alphaSpread: 0, alphaStart: 0.7, alphaFinish: 0, From 4d27d5c9f2787e0d0051ee934b5632101cafa1bc Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Thu, 25 Feb 2016 13:45:08 -0800 Subject: [PATCH 25/25] Update fireworksLaunchButtonEntityScript.js --- .../playa/fireworks/fireworksLaunchButtonEntityScript.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js index 7e85f5695f..63c4f3616e 100644 --- a/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js +++ b/examples/playa/fireworks/fireworksLaunchButtonEntityScript.js @@ -2,8 +2,8 @@ // fireworksLaunchEntityScript.js // examples/playa/fireworks // - // Created by Eric Levina on 2/24/16. - // Copyright 2015 High Fidelity, Inc. + // Created by Eric Levin on 2/24/16. + // Copyright 2016 High Fidelity, Inc. // // Run this script to spawn a big fireworks launch button that a user can press // @@ -226,4 +226,4 @@ // entity scripts always need to return a newly constructed object of our type return new Fireworks(); - }); \ No newline at end of file + });