Commit: 18f45f874cfdc298c5c87d2845fae125f9cb8038 Author: Fabian Schempp Date: Fri Jul 23 12:03:45 2021 +0200 Branches: soc-2021-porting-modifiers-to-nodes-merge-by-distance https://developer.blender.org/rB18f45f874cfdc298c5c87d2845fae125f9cb8038
Geometry Nodes: Merge by Distance (Direct Modifier Port) This patch is a direct port of the Weld modifier that moves the common code to the geometry module. I had made another version of a Merge by Distance Modifier (D10888), with an own implementation, but I found that the original modifiers algorithm gives finer results. Differential Revision: https://developer.blender.org/D12019 =================================================================== M source/blender/geometry/GEO_weld.h M source/blender/geometry/intern/weld.c M source/blender/modifiers/intern/MOD_weld.c M source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc =================================================================== diff --git a/source/blender/geometry/GEO_weld.h b/source/blender/geometry/GEO_weld.h index 08bcb789eaa..23395828f7e 100644 --- a/source/blender/geometry/GEO_weld.h +++ b/source/blender/geometry/GEO_weld.h @@ -31,7 +31,10 @@ enum { WELD_MODE_CONNECTED = 1, }; -Mesh *GEO_weld(const Mesh *mesh, const bool *mask, const float merge_distance, const int weld_mode); +Mesh *GEO_weld(const Mesh *mesh, + const bool *mask, + const float merge_distance, + const int weld_mode); #ifdef __cplusplus } diff --git a/source/blender/geometry/intern/weld.c b/source/blender/geometry/intern/weld.c index 1d6933e70b9..2490ba7d932 100644 --- a/source/blender/geometry/intern/weld.c +++ b/source/blender/geometry/intern/weld.c @@ -21,7 +21,7 @@ #include "BKE_mesh.h" #include "BKE_modifier.h" -#include "GEO_weld.h" // Own include. +#include "GEO_weld.h" // Own include. /* Indicates when the element was not computed. */ #define OUT_OF_CONTEXT (uint)(-1) @@ -884,7 +884,7 @@ static void weld_poly_loop_ctx_alloc(const MPoly *mpoly, static void weld_poly_split_recursive(const uint *vert_dest_map, #ifdef USE_WELD_DEBUG - const MLoop *mloop, + const MLoop *mloop, #endif uint ctx_verts_len, WeldPoly *r_wp, @@ -909,7 +909,7 @@ static void weld_poly_split_recursive(const uint *vert_dest_map, } const uint la_len = ctx_loops_len - 1; for (uint la = 0; la < la_len; la++, wla++) { - wa_continue: + wa_continue: if (wla->flag == ELEM_COLLAPSED) { continue; } @@ -980,7 +980,7 @@ static void weld_poly_split_recursive(const uint *vert_dest_map, new_wp->len = dist_a; weld_poly_split_recursive(vert_dest_map, #ifdef USE_WELD_DEBUG - mloop, + mloop, #endif ctx_verts_len, new_wp, @@ -1024,7 +1024,7 @@ static void weld_poly_split_recursive(const uint *vert_dest_map, static void weld_poly_loop_ctx_setup(const MLoop *mloop, #ifdef USE_WELD_DEBUG - const MPoly *mpoly, + const MPoly *mpoly, const uint mpoly_len, const uint mloop_len, #endif @@ -1091,7 +1091,7 @@ static void weld_poly_loop_ctx_setup(const MLoop *mloop, weld_poly_split_recursive(vert_dest_map, #ifdef USE_WELD_DEBUG - mloop, + mloop, #endif ctx_verts_len, wp, @@ -1307,7 +1307,7 @@ static void weld_mesh_context_create(const Mesh *mesh, weld_poly_loop_ctx_setup(mloop, #ifdef USE_WELD_DEBUG - mpoly, + mpoly, mpoly_len, mloop_len, #endif @@ -1547,7 +1547,7 @@ Mesh *GEO_weld(const Mesh *mesh, const bool *mask, const float merge_distance, c uint vert_kill_len = 0; if (weld_mode == WELD_MODE_ALL) #ifdef USE_BVHTREEKDOP - { + { /* Get overlap map. */ struct BVHTreeFromMesh treedata; BVHTree *bvhtree = bvhtree_from_mesh_verts_ex(&treedata, @@ -1839,7 +1839,7 @@ Mesh *GEO_weld(const Mesh *mesh, const bool *mask, const float merge_distance, c WeldPoly *wp = &weld_mesh.wpoly[poly_ctx]; WeldLoopOfPolyIter iter; if (!weld_iter_loop_of_poly_begin( - &iter, wp, weld_mesh.wloop, mloop, weld_mesh.loop_map, group_buffer)) { + &iter, wp, weld_mesh.wloop, mloop, weld_mesh.loop_map, group_buffer)) { continue; } @@ -1873,7 +1873,7 @@ Mesh *GEO_weld(const Mesh *mesh, const bool *mask, const float merge_distance, c int loop_start = loop_cur; WeldLoopOfPolyIter iter; if (!weld_iter_loop_of_poly_begin( - &iter, wp, weld_mesh.wloop, mloop, weld_mesh.loop_map, group_buffer)) { + &iter, wp, weld_mesh.wloop, mloop, weld_mesh.loop_map, group_buffer)) { continue; } diff --git a/source/blender/modifiers/intern/MOD_weld.c b/source/blender/modifiers/intern/MOD_weld.c index 0e14e1d714b..2937be444ea 100644 --- a/source/blender/modifiers/intern/MOD_weld.c +++ b/source/blender/modifiers/intern/MOD_weld.c @@ -33,8 +33,8 @@ #include "MEM_guardedalloc.h" -#include "BLI_utildefines.h" #include "BLI_math.h" +#include "BLI_utildefines.h" #include "BLT_translation.h" @@ -80,12 +80,14 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx) const bool found = BKE_defvert_find_weight(dv, defgrp_index) > 0.0f; if (found != invert_vgroup) { mask[i] = true; - }else{ + } + else { mask[i] = false; } } } - }else{ + } + else { for (int i = 0; i < totvert; i++) { mask[i] = true; } @@ -95,8 +97,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx) MEM_freeN(mask); return result; - - } static void initData(ModifierData *md) diff --git a/source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc b/source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc index 82518ea8025..f72b1b33ed3 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc @@ -25,7 +25,7 @@ static bNodeSocketTemplate geo_node_merge_by_distance_in[] = { {SOCK_GEOMETRY, N_("Geometry")}, - {SOCK_FLOAT, N_("Distance"), 0.0f, 0, 0, 0, 0, 10000.0f,PROP_DISTANCE}, + {SOCK_FLOAT, N_("Distance"), 0.0f, 0, 0, 0, 0, 10000.0f, PROP_DISTANCE}, {SOCK_STRING, N_("Selection")}, {-1, ""}, }; @@ -35,7 +35,9 @@ static bNodeSocketTemplate geo_node_merge_by_distance_out[] = { {-1, ""}, }; -static void geo_node_merge_by_distance_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +static void geo_node_merge_by_distance_layout(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) { uiItemR(layout, ptr, "merge_mode", 0, "", ICON_NONE); } @@ -75,8 +77,10 @@ static void geo_node_merge_by_distance_exec(GeoNodeExecParams params) void register_node_type_geo_merge_by_distance() { static bNodeType ntype; - geo_node_type_base(&ntype, GEO_NODE_MERGE_BY_DISTANCE, "Merge By Distance", NODE_CLASS_GEOMETRY, 0); - node_type_socket_templates(&ntype, geo_node_merge_by_distance_in, geo_node_merge_by_distance_out); + geo_node_type_base( + &ntype, GEO_NODE_MERGE_BY_DISTANCE, "Merge By Distance", NODE_CLASS_GEOMETRY, 0); + node_type_socket_templates( + &ntype, geo_node_merge_by_distance_in, geo_node_merge_by_distance_out); node_type_init(&ntype, geo_merge_by_distance_init); ntype.geometry_node_execute = blender::nodes::geo_node_merge_by_distance_exec; ntype.draw_buttons = geo_node_merge_by_distance_layout; _______________________________________________ Bf-blender-cvs mailing list [email protected] List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
