|
Blender V5.0
|
#include <BKE_node_socket_value.hh>
Public Member Functions | |
| SocketValueVariant ()=default | |
| SocketValueVariant (const SocketValueVariant &other)=default | |
| SocketValueVariant (SocketValueVariant &&other)=default | |
| SocketValueVariant & | operator= (const SocketValueVariant &other)=default |
| SocketValueVariant & | operator= (SocketValueVariant &&other)=default |
| ~SocketValueVariant ()=default | |
| template<typename T, BLI_ENABLE_IF((std::is_trivial_v< std::decay_t< T > >|| is_same_any_v< std::decay_t< T >, std::string >))> | |
| 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 |
| bool | is_single () const |
| bool | is_list () 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) |
Static Public Member Functions | |
| template<typename T> | |
| static SocketValueVariant & | ConstructIn (void *ptr, T &&value) |
| template<typename T> | |
| static SocketValueVariant | From (T &&value) |
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 34 of file BKE_node_socket_value.hh.
|
default |
Create an empty variant. This is not valid for any socket type yet.
Referenced by ConstructIn(), From(), get(), get_single_ptr(), operator<<, operator=(), operator=(), set(), SocketValueVariant(), and SocketValueVariant().
|
default |
References SocketValueVariant().
|
default |
References SocketValueVariant().
|
default |
References blender::is_same_any_v, and T.
|
inlineexplicit |
Create a variant based on the given value. This works for primitive types. For more complex types use set explicitly. Alternatively, one can use the From or ConstructIn utilities.
Definition at line 102 of file BKE_node_socket_value.hh.
| 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 431 of file node_socket_value.cc.
References BLI_assert_unreachable, SOCK_BOOLEAN, SOCK_BUNDLE, SOCK_CLOSURE, SOCK_COLLECTION, SOCK_FLOAT, SOCK_IMAGE, SOCK_INT, SOCK_MATERIAL, SOCK_MATRIX, SOCK_MENU, SOCK_OBJECT, SOCK_RGBA, SOCK_ROTATION, SOCK_STRING, SOCK_TEXTURE, 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().
|
inlinestatic |
Construct a SocketValueVariant at the given pointer from the given value.
Definition at line 205 of file BKE_node_socket_value.hh.
References ptr, set(), SocketValueVariant(), and T.
Referenced by blender::nodes::implicit_field_inputs::handle_left(), blender::nodes::implicit_field_inputs::handle_right(), blender::nodes::implicit_field_inputs::id_or_index(), blender::nodes::implicit_field_inputs::index(), blender::nodes::implicit_field_inputs::instance_transform(), blender::nodes::implicit_field_inputs::normal(), and blender::nodes::implicit_field_inputs::position().
| 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 386 of file node_socket_value.cc.
References allocate_single(), BLI_assert_unreachable, blender::CPPType::default_value(), blender::fn::evaluate_constant_field(), 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(), blender::nodes::mix_baked_data_item(), blender::bke::bake::move_common_socket_value_to_bake_item(), and operator<<.
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 147 of file node_socket_value.cc.
References BLI_assert, BLI_assert_unreachable, blender::CPPType::default_value(), blender::fn::evaluate_constant_field(), extract(), blender::GPointer::get(), get_single_ptr(), blender::fn::is_field_v, blender::bke::is_VolumeGrid_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::ed::spreadsheet::data_source_from_geometry(), blender::nodes::node_geo_switch_cc::LazyFunctionForSwitchNode::execute_field(), blender::nodes::node_geo_warning_cc::LazyFunctionForWarningNode::execute_impl(), blender::nodes::execute_multi_function_on_value_variant__list(), extract(), blender::nodes::GeoNodeExecParams::extract_input(), get(), blender::nodes::geo_eval_log::GeoTreeLogger::log_value(), blender::bke::bake::move_common_socket_value_to_bake_item(), and blender::ed::spreadsheet::root_geometry_set_get().
|
inlinestatic |
Create a new SocketValueVariant from the given value.
Definition at line 212 of file BKE_node_socket_value.hh.
References set(), SocketValueVariant(), and T.
Referenced by blender::nodes::Bundle::add_path_override(), blender::bke::bake::copy_bake_item_to_socket_value(), blender::nodes::LazyFunctionForClosureZone::execute_impl(), blender::ed::spreadsheet::geometry_display_data_get(), blender::nodes::init_socket_cpp_value_from_property(), blender::nodes::initialize_group_input(), blender::nodes::node_geo_curve_sample_cc::node_geo_exec(), and blender::nodes::to_stored_type().
Same as extract, but always leaves the variant unchanged. So this method can be called multiple times.
Definition at line 224 of file node_socket_value.cc.
References extract(), SocketValueVariant(), and T.
Referenced by blender::nodes::BundleItemValue::as(), blender::nodes::BundleItemValue::as_socket_value(), blender::ed::spreadsheet::data_source_from_geometry(), blender::nodes::LazyFunctionForEnableOutputSocketUsage::execute_impl(), blender::nodes::LazyFunctionForExtractingReferenceSet::execute_impl(), blender::nodes::LazyFunctionForIndexSwitchSocketUsage::execute_impl(), blender::nodes::LazyFunctionForSwitchSocketUsage::execute_impl(), blender::nodes::node_geo_enable_output_cc::LazyFunctionForEnableOutputNode::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::execute_multi_function_on_value_variant__list(), blender::nodes::find_output_attributes_to_store(), blender::nodes::GeoNodeExecParams::get_input(), blender::nodes::LazyFunctionForRepeatZone::initialize_execution_graph(), blender::nodes::geo_eval_log::GeoTreeLogger::log_value(), blender::bke::bake::move_common_socket_value_to_bake_item(), blender::bke::bake::move_socket_values_to_bake_items(), 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 425 of file node_socket_value.cc.
References get_single_ptr(), ptr, and SocketValueVariant().
| 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 416 of file node_socket_value.cc.
References BLI_assert, data, and blender::bke::socket_type_to_geo_nodes_base_cpp_type().
Referenced by blender::ed::spreadsheet::ViewerDataTreeView::build_value(), blender::ed::spreadsheet::data_source_from_geometry(), blender::ed::spreadsheet::SpreadsheetLayoutDrawer::draw_content_cell_value(), blender::nodes::node_geo_viewer_cc::draw_from_viewer_log_value(), extract(), blender::nodes::node_geo_viewer_cc::geo_viewer_node_log_impl(), blender::ed::spreadsheet::geometry_display_data_get(), blender::nodes::get_geometry_nodes_input_inference_values(), get_single_ptr(), blender::nodes::geo_eval_log::GeoTreeLogger::log_value(), blender::nodes::node_geo_viewer_cc::log_viewer_attribute(), blender::nodes::mix_baked_data_item(), blender::bke::bake::move_common_socket_value_to_bake_item(), operator<<, and blender::ed::spreadsheet::root_geometry_set_get().
|
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 225 of file BKE_node_socket_value.hh.
References BLI_assert.
Referenced by blender::nodes::inverse_eval::convert_single_socket_value(), blender::nodes::execute_multi_function_on_value_variant__list(), 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 359 of file node_socket_value.cc.
References blender::fn::FieldNode::depends_on_input(), and blender::fn::GFieldBase< NodePtr >::node().
Referenced by blender::ed::spreadsheet::data_source_from_geometry(), blender::nodes::LazyFunctionForExtractingReferenceSet::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::execute_multi_function_on_value_variant(), blender::nodes::execute_multi_function_on_value_variant__list(), blender::ed::spreadsheet::geometry_display_data_get(), blender::nodes::geo_eval_log::GeoTreeLogger::log_value(), blender::bke::bake::move_common_socket_value_to_bake_item(), and blender::bke::bake::move_socket_values_to_bake_items().
| bool blender::bke::SocketValueVariant::is_list | ( | ) | const |
The stored value is a list.
Definition at line 381 of file node_socket_value.cc.
Referenced by blender::nodes::BundleItemValue::as(), blender::ed::spreadsheet::data_source_from_geometry(), blender::nodes::execute_multi_function_on_value_variant(), blender::nodes::execute_multi_function_on_value_variant__list(), and blender::nodes::geo_eval_log::GeoTreeLogger::log_value().
| bool blender::bke::SocketValueVariant::is_single | ( | ) | const |
The stored value is a single value.
Definition at line 376 of file node_socket_value.cc.
Referenced by blender::ed::spreadsheet::ViewerDataTreeView::build_value(), blender::ed::spreadsheet::data_source_from_geometry(), blender::ed::spreadsheet::SpreadsheetLayoutDrawer::draw_content_cell_value(), blender::nodes::node_geo_viewer_cc::draw_from_viewer_log_value(), blender::nodes::LazyFunctionForEnableOutputSocketUsage::execute_impl(), blender::nodes::node_geo_enable_output_cc::LazyFunctionForEnableOutputNode::execute_impl(), blender::nodes::execute_multi_function_on_value_variant__list(), blender::nodes::node_geo_viewer_cc::geo_viewer_node_log_impl(), blender::ed::spreadsheet::geometry_display_data_get(), blender::nodes::get_geometry_nodes_input_inference_values(), and blender::ed::spreadsheet::root_geometry_set_get().
| bool blender::bke::SocketValueVariant::is_volume_grid | ( | ) | const |
The stored value is a volume grid.
Definition at line 371 of file node_socket_value.cc.
Referenced by blender::ed::spreadsheet::data_source_from_geometry(), blender::nodes::execute_multi_function_on_value_variant(), blender::nodes::geo_eval_log::GeoTreeLogger::log_value(), and blender::bke::bake::move_common_socket_value_to_bake_item().
|
default |
References SocketValueVariant().
|
default |
References SocketValueVariant().
Replaces the stored value with a new value of potentially a different type.
Definition at line 219 of file BKE_node_socket_value.hh.
References blender::is_same_any_v, SocketValueVariant(), and T.
Referenced by ConstructIn(), blender::nodes::execute_geometry_nodes_on_geometry(), blender::nodes::execute_multi_function_on_value_variant__list(), From(), 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 279 of file node_socket_value.cc.
References BLI_assert_unreachable, SOCK_BOOLEAN, SOCK_BUNDLE, SOCK_CLOSURE, SOCK_COLLECTION, SOCK_FLOAT, SOCK_GEOMETRY, SOCK_IMAGE, SOCK_INT, SOCK_MATERIAL, SOCK_MATRIX, SOCK_MENU, SOCK_OBJECT, SOCK_RGBA, SOCK_ROTATION, SOCK_STRING, SOCK_TEXTURE, 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 493 of file node_socket_value.cc.
Referenced by blender::nodes::geo_eval_log::GeoTreeLogger::log_value().
|
friend |
Definition at line 475 of file node_socket_value.cc.
References convert_to_single(), blender::GPointer::get(), get_single_ptr(), blender::CPPType::is_printable(), blender::CPPType::print(), SocketValueVariant(), and blender::GPointer::type().