From b7d0a75f2534759a756345373fec5846609b9a88 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 30 Dec 2015 11:46:16 -0800 Subject: [PATCH] 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