Blender V5.0
NOD_socket_value_inference.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
9
11
12#include "DNA_material_types.h"
14
15struct bNodeTree;
16
17namespace blender::nodes {
18
24class InferenceValue {
25 private:
31 const void *value_ = nullptr;
32
33 InferenceValue(const void *value) : value_(value) {}
34
35 public:
36 static InferenceValue from_primitive(const void *value)
37 {
38 BLI_assert(value != nullptr);
39 return InferenceValue(value);
40 }
41
42 static InferenceValue Unknown()
43 {
44 return InferenceValue(nullptr);
45 }
46
47 bool is_unknown() const
48 {
49 return value_ == nullptr;
50 }
51
52 bool is_primitive_value() const
53 {
54 return !this->is_unknown();
55 }
56
57 const void *get_primitive_ptr() const
58 {
60 return value_;
61 }
62
63 template<typename T> T get_primitive() const
64 {
66 return *static_cast<const T *>(this->value_);
67 }
68
69 template<typename T> std::optional<T> get_if_primitive() const
70 {
71 if (!this->is_primitive_value()) {
72 return std::nullopt;
73 }
74 return this->get_primitive<T>();
75 }
76};
77
78class SocketValueInferencerImpl;
79
81 private:
83
84 public:
86 const bNodeTree &tree,
87 ResourceScope &scope,
88 bke::ComputeContextCache &compute_context_cache,
89 FunctionRef<InferenceValue(int group_input_i)> group_input_value_fn = nullptr,
90 std::optional<Span<bool>> top_level_ignored_inputs = std::nullopt);
91
93};
94
96
97bool is_socket_selected__switch(const SocketInContext &socket, const InferenceValue &condition);
99 const InferenceValue &condition);
101 const InferenceValue &condition);
102bool is_socket_selected__mix_node(const SocketInContext &socket, const InferenceValue &condition);
104 const InferenceValue &condition);
105
106} // namespace switch_node_inference_utils
107
108} // namespace blender::nodes
#define BLI_assert(a)
Definition BLI_assert.h:46
std::optional< T > get_if_primitive() const
static InferenceValue from_primitive(const void *value)
SocketValueInferencer(const bNodeTree &tree, ResourceScope &scope, bke::ComputeContextCache &compute_context_cache, FunctionRef< InferenceValue(int group_input_i)> group_input_value_fn=nullptr, std::optional< Span< bool > > top_level_ignored_inputs=std::nullopt)
InferenceValue get_socket_value(const SocketInContext &socket)
KDTree_3d * tree
#define T
bool is_socket_selected__shader_mix_node(const SocketInContext &socket, const InferenceValue &condition)
bool is_socket_selected__mix_node(const SocketInContext &socket, const InferenceValue &condition)
bool is_socket_selected__menu_switch(const SocketInContext &socket, const InferenceValue &condition)
bool is_socket_selected__index_switch(const SocketInContext &socket, const InferenceValue &condition)
bool is_socket_selected__switch(const SocketInContext &socket, const InferenceValue &condition)