Blender V5.3
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
8
9#pragma once
10
12#include "BLI_resource_scope.hh"
13
15
16#include "DNA_material_types.h"
18
19namespace blender {
20
21struct bNodeTree;
22
23namespace nodes {
24
30class InferenceValue {
31 private:
37 const void *value_ = nullptr;
38
39 InferenceValue(const void *value) : value_(value) {}
40
41 public:
42 static InferenceValue from_primitive(const void *value)
43 {
44 BLI_assert(value != nullptr);
45 return InferenceValue(value);
46 }
47
48 static InferenceValue Unknown()
49 {
50 return InferenceValue(nullptr);
51 }
52
53 bool is_unknown() const
54 {
55 return value_ == nullptr;
56 }
57
58 bool is_primitive_value() const
59 {
60 return !this->is_unknown();
61 }
62
63 const void *get_primitive_ptr() const
64 {
66 return value_;
67 }
68
69 template<typename T> T get_primitive() const
70 {
72 return *static_cast<const T *>(this->value_);
73 }
74
75 template<typename T> std::optional<T> get_if_primitive() const
76 {
77 if (!this->is_primitive_value()) {
78 return std::nullopt;
79 }
80 return this->get_primitive<T>();
81 }
82};
83
85
87 private:
89
90 public:
92 const bNodeTree &tree,
93 ResourceScope &scope,
94 bke::ComputeContextCache &compute_context_cache,
95 FunctionRef<InferenceValue(int group_input_i)> group_input_value_fn = nullptr,
96 std::optional<Span<bool>> top_level_ignored_inputs = std::nullopt);
97
99};
100
102
111
112} // namespace switch_node_inference_utils
113
114} // namespace nodes
115} // namespace blender
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)
#define condition(cond)
#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)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)