Skip to content

Commit 96c37a3

Browse files
Support bloom component with initial enabled:false (#5696)
1 parent 7c71302 commit 96c37a3

File tree

1 file changed

+11
-10
lines changed
  • examples/showcase/post-processing

1 file changed

+11
-10
lines changed

‎examples/showcase/post-processing/bloom.js‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ AFRAME.registerComponent('bloom', {
2121
},
2222
events: {
2323
rendererresize: function () {
24+
if (!this.composer) { return; }
2425
this.renderer.getSize(this.size);
2526
this.composer.setSize(this.size.width, this.size.height);
2627
}
@@ -30,7 +31,9 @@ AFRAME.registerComponent('bloom', {
3031
this.scene = this.el.object3D;
3132
this.renderer = this.el.renderer;
3233
this.originalRender = this.el.renderer.render;
33-
this.bind();
34+
if (this.data.enabled) {
35+
this.bind();
36+
}
3437
},
3538
update: function (oldData) {
3639
if (oldData.enabled === false && this.data.enabled === true) {
@@ -41,6 +44,8 @@ AFRAME.registerComponent('bloom', {
4144
this.el.renderer.render = this.originalRender;
4245
}
4346

47+
if (!this.data.enabled) { return; }
48+
4449
if (this.composer) {
4550
this.composer.dispose();
4651
}
@@ -64,9 +69,7 @@ AFRAME.registerComponent('bloom', {
6469
var strength = this.data.strength;
6570
var radius = this.data.radius;
6671
var threshold = this.data.threshold;
67-
if (this.bloomPass) {
68-
this.bloomPass.dispose();
69-
}
72+
if (this.bloomPass) { this.bloomPass.dispose(); }
7073
this.bloomPass = new UnrealBloomPass(
7174
resolution,
7275
strength,
@@ -76,9 +79,7 @@ AFRAME.registerComponent('bloom', {
7679
this.composer.addPass(this.bloomPass);
7780

7881
// create output pass
79-
if (this.outputPass) {
80-
this.outputPass.dispose();
81-
}
82+
if (this.outputPass) { this.outputPass.dispose(); }
8283
this.outputPass = new OutputPass();
8384
this.composer.addPass(this.outputPass);
8485
},
@@ -103,8 +104,8 @@ AFRAME.registerComponent('bloom', {
103104

104105
remove: function () {
105106
this.el.renderer.render = this.originalRender;
106-
this.bloomPass.dispose();
107-
this.outputPass.dispose();
108-
this.composer.dispose();
107+
if (this.bloomPass) { this.bloomPass.dispose(); }
108+
if (this.outputPass) { this.outputPass.dispose(); }
109+
if (this.composer) { this.composer.dispose(); }
109110
}
110111
});

0 commit comments

Comments
 (0)