repo: janusweb action: commit revision: path_from: revision_from: 17ae509ba2ca4eb3f70d6d17b0bf2a994d1d4b12: path_to: revision_to:
commit 17ae509ba2ca4eb3f70d6d17b0bf2a994d1d4b12 Author: James BaicoianuDate: Thu Feb 22 07:43:18 2018 +0000 Particle setPoint(), more efficient/immediate bounding sphere calculations diff --git a/scripts/janusparticle.js b/scripts/janusparticle.js
--- a/scripts/janusparticle.js
+++ b/scripts/janusparticle.js
@@ -37,6 +37,7 @@ elation.require(['janusweb.janusbase'], function() {
this.pickable = false;
this.collidable = false;
this.lastboundingsphereupdate = 0;
+ this.boundingRadiusSq = 0;
this.updateParticles = elation.bind(this, this.updateParticles); // FIXME - hack, this should happen at the lower level of all components
}
this.createObject3D = function() {
@@ -151,7 +152,7 @@ elation.require(['janusweb.janusbase'], function() {
this.currentpoint = 0;
this.lasttime = performance.now();
- this.updateBoundingSphere();
+ //this.updateBoundingSphere();
}
this.resetParticles = function() {
var geo = this.geometry;
@@ -212,16 +213,18 @@ elation.require(['janusweb.janusbase'], function() {
this.geometry.attributes.position.needsUpdate = true;
this.geometry.attributes.color.needsUpdate = true;
-
- if (now - this.lastboundingsphereupdate > this.duration * 1000) {
- this.updateBoundingSphere();
- this.lastboundingsphereupdate = now;
- }
- this.refresh();
}
- this.updateBoundingSphere = function() {
- if (this.objects['3d'] && this.objects['3d'].geometry) {
- this.objects['3d'].geometry.computeBoundingSphere();
+ this.updateBoundingSphere = function(vec) {
+ if (this.objects['3d']) {
+ var lengthSq = vec.lengthSq();
+ if (lengthSq > this.boundingRadiusSq) {
+ this.boundingRadiusSq = lengthSq;
+ var geo = this.objects['3d'].geometry;
+ if (!geo.boundingSphere) {
+ geo.boundingSphere = new THREE.Sphere();
+ }
+ geo.boundingSphere.radius = Math.sqrt(lengthSq);
+ }
}
}
this.createPoint = function() {
@@ -311,6 +314,8 @@ elation.require(['janusweb.janusbase'], function() {
color[idx*3] = point.color.r;
color[idx*3+1] = point.color.g;
color[idx*3+2] = point.color.b;
+
+ this.updateBoundingSphere(point.pos);
}
}
this.extractEmitPoints = function(mesh) {
@@ -378,5 +383,48 @@ elation.require(['janusweb.janusbase'], function() {
}
return this._proxyobject;
}
+ this.setPoint = function(pointnum, newpos, newvel, newaccel, newcol) {
+ var offset = pointnum * 3;
+
+ var point = this.particles[pointnum];
+ if (!point) {
+ point = this.createPoint();
+ this.particles[pointnum] = point;
+ }
+
+ point.active = 1;
+
+ var pos = this.geometry.attributes.position.array,
+ color = this.geometry.attributes.color.array;
+
+ if (newpos) {
+ point.pos.copy(newpos);
+
+ pos[offset ] = newpos.x;
+ pos[offset + 1] = newpos.y;
+ pos[offset + 2] = newpos.z;
+
+ this.geometry.attributes.position.needsUpdate = true;
+ this.updateBoundingSphere(newpos);
+ }
+
+ if (newvel) {
+ point.vel.copy(newvel);
+ }
+
+ if (newaccel) {
+ point.accel.copy(newaccel);
+ }
+
+ if (newcol) {
+ point.col.copy(newcol);
+
+ col[offset ] = newcol.x;
+ col[offset + 1] = newcol.y;
+ col[offset + 2] = newcol.z;
+
+ this.geometry.attributes.color.needsUpdate = true;
+ }
+ }
}, elation.engine.things.janusbase);
});
-----END OF PAGE-----