Blender V5.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
8
9#pragma once
10
22
23#include <optional>
24#include <variant>
25
26#include "BLI_hash.hh"
27
28#include "DNA_node_types.h"
29
31
36 bool affected = false;
37
38 operator bool() const
39 {
40 return this->affected;
41 }
42
43 friend bool operator==(const PrimitiveValueElem &a, const PrimitiveValueElem &b) = default;
44
45 void merge(const PrimitiveValueElem &other)
46 {
47 this->affected |= other.affected;
48 }
49
50 void intersect(const PrimitiveValueElem &other)
51 {
52 this->affected &= other.affected;
53 }
54
55 uint64_t hash() const
56 {
57 return get_default_hash(this->affected);
58 }
59};
60
62 static BoolElem all()
63 {
64 return {true};
65 }
66};
67
69 static FloatElem all()
70 {
71 return {true};
72 }
73};
74
75struct IntElem : public PrimitiveValueElem {
76 static IntElem all()
77 {
78 return {true};
79 }
80};
81
82struct VectorElem {
87
88 operator bool() const
89 {
90 return this->x || this->y || this->z;
91 }
92
93 friend bool operator==(const VectorElem &a, const VectorElem &b) = default;
94
95 uint64_t hash() const
96 {
97 return get_default_hash(this->x, this->y, this->z);
98 }
99
100 void merge(const VectorElem &other)
101 {
102 this->x.merge(other.x);
103 this->y.merge(other.y);
104 this->z.merge(other.z);
105 }
106
107 void intersect(const VectorElem &other)
108 {
109 this->x.intersect(other.x);
110 this->y.intersect(other.y);
111 this->z.intersect(other.z);
112 }
113
115 {
116 return {{true}, {true}, {true}};
117 }
118};
119
129
130 operator bool() const
131 {
132 return this->euler || this->axis || this->angle;
133 }
134
135 friend bool operator==(const RotationElem &a, const RotationElem &b) = default;
136
138 {
139 return get_default_hash(this->euler, this->axis, this->angle);
140 }
141
142 void merge(const RotationElem &other)
143 {
144 this->euler.merge(other.euler);
145 this->axis.merge(other.axis);
146 this->angle.merge(other.angle);
147 }
148
149 void intersect(const RotationElem &other)
150 {
151 this->euler.intersect(other.euler);
152 this->axis.intersect(other.axis);
153 this->angle.intersect(other.angle);
154 }
155
157 {
158 return {VectorElem::all(), VectorElem::all(), {true}};
159 }
160};
161
168
169 operator bool() const
170 {
171 return this->translation || this->rotation || this->scale || this->any_non_transform;
172 }
173
174 friend bool operator==(const MatrixElem &a, const MatrixElem &b) = default;
175
177 {
178 return get_default_hash(
179 this->translation, this->rotation, this->scale, this->any_non_transform);
180 }
181
182 void merge(const MatrixElem &other)
183 {
184 this->translation.merge(other.translation);
185 this->rotation.merge(other.rotation);
186 this->scale.merge(other.scale);
187 this->any_non_transform.merge(other.any_non_transform);
188 }
189
190 void intersect(const MatrixElem &other)
191 {
192 this->translation.intersect(other.translation);
193 this->rotation.intersect(other.rotation);
194 this->scale.intersect(other.scale);
195 this->any_non_transform.intersect(other.any_non_transform);
196 }
197
199 {
201 }
202};
203
209 std::variant<BoolElem, FloatElem, IntElem, VectorElem, RotationElem, MatrixElem> elem;
210
211 operator bool() const
212 {
213 return std::visit([](const auto &value) { return bool(value); }, this->elem);
214 }
215
217 {
218 return std::visit([](auto &value) { return value.hash(); }, this->elem);
219 }
220
221 void merge(const ElemVariant &other)
222 {
223 BLI_assert(this->elem.index() == other.elem.index());
224 std::visit(
225 [&](auto &value) {
226 using T = std::decay_t<decltype(value)>;
227 value.merge(std::get<T>(other.elem));
228 },
229 this->elem);
230 }
231
232 void intersect(const ElemVariant &other)
233 {
234 BLI_assert(this->elem.index() == other.elem.index());
235 std::visit(
236 [&](auto &value) {
237 using T = std::decay_t<decltype(value)>;
238 value.intersect(std::get<T>(other.elem));
239 },
240 this->elem);
241 }
242
243 void set_all()
244 {
245 std::visit(
246 [](auto &value) {
247 using T = std::decay_t<decltype(value)>;
248 value = T::all();
249 },
250 this->elem);
251 }
252
254 {
255 std::visit(
256 [](auto &value) {
257 using T = std::decay_t<decltype(value)>;
258 value = T();
259 },
260 this->elem);
261 }
262
263 friend bool operator==(const ElemVariant &a, const ElemVariant &b) = default;
264};
265
268 const bNodeSocket *socket = nullptr;
270
272 {
273 return get_default_hash(this->socket, this->elem);
274 }
275
276 friend bool operator==(const SocketElem &a, const SocketElem &b) = default;
277};
278
283
285 {
286 return get_default_hash(this->group_input_index, this->elem);
287 }
288
289 friend bool operator==(const GroupInputElem &a, const GroupInputElem &b) = default;
290};
291
294 const bNode *node = nullptr;
296
298 {
299 return get_default_hash(this->node, this->elem);
300 }
301
302 friend bool operator==(const ValueNodeElem &a, const ValueNodeElem &b) = default;
303};
304
308std::optional<ElemVariant> get_elem_variant_for_socket_type(eNodeSocketDatatype type);
309
311std::optional<ElemVariant> convert_socket_elem(const bNodeSocket &old_socket,
312 const bNodeSocket &new_socket,
313 const ElemVariant &old_elem);
314
315} // namespace blender::nodes::value_elem
#define T
std::optional< ElemVariant > get_elem_variant_for_socket_type(const eNodeSocketDatatype type)
Definition value_elem.cc:13
std::optional< ElemVariant > convert_socket_elem(const bNodeSocket &old_socket, const bNodeSocket &new_socket, const ElemVariant &old_elem)
Definition value_elem.cc:33
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252
std::variant< BoolElem, FloatElem, IntElem, VectorElem, RotationElem, MatrixElem > elem
void merge(const ElemVariant &other)
void intersect(const ElemVariant &other)
friend bool operator==(const ElemVariant &a, const ElemVariant &b)=default
friend bool operator==(const GroupInputElem &a, const GroupInputElem &b)=default
void merge(const MatrixElem &other)
friend bool operator==(const MatrixElem &a, const MatrixElem &b)=default
void intersect(const MatrixElem &other)
friend bool operator==(const PrimitiveValueElem &a, const PrimitiveValueElem &b)=default
void intersect(const PrimitiveValueElem &other)
void merge(const PrimitiveValueElem &other)
friend bool operator==(const RotationElem &a, const RotationElem &b)=default
void intersect(const RotationElem &other)
void merge(const RotationElem &other)
friend bool operator==(const SocketElem &a, const SocketElem &b)=default
friend bool operator==(const ValueNodeElem &a, const ValueNodeElem &b)=default
void merge(const VectorElem &other)
friend bool operator==(const VectorElem &a, const VectorElem &b)=default
void intersect(const VectorElem &other)