repo: janusweb
action: commit
revision: 
path_from: 
revision_from: 17171ca8d441e33f8bf3776ab9fcb4af757635a7:
path_to: 
revision_to: 
git.thebackupbox.net
janusweb
git clone git://git.thebackupbox.net/janusweb
commit 17171ca8d441e33f8bf3776ab9fcb4af757635a7
Author: James Baicoianu 
Date:   Wed May 16 17:36:19 2018 -0700

    Particle optimizations (min fps, frustum culling)

diff --git a/scripts/janusparticle.js b/scripts/janusparticle.js
index e8f3a429728bb6c18c8753eda5c73b6b9f6c1f10..
index ..958cf102c087756ec8b9c88971abdc2f70758a4a 100644
--- a/scripts/janusparticle.js
+++ b/scripts/janusparticle.js
@@ -23,6 +23,7 @@ elation.require(['janusweb.janusbase'], function() {
         rand_col: { type: 'vector3', default: [0, 0, 0]},
         rand_scale: { type: 'vector3', default: [0, 0, 0]},
         loop: { type: 'bool', default: false },
+        refreshrate: { type: 'int', default: 30 },
         blend_src: { type: 'string', default: 'src_alpha', set: this.updateMaterial },
         blend_dest: { type: 'string', default: 'one_minus_src_alpha', set: this.updateMaterial },
       });
@@ -36,8 +37,9 @@ elation.require(['janusweb.janusbase'], function() {
       this.started = false;
       this.pickable = false;
       this.collidable = false;
-      this.lastboundingsphereupdate = 0;
       this.boundingRadiusSq = 0;
+      this.boundingSphereWorld = new THREE.Sphere();
+      this.lastrefresh = 0;
       this.updateParticles = elation.bind(this, this.updateParticles); // FIXME - hack, this should happen at the lower level of all components
     }
     this.createObject3D = function() {
@@ -210,6 +212,15 @@ elation.require(['janusweb.janusbase'], function() {
         } 
       }
       this.lasttime = now;
+      // Notify the renderer of our changes, but only if we're visible to the player
+      // We also rate limit here, so if nothing else in the scene is changing, we
+      // render at a lower fps
+      this.localToWorld(this.boundingSphereWorld.center.set(0,0,0));
+      this.boundingSphereWorld.radius = this.objects['3d'].geometry.boundingSphere.radius;
+      if (player.viewfrustum.intersectsSphere(this.boundingSphereWorld) && now - this.lastrefresh > (1000 / this.refreshrate)) {
+        this.refresh();
+        this.lastrefresh = now;
+      }

       this.geometry.attributes.position.needsUpdate = true;
       this.geometry.attributes.color.needsUpdate = true;

-----END OF PAGE-----