-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathIsoColor.ts
108 lines (74 loc) · 2.39 KB
/
IsoColor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import * as THREE from 'three';
import * as Nodes from 'three/examples/jsm/nodes/Nodes';
import {
Effect, Input, InputDimension
} from '../EffectBlock';
import {
Block
} from '../Block';
import {
Component
} from '../Data';
import {
NodeOperation
} from '../NodeMesh';
import {
getColorMapTexture
} from '../utils/colormaps';
export
class IsoColor extends Effect {
constructor (parent: Block, input: Input, min: number, max: number, colorMap: string = 'Black-Body Radiation') {
super(parent, input);
this.texture = getColorMapTexture(colorMap);
this.textureNode = new Nodes.TextureNode(this.texture);
const functionNode = new Nodes.FunctionNode(
`vec3 isoColorFunc${this.id}(sampler2D textureMap, float min, float max, float data){
vec2 colorPosition = vec2((data - min) / (max - min), 0.0);
return vec3(texture2D(textureMap, colorPosition));
}`
);
this.minNode = new Nodes.FloatNode(min);
this.maxNode = new Nodes.FloatNode(max);
this.functionCallNode = new Nodes.FunctionCallNode(functionNode, [this.textureNode, this.minNode, this.maxNode, this.inputNode]);
this.addColorNode(NodeOperation.ASSIGN, this.functionCallNode);
this.buildMaterial();
this.initialized = true;
// There is no new geometry specific to this effect, we forward the parent event
this.parent.on('change:geometry', () => { this.trigger('change:geometry'); });
this.updateMatrix();
}
setInput(input?: Input) : void {
super.setInput(input);
if (this.initialized) {
this.functionCallNode.inputs = [this.textureNode, this.minNode, this.maxNode, this.inputNode];
this.buildMaterial();
}
}
set min (value: number) {
this.minNode.value = value;
}
get min () {
return this.minNode.value;
}
set max (value: number) {
this.maxNode.value = value;
}
get max () {
return this.maxNode.value;
}
get inputDimension () : InputDimension {
return 1;
}
set colorMap (colorMap: string) {
this.texture = getColorMapTexture(colorMap);
this.textureNode.value = this.texture;
}
private initialized: boolean = false;
private functionCallNode: Nodes.FunctionCallNode;
private minNode: Nodes.FloatNode;
private maxNode: Nodes.FloatNode;
private texture: THREE.DataTexture;
private textureNode: Nodes.TextureNode;
protected inputs: [Component];
protected inputNode: Nodes.Node;
}