Changeset View
Changeset View
Standalone View
Standalone View
source/blender/modifiers/intern/MOD_nodes.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| #include "ED_undo.h" | #include "ED_undo.h" | ||||
| #include "NOD_derived_node_tree.hh" | #include "NOD_derived_node_tree.hh" | ||||
| #include "NOD_geometry.h" | #include "NOD_geometry.h" | ||||
| #include "NOD_geometry_nodes_eval_log.hh" | #include "NOD_geometry_nodes_eval_log.hh" | ||||
| #include "NOD_node_declaration.hh" | #include "NOD_node_declaration.hh" | ||||
| #include "FN_field.hh" | #include "FN_field.hh" | ||||
| #include "FN_field_cpp_type.hh" | |||||
| #include "FN_multi_function.hh" | #include "FN_multi_function.hh" | ||||
| using blender::Array; | using blender::Array; | ||||
| using blender::ColorGeometry4f; | using blender::ColorGeometry4f; | ||||
| using blender::destruct_ptr; | using blender::destruct_ptr; | ||||
| using blender::float3; | using blender::float3; | ||||
| using blender::FunctionRef; | using blender::FunctionRef; | ||||
| using blender::IndexRange; | using blender::IndexRange; | ||||
| using blender::Map; | using blender::Map; | ||||
| using blender::Set; | using blender::Set; | ||||
| using blender::Span; | using blender::Span; | ||||
| using blender::StringRef; | using blender::StringRef; | ||||
| using blender::StringRefNull; | using blender::StringRefNull; | ||||
| using blender::Vector; | using blender::Vector; | ||||
| using blender::bke::OutputAttribute; | using blender::bke::OutputAttribute; | ||||
| using blender::fn::Field; | |||||
| using blender::fn::GField; | using blender::fn::GField; | ||||
| using blender::fn::GMutablePointer; | using blender::fn::GMutablePointer; | ||||
| using blender::fn::GPointer; | using blender::fn::GPointer; | ||||
| using blender::fn::ValueOrField; | |||||
| using blender::nodes::FieldInferencingInterface; | using blender::nodes::FieldInferencingInterface; | ||||
| using blender::nodes::GeoNodeExecParams; | using blender::nodes::GeoNodeExecParams; | ||||
| using blender::nodes::InputSocketFieldType; | using blender::nodes::InputSocketFieldType; | ||||
| using blender::threading::EnumerableThreadSpecific; | using blender::threading::EnumerableThreadSpecific; | ||||
| using namespace blender::fn::multi_function_types; | using namespace blender::fn::multi_function_types; | ||||
| using namespace blender::nodes::derived_node_tree_types; | using namespace blender::nodes::derived_node_tree_types; | ||||
| using geo_log::GeometryAttributeInfo; | using geo_log::GeometryAttributeInfo; | ||||
| ▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | switch (socket_value_type) { | ||||
| case SOCK_FLOAT: { | case SOCK_FLOAT: { | ||||
| float value = 0.0f; | float value = 0.0f; | ||||
| if (property.type == IDP_FLOAT) { | if (property.type == IDP_FLOAT) { | ||||
| value = IDP_Float(&property); | value = IDP_Float(&property); | ||||
| } | } | ||||
| else if (property.type == IDP_DOUBLE) { | else if (property.type == IDP_DOUBLE) { | ||||
| value = (float)IDP_Double(&property); | value = (float)IDP_Double(&property); | ||||
| } | } | ||||
| new (r_value) blender::fn::Field<float>(blender::fn::make_constant_field(value)); | new (r_value) ValueOrField<float>(value); | ||||
| break; | break; | ||||
| } | } | ||||
| case SOCK_INT: { | case SOCK_INT: { | ||||
| int value = IDP_Int(&property); | int value = IDP_Int(&property); | ||||
| new (r_value) blender::fn::Field<int>(blender::fn::make_constant_field(value)); | new (r_value) ValueOrField<int>(value); | ||||
| break; | break; | ||||
| } | } | ||||
| case SOCK_VECTOR: { | case SOCK_VECTOR: { | ||||
| float3 value; | float3 value; | ||||
| copy_v3_v3(value, (const float *)IDP_Array(&property)); | copy_v3_v3(value, (const float *)IDP_Array(&property)); | ||||
| new (r_value) blender::fn::Field<float3>(blender::fn::make_constant_field(value)); | new (r_value) ValueOrField<float3>(value); | ||||
| break; | break; | ||||
| } | } | ||||
| case SOCK_RGBA: { | case SOCK_RGBA: { | ||||
| blender::ColorGeometry4f value; | blender::ColorGeometry4f value; | ||||
| copy_v4_v4((float *)value, (const float *)IDP_Array(&property)); | copy_v4_v4((float *)value, (const float *)IDP_Array(&property)); | ||||
| new (r_value) blender::fn::Field<ColorGeometry4f>(blender::fn::make_constant_field(value)); | new (r_value) ValueOrField<ColorGeometry4f>(value); | ||||
| break; | break; | ||||
| } | } | ||||
| case SOCK_BOOLEAN: { | case SOCK_BOOLEAN: { | ||||
| bool value = IDP_Int(&property) != 0; | bool value = IDP_Int(&property) != 0; | ||||
| new (r_value) blender::fn::Field<bool>(blender::fn::make_constant_field(value)); | new (r_value) ValueOrField<bool>(value); | ||||
| break; | break; | ||||
| } | } | ||||
| case SOCK_STRING: { | case SOCK_STRING: { | ||||
| std::string value = IDP_String(&property); | std::string value = IDP_String(&property); | ||||
| new (r_value) | new (r_value) ValueOrField<std::string>(std::move(value)); | ||||
| blender::fn::Field<std::string>(blender::fn::make_constant_field(std::move(value))); | |||||
| break; | break; | ||||
| } | } | ||||
| case SOCK_OBJECT: { | case SOCK_OBJECT: { | ||||
| ID *id = IDP_Id(&property); | ID *id = IDP_Id(&property); | ||||
| Object *object = (id && GS(id->name) == ID_OB) ? (Object *)id : nullptr; | Object *object = (id && GS(id->name) == ID_OB) ? (Object *)id : nullptr; | ||||
| *(Object **)r_value = object; | *(Object **)r_value = object; | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | init_socket_cpp_value_from_property( | ||||
| *property, static_cast<eNodeSocketDatatype>(bsocket.type), r_value); | *property, static_cast<eNodeSocketDatatype>(bsocket.type), r_value); | ||||
| return; | return; | ||||
| } | } | ||||
| const bool use_attribute = IDP_Int(property_use_attribute) != 0; | const bool use_attribute = IDP_Int(property_use_attribute) != 0; | ||||
| if (use_attribute) { | if (use_attribute) { | ||||
| const StringRef attribute_name{IDP_String(property_attribute_name)}; | const StringRef attribute_name{IDP_String(property_attribute_name)}; | ||||
| auto attribute_input = std::make_shared<blender::bke::AttributeFieldInput>( | auto attribute_input = std::make_shared<blender::bke::AttributeFieldInput>( | ||||
| attribute_name, *socket_type.get_base_cpp_type()); | attribute_name, *socket_type.base_cpp_type); | ||||
| new (r_value) blender::fn::GField(std::move(attribute_input), 0); | GField attribute_field{std::move(attribute_input), 0}; | ||||
| const blender::fn::ValueOrFieldCPPType *cpp_type = | |||||
| dynamic_cast<const blender::fn::ValueOrFieldCPPType *>( | |||||
| socket_type.geometry_nodes_cpp_type); | |||||
| BLI_assert(cpp_type != nullptr); | |||||
| cpp_type->construct_from_field(r_value, std::move(attribute_field)); | |||||
| } | } | ||||
| else { | else { | ||||
| init_socket_cpp_value_from_property( | init_socket_cpp_value_from_property( | ||||
| *property, static_cast<eNodeSocketDatatype>(bsocket.type), r_value); | *property, static_cast<eNodeSocketDatatype>(bsocket.type), r_value); | ||||
| } | } | ||||
| } | } | ||||
| static Vector<SpaceSpreadsheet *> find_spreadsheet_editors(Main *bmain) | static Vector<SpaceSpreadsheet *> find_spreadsheet_editors(Main *bmain) | ||||
| ▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | static void store_output_value_in_geometry(GeometrySet &geometry_set, | ||||
| const IDProperty *prop = IDP_GetPropertyFromGroup(nmd->settings.properties, prop_name.c_str()); | const IDProperty *prop = IDP_GetPropertyFromGroup(nmd->settings.properties, prop_name.c_str()); | ||||
| if (prop == nullptr) { | if (prop == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| const StringRefNull attribute_name = IDP_String(prop); | const StringRefNull attribute_name = IDP_String(prop); | ||||
| if (attribute_name.is_empty()) { | if (attribute_name.is_empty()) { | ||||
| return; | return; | ||||
| } | } | ||||
| const GField &field = *(const GField *)value.get(); | const blender::fn::ValueOrFieldCPPType *cpp_type = | ||||
| dynamic_cast<const blender::fn::ValueOrFieldCPPType *>(value.type()); | |||||
| BLI_assert(cpp_type != nullptr); | |||||
| const GField field = cpp_type->as_field(value.get()); | |||||
| const bNodeSocket *interface_socket = (bNodeSocket *)BLI_findlink(&nmd->node_group->outputs, | const bNodeSocket *interface_socket = (bNodeSocket *)BLI_findlink(&nmd->node_group->outputs, | ||||
| socket.index()); | socket.index()); | ||||
| const AttributeDomain domain = (AttributeDomain)interface_socket->attribute_domain; | const AttributeDomain domain = (AttributeDomain)interface_socket->attribute_domain; | ||||
| if (geometry_set.has_mesh()) { | if (geometry_set.has_mesh()) { | ||||
| MeshComponent &component = geometry_set.get_component_for_write<MeshComponent>(); | MeshComponent &component = geometry_set.get_component_for_write<MeshComponent>(); | ||||
| store_field_on_geometry_component(component, attribute_name, domain, field); | store_field_on_geometry_component(component, attribute_name, domain, field); | ||||
| } | } | ||||
| if (geometry_set.has_pointcloud()) { | if (geometry_set.has_pointcloud()) { | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if (first_input_socket->bsocket()->type == SOCK_GEOMETRY) { | ||||
| GeometrySet *geometry_set_in = | GeometrySet *geometry_set_in = | ||||
| allocator.construct<GeometrySet>(input_geometry_set).release(); | allocator.construct<GeometrySet>(input_geometry_set).release(); | ||||
| group_inputs.add_new({root_context, first_input_socket}, geometry_set_in); | group_inputs.add_new({root_context, first_input_socket}, geometry_set_in); | ||||
| remaining_input_sockets = remaining_input_sockets.drop_front(1); | remaining_input_sockets = remaining_input_sockets.drop_front(1); | ||||
| } | } | ||||
| /* Initialize remaining group inputs. */ | /* Initialize remaining group inputs. */ | ||||
| for (const OutputSocketRef *socket : remaining_input_sockets) { | for (const OutputSocketRef *socket : remaining_input_sockets) { | ||||
| const CPPType &cpp_type = *socket->typeinfo()->get_geometry_nodes_cpp_type(); | const CPPType &cpp_type = *socket->typeinfo()->geometry_nodes_cpp_type; | ||||
| void *value_in = allocator.allocate(cpp_type.size(), cpp_type.alignment()); | void *value_in = allocator.allocate(cpp_type.size(), cpp_type.alignment()); | ||||
| initialize_group_input(*nmd, *socket, value_in); | initialize_group_input(*nmd, *socket, value_in); | ||||
| group_inputs.add_new({root_context, socket}, {cpp_type, value_in}); | group_inputs.add_new({root_context, socket}, {cpp_type, value_in}); | ||||
| } | } | ||||
| } | } | ||||
| Vector<DInputSocket> group_outputs; | Vector<DInputSocket> group_outputs; | ||||
| for (const InputSocketRef *socket_ref : output_node.inputs().drop_back(1)) { | for (const InputSocketRef *socket_ref : output_node.inputs().drop_back(1)) { | ||||
| ▲ Show 20 Lines • Show All 621 Lines • Show Last 20 Lines | |||||