Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "BKE_attribute.hh" | |||||
| #include "BKE_attribute_math.hh" | #include "BKE_attribute_math.hh" | ||||
| #include "NOD_socket_search_link.hh" | #include "NOD_socket_search_link.hh" | ||||
| #include "node_geometry_util.hh" | #include "node_geometry_util.hh" | ||||
| namespace blender::nodes::node_geo_attribute_capture_cc { | namespace blender::nodes::node_geo_attribute_capture_cc { | ||||
| NODE_STORAGE_FUNCS(NodeGeometryAttributeCapture) | NODE_STORAGE_FUNCS(NodeGeometryAttributeCapture) | ||||
| static void node_declare(NodeDeclarationBuilder &b) | static void node_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.add_input<decl::Geometry>(N_("Geometry")); | b.add_input<decl::Geometry>(N_("Geometry")); | ||||
| b.add_input<decl::Vector>(N_("Value")).supports_field(); | b.add_input<decl::Vector>(N_("Value"), "Value_Vector").supports_field(); | ||||
| b.add_input<decl::Float>(N_("Value"), "Value_001").supports_field(); | b.add_input<decl::Float>(N_("Value"), "Value_Float").supports_field(); | ||||
| b.add_input<decl::Color>(N_("Value"), "Value_002").supports_field(); | b.add_input<decl::Color>(N_("Value"), "Value_Color").supports_field(); | ||||
| b.add_input<decl::Bool>(N_("Value"), "Value_003").supports_field(); | b.add_input<decl::Bool>(N_("Value"), "Value_Bool").supports_field(); | ||||
| b.add_input<decl::Int>(N_("Value"), "Value_004").supports_field(); | b.add_input<decl::Int>(N_("Value"), "Value_Int").supports_field(); | ||||
| b.add_output<decl::Geometry>(N_("Geometry")); | b.add_output<decl::Geometry>(N_("Geometry")); | ||||
| b.add_output<decl::Vector>(N_("Attribute")).field_source(); | b.add_output<decl::Vector>(N_("Attribute"), "Value_Vector").field_source(); | ||||
| b.add_output<decl::Float>(N_("Attribute"), "Attribute_001").field_source(); | b.add_output<decl::Float>(N_("Attribute"), "Value_Float").field_source(); | ||||
| b.add_output<decl::Color>(N_("Attribute"), "Attribute_002").field_source(); | b.add_output<decl::Color>(N_("Attribute"), "Value_Color").field_source(); | ||||
| b.add_output<decl::Bool>(N_("Attribute"), "Attribute_003").field_source(); | b.add_output<decl::Bool>(N_("Attribute"), "Value_Bool").field_source(); | ||||
| b.add_output<decl::Int>(N_("Attribute"), "Attribute_004").field_source(); | b.add_output<decl::Int>(N_("Attribute"), "Value_Int").field_source(); | ||||
| } | } | ||||
| static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr) | static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr) | ||||
| { | { | ||||
| uiLayoutSetPropSep(layout, true); | uiLayoutSetPropSep(layout, true); | ||||
| uiLayoutSetPropDecorate(layout, false); | uiLayoutSetPropDecorate(layout, false); | ||||
| uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE); | uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE); | ||||
| uiItemR(layout, ptr, "domain", 0, "", ICON_NONE); | uiItemR(layout, ptr, "domain", 0, "", ICON_NONE); | ||||
| ▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | else { | ||||
| bNode &node = params.add_node(node_type); | bNode &node = params.add_node(node_type); | ||||
| node_storage(node).data_type = *type; | node_storage(node).data_type = *type; | ||||
| params.update_and_connect_available_socket(node, "Value"); | params.update_and_connect_available_socket(node, "Value"); | ||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static StringRefNull identifier_suffix(eCustomDataType data_type) | |||||
| { | |||||
| switch (data_type) { | |||||
| case CD_PROP_FLOAT: | |||||
| return "_001"; | |||||
| case CD_PROP_INT32: | |||||
| return "_004"; | |||||
| case CD_PROP_COLOR: | |||||
| return "_002"; | |||||
| case CD_PROP_BOOL: | |||||
| return "_003"; | |||||
| case CD_PROP_FLOAT3: | |||||
| return ""; | |||||
| default: | |||||
| BLI_assert_unreachable(); | |||||
| return ""; | |||||
| } | |||||
| } | |||||
| static void node_geo_exec(GeoNodeExecParams params) | static void node_geo_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | ||||
| if (!params.output_is_required("Geometry")) { | if (!params.output_is_required("Geometry")) { | ||||
| params.error_message_add( | params.error_message_add( | ||||
| NodeWarningType::Info, | NodeWarningType::Info, | ||||
| TIP_("The attribute output can not be used without the geometry output")); | TIP_("The attribute output can not be used without the geometry output")); | ||||
| params.set_default_remaining_outputs(); | params.set_default_remaining_outputs(); | ||||
| return; | return; | ||||
| } | } | ||||
| const NodeGeometryAttributeCapture &storage = node_storage(params.node()); | const NodeGeometryAttributeCapture &storage = node_storage(params.node()); | ||||
| const eCustomDataType data_type = eCustomDataType(storage.data_type); | const eCustomDataType data_type = eCustomDataType(storage.data_type); | ||||
| const eAttrDomain domain = eAttrDomain(storage.domain); | const eAttrDomain domain = eAttrDomain(storage.domain); | ||||
| const std::string output_identifier = "Attribute" + identifier_suffix(data_type); | const std::string identifier = "Value_" + bke::type_name_identifier(data_type); | ||||
HooglyBoogly: `postfix` -> `suffix` | |||||
| if (!params.output_is_required(output_identifier)) { | if (!params.output_is_required(identifier)) { | ||||
| params.set_output("Geometry", geometry_set); | params.set_output("Geometry", geometry_set); | ||||
| return; | return; | ||||
| } | } | ||||
| const std::string input_identifier = "Value" + identifier_suffix(data_type); | |||||
| GField field; | GField field; | ||||
| switch (data_type) { | attribute_math::convert_to_static_type(data_type, [&](auto dummy) { | ||||
| case CD_PROP_FLOAT: | using T = decltype(dummy); | ||||
| field = params.get_input<Field<float>>(input_identifier); | field = params.get_input<Field<T>>(identifier); | ||||
| break; | }); | ||||
| case CD_PROP_FLOAT3: | |||||
| field = params.get_input<Field<float3>>(input_identifier); | |||||
| break; | |||||
| case CD_PROP_COLOR: | |||||
| field = params.get_input<Field<ColorGeometry4f>>(input_identifier); | |||||
| break; | |||||
| case CD_PROP_BOOL: | |||||
| field = params.get_input<Field<bool>>(input_identifier); | |||||
| break; | |||||
| case CD_PROP_INT32: | |||||
| field = params.get_input<Field<int>>(input_identifier); | |||||
| break; | |||||
| default: | |||||
| break; | |||||
| } | |||||
| WeakAnonymousAttributeID anonymous_id{"Attribute"}; | WeakAnonymousAttributeID anonymous_id{"Attribute"}; | ||||
| const CPPType &type = field.cpp_type(); | const CPPType &type = field.cpp_type(); | ||||
| /* Run on the instances component separately to only affect the top level of instances. */ | /* Run on the instances component separately to only affect the top level of instances. */ | ||||
| if (domain == ATTR_DOMAIN_INSTANCE) { | if (domain == ATTR_DOMAIN_INSTANCE) { | ||||
| if (geometry_set.has_instances()) { | if (geometry_set.has_instances()) { | ||||
| GeometryComponent &component = geometry_set.get_component_for_write( | GeometryComponent &component = geometry_set.get_component_for_write( | ||||
| Show All 13 Lines | geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { | ||||
| } | } | ||||
| } | } | ||||
| }); | }); | ||||
| } | } | ||||
| GField output_field{std::make_shared<bke::AnonymousAttributeFieldInput>( | GField output_field{std::make_shared<bke::AnonymousAttributeFieldInput>( | ||||
| std::move(anonymous_id), type, params.attribute_producer_name())}; | std::move(anonymous_id), type, params.attribute_producer_name())}; | ||||
| switch (data_type) { | attribute_math::convert_to_static_type(data_type, [&](auto dummy) { | ||||
| case CD_PROP_FLOAT: { | using T = decltype(dummy); | ||||
| params.set_output(output_identifier, Field<float>(output_field)); | params.set_output(identifier, Field<T>(output_field)); | ||||
| break; | }); | ||||
| } | |||||
| case CD_PROP_FLOAT3: { | |||||
| params.set_output(output_identifier, Field<float3>(output_field)); | |||||
| break; | |||||
| } | |||||
| case CD_PROP_COLOR: { | |||||
| params.set_output(output_identifier, Field<ColorGeometry4f>(output_field)); | |||||
| break; | |||||
| } | |||||
| case CD_PROP_BOOL: { | |||||
| params.set_output(output_identifier, Field<bool>(output_field)); | |||||
| break; | |||||
| } | |||||
| case CD_PROP_INT32: { | |||||
| params.set_output(output_identifier, Field<int>(output_field)); | |||||
| break; | |||||
| } | |||||
| default: | |||||
| break; | |||||
| } | |||||
| params.set_output("Geometry", geometry_set); | params.set_output("Geometry", geometry_set); | ||||
| } | } | ||||
| } // namespace blender::nodes::node_geo_attribute_capture_cc | } // namespace blender::nodes::node_geo_attribute_capture_cc | ||||
| void register_node_type_geo_attribute_capture() | void register_node_type_geo_attribute_capture() | ||||
| { | { | ||||
| Show All 18 Lines | |||||
postfix -> suffix