|
Blender V4.3
|
#include <BKE_node_socket_value.hh>
Public Member Functions | |
| SocketValueVariant ()=default | |
| template<typename T > | |
| SocketValueVariant (T &&value) | |
| bool | valid_for_socket (eNodeSocketDatatype socket_type) const |
| template<typename T > | |
| T | extract () |
| template<typename T > | |
| T | get () const |
| template<typename T > | |
| void | set (T &&value) |
| bool | is_context_dependent_field () const |
| bool | is_volume_grid () const |
| void | convert_to_single () |
| GPointer | get_single_ptr () const |
| GMutablePointer | get_single_ptr () |
| const void * | get_single_ptr_raw () const |
| void | store_single (eNodeSocketDatatype socket_type, const void *value) |
| void * | allocate_single (eNodeSocketDatatype socket_type) |
Friends | |
| std::ostream & | operator<< (std::ostream &stream, const SocketValueVariant &value_variant) |
SocketValueVariant is used by geometry nodes in the lazy-function evaluator to pass data between nodes. Specifically, it is the container type for the following socket types: bool, float, integer, vector, rotation, color and string.
The data passed through e.g. an integer socket can be a single value, a field or a grid (and in the lists and images). Each of those is stored differently, but this container can store them all.
A key requirement for this container is that it is type-erased, i.e. not all code that uses it has to include all the headers required to process the other storage types. This is achieved by using the #Any type and by providing templated accessors that are implemented outside of a header.
Definition at line 33 of file BKE_node_socket_value.hh.
|
default |
Create an empty variant. This is not valid for any socket type yet.
|
inlineexplicit |
Create a variant based on the given value. This works for primitive types, #GField and Field<T>.
Definition at line 173 of file BKE_node_socket_value.hh.
References set().
| void * blender::bke::SocketValueVariant::allocate_single | ( | eNodeSocketDatatype | socket_type | ) |
Replaces the stored value with a new uninitialized single value for the given socket type. The caller is responsible to construct the value in the returned memory before it is used.
Definition at line 323 of file node_socket_value.cc.
References blender::Any< ExtraInfo, InlineBufferCapacity, Alignment >::allocate(), BLI_assert_unreachable, SOCK_BOOLEAN, SOCK_FLOAT, SOCK_INT, SOCK_MATRIX, SOCK_MENU, SOCK_RGBA, SOCK_ROTATION, SOCK_STRING, and SOCK_VECTOR.
Referenced by blender::nodes::inverse_eval::convert_single_socket_value(), convert_to_single(), blender::nodes::execute_multi_function_on_value_variant__single(), and blender::nodes::LazyFunctionForForeachGeometryElementZone::prepare_components().
| void blender::bke::SocketValueVariant::convert_to_single | ( | ) |
Convert the stored value into a single value. For simple value access, this is not necessary, because get` does the conversion implicitly. However, it is necessary if one wants to use get_single_ptr. Context-dependent fields or grids will just result in a fallback value.
The caller has to make sure that the stored value is a single value, field or grid.
Definition at line 279 of file node_socket_value.cc.
References allocate_single(), BLI_assert_unreachable, blender::CPPType::default_value(), blender::fn::evaluate_constant_field(), blender::Any< ExtraInfo, InlineBufferCapacity, Alignment >::get(), blender::bke::socket_type_to_geo_nodes_base_cpp_type(), and store_single().
Referenced by blender::nodes::execute_multi_function_on_value_variant__single(), blender::nodes::LazyFunctionForReduceForeachGeometryElement::handle_main_items_and_geometry(), blender::nodes::geo_eval_log::GeoTreeLogger::log_value(), and blender::nodes::mix_baked_data_item().
Get the stored value as a specific type. For convenience this allows accessing the stored type as a different type. For example, a stored single int can also be accessed as GField or Field<int> (but not float or Field<float>).
This method may leave the variant empty, in a moved from state or unchanged. Therefore, this should only be called once.
Definition at line 105 of file node_socket_value.cc.
References BLI_assert, BLI_assert_unreachable, blender::CPPType::default_value(), blender::fn::evaluate_constant_field(), extract(), blender::Any< ExtraInfo, InlineBufferCapacity, Alignment >::get(), blender::GPointer::get(), get_single_ptr(), blender::fn::is_field_v, blender::fn::make_constant_field(), blender::bke::socket_type_to_geo_nodes_base_cpp_type(), blender::bke::socket_type_to_grid_type(), blender::bke::static_type_is_base_socket_type(), T, and blender::GPointer::type().
Referenced by blender::nodes::node_geo_switch_cc::LazyFunctionForSwitchNode::execute_field(), blender::nodes::LazyFunctionForViewerNode::execute_impl(), blender::nodes::node_geo_warning_cc::LazyFunctionForWarningNode::execute_impl(), extract(), blender::nodes::GeoNodeExecParams::extract_input(), get(), and blender::nodes::geo_eval_log::GeoTreeLogger::log_value().
Same as extract, but always leaves the variant unchanged. So this method can be called multiple times.
Definition at line 171 of file node_socket_value.cc.
References extract().
Referenced by blender::nodes::LazyFunctionForAnonymousAttributeSetExtract::execute_impl(), blender::nodes::LazyFunctionForIndexSwitchSocketUsage::execute_impl(), blender::nodes::LazyFunctionForSwitchSocketUsage::execute_impl(), blender::nodes::node_geo_index_switch_cc::LazyFunctionForIndexSwitchNode::execute_impl(), blender::nodes::node_geo_menu_switch_cc::LazyFunctionForMenuSwitchNode::execute_impl(), blender::nodes::node_geo_menu_switch_cc::LazyFunctionForMenuSwitchSocketUsage::execute_impl(), blender::nodes::node_geo_switch_cc::LazyFunctionForSwitchNode::execute_impl(), blender::nodes::node_geo_warning_cc::LazyFunctionForWarningNode::execute_impl(), blender::nodes::find_output_attributes_to_store(), blender::nodes::LazyFunctionForRepeatZone::initialize_execution_graph(), blender::nodes::geo_eval_log::GeoTreeLogger::log_value(), blender::nodes::inverse_eval::set_modifier_value(), blender::nodes::inverse_eval::set_socket_value(), blender::nodes::inverse_eval::set_value_node_value(), blender::nodes::node_geo_simulation_cc::sim_output_node::LazyFunctionForSimulationOutputNode::store_new_state(), blender::ed::view3d::geometry_nodes_gizmos::TransformGizmos::update_rotate_transform_and_target_property(), blender::ed::view3d::geometry_nodes_gizmos::TransformGizmos::update_scale_transform_and_target_property(), blender::ed::view3d::geometry_nodes_gizmos::DialGizmo::update_target_property(), blender::ed::view3d::geometry_nodes_gizmos::LinearGizmo::update_target_property(), and blender::ed::view3d::geometry_nodes_gizmos::TransformGizmos::update_translate_transform_and_target_property().
| GMutablePointer blender::bke::SocketValueVariant::get_single_ptr | ( | ) |
Definition at line 317 of file node_socket_value.cc.
References get_single_ptr(), ptr, and PointerRNA::type.
| GPointer blender::bke::SocketValueVariant::get_single_ptr | ( | ) | const |
Get a pointer to the embedded single value. The caller has to make sure that there actually is a single value stored, e.g. by calling convert_to_single.
Definition at line 308 of file node_socket_value.cc.
References BLI_assert, blender::Any< ExtraInfo, InlineBufferCapacity, Alignment >::get(), and blender::bke::socket_type_to_geo_nodes_base_cpp_type().
Referenced by extract(), get_single_ptr(), blender::nodes::geo_eval_log::GeoTreeLogger::log_value(), and blender::nodes::mix_baked_data_item().
|
inline |
Similar to get_single_ptr, but returns an untyped pointer. This can only be used if the caller knows for sure which type is contained. In that case, it can be a bit faster though, because the corresponding #CPPType does not have to be looked up based on the socket type.
Definition at line 183 of file BKE_node_socket_value.hh.
References BLI_assert, and blender::Any< ExtraInfo, InlineBufferCapacity, Alignment >::get().
Referenced by blender::nodes::inverse_eval::convert_single_socket_value(), blender::nodes::execute_multi_function_on_value_variant__single(), and blender::nodes::LazyFunctionForReduceForeachGeometryElement::handle_main_items_and_geometry().
| bool blender::bke::SocketValueVariant::is_context_dependent_field | ( | ) | const |
If true, the stored value cannot be converted to a single value without loss of information.
Definition at line 262 of file node_socket_value.cc.
References blender::fn::FieldNode::depends_on_input(), blender::Any< ExtraInfo, InlineBufferCapacity, Alignment >::get(), blender::Any< ExtraInfo, InlineBufferCapacity, Alignment >::is(), and blender::fn::GFieldBase< NodePtr >::node().
Referenced by blender::nodes::LazyFunctionForAnonymousAttributeSetExtract::execute_impl(), blender::nodes::LazyFunctionForIndexSwitchSocketUsage::execute_impl(), blender::nodes::LazyFunctionForSwitchSocketUsage::execute_impl(), blender::nodes::node_geo_index_switch_cc::LazyFunctionForIndexSwitchNode::execute_impl(), blender::nodes::node_geo_menu_switch_cc::LazyFunctionForMenuSwitchNode::execute_impl(), blender::nodes::node_geo_menu_switch_cc::LazyFunctionForMenuSwitchSocketUsage::execute_impl(), blender::nodes::node_geo_switch_cc::LazyFunctionForSwitchNode::execute_impl(), blender::nodes::geo_eval_log::GeoTreeLogger::log_value(), and blender::nodes::mix_baked_data_item().
| bool blender::bke::SocketValueVariant::is_volume_grid | ( | ) | const |
The stored value is a volume grid.
Definition at line 274 of file node_socket_value.cc.
Referenced by blender::nodes::geo_eval_log::GeoTreeLogger::log_value().
Replaces the stored value with a new value of potentially a different type.
Definition at line 178 of file BKE_node_socket_value.hh.
Referenced by SocketValueVariant(), blender::ed::view3d::geometry_nodes_gizmos::TransformGizmos::update_rotate_transform_and_target_property(), blender::ed::view3d::geometry_nodes_gizmos::TransformGizmos::update_scale_transform_and_target_property(), blender::ed::view3d::geometry_nodes_gizmos::DialGizmo::update_target_property(), blender::ed::view3d::geometry_nodes_gizmos::LinearGizmo::update_target_property(), and blender::ed::view3d::geometry_nodes_gizmos::TransformGizmos::update_translate_transform_and_target_property().
| void blender::bke::SocketValueVariant::store_single | ( | eNodeSocketDatatype | socket_type, |
| const void * | value ) |
Replace the stored value with the given single value.
Definition at line 218 of file node_socket_value.cc.
References BLI_assert_unreachable, blender::Any< ExtraInfo, InlineBufferCapacity, Alignment >::emplace(), SOCK_BOOLEAN, SOCK_FLOAT, SOCK_INT, SOCK_MATRIX, SOCK_RGBA, SOCK_ROTATION, SOCK_STRING, and SOCK_VECTOR.
Referenced by convert_to_single(), and blender::bke::bake::copy_bake_item_to_socket_value().
| bool blender::bke::SocketValueVariant::valid_for_socket | ( | eNodeSocketDatatype | socket_type | ) | const |
Definition at line 371 of file node_socket_value.cc.
|
friend |
Definition at line 353 of file node_socket_value.cc.