Skip to content

Commit 01e5db2

Browse files
authored
Merge pull request #20 from martinRenou/refactor
Refactor the Water effect
2 parents f90d698 + 6ecd86f commit 01e5db2

16 files changed

Lines changed: 644 additions & 465 deletions

src/Effects/Alpha.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ class Alpha extends Effect {
3535

3636
this.sortTriangleIndices();
3737

38-
this.parent.on('change:geometry', this.sortTriangleIndices.bind(this));
38+
// There is no new geometry specific to this effect, we forward the parent event
39+
this.parent.on('change:geometry', () => {
40+
this.sortTriangleIndices.bind(this);
41+
42+
this.trigger('change:geometry');
43+
});
3944

4045
this.initialized = true;
4146
this.updateMatrix();

src/Effects/IsoColor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class IsoColor extends Effect {
4545
this.buildMaterial();
4646

4747
this.initialized = true;
48+
49+
// There is no new geometry specific to this effect, we forward the parent event
50+
this.parent.on('change:geometry', () => { this.trigger('change:geometry'); });
51+
4852
this.updateMatrix();
4953
}
5054

src/Effects/RGB.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class RGB extends Effect {
3434
this.buildMaterial();
3535

3636
this.initialized = true;
37+
38+
// There is no new geometry specific to this effect, we forward the parent event
39+
this.parent.on('change:geometry', () => { this.trigger('change:geometry'); });
40+
3741
this.updateMatrix();
3842
}
3943

src/Effects/Threshold.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Threshold extends Effect {
5555
// Returns 1 if input > min, 0 otherwise
5656
this.isOverMin = new Nodes.MathNode(this.minNode, this.inputNode, Nodes.MathNode.STEP);
5757

58+
// TODO: Use a mask node instead of an alpha node?
5859
this.thresholdAlpha = new Nodes.OperatorNode(this.isUnderMax, this.isOverMin, Nodes.OperatorNode.MUL);
5960

6061
this.addAlphaNode(NodeOperation.MUL, this.thresholdAlpha);
@@ -83,10 +84,14 @@ class Threshold extends Effect {
8384
this.meshes.push(this.mesh2);
8485

8586
this.inputComponent.on('change:array', this.onInputArrayChange.bind(this));
87+
} else {
88+
// There is no new geometry specific to this effect, we forward the parent event
89+
this.parent.on('change:geometry', () => { this.trigger('change:geometry'); });
8690
}
8791

8892
this.buildMaterial();
8993

94+
9095
this.initialized = true;
9196
}
9297

src/Effects/Warp.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class Warp extends Effect {
3838
this.buildMaterial();
3939

4040
this.initialized = true;
41+
42+
// There is no new geometry specific to this effect, we forward the parent event
43+
this.parent.on('change:geometry', () => { this.trigger('change:geometry'); });
44+
4145
this.updateMatrix();
4246
}
4347

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ float noise(vec2 st) {
145145
dot(random2(i + vec2(1.0, 0.0)), f - vec2(1.0, 0.0)),
146146
u.x
147147
),
148-
mix(
148+
mix(
149149
dot(random2(i + vec2(0.0, 1.0)), f - vec2(0.0, 1.0)),
150-
dot(random2(i + vec2(1.0, 1.0) ), f - vec2(1.0, 1.0)),
150+
dot(random2(i + vec2(1.0, 1.0) ), f - vec2(1.0, 1.0)),
151151
u.x
152152
),
153153
u.y

0 commit comments

Comments
 (0)