@@ -28,6 +28,7 @@ interface ThresholdOptions extends BlockOptions {
28
28
max ?: number ;
29
29
30
30
dynamic ?: boolean ;
31
+ inclusive ?: boolean ;
31
32
32
33
}
33
34
@@ -42,24 +43,28 @@ class Threshold extends Effect {
42
43
this . _min = options . min !== undefined ? options . min : this . _min ;
43
44
this . _max = options . max !== undefined ? options . max : this . _max ;
44
45
this . dynamic = options . dynamic !== undefined ? options . dynamic : this . dynamic ;
46
+ this . _inclusive = options . inclusive !== undefined ? options . inclusive : this . _inclusive ;
45
47
}
46
48
47
49
// Create min and max float nodes
48
50
this . minNode = new Nodes . FloatNode ( this . _min ) ;
49
51
this . maxNode = new Nodes . FloatNode ( this . _max ) ;
50
52
51
- // GLSL's STEP function is more optimized than an if statement
52
- // Returns 1 if input < max, 0 otherwise
53
- this . isUnderMax = new Nodes . MathNode ( this . inputNode , this . maxNode , Nodes . MathNode . STEP ) ;
54
-
55
- // Returns 1 if input > min, 0 otherwise
56
- this . isOverMin = new Nodes . MathNode ( this . minNode , this . inputNode , Nodes . MathNode . STEP ) ;
57
-
58
- this . addMaskNode ( new Nodes . CondNode (
59
- new Nodes . OperatorNode ( this . isUnderMax , this . isOverMin , Nodes . OperatorNode . MUL ) , new Nodes . FloatNode ( 0 ) ,
60
- Nodes . CondNode . EQUAL ,
61
- new Nodes . BoolNode ( false ) , new Nodes . BoolNode ( true )
62
- ) ) ;
53
+ // Show only if min < or<= input
54
+ this . condNode1 = new Nodes . CondNode (
55
+ this . minNode , this . inputNode ,
56
+ this . _inclusive ? Nodes . CondNode . LESS_EQUAL : Nodes . CondNode . LESS ,
57
+ new Nodes . BoolNode ( true ) , new Nodes . BoolNode ( false )
58
+ ) ;
59
+ this . addMaskNode ( this . condNode1 ) ;
60
+
61
+ // Show only if input < or<= max
62
+ this . condNode2 = new Nodes . CondNode (
63
+ this . inputNode , this . maxNode ,
64
+ this . _inclusive ? Nodes . CondNode . LESS_EQUAL : Nodes . CondNode . LESS ,
65
+ new Nodes . BoolNode ( true ) , new Nodes . BoolNode ( false )
66
+ ) ;
67
+ this . addMaskNode ( this . condNode2 ) ;
63
68
64
69
// If there are tetrahedrons, compute new iso-surfaces
65
70
if ( this . parent . tetrahedronIndices != null ) {
@@ -92,7 +97,6 @@ class Threshold extends Effect {
92
97
93
98
this . buildMaterial ( ) ;
94
99
95
-
96
100
this . initialized = true ;
97
101
}
98
102
@@ -168,6 +172,12 @@ class Threshold extends Effect {
168
172
return this . _max ;
169
173
}
170
174
175
+ set inclusive ( value : boolean ) {
176
+ const op = this . _inclusive ? Nodes . CondNode . LESS_EQUAL : Nodes . CondNode . LESS ;
177
+ this . condNode1 . op = op ;
178
+ this . condNode2 . op = op ;
179
+ }
180
+
171
181
get inputDimension ( ) : InputDimension {
172
182
return 1 ;
173
183
}
@@ -178,9 +188,12 @@ class Threshold extends Effect {
178
188
private _max : number = 1 ;
179
189
180
190
private dynamic : boolean = false ;
191
+ private _inclusive : boolean = true ;
181
192
182
193
private minNode : Nodes . FloatNode ;
183
194
private maxNode : Nodes . FloatNode ;
195
+ private condNode1 : Nodes . CondNode ;
196
+ private condNode2 : Nodes . CondNode ;
184
197
185
198
private isUnderMax : Nodes . MathNode ;
186
199
private isOverMin : Nodes . MathNode ;
0 commit comments