diff options
author | Fabian Schempp <fabianschempp@googlemail.com> | 2022-02-05 01:39:06 +0300 |
---|---|---|
committer | Fabian Schempp <fabianschempp@googlemail.com> | 2022-02-05 01:39:06 +0300 |
commit | 06dadc78a7ea879d296b6d3f4d906069550765f6 (patch) | |
tree | f27b445dd045155d3000044616764fd2c8972934 /source/blender/nodes/geometry/nodes/node_geo_solidify.cc | |
parent | c1ae3b850c9c1b43ce6928add5362bcea63d7223 (diff) |
updated to fields workflowgsoc-2021-porting-modifiers-to-nodes-solidify
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_solidify.cc')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_solidify.cc | 241 |
1 files changed, 126 insertions, 115 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_solidify.cc b/source/blender/nodes/geometry/nodes/node_geo_solidify.cc index 197aa0a09c1..41448a37d34 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_solidify.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_solidify.cc @@ -27,31 +27,36 @@ #include "node_geometry_util.hh" -static bNodeSocketTemplate geo_node_solidify_in[] = { - {SOCK_GEOMETRY, N_("Geometry")}, - {SOCK_STRING, N_("Thickness")}, - {SOCK_FLOAT, N_("Thickness"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_DISTANCE}, - {SOCK_FLOAT, N_("Clamp"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_FACTOR}, - {SOCK_FLOAT, N_("Offset"), -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_FACTOR}, - {SOCK_BOOLEAN, N_("Fill"), true}, - {SOCK_BOOLEAN, N_("Rim"), true}, - {SOCK_STRING, N_("Fill Faces")}, - {SOCK_STRING, N_("Rim Faces")}, - {-1, ""}, -}; - -static bNodeSocketTemplate geo_node_solidify_out[] = { - {SOCK_GEOMETRY, N_("Geometry")}, - {-1, ""}, -}; - -namespace blender::nodes { - -static void geo_node_solidify_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +namespace blender::nodes::node_geo_solidify { +static void node_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Geometry>(N_("Mesh")).supported_type(GEO_COMPONENT_TYPE_MESH); + b.add_input<decl::Float>(N_("Thickness")) + .default_value(0.0f) + .subtype(PROP_DISTANCE) + .supports_field(); + b.add_input<decl::Float>(N_("Clamp")) + .default_value(0.0f) + .min(0.0f) + .max(2.0f) + .subtype(PROP_FACTOR); + b.add_input<decl::Float>(N_("Offset")) + .default_value(0.0f) + .min(-1.0f) + .max(1.0f) + .subtype(PROP_FACTOR); + b.add_input<decl::Bool>(N_("Fill")).default_value(true); + b.add_input<decl::Bool>(N_("Rim")).default_value(true); + + b.add_output<decl::Geometry>(N_("Mesh")); + b.add_output<decl::Bool>(N_("Fill Faces")).field_source(); + b.add_output<decl::Bool>(N_("Rim Faces")).field_source(); +} + +static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { uiLayoutSetPropSep(layout, true); uiLayoutSetPropDecorate(layout, false); - uiItemR(layout, ptr, "thickness_mode", 0, nullptr, ICON_NONE); uiItemR(layout, ptr, "nonmanifold_offset_mode", 0, nullptr, ICON_NONE); uiItemR(layout, ptr, "nonmanifold_boundary_mode", 0, nullptr, ICON_NONE); } @@ -62,126 +67,132 @@ static void geo_node_solidify_init(bNodeTree *UNUSED(tree), bNode *node) sizeof(NodeGeometrySolidify), __func__); node->storage = node_storage; - node_storage->thickness_mode = GEO_NODE_ATTRIBUTE_INPUT_FLOAT; -} - -static void geo_node_solidify_update(bNodeTree *UNUSED(ntree), bNode *node) -{ - const NodeGeometrySolidify *node_storage = (NodeGeometrySolidify *)node->storage; - - update_attribute_input_socket_availabilities( - *node, "Thickness", (GeometryNodeAttributeInputMode)node_storage->thickness_mode, true); } -static void geo_node_solidify_exec(GeoNodeExecParams params) +static void node_geo_exec(GeoNodeExecParams params) { const bNode &node = params.node(); NodeGeometrySolidify &node_storage = *(NodeGeometrySolidify *)node.storage; const Object *self_object = params.self_object(); - GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); bool add_fill = params.extract_input<bool>("Fill"); bool add_rim = params.extract_input<bool>("Rim"); - - char flag = 0; - - if (add_fill) { - flag |= MOD_SOLIDIFY_SHELL; - } - - if (add_rim) { - flag |= MOD_SOLIDIFY_RIM; - } + GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh"); float offset = params.extract_input<float>("Offset"); float offset_clamp = params.extract_input<float>("Clamp"); - geometry_set = geometry_set_realize_instances(geometry_set); + bke::StrongAnonymousAttributeID fill_id; + bke::StrongAnonymousAttributeID rim_id; if (geometry_set.has<MeshComponent>()) { - MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>(); - Mesh *input_mesh = mesh_component.get_for_write(); - - const float default_thickness = 0; - GVArray_Typed<float> thickness_attribute = params.get_input_attribute<float>( - - "Thickness", mesh_component, ATTR_DOMAIN_POINT, default_thickness); - VArray_Span<float> thickness{thickness_attribute}; - - SolidifyData solidify_node_data = { - self_object, - 1, - offset, - 0.0f, - offset_clamp, - node_storage.nonmanifold_offset_mode, - node_storage.nonmanifold_boundary_mode, - flag, - 0.01f, - 0.0f, - thickness.data(), - }; - - bool *shell_verts = nullptr; - bool *rim_verts = nullptr; - bool *shell_faces = nullptr; - bool *rim_faces = nullptr; - - Mesh *output_mesh = solidify_nonmanifold( - &solidify_node_data, input_mesh, &shell_verts, &rim_verts, &shell_faces, &rim_faces); - - if (output_mesh != input_mesh) { - geometry_set.replace_mesh(output_mesh); - } - - const AttributeDomain result_face_domain = ATTR_DOMAIN_FACE; - - const std::string shell_faces_attribute_name = params.get_input<std::string>("Fill Faces"); - const std::string rim_faces_attribute_name = params.get_input<std::string>("Rim Faces"); - - if (solidify_node_data.flag & MOD_SOLIDIFY_SHELL) { - if (!shell_faces_attribute_name.empty()) { - OutputAttribute_Typed<bool> shell_faces_attribute = - mesh_component.attribute_try_get_for_output_only<bool>(shell_faces_attribute_name, - result_face_domain); - Span<bool> shell_faces_span(shell_faces, shell_faces_attribute->size()); - shell_faces_attribute->set_all(shell_faces_span); - shell_faces_attribute.save(); + geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { + MeshComponent &component = geometry_set.get_component_for_write<MeshComponent>(); + Mesh *input_mesh = component.get_for_write(); + + const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_POINT); + GeometryComponentFieldContext context{component, ATTR_DOMAIN_POINT}; + + Field<float> thickness_field = params.extract_input<Field<float>>("Thickness"); + FieldEvaluator thickness_evaluator{context, domain_size}; + thickness_evaluator.add(thickness_field); + thickness_evaluator.evaluate(); + Array<float> thickness(domain_size); + thickness_evaluator.get_evaluated<float>(0).materialize(thickness); + + char flag = 0; + + if (add_fill) { + flag |= MOD_SOLIDIFY_SHELL; + } + + if (add_rim) { + flag |= MOD_SOLIDIFY_RIM; } - } - - if (solidify_node_data.flag & MOD_SOLIDIFY_RIM) { - if (!rim_faces_attribute_name.empty()) { - OutputAttribute_Typed<bool> rim_faces_attribute = - mesh_component.attribute_try_get_for_output_only<bool>(rim_faces_attribute_name, - result_face_domain); - Span<bool> rim_faces_span(rim_faces, rim_faces_attribute->size()); - rim_faces_attribute->set_all(rim_faces_span); - rim_faces_attribute.save(); + + SolidifyData solidify_node_data = { + self_object, + 1, + offset, + 0.0f, + offset_clamp, + node_storage.nonmanifold_offset_mode, + node_storage.nonmanifold_boundary_mode, + flag, + 0.01f, + 0.0f, + thickness.begin(), + }; + + bool *shell_verts = nullptr; + bool *rim_verts = nullptr; + bool *shell_faces = nullptr; + bool *rim_faces = nullptr; + + Mesh *output_mesh = solidify_nonmanifold( + &solidify_node_data, input_mesh, &shell_verts, &rim_verts, &shell_faces, &rim_faces); + + if (output_mesh != input_mesh) { + component.replace(output_mesh, GeometryOwnershipType::Editable); + + if (params.output_is_required("Fill Faces")) { + fill_id = StrongAnonymousAttributeID("fill_faces"); + if (add_fill) { + OutputAttribute_Typed<bool> shell_faces_attribute = + component.attribute_try_get_for_output_only<bool>(fill_id.get(), ATTR_DOMAIN_FACE); + Span<bool> shell_faces_span(shell_faces, shell_faces_attribute->size()); + shell_faces_attribute->set_all(shell_faces_span); + shell_faces_attribute.save(); + } + } + + if (params.output_is_required("Rim Faces")) { + rim_id = StrongAnonymousAttributeID("rim_faces"); + if (add_rim) { + OutputAttribute_Typed<bool> rim_faces_attribute = + component.attribute_try_get_for_output_only<bool>(rim_id.get(), ATTR_DOMAIN_FACE); + Span<bool> rim_faces_span(rim_faces, rim_faces_attribute->size()); + rim_faces_attribute->set_all(rim_faces_span); + rim_faces_attribute.save(); + } + } } - } - MEM_freeN(shell_verts); - MEM_freeN(rim_verts); - MEM_freeN(shell_faces); - MEM_freeN(rim_faces); + MEM_freeN(shell_verts); + MEM_freeN(rim_verts); + MEM_freeN(shell_faces); + MEM_freeN(rim_faces); + }); + } + if (fill_id) { + params.set_output("Fill Faces", + AnonymousAttributeFieldInput::Create<bool>( + std::move(fill_id), params.attribute_producer_name())); + } + if (rim_id) { + params.set_output("Rim Faces", + AnonymousAttributeFieldInput::Create<bool>( + std::move(rim_id), params.attribute_producer_name())); } - params.set_output("Geometry", geometry_set); + + params.set_output("Mesh", geometry_set); } -} // namespace blender::nodes +} // namespace blender::nodes::node_geo_solidify void register_node_type_geo_solidify() { + namespace file_ns = blender::nodes::node_geo_solidify; + static bNodeType ntype; - geo_node_type_base(&ntype, GEO_NODE_SOLIDIFY, "Solidify", NODE_CLASS_GEOMETRY, 0); - node_type_socket_templates(&ntype, geo_node_solidify_in, geo_node_solidify_out); + + geo_node_type_base(&ntype, GEO_NODE_SOLIDIFY, "Solidify", NODE_CLASS_GEOMETRY); + ntype.declare = file_ns::node_declare; node_type_storage( &ntype, "NodeGeometrySolidify", node_free_standard_storage, node_copy_standard_storage); - node_type_init(&ntype, blender::nodes::geo_node_solidify_init); + node_type_init(&ntype, file_ns::geo_node_solidify_init); node_type_size(&ntype, 172, 100, 600); - node_type_update(&ntype, blender::nodes::geo_node_solidify_update); - ntype.geometry_node_execute = blender::nodes::geo_node_solidify_exec; - ntype.draw_buttons = blender::nodes::geo_node_solidify_layout; + ntype.geometry_node_execute = file_ns::node_geo_exec; + ntype.draw_buttons = file_ns::node_layout; nodeRegisterType(&ntype); } |