diff options
author | Fabian Schempp <fabianschempp@googlemail.com> | 2021-08-19 08:22:53 +0300 |
---|---|---|
committer | Fabian Schempp <fabianschempp@googlemail.com> | 2021-08-19 08:30:47 +0300 |
commit | c674adb6f40ec98722a4d39e3973184980ccd524 (patch) | |
tree | 6809b738909ba48beb3b1aea9b29209f1a6baff1 | |
parent | 2fb714443c85f46e64880abcc458b65f7d2cb350 (diff) |
SOC2021 Porting Modifiers To nodes all
This branch merges all branches from soc2021 porting modifiers to nodes
into one. The branche is mainly used to make a testbuild.
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 7 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh.c | 111 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh.h | 24 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_enum_types.h | 3 | ||||
-rw-r--r-- | source/blender/nodes/CMakeLists.txt | 11 | ||||
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_mesh_inset.cc | 215 |
6 files changed, 298 insertions, 73 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 8e598a34c85..ae46f4759f4 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1483,10 +1483,9 @@ int ntreeTexExecTree(struct bNodeTree *ntree, #define GEO_NODE_MERGE_BY_DISTANCE 1078 #define GEO_NODE_MESH_EXTRUDE 1079 #define GEO_NODE_MESH_INSET 1080 -#define GEO_NODE_CURVE_SELECT_HANDLES 1081 -#define GEO_NODE_COLLAPSE 1082 -#define GEO_NODE_UNSUBDIVIDE 1083 -#define GEO_NODE_DISSOLVE 1084 +#define GEO_NODE_COLLAPSE 1081 +#define GEO_NODE_UNSUBDIVIDE 1082 +#define GEO_NODE_DISSOLVE 1083 /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index 6d9e5c1a9cf..1b420cea417 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -1447,8 +1447,8 @@ void BM_mesh_vert_coords_apply_with_mat4(BMesh *bm, } /** -* Use to select bmesh vertex data based on an array of bool. -*/ + * Use to select bmesh vertex data based on an array of bool. + */ void BM_select_vertices(BMesh *bm, const bool *mask) { BMIter iter; @@ -1485,155 +1485,164 @@ void BM_select_faces(BMesh *bm, const bool *mask) } } -void BM_get_selected_vertices(BMesh *bm, bool *selection) +/** + * Use to temporary tag bmesh edge data based on an array of bool. + */ +void BM_tag_vertices(BMesh *bm, const bool *mask) { BMIter iter; - BMVert *v; + BMEdge *e; int i; - BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) { - selection[i] = BM_elem_flag_test(v, BM_ELEM_SELECT); + BM_ITER_MESH_INDEX (e, &iter, bm, BM_EDGES_OF_MESH, i) { + BM_elem_flag_set(e, BM_ELEM_TAG, mask[i]); } } -void BM_get_tagged_faces(BMesh *bm, bool *selection) +/** + * Use to temporary tag bmesh edge data based on an array of bool. + */ +void BM_tag_edges(BMesh *bm, const bool *mask) { BMIter iter; - BMFace *f; + BMEdge *e; int i; - BM_ITER_MESH_INDEX (f, &iter, bm, BM_FACES_OF_MESH, i) { - selection[i] = BM_elem_flag_test(f, BM_ELEM_TAG); + BM_ITER_MESH_INDEX (e, &iter, bm, BM_EDGES_OF_MESH, i) { + BM_elem_flag_set(e, BM_ELEM_TAG, mask[i]); } } -void BM_tag_new_faces(BMesh *bm, BMOperator *b_mesh_operator) +/** + * Use to temporary tag bmesh face data based on an array of bool. + */ +void BM_tag_faces(BMesh *bm, const bool *mask) { BMIter iter; BMFace *f; - BM_mesh_elem_hflag_disable_all(bm, BM_FACE, BM_ELEM_TAG, false); - BMO_ITER (f, &iter, b_mesh_operator->slots_out, "faces.out", BM_FACE) { - BM_elem_flag_enable(f, BM_ELEM_TAG); + int i; + BM_ITER_MESH_INDEX (f, &iter, bm, BM_FACES_OF_MESH, i) { + BM_elem_flag_set(f, BM_ELEM_TAG, mask[i]); } } -void BM_tag_vertices(BMesh *bm, const bool *mask) +/** + * Write selected bmesh vertex to array of bool with length of totvert. + */ +void BM_get_selected_vertices(BMesh *bm, bool *selection) { BMIter iter; BMVert *v; int i; BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) { - BM_elem_flag_set(v, BM_ELEM_TAG, mask[i]); + selection[i] = BM_elem_flag_test(v, BM_ELEM_SELECT); } } /** - * Use to temporary tag bmesh edge data based on an array of bool. + * Write selected bmesh edge to array of bool with length of totedge. */ -void BM_tag_edges(BMesh *bm, const bool *mask) +void BM_get_selected_edges(BMesh *bm, bool *selection) { BMIter iter; BMEdge *e; int i; BM_ITER_MESH_INDEX (e, &iter, bm, BM_EDGES_OF_MESH, i) { - BM_elem_flag_set(e, BM_ELEM_TAG, mask[i]); + selection[i] = BM_elem_flag_test(e, BM_ELEM_SELECT); } } /** - * Use to temporary tag bmesh face data based on an array of bool. + * Write selected bmesh face to array of bool with length of totpoly. */ -void BM_tag_faces(BMesh *bm, const bool *mask) +void BM_get_selected_faces(BMesh *bm, bool *selection) { BMIter iter; BMFace *f; int i; BM_ITER_MESH_INDEX (f, &iter, bm, BM_FACES_OF_MESH, i) { - BM_elem_flag_set(f, BM_ELEM_TAG, mask[i]); + selection[i] = BM_elem_flag_test(f, BM_ELEM_SELECT); } } -void BM_untag_faces_by_tag(BMesh *bm, int tag) -{ - BMIter iter; - BMFace *f; - int i; - BM_ITER_MESH_INDEX (f, &iter, bm, BM_FACES_OF_MESH, i) { - if (BM_elem_flag_test(f, tag)) { - BM_elem_flag_disable(f, BM_ELEM_TAG); - } - } -} /** - * Use to select bmesh vertex data based on an array of bool. + * Write tagged bmesh vertex to array of bool with length of totvert. */ -void BM_select_vertices(BMesh *bm, const bool *mask) +void BM_get_tagged_vertices(BMesh *bm, bool *selection) { BMIter iter; BMVert *v; int i; BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) { - BM_elem_flag_set(v, BM_ELEM_SELECT, mask[i]); + selection[i] = BM_elem_flag_test(v, BM_ELEM_TAG); } } /** - * Use to select bmesh edge data based on an array of bool. + * Write tagged bmesh edge to array of bool with length of totedge. */ -void BM_select_edges(BMesh *bm, const bool *mask) +void BM_get_tagged_edges(BMesh *bm, bool *selection) { BMIter iter; BMEdge *e; int i; BM_ITER_MESH_INDEX (e, &iter, bm, BM_EDGES_OF_MESH, i) { - BM_elem_flag_set(e, BM_ELEM_SELECT, mask[i]); + selection[i] = BM_elem_flag_test(e, BM_ELEM_TAG); } } /** - * Use to select bmesh face data based on an array of bool. + * Write tagged bmesh faces to array of bool with length of totpoly. */ -void BM_select_faces(BMesh *bm, const bool *mask) +void BM_get_tagged_faces(BMesh *bm, bool *selection) { BMIter iter; BMFace *f; int i; BM_ITER_MESH_INDEX (f, &iter, bm, BM_FACES_OF_MESH, i) { - BM_elem_flag_set(f, BM_ELEM_SELECT, mask[i]); + selection[i] = BM_elem_flag_test(f, BM_ELEM_TAG); } } -void BM_tag_vertices(BMesh *bm, const bool *mask) +/** + * Use to remove tag from all bmesh verts that are tagged with another tag. + */ +void BM_untag_vertices_by_tag(BMesh *bm, int tag) { BMIter iter; BMVert *v; int i; BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) { - BM_elem_flag_set(v, BM_ELEM_TAG, mask[i]); + if (BM_elem_flag_test(v, tag)) { + BM_elem_flag_disable(v, BM_ELEM_TAG); + } } } /** - * Use to temporary tag bmesh edge data based on an array of bool. + * Use to remove tag from all bmesh edges that are tagged with another tag. */ -void BM_tag_edges(BMesh *bm, const bool *mask) +void BM_untag_edges_by_tag(BMesh *bm, int tag) { BMIter iter; BMEdge *e; int i; BM_ITER_MESH_INDEX (e, &iter, bm, BM_EDGES_OF_MESH, i) { - BM_elem_flag_set(e, BM_ELEM_TAG, mask[i]); + if (BM_elem_flag_test(e, tag)) { + BM_elem_flag_disable(e, BM_ELEM_TAG); + } } } /** - * Use to temporary tag bmesh face data based on an array of bool. + * Use to remove tag from all bmesh faces that are tagged with another tag. */ -void BM_tag_faces(BMesh *bm, const bool *mask) +void BM_untag_faces_by_tag(BMesh *bm, int tag) { BMIter iter; BMFace *f; int i; BM_ITER_MESH_INDEX (f, &iter, bm, BM_FACES_OF_MESH, i) { - BM_elem_flag_set(f, BM_ELEM_TAG, mask[i]); + if (BM_elem_flag_test(f, tag)) { + BM_elem_flag_disable(f, BM_ELEM_TAG); + } } } -/** \} */ diff --git a/source/blender/bmesh/intern/bmesh_mesh.h b/source/blender/bmesh/intern/bmesh_mesh.h index 3d6da9bfc53..1cc9f4a6aca 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.h +++ b/source/blender/bmesh/intern/bmesh_mesh.h @@ -138,17 +138,23 @@ void BM_mesh_vert_coords_apply_with_mat4(BMesh *bm, void BM_select_vertices(BMesh *bm, const bool *mask); void BM_select_edges(BMesh *bm, const bool *mask); void BM_select_faces(BMesh *bm, const bool *mask); -void BM_get_selected_vertices(BMesh *bm, bool *selection); + void BM_tag_vertices(BMesh *bm, const bool *mask); void BM_tag_edges(BMesh *bm, const bool *mask); void BM_tag_faces(BMesh *bm, const bool *mask); -void BM_untag_faces_by_tag(BMesh *bm, int tag); + +void BM_get_selected_vertices(BMesh *bm, bool *selection); +void BM_get_selected_edges(BMesh *bm, bool *selection); +void BM_get_selected_faces(BMesh *bm, bool *selection); + +void BM_get_tagged_vertices(BMesh *bm, bool *selection); +void BM_get_tagged_edges(BMesh *bm, bool *selection); void BM_get_tagged_faces(BMesh *bm, bool *selection); -void BM_tag_new_faces(BMesh *bm, BMOperator *b_mesh_operator); -void BM_select_vertices(BMesh *bm, const bool *mask); -void BM_select_edges(BMesh *bm, const bool *mask); -void BM_select_faces(BMesh *bm, const bool *mask); -void BM_tag_vertices(BMesh *bm, const bool *mask); -void BM_tag_edges(BMesh *bm, const bool *mask); -void BM_tag_faces(BMesh *bm, const bool *mask);
\ No newline at end of file +void BM_untag_vertices_by_tag(BMesh *bm, int tag); +void BM_untag_edges_by_tag(BMesh *bm, int tag); +void BM_untag_faces_by_tag(BMesh *bm, int tag); + +void BM_tag_new_vertices(BMesh *bm, BMOperator *b_mesh_operator); +void BM_tag_new_edges(BMesh *bm, BMOperator *b_mesh_operator); +void BM_tag_new_faces(BMesh *bm, BMOperator *b_mesh_operator);
\ No newline at end of file diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h index 19f0aadecd9..c7e7dc84775 100644 --- a/source/blender/makesrna/RNA_enum_types.h +++ b/source/blender/makesrna/RNA_enum_types.h @@ -78,6 +78,9 @@ extern const EnumPropertyItem rna_enum_linestyle_alpha_modifier_type_items[]; extern const EnumPropertyItem rna_enum_linestyle_thickness_modifier_type_items[]; extern const EnumPropertyItem rna_enum_linestyle_geometry_modifier_type_items[]; +extern const EnumPropertyItem nonmanifold_thickness_mode_items[]; +extern const EnumPropertyItem nonmanifold_boundary_mode_items[]; + extern const EnumPropertyItem rna_enum_window_cursor_items[]; extern const EnumPropertyItem rna_enum_dt_method_vertex_items[]; diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index b8ee7473369..73ff2e6f2e4 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -187,7 +187,7 @@ set(SRC geometry/nodes/node_geo_delete_geometry.cc geometry/nodes/node_geo_dissolve.cc geometry/nodes/node_geo_edge_split.cc - geometry/nodes/node_geo_mesh_extrude.cc + geometry/nodes/node_geo_mesh_extrude.cc geometry/nodes/node_geo_input_material.cc geometry/nodes/node_geo_is_viewport.cc geometry/nodes/node_geo_join_geometry.cc @@ -417,7 +417,7 @@ if(WITH_BULLET) if(NOT WITH_SYSTEM_BULLET) list(APPEND LIB extern_bullet - ) + ) endif() list(APPEND LIB @@ -488,16 +488,9 @@ if(WITH_GMP) endif() if(WITH_OPENVDB) - list(APPEND INC - ../../../intern/openvdb - ) list(APPEND INC_SYS ${OPENVDB_INCLUDE_DIRS} ) - list(APPEND LIB - bf_intern_openvdb - ${OPENVDB_LIBRARIES} - ) add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS}) endif() diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_inset.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_inset.cc new file mode 100644 index 00000000000..d79864d4b51 --- /dev/null +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_inset.cc @@ -0,0 +1,215 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" + +#include "BKE_mesh.h" +#include "BKE_node.h" + +#include "UI_interface.h" +#include "UI_resources.h" + +#include "bmesh.h" +#include "bmesh_tools.h" + +#include "node_geometry_util.hh" + +static bNodeSocketTemplate geo_node_mesh_inset_in[] = { + {SOCK_GEOMETRY, N_("Geometry")}, + {SOCK_STRING, N_("Distance")}, + {SOCK_FLOAT, N_("Distance"), 0.0f, 0, 0, 0, FLT_MIN, FLT_MAX, PROP_DISTANCE}, + {SOCK_STRING, N_("mesh_inset")}, + {SOCK_FLOAT, N_("mesh_inset"), 0.0f, 0, 0, 0, FLT_MIN, FLT_MAX, PROP_DISTANCE}, + {SOCK_BOOLEAN, N_("Individual")}, + {SOCK_STRING, N_("Selection")}, + {SOCK_STRING, N_("Top Face")}, + {SOCK_STRING, N_("Side Face")}, + {-1, ""}, +}; + +static bNodeSocketTemplate geo_node_mesh_inset_out[] = { + {SOCK_GEOMETRY, N_("Geometry")}, + {-1, ""}, +}; + +static void geo_node_mesh_inset_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +{ + uiLayoutSetPropSep(layout, true); + uiLayoutSetPropDecorate(layout, false); + uiItemR(layout, ptr, "distance_mode", 0, nullptr, ICON_NONE); + uiItemR(layout, ptr, "inset_mode", 0, nullptr, ICON_NONE); +} + +static void geo_node_mesh_inset_init(bNodeTree *UNUSED(tree), bNode *node) +{ + node->custom1 = GEO_NODE_ATTRIBUTE_INPUT_FLOAT; + node->custom2 = GEO_NODE_ATTRIBUTE_INPUT_FLOAT; +} + +static void geo_node_mesh_inset_update(bNodeTree *UNUSED(ntree), bNode *node) +{ + blender::nodes::update_attribute_input_socket_availabilities( + *node, "Distance", (GeometryNodeAttributeInputMode)node->custom1, true); + blender::nodes::update_attribute_input_socket_availabilities( + *node, "mesh_inset", (GeometryNodeAttributeInputMode)node->custom2, true); +} + +using blender::Span; + +static Mesh *mesh_inset_mesh(const Mesh *mesh, + const Span<bool> selection, + const Span<float> distance, + const Span<float> mesh_inset, + const bool mesh_inset_individual_faces, + std::string selection_top_faces_out_attribute_name, + std::string selection_side_faces_out_attribute_name) +{ + const BMeshCreateParams bmesh_create_params = {true}; + const BMeshFromMeshParams bmesh_from_mesh_params = { + true, 0, 0, 0, {CD_MASK_ORIGINDEX, CD_MASK_ORIGINDEX, CD_MASK_ORIGINDEX}}; + + BMesh *bm = BKE_mesh_to_bmesh_ex(mesh, &bmesh_create_params, &bmesh_from_mesh_params); + + BM_select_faces(bm, selection.data()); + BMOperator op; + if (mesh_inset_individual_faces) { + BMO_op_initf(bm, + &op, + 0, + "inset_individual faces=%hf use_even_offset=%b thickness=%f depth=%f " + "thickness_array=%p depth_array=%p use_attributes=%b", + BM_ELEM_SELECT, + true, + mesh_inset[0], + distance[0], + mesh_inset.data(), + distance.data(), + true); + } + else { + BMO_op_initf(bm, + &op, + 0, + "inset_region faces=%hf use_boundary=%b use_even_offset=%b thickness=%f depth=%f " + "thickness_array=%p depth_array=%p use_attributes=%b", + BM_ELEM_SELECT, + true, + true, + mesh_inset[0], + distance[0], + mesh_inset.data(), + distance.data(), + true); + } + BM_tag_new_faces(bm, &op); + BM_untag_faces_by_tag(bm, BM_ELEM_SELECT); + + BMO_op_exec(bm, &op); + BMO_op_finish(bm, &op); + + CustomData_MeshMasks cd_mask_extra = {CD_MASK_ORIGINDEX, CD_MASK_ORIGINDEX, CD_MASK_ORIGINDEX}; + + Mesh *result = BKE_mesh_from_bmesh_for_eval_nomain(bm, &cd_mask_extra, mesh); + + MeshComponent component; + component.replace(result, GeometryOwnershipType::Editable); + + if (!selection_top_faces_out_attribute_name.empty()) { + blender::bke::OutputAttribute_Typed<bool> attribute = + component.attribute_try_get_for_output_only<bool>(selection_top_faces_out_attribute_name, + ATTR_DOMAIN_FACE); + BM_get_selected_faces(bm, attribute.as_span().data()); + attribute.save(); + } + + if (!selection_side_faces_out_attribute_name.empty()) { + blender::bke::OutputAttribute_Typed<bool> attribute = + component.attribute_try_get_for_output_only<bool>(selection_side_faces_out_attribute_name, + ATTR_DOMAIN_FACE); + BM_get_tagged_faces(bm, attribute.as_span().data()); + attribute.save(); + } + + BM_mesh_free(bm); + BKE_mesh_normals_tag_dirty(result); + + return result; +} + +namespace blender::nodes { +static void geo_node_mesh_inset_exec(GeoNodeExecParams params) +{ + GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); + + geometry_set = geometry_set_realize_instances(geometry_set); + + MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>(); + if (mesh_component.has_mesh()) { + const bool default_selection = true; + GVArray_Typed<bool> selection_attribute = params.get_input_attribute<bool>( + "Selection", mesh_component, ATTR_DOMAIN_FACE, default_selection); + VArray_Span<bool> selection{selection_attribute}; + const Mesh *input_mesh = mesh_component.get_for_read(); + + AttributeDomain attribute_domain = ATTR_DOMAIN_POINT; + const bool mesh_inset_individual_faces = params.extract_input<bool>("Individual"); + + if (mesh_inset_individual_faces) { + attribute_domain = ATTR_DOMAIN_FACE; + } + + const float default_distance = 0; + GVArray_Typed<float> distance_attribute = params.get_input_attribute<float>( + "Distance", mesh_component, attribute_domain, default_distance); + VArray_Span<float> distance{distance_attribute}; + + const float default_mesh_inset = 0; + GVArray_Typed<float> mesh_inset_attribute = params.get_input_attribute<float>( + "mesh_inset", mesh_component, attribute_domain, default_mesh_inset); + VArray_Span<float> mesh_inset{mesh_inset_attribute}; + + std::string selection_top_faces_out_attribute_name = params.get_input<std::string>("Top Face"); + std::string selection_side_faces_out_attribute_name = params.get_input<std::string>( + "Side Face"); + + Mesh *result = mesh_inset_mesh(input_mesh, + selection, + distance, + mesh_inset, + mesh_inset_individual_faces, + selection_top_faces_out_attribute_name, + selection_side_faces_out_attribute_name); + + geometry_set.replace_mesh(result); + } + + params.set_output("Geometry", std::move(geometry_set)); +} +} // namespace blender::nodes + +void register_node_type_geo_mesh_inset() +{ + static bNodeType ntype; + + geo_node_type_base(&ntype, GEO_NODE_MESH_INSET, "MeshInset", NODE_CLASS_GEOMETRY, 0); + node_type_socket_templates(&ntype, geo_node_mesh_inset_in, geo_node_mesh_inset_out); + node_type_init(&ntype, geo_node_mesh_inset_init); + node_type_update(&ntype, geo_node_mesh_inset_update); + ntype.draw_buttons = geo_node_mesh_inset_layout; + ntype.geometry_node_execute = blender::nodes::geo_node_mesh_inset_exec; + nodeRegisterType(&ntype); +} |