Skip to content

Commit

Permalink
Merge pull request #629 from guycalledfrank/prtdrawcalls
Browse files Browse the repository at this point in the history
Skip rendering particle systems when they're invisible
  • Loading branch information
guycalledfrank committed Jun 8, 2016
2 parents fa9a98b + 69fb2fe commit 68633c5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 27 deletions.
2 changes: 2 additions & 0 deletions src/framework/components/particle-system/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ pc.extend(pc, function() {

if (!this.data.autoPlay) {
this.pause();
this.emitter.meshInstance.visible = false;
}
}

Expand Down Expand Up @@ -561,6 +562,7 @@ pc.extend(pc, function() {
play: function() {
this.data.paused = false;
if (this.emitter) {
this.emitter.meshInstance.visible = true;
this.emitter.loop = this.data.loop;
this.emitter.resetTime();
}
Expand Down
1 change: 1 addition & 0 deletions src/framework/components/particle-system/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ pc.extend(pc, function() {

if (data.enabled && entity.enabled) {
var emitter = data.model.emitter;
if (!emitter.meshInstance.visible) continue;

if (!data.paused) {

Expand Down
2 changes: 1 addition & 1 deletion src/scene/forward-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ pc.extend(pc, function () {
visible = true;
meshPos = null;
if (!drawCall.command) {
if (!drawCall.visible) continue; // use hidden property to quickly hide/show meshInstances
if (!drawCall.visible) continue; // use visible property to quickly hide/show meshInstances
meshInstance = drawCall;

// Only alpha sort and cull mesh instances in the main world
Expand Down
29 changes: 3 additions & 26 deletions src/scene/particle-emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,6 @@ pc.extend(pc, function() {
return x - y * Math.floor(x / y);
}

function tex1D(arr, u, chans, outArr, test) {
var a, b, c;

if ((chans === undefined) || (chans < 2)) {
u *= arr.length - 1;
a = arr[Math.floor(u)];
b = arr[Math.ceil(u)];
c = u % 1;
return a + (b - a) * c;//pc.math.lerp(a, b, c);
}

u *= arr.length / chans - 1;
if (!outArr) outArr = [];
for (var i = 0; i < chans; i++) {
a = arr[Math.floor(u) * chans + i];
b = arr[Math.ceil(u) * chans + i];
c = u % 1;
outArr[i] = a + (b - a) * c;//pc.math.lerp(a, b, c);
}
return outArr;
}

var default0Curve = new pc.Curve([0, 0, 1, 0]);
var default1Curve = new pc.Curve([0, 1, 1, 1]);
var default0Curve3 = new pc.CurveSet([0, 0, 1, 0], [0, 0, 1, 0], [0, 0, 1, 0]);
Expand Down Expand Up @@ -1538,10 +1516,9 @@ pc.extend(pc, function() {
}

if (!this.loop) {
if (this.onFinished) {
if (Date.now() > this.endTime) {
this.onFinished();
}
if (Date.now() > this.endTime) {
if (this.onFinished) this.onFinished();
this.meshInstance.visible = false;
}
}

Expand Down

0 comments on commit 68633c5

Please sign in to comment.