-
Notifications
You must be signed in to change notification settings - Fork 6
/
visual_noise.h
309 lines (215 loc) · 7.85 KB
/
visual_noise.h
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#ifndef VISUAL_ACCIDENTAL_NOISE_H
#define VISUAL_ACCIDENTAL_NOISE_H
#include "noise.h"
struct Axis {
enum AxisType {
AXIS_DOMAIN,
AXIS_X,
AXIS_Y,
AXIS_Z,
AXIS_W,
AXIS_U,
AXIS_V,
};
AxisType type;
String as_alpha() const {
switch (type) {
case AXIS_DOMAIN: return "";
case AXIS_X: return "x";
case AXIS_Y: return "y";
case AXIS_Z: return "z";
case AXIS_W: return "w";
case AXIS_U: return "u";
case AXIS_V: return "v";
}
return "";
}
_FORCE_INLINE_ static String get_hints() {
return "Domain,X,Y,Z,W,U,V";
}
Axis() { type = AXIS_DOMAIN; }
};
VARIANT_ENUM_CAST(Axis::AxisType);
class VisualAccidentalNoiseNode;
class VisualAccidentalNoiseNodeComponent;
class VisualAccidentalNoise : public AccidentalNoise {
GDCLASS(VisualAccidentalNoise, AccidentalNoise);
Ref<VisualAccidentalNoiseNodeComponent> component; // default, tree root
void _update_noise();
void _queue_update();
void _component_updated();
volatile mutable bool dirty;
protected:
static void _bind_methods();
virtual void _validate_property(PropertyInfo &property) const;
public:
void set_clamping_enabled(bool p_enable);
bool is_clamping_enabled() const;
void set_clamp_low(double p_value);
double get_clamp_low() const;
void set_clamp_high(double p_value);
double get_clamp_high() const;
void generate();
void set_component(const Ref<VisualAccidentalNoiseNodeComponent> &p_component);
Ref<VisualAccidentalNoiseNodeComponent> get_component() const;
VisualAccidentalNoise();
private:
bool clamping_enabled;
double clamp_low;
double clamp_high;
};
class VisualAccidentalNoiseNode : public Resource {
GDCLASS(VisualAccidentalNoiseNode, Resource);
int port_preview;
Map<int, Variant> default_input_values;
protected:
Variant output_value;
Array get_default_input_values() const;
void set_default_input_values(const Array &p_values);
static void _bind_methods();
public:
static const int OUTPUT_PORT;
enum PortType {
PORT_TYPE_SCALAR,
PORT_TYPE_INDEX,
};
virtual String get_caption() const = 0;
virtual int get_input_port_count() const = 0;
virtual PortType get_input_port_type(int p_port) const = 0;
virtual String get_input_port_name(int p_port) const = 0;
virtual void set_input_port_value(int p_port, const Variant &p_value);
virtual Variant get_input_port_value(int p_port) const;
void set_input_port_default_value(int p_port, const Variant &p_value);
Variant get_input_port_default_value(int p_port) const; // if NIL (default if node does not set anything) is returned, it means no default value is wanted if disconnected, thus no input var must be supplied (empty string will be supplied)
virtual int get_output_port_count() const = 0;
virtual PortType get_output_port_type(int p_port) const = 0;
virtual String get_output_port_name(int p_port) const = 0;
virtual void set_output_port_value(int p_port, const Variant &p_value);
virtual Variant get_output_port_value(int p_port) const;
void set_output_port_for_preview(int p_index);
int get_output_port_for_preview() const;
virtual bool is_port_separator(int p_index) const;
virtual Vector<StringName> get_editable_properties() const;
virtual String get_warning() const;
virtual void evaluate(Ref<VisualAccidentalNoise> noise);
VisualAccidentalNoiseNode();
};
VARIANT_ENUM_CAST(VisualAccidentalNoiseNode::PortType);
class VisualAccidentalNoiseNodeComponent : public VisualAccidentalNoiseNode {
GDCLASS(VisualAccidentalNoiseNodeComponent, VisualAccidentalNoiseNode);
friend class VisualAccidentalNoise;
public:
struct Connection {
int from_node;
int from_port;
int to_node;
int to_port;
};
private:
String name;
struct Node {
Ref<VisualAccidentalNoiseNode> node;
Vector2 position;
};
struct Graph {
Map<int, Node> nodes;
List<Connection> connections;
} graph;
union ConnectionKey {
struct {
uint64_t node : 32;
uint64_t port : 32;
};
uint64_t key;
bool operator<(const ConnectionKey &p_key) const {
return key < p_key.key;
}
};
Vector2 graph_offset;
volatile mutable bool dirty;
Array _get_node_connections() const;
void _queue_update();
void _notify_changed();
protected:
static void _bind_methods();
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
public:
using Connections = VMap<ConnectionKey, const List<Connection>::Element *>;
enum {
NODE_ID_INVALID = -1,
NODE_ID_OUTPUT = 0,
};
void set_component_name(const String &p_name);
String get_component_name() const;
void add_node(const Ref<VisualAccidentalNoiseNode> &p_node, const Vector2 &p_position, int p_id);
void set_node_position(int p_id, const Vector2 &p_position);
Vector2 get_node_position(int p_id) const;
Ref<VisualAccidentalNoiseNode> get_node(int p_id) const;
bool has_node(int p_id) const;
Vector<int> get_node_list() const;
int get_valid_node_id() const;
int find_node_id(const Ref<VisualAccidentalNoiseNode> &p_node) const;
void remove_node(int p_id);
void evaluate_node(int p_id, Ref<VisualAccidentalNoise> noise, Connections &input_connections, Connections &output_connections, Set<int> &processed);
bool is_node_connection(int p_from_node, int p_from_port, int p_to_node, int p_to_port) const;
bool can_connect_nodes(int p_from_node, int p_from_port, int p_to_node, int p_to_port) const;
Error connect_nodes(int p_from_node, int p_from_port, int p_to_node, int p_to_port);
void disconnect_nodes(int p_from_node, int p_from_port, int p_to_node, int p_to_port);
void get_node_connections(List<Connection> *r_connections) const;
void set_graph_offset(const Vector2 &p_offset);
Vector2 get_graph_offset() const;
// String generate_preview_noise(int p_node, int p_port) const;
VisualAccidentalNoiseNodeComponent();
public:
virtual String get_caption() const;
virtual void set_input_port_value(int p_port, const Variant &p_value);
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
virtual void evaluate(Ref<VisualAccidentalNoise> p_noise);
};
class VisualAccidentalNoiseNodeInput : public VisualAccidentalNoiseNode {
GDCLASS(VisualAccidentalNoiseNodeInput, VisualAccidentalNoiseNode);
private:
String input_name;
protected:
static void _bind_methods();
public:
friend class VisualAccidentalNoise;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
virtual void set_output_port_value(int p_port, const Variant &p_value);
virtual Variant get_output_port_value(int p_port) const;
virtual bool is_port_separator(int p_index) const;
virtual String get_caption() const;
public:
void set_input_name(const String &p_input_name);
String get_input_name() const;
VisualAccidentalNoiseNodeInput();
};
class VisualAccidentalNoiseNodeOutput : public VisualAccidentalNoiseNode {
GDCLASS(VisualAccidentalNoiseNodeOutput, VisualAccidentalNoiseNode);
public:
friend class VisualAccidentalNoise;
public:
virtual void set_input_port_value(int p_port, const Variant &p_value);
virtual Variant get_input_port_value(int p_port) const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
virtual String get_caption() const;
VisualAccidentalNoiseNodeOutput();
};
#endif