From b7d0a75f2534759a756345373fec5846609b9a88 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 30 Dec 2015 11:46:16 -0800 Subject: [PATCH 1/5] dynamic lifetimes for particle systems --- examples/controllers/handControllerGrab.js | 34 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 9652132c08..3ad1a21fd3 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -56,7 +56,6 @@ var LINE_ENTITY_DIMENSIONS = { var LINE_LENGTH = 500; var PICK_MAX_DISTANCE = 500; // max length of pick-ray - // // near grabbing // @@ -129,6 +128,7 @@ var USE_PARTICLE_BEAM_FOR_SEARCHING = true; var USE_ENTITY_LINES_FOR_MOVING = false; var USE_OVERLAY_LINES_FOR_MOVING = false; var USE_PARTICLE_BEAM_FOR_MOVING = true; +var TEMPORARY_PARTICLE_BEAM_LIFETIME = 30; var USE_SPOTLIGHT = false; var USE_POINTLIGHT = false; @@ -549,6 +549,14 @@ function MyController(hand) { }; + this.renewParticleBeamLifetime = function(){ + var props = Entities.getEntityProperties(this.particleBeam,"age"); + Entities.editEntity(this.particleBeam,{ + lifetime: TEMPORARY_PARTICLE_BEAM_LIFETIME + props.age // renew lifetime + }) + var lifetime = Entities.getEntityProperties(this.particleBeam,"lfietime").lifetime; + } + this.evalLightWorldTransform = function(modelPos, modelRot) { var MODEL_LIGHT_POSITION = { @@ -1803,4 +1811,26 @@ function cleanup() { } Script.scriptEnding.connect(cleanup); -Script.update.connect(update); \ No newline at end of file +Script.update.connect(update); + +// particle systems can end up hanging around if a user crashes or something else causes controller cleanup not to get called. +// we can't create the search system on-demand since it takes some time for the particles to reach their entire length. +// thus the system cannot have a fixed lifetime. this loop updates the lifetimes and will stop updating if a user crashes. + +if(USE_PARTICLE_BEAM_FOR_SEARCHING===true || USE_PARTICLE_BEAM_FOR_SEARCHING ===true){ +Script.update.connect(renewParticleBeamLifetimes) +} + +var sinceLastParticleLifetimeUpdate = 0; + +function renewParticleBeamLifetimes(deltaTime) { + //debounce this call since we don't want it 60x a second + sinceLastParticleLifetimeUpdate = sinceLastParticleLifetimeUpdate + deltaTime; + if (sinceLastParticleLifetimeUpdate > TEMPORARY_PARTICLE_BEAM_LIFETIME - 10) { + sinceLastParticleLifetimeUpdate = 0; + } else { + return; + } + rightController.renewParticleBeamLifetime(); + leftController.renewParticleBeamLifetime(); +} \ No newline at end of file From 2de517c70fb8593a63c4fbf83996ebe90272becc Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 30 Dec 2015 11:50:20 -0800 Subject: [PATCH 2/5] remove unused line --- examples/controllers/handControllerGrab.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index e66890a640..0de2286b79 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -577,7 +577,6 @@ function MyController(hand) { Entities.editEntity(this.particleBeam,{ lifetime: TEMPORARY_PARTICLE_BEAM_LIFETIME + props.age // renew lifetime }) - var lifetime = Entities.getEntityProperties(this.particleBeam,"lfietime").lifetime; } this.evalLightWorldTransform = function(modelPos, modelRot) { From eae8b4851389e98615905896576cc37d84f06002 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 30 Dec 2015 11:58:18 -0800 Subject: [PATCH 3/5] fix conditional --- examples/controllers/handControllerGrab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 0de2286b79..a62507fcf9 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -1865,7 +1865,7 @@ Script.update.connect(update); // we can't create the search system on-demand since it takes some time for the particles to reach their entire length. // thus the system cannot have a fixed lifetime. this loop updates the lifetimes and will stop updating if a user crashes. -if(USE_PARTICLE_BEAM_FOR_SEARCHING===true || USE_PARTICLE_BEAM_FOR_SEARCHING ===true){ +if(USE_PARTICLE_BEAM_FOR_SEARCHING===true || USE_PARTICLE_BEAM_FOR_MOVING ===true){ Script.update.connect(renewParticleBeamLifetimes) } From 58257b00e730faad116abe591f73530187bf2f6c Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 30 Dec 2015 17:18:33 -0800 Subject: [PATCH 4/5] reduce gap btw refresh --- examples/controllers/handControllerGrab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index a62507fcf9..ecf5de4128 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -1874,7 +1874,7 @@ var sinceLastParticleLifetimeUpdate = 0; function renewParticleBeamLifetimes(deltaTime) { //debounce this call since we don't want it 60x a second sinceLastParticleLifetimeUpdate = sinceLastParticleLifetimeUpdate + deltaTime; - if (sinceLastParticleLifetimeUpdate > TEMPORARY_PARTICLE_BEAM_LIFETIME - 10) { + if (sinceLastParticleLifetimeUpdate > TEMPORARY_PARTICLE_BEAM_LIFETIME - 2) { sinceLastParticleLifetimeUpdate = 0; } else { return; From 40aee910d78d8122db76368c49b52a533f35b1e4 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 30 Dec 2015 20:18:52 -0800 Subject: [PATCH 5/5] disconnect --- examples/controllers/handControllerGrab.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index ecf5de4128..812e575491 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -1856,8 +1856,10 @@ function cleanup() { rightController.cleanup(); leftController.cleanup(); Controller.disableMapping(MAPPING_NAME); + if (USE_PARTICLE_BEAM_FOR_SEARCHING === true || USE_PARTICLE_BEAM_FOR_MOVING === true) { + Script.update.disconnect(renewParticleBeamLifetimes); + } } - Script.scriptEnding.connect(cleanup); Script.update.connect(update);