From 6c036a65c9741786deb53191fa77d83e7ffb1be3 Mon Sep 17 00:00:00 2001 From: Pablo Dobarro Date: Tue, 31 Mar 2020 17:06:17 +0200 Subject: Add Voxel Mode to the Remesh modifier This adds the Voxel Mode to the current remesh modifier. It works exactly the same way as the voxel remesh operator and uses the same properties to control the remeshing. We can exand this with more options in the future (fix poles, reprojection...) Reviewed By: brecht Differential Revision: https://developer.blender.org/D7292 --- source/blender/modifiers/intern/MOD_remesh.c | 73 +++++++++++++++++----------- 1 file changed, 45 insertions(+), 28 deletions(-) (limited to 'source/blender/modifiers') diff --git a/source/blender/modifiers/intern/MOD_remesh.c b/source/blender/modifiers/intern/MOD_remesh.c index 3300cda947c..2fa8dc973a1 100644 --- a/source/blender/modifiers/intern/MOD_remesh.c +++ b/source/blender/modifiers/intern/MOD_remesh.c @@ -34,6 +34,7 @@ #include "MOD_modifiertypes.h" #include "BKE_mesh.h" +#include "BKE_mesh_remesh_voxel.h" #include "BKE_mesh_runtime.h" #include @@ -54,8 +55,10 @@ static void initData(ModifierData *md) rmd->depth = 4; rmd->hermite_num = 1; rmd->flag = MOD_REMESH_FLOOD_FILL; - rmd->mode = MOD_REMESH_SHARP_FEATURES; + rmd->mode = MOD_REMESH_VOXEL; rmd->threshold = 1; + rmd->voxel_size = 0.1f; + rmd->adaptivity = 0.0f; } #ifdef WITH_MOD_REMESH @@ -144,36 +147,50 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *UNUSED(c rmd = (RemeshModifierData *)md; - init_dualcon_mesh(&input, mesh); - - if (rmd->flag & MOD_REMESH_FLOOD_FILL) { - flags |= DUALCON_FLOOD_FILL; + if (rmd->mode == MOD_REMESH_VOXEL) { + /* OpenVDB modes. */ + if (rmd->voxel_size == 0.0f) { + return NULL; + } + result = BKE_mesh_remesh_voxel_to_mesh_nomain(mesh, rmd->voxel_size, rmd->adaptivity, 0.0f); } + else { + /* Dualcon modes. */ + init_dualcon_mesh(&input, mesh); - switch (rmd->mode) { - case MOD_REMESH_CENTROID: - mode = DUALCON_CENTROID; - break; - case MOD_REMESH_MASS_POINT: - mode = DUALCON_MASS_POINT; - break; - case MOD_REMESH_SHARP_FEATURES: - mode = DUALCON_SHARP_FEATURES; - break; - } + if (rmd->flag & MOD_REMESH_FLOOD_FILL) { + flags |= DUALCON_FLOOD_FILL; + } - output = dualcon(&input, - dualcon_alloc_output, - dualcon_add_vert, - dualcon_add_quad, - flags, - mode, - rmd->threshold, - rmd->hermite_num, - rmd->scale, - rmd->depth); - result = output->mesh; - MEM_freeN(output); + switch (rmd->mode) { + case MOD_REMESH_CENTROID: + mode = DUALCON_CENTROID; + break; + case MOD_REMESH_MASS_POINT: + mode = DUALCON_MASS_POINT; + break; + case MOD_REMESH_SHARP_FEATURES: + mode = DUALCON_SHARP_FEATURES; + break; + case MOD_REMESH_VOXEL: + /* Should have been processed before as an OpenVDB operation. */ + BLI_assert(false); + break; + } + + output = dualcon(&input, + dualcon_alloc_output, + dualcon_add_vert, + dualcon_add_quad, + flags, + mode, + rmd->threshold, + rmd->hermite_num, + rmd->scale, + rmd->depth); + result = output->mesh; + MEM_freeN(output); + } if (rmd->flag & MOD_REMESH_SMOOTH_SHADING) { MPoly *mpoly = result->mpoly; -- cgit v1.2.3 From 74b5e5f6e15fa82a43d97329da157305cb055cc8 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Tue, 31 Mar 2020 20:27:46 -0300 Subject: Fix T74588: Weld Modifier: Vertex colors and UVs get incorrect values --- source/blender/modifiers/intern/MOD_weld.c | 88 +++++++++++++++++++----------- 1 file changed, 56 insertions(+), 32 deletions(-) (limited to 'source/blender/modifiers') diff --git a/source/blender/modifiers/intern/MOD_weld.c b/source/blender/modifiers/intern/MOD_weld.c index 5d56152e0ff..11fd411459c 100644 --- a/source/blender/modifiers/intern/MOD_weld.c +++ b/source/blender/modifiers/intern/MOD_weld.c @@ -800,6 +800,33 @@ static bool weld_iter_loop_of_poly_begin(WeldLoopOfPolyIter *iter, iter->mloop = mloop; iter->loop_map = loop_map; iter->group = group_buffer; + if (group_buffer) { + /* First loop group needs more attention. */ + uint loop_start, loop_end, l; + loop_start = iter->loop_start; + loop_end = l = iter->loop_end; + while (l >= loop_start) { + const uint loop_ctx = loop_map[l]; + if (loop_ctx != OUT_OF_CONTEXT) { + const WeldLoop *wl = &wloop[loop_ctx]; + if (wl->flag == ELEM_COLLAPSED) { + l--; + continue; + } + } + break; + } + if (l != loop_end) { + iter->group_len = iter->loop_end - l; + int i = 0; + while (l < loop_end) { + iter->group[i++] = ++l; + } + } + } + else { + iter->group_len = 0; + } iter->l_next = iter->loop_start; #ifdef USE_WELD_DEBUG @@ -813,8 +840,13 @@ static bool weld_iter_loop_of_poly_next(WeldLoopOfPolyIter *iter) uint loop_end = iter->loop_end; const WeldLoop *wloop = iter->wloop; const uint *loop_map = iter->loop_map; - iter->group_len = 0; uint l = iter->l_curr = iter->l_next; + if (l == iter->loop_start) { + /* `grupo_len` is already calculated in the first loop */ + } + else { + iter->group_len = 0; + } while (l <= loop_end) { uint l_next = l + 1; const uint loop_ctx = loop_map[l]; @@ -825,20 +857,6 @@ static bool weld_iter_loop_of_poly_next(WeldLoopOfPolyIter *iter) } if (wl->flag == ELEM_COLLAPSED) { if (iter->group) { - if (l == iter->loop_start) { - uint l_prev = loop_end; - const uint loop_ctx_end = loop_map[l_prev]; - if (loop_ctx_end != OUT_OF_CONTEXT) { - const WeldLoop *wl_prev = &wloop[loop_ctx_end]; - while (wl_prev->flag == ELEM_COLLAPSED) { - iter->group[iter->group_len++] = l_prev--; - wl_prev--; - if (wl_prev->loop_orig != l_prev) { - break; - } - } - } - } iter->group[iter->group_len++] = l; } l = l_next; @@ -1503,16 +1521,7 @@ static void customdata_weld( if (dest->layers[dest_i].type == type) { void *src_data = source->layers[src_i].data; - if (CustomData_layer_has_math(dest, dest_i)) { - const int size = CustomData_sizeof(type); - void *dst_data = dest->layers[dest_i].data; - void *v_dst = POINTER_OFFSET(dst_data, (size_t)dest_index * size); - for (j = 0; j < count; j++) { - CustomData_data_add( - type, v_dst, POINTER_OFFSET(src_data, (size_t)src_indices[j] * size)); - } - } - else if (type == CD_MVERT) { + if (type == CD_MVERT) { for (j = 0; j < count; j++) { MVert *mv_src = &((MVert *)src_data)[src_indices[j]]; add_v3_v3(co, mv_src->co); @@ -1534,6 +1543,18 @@ static void customdata_weld( flag |= me_src->flag; } } + else if (CustomData_layer_has_interp(dest, dest_i)) { + CustomData_interp(source, dest, (const int *)src_indices, NULL, NULL, count, dest_index); + } + else if (CustomData_layer_has_math(dest, dest_i)) { + const int size = CustomData_sizeof(type); + void *dst_data = dest->layers[dest_i].data; + void *v_dst = POINTER_OFFSET(dst_data, (size_t)dest_index * size); + for (j = 0; j < count; j++) { + CustomData_data_add( + type, v_dst, POINTER_OFFSET(src_data, (size_t)src_indices[j] * size)); + } + } else { CustomData_copy_layer_type_data(source, dest, type, src_indices[0], dest_index, 1); } @@ -1551,13 +1572,7 @@ static void customdata_weld( for (dest_i = 0; dest_i < dest->totlayer; dest_i++) { CustomDataLayer *layer_dst = &dest->layers[dest_i]; const int type = layer_dst->type; - if (CustomData_layer_has_math(dest, dest_i)) { - const int size = CustomData_sizeof(type); - void *dst_data = layer_dst->data; - void *v_dst = POINTER_OFFSET(dst_data, (size_t)dest_index * size); - CustomData_data_multiply(type, v_dst, fac); - } - else if (type == CD_MVERT) { + if (type == CD_MVERT) { MVert *mv = &((MVert *)layer_dst->data)[dest_index]; mul_v3_fl(co, fac); bweight *= fac; @@ -1586,6 +1601,15 @@ static void customdata_weld( me->bweight = (char)bweight; me->flag = flag; } + else if (CustomData_layer_has_interp(dest, dest_i)) { + /* Already calculated. */ + } + else if (CustomData_layer_has_math(dest, dest_i)) { + const int size = CustomData_sizeof(type); + void *dst_data = layer_dst->data; + void *v_dst = POINTER_OFFSET(dst_data, (size_t)dest_index * size); + CustomData_data_multiply(type, v_dst, fac); + } } } -- cgit v1.2.3 From 18fc4155fd4299d61789aa0d5b9c1c3f7883636b Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Tue, 31 Mar 2020 20:57:18 -0300 Subject: Fix customdata interpolation being done multiple times in Weld Modifier --- source/blender/modifiers/intern/MOD_weld.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source/blender/modifiers') diff --git a/source/blender/modifiers/intern/MOD_weld.c b/source/blender/modifiers/intern/MOD_weld.c index 11fd411459c..a7d3280b113 100644 --- a/source/blender/modifiers/intern/MOD_weld.c +++ b/source/blender/modifiers/intern/MOD_weld.c @@ -1489,6 +1489,8 @@ static void customdata_weld( return; } + CustomData_interp(source, dest, (const int *)src_indices, NULL, NULL, count, dest_index); + int src_i, dest_i; int j; @@ -1544,7 +1546,8 @@ static void customdata_weld( } } else if (CustomData_layer_has_interp(dest, dest_i)) { - CustomData_interp(source, dest, (const int *)src_indices, NULL, NULL, count, dest_index); + /* Already calculated. + * TODO: Optimize by exposing `typeInfo->interp`. */ } else if (CustomData_layer_has_math(dest, dest_i)) { const int size = CustomData_sizeof(type); -- cgit v1.2.3 From 186ac842103f410c663dfab440c9e40038dcea5b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 1 Apr 2020 18:54:34 +1100 Subject: Cleanup: clang-format --- source/blender/modifiers/intern/MOD_warp.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source/blender/modifiers') diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c index b8db14f610a..c3515578e42 100644 --- a/source/blender/modifiers/intern/MOD_warp.c +++ b/source/blender/modifiers/intern/MOD_warp.c @@ -30,9 +30,9 @@ #include "DNA_meshdata_types.h" #include "DNA_object_types.h" +#include "BKE_action.h" /* BKE_pose_channel_find_name */ #include "BKE_colortools.h" #include "BKE_deform.h" -#include "BKE_action.h" /* BKE_pose_channel_find_name */ #include "BKE_editmesh.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" @@ -86,7 +86,10 @@ static void requiredDataMask(Object *UNUSED(ob), } } -static void matrix_from_obj_pchan(float mat[4][4], float obinv[4][4], Object *ob, const char *bonename) +static void matrix_from_obj_pchan(float mat[4][4], + const float obinv[4][4], + Object *ob, + const char *bonename) { bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, bonename); if (pchan) { @@ -150,8 +153,8 @@ static void foreachTexLink(ModifierData *md, Object *ob, TexWalkFunc walk, void } static void warp_deps_object_bone_new(struct DepsNodeHandle *node, - Object *object, - const char *bonename) + Object *object, + const char *bonename) { if (bonename[0] && object->type == OB_ARMATURE) { DEG_add_object_relation(node, object, DEG_OB_COMP_EVAL_POSE, "Warp Modifier"); -- cgit v1.2.3 From 3dad6294dae2f13ca1b9e8b08933ba32bf0f3bed Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 2 Apr 2020 10:10:13 +0200 Subject: Sculpt: Store explicit value for multires sculpt level Allows to know what level sculpting has been done after the value has been changed in the MultiresModifierData. No functional changes, just preparing code to have everything needed for propagation undo. Differential Revision: https://developer.blender.org/D7307 --- source/blender/modifiers/intern/MOD_multires.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source/blender/modifiers') diff --git a/source/blender/modifiers/intern/MOD_multires.c b/source/blender/modifiers/intern/MOD_multires.c index ad8e0a9f259..f9d53d08c2e 100644 --- a/source/blender/modifiers/intern/MOD_multires.c +++ b/source/blender/modifiers/intern/MOD_multires.c @@ -211,7 +211,9 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes if (ctx->object->sculpt != NULL) { SculptSession *sculpt_session = ctx->object->sculpt; sculpt_session->subdiv_ccg = result->runtime.subdiv_ccg; - sculpt_session->multires = mmd; + sculpt_session->multires.active = true; + sculpt_session->multires.modifier = mmd; + sculpt_session->multires.level = mmd->sculptlvl; sculpt_session->totvert = mesh->totvert; sculpt_session->totpoly = mesh->totpoly; sculpt_session->mvert = NULL; -- cgit v1.2.3 From b0c1184875d39abac4a65a5d20e263ea6d841009 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 3 Apr 2020 17:38:58 +0200 Subject: Cleanup: Including "BLI_listbase.h" for LISTBASE_FOREACH macro These headers are not needed right away, but will be in the upcoming commit. --- source/blender/modifiers/intern/MOD_dynamicpaint.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender/modifiers') diff --git a/source/blender/modifiers/intern/MOD_dynamicpaint.c b/source/blender/modifiers/intern/MOD_dynamicpaint.c index 457f47bf025..d9fe2504e22 100644 --- a/source/blender/modifiers/intern/MOD_dynamicpaint.c +++ b/source/blender/modifiers/intern/MOD_dynamicpaint.c @@ -20,6 +20,7 @@ #include +#include "BLI_listbase.h" #include "BLI_utildefines.h" #include "DNA_dynamicpaint_types.h" -- cgit v1.2.3 From d138cbfb47e379edc1ee915a8c6ff65b01f000d6 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 3 Apr 2020 19:15:01 +0200 Subject: Code Quality: Replace for loops with LISTBASE_FOREACH Note this only changes cases where the variable was declared inside the for loop. To handle it outside as well is a different challenge. Differential Revision: https://developer.blender.org/D7320 --- source/blender/modifiers/intern/MOD_dynamicpaint.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source/blender/modifiers') diff --git a/source/blender/modifiers/intern/MOD_dynamicpaint.c b/source/blender/modifiers/intern/MOD_dynamicpaint.c index d9fe2504e22..d36fce3752b 100644 --- a/source/blender/modifiers/intern/MOD_dynamicpaint.c +++ b/source/blender/modifiers/intern/MOD_dynamicpaint.c @@ -124,8 +124,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md; /* Add relation from canvases to all brush objects. */ if (pmd->canvas != NULL && pmd->type == MOD_DYNAMICPAINT_TYPE_CANVAS) { - for (DynamicPaintSurface *surface = pmd->canvas->surfaces.first; surface; - surface = surface->next) { + LISTBASE_FOREACH (DynamicPaintSurface *, surface, &pmd->canvas->surfaces) { if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) { DEG_add_forcefield_relations( ctx->node, ctx->object, surface->effector_weights, true, 0, "Dynamic Paint Field"); -- cgit v1.2.3 From d38023f2f38ccfc81a1c0394b0982514df352b3c Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Fri, 3 Apr 2020 15:08:54 -0300 Subject: fix (unreported): Weld Modifier: possible use of uninitialized variable --- source/blender/modifiers/intern/MOD_weld.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender/modifiers') diff --git a/source/blender/modifiers/intern/MOD_weld.c b/source/blender/modifiers/intern/MOD_weld.c index a7d3280b113..90b71b2d504 100644 --- a/source/blender/modifiers/intern/MOD_weld.c +++ b/source/blender/modifiers/intern/MOD_weld.c @@ -800,6 +800,8 @@ static bool weld_iter_loop_of_poly_begin(WeldLoopOfPolyIter *iter, iter->mloop = mloop; iter->loop_map = loop_map; iter->group = group_buffer; + + uint group_len = 0; if (group_buffer) { /* First loop group needs more attention. */ uint loop_start, loop_end, l; @@ -817,16 +819,14 @@ static bool weld_iter_loop_of_poly_begin(WeldLoopOfPolyIter *iter, break; } if (l != loop_end) { - iter->group_len = iter->loop_end - l; + group_len = loop_end - l; int i = 0; while (l < loop_end) { iter->group[i++] = ++l; } } } - else { - iter->group_len = 0; - } + iter->group_len = group_len; iter->l_next = iter->loop_start; #ifdef USE_WELD_DEBUG -- cgit v1.2.3