Blender V4.3
NOD_value_elem.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
19#include <optional>
20#include <variant>
21
22#include "BLI_hash.hh"
24
25#include "DNA_node_types.h"
26
28
33 bool affected = false;
34
35 operator bool() const
36 {
37 return this->affected;
38 }
39
41
42 void merge(const PrimitiveValueElem &other)
43 {
44 this->affected |= other.affected;
45 }
46
47 void intersect(const PrimitiveValueElem &other)
48 {
49 this->affected &= other.affected;
50 }
51
52 uint64_t hash() const
53 {
54 return get_default_hash(this->affected);
55 }
56};
57
59 static BoolElem all()
60 {
61 return {true};
62 }
63};
64
66 static FloatElem all()
67 {
68 return {true};
69 }
70};
71
72struct IntElem : public PrimitiveValueElem {
73 static IntElem all()
74 {
75 return {true};
76 }
77};
78
79struct VectorElem {
84
85 operator bool() const
86 {
87 return this->x || this->y || this->z;
88 }
89
91
92 uint64_t hash() const
93 {
94 return get_default_hash(this->x, this->y, this->z);
95 }
96
97 void merge(const VectorElem &other)
98 {
99 this->x.merge(other.x);
100 this->y.merge(other.y);
101 this->z.merge(other.z);
102 }
103
104 void intersect(const VectorElem &other)
105 {
106 this->x.intersect(other.x);
107 this->y.intersect(other.y);
108 this->z.intersect(other.z);
109 }
110
112 {
113 return {{true}, {true}, {true}};
114 }
115};
116
126
127 operator bool() const
128 {
129 return this->euler || this->axis || this->angle;
130 }
131
133
135 {
136 return get_default_hash(this->euler, this->axis, this->angle);
137 }
138
139 void merge(const RotationElem &other)
140 {
141 this->euler.merge(other.euler);
142 this->axis.merge(other.axis);
143 this->angle.merge(other.angle);
144 }
145
146 void intersect(const RotationElem &other)
147 {
148 this->euler.intersect(other.euler);
149 this->axis.intersect(other.axis);
150 this->angle.intersect(other.angle);
151 }
152
154 {
155 return {VectorElem::all(), VectorElem::all(), {true}};
156 }
157};
158
165
166 operator bool() const
167 {
168 return this->translation || this->rotation || this->scale || this->any_non_transform;
169 }
170
172
174 {
175 return get_default_hash(
176 this->translation, this->rotation, this->scale, this->any_non_transform);
177 }
178
179 void merge(const MatrixElem &other)
180 {
181 this->translation.merge(other.translation);
182 this->rotation.merge(other.rotation);
183 this->scale.merge(other.scale);
184 this->any_non_transform.merge(other.any_non_transform);
185 }
186
187 void intersect(const MatrixElem &other)
188 {
189 this->translation.intersect(other.translation);
190 this->rotation.intersect(other.rotation);
191 this->scale.intersect(other.scale);
192 this->any_non_transform.intersect(other.any_non_transform);
193 }
194
196 {
198 }
199};
200
206 std::variant<BoolElem, FloatElem, IntElem, VectorElem, RotationElem, MatrixElem> elem;
207
208 operator bool() const
209 {
210 return std::visit([](const auto &value) { return bool(value); }, this->elem);
211 }
212
214 {
215 return std::visit([](auto &value) { return value.hash(); }, this->elem);
216 }
217
218 void merge(const ElemVariant &other)
219 {
220 BLI_assert(this->elem.index() == other.elem.index());
221 std::visit(
222 [&](auto &value) {
223 using T = std::decay_t<decltype(value)>;
224 value.merge(std::get<T>(other.elem));
225 },
226 this->elem);
227 }
228
229 void intersect(const ElemVariant &other)
230 {
231 BLI_assert(this->elem.index() == other.elem.index());
232 std::visit(
233 [&](auto &value) {
234 using T = std::decay_t<decltype(value)>;
235 value.intersect(std::get<T>(other.elem));
236 },
237 this->elem);
238 }
239
240 void set_all()
241 {
242 std::visit(
243 [](auto &value) {
244 using T = std::decay_t<decltype(value)>;
245 value = T::all();
246 },
247 this->elem);
248 }
249
251 {
252 std::visit(
253 [](auto &value) {
254 using T = std::decay_t<decltype(value)>;
255 value = T();
256 },
257 this->elem);
258 }
259
261};
262
265 const bNodeSocket *socket = nullptr;
267
269 {
270 return get_default_hash(this->socket, this->elem);
271 }
272
274};
275
280
282 {
283 return get_default_hash(this->group_input_index, this->elem);
284 }
285
287};
288
291 const bNode *node = nullptr;
293
295 {
296 return get_default_hash(this->node, this->elem);
297 }
298
300};
301
305std::optional<ElemVariant> get_elem_variant_for_socket_type(eNodeSocketDatatype type);
306
308std::optional<ElemVariant> convert_socket_elem(const bNodeSocket &old_socket,
309 const bNodeSocket &new_socket,
310 const ElemVariant &old_elem);
311
312} // namespace blender::nodes::value_elem
#define BLI_assert(a)
Definition BLI_assert.h:50
#define BLI_STRUCT_EQUALITY_OPERATORS_1(Type, m)
#define BLI_STRUCT_EQUALITY_OPERATORS_3(Type, m1, m2, m3)
#define BLI_STRUCT_EQUALITY_OPERATORS_4(Type, m1, m2, m3, m4)
#define BLI_STRUCT_EQUALITY_OPERATORS_2(Type, m1, m2)
eNodeSocketDatatype
#define T
std::optional< ElemVariant > get_elem_variant_for_socket_type(const eNodeSocketDatatype type)
Definition value_elem.cc:9
std::optional< ElemVariant > convert_socket_elem(const bNodeSocket &old_socket, const bNodeSocket &new_socket, const ElemVariant &old_elem)
Definition value_elem.cc:29
uint64_t get_default_hash(const T &v)
Definition BLI_hash.hh:219
unsigned __int64 uint64_t
Definition stdint.h:90
std::variant< BoolElem, FloatElem, IntElem, VectorElem, RotationElem, MatrixElem > elem
void merge(const ElemVariant &other)
void intersect(const ElemVariant &other)
void merge(const MatrixElem &other)
void intersect(const MatrixElem &other)
void intersect(const PrimitiveValueElem &other)
void merge(const PrimitiveValueElem &other)
void intersect(const RotationElem &other)
void merge(const RotationElem &other)
void merge(const VectorElem &other)
void intersect(const VectorElem &other)