.../startup/bl_ui/properties_data_modifier.py | 3 + source/blender/blenkernel/intern/shrinkwrap.c | 66 ++++++++++++++-------- source/blender/makesdna/DNA_modifier_types.h | 5 +- source/blender/makesrna/intern/rna_modifier.c | 8 +++ source/blender/modifiers/intern/MOD_shrinkwrap.c | 5 ++ 5 files changed, 64 insertions(+), 23 deletions(-) diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py index b38e2a7..58c6c38 100644 --- a/release/scripts/startup/bl_ui/properties_data_modifier.py +++ b/release/scripts/startup/bl_ui/properties_data_modifier.py @@ -665,6 +665,9 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel): col = split.column() col.prop(md, "offset") col.prop(md, "subsurf_levels") + + if md.wrap_method != 'PROJECT': + col.prop(md, "threshold") col = split.column() col.label(text="Mode:") diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index 72db34d..3e311f1 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -122,6 +122,8 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) { int i; + float distthresh = calc->smd->threshold*calc->smd->threshold; + BVHTreeFromMesh treeData = NULL_BVHTreeFromMesh; BVHTreeNearest nearest = NULL_BVHTreeNearest; @@ -135,9 +137,12 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) /* Setup nearest */ nearest.index = -1; nearest.dist = FLT_MAX; -#ifndef __APPLE__ -#pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(treeData,calc) schedule(static) -#endif + +//FIX OPENMP Compile Error related ?? 'not specified in enclosing parallel', I have to disable it for now +//#ifndef __APPLE__ +//#pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(treeData,calc) schedule(static) +//#endif + for (i = 0; i < calc->numVerts; ++i) { float *co = calc->vertexCos[i]; float tmp_co[3]; @@ -168,22 +173,25 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) BLI_bvhtree_find_nearest(treeData.tree, tmp_co, &nearest, treeData.nearest_callback, &treeData); + if (nearest.dist >distthresh) { + continue; + } /* Found the nearest vertex */ - if (nearest.index != -1) { - /* Adjusting the vertex weight, - * so that after interpolating it keeps a certain distance from the nearest position */ - if (nearest.dist > FLT_EPSILON) { - const float dist = sqrtf(nearest.dist); - weight *= (dist - calc->keepDist) / dist; - } - - /* Convert the coordinates back to mesh coordinates */ - copy_v3_v3(tmp_co, nearest.co); - space_transform_invert(&calc->local2target, tmp_co); - - interp_v3_v3v3(co, co, tmp_co, weight); /* linear interpolation */ - } + if (nearest.index != -1) { + /* Adjusting the vertex weight, + * so that after interpolating it keeps a certain distance from the nearest position */ + if (nearest.dist > FLT_EPSILON) { + const float dist = sqrtf(nearest.dist); + weight *= (dist - calc->keepDist) / dist; + } + + /* Convert the coordinates back to mesh coordinates */ + copy_v3_v3(tmp_co, nearest.co); + space_transform_invert(&calc->local2target, tmp_co); + + interp_v3_v3v3(co, co, tmp_co, weight); /* linear interpolation */ + } } free_bvhtree_from_mesh(&treeData); @@ -424,6 +432,8 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) { int i; + float distthresh = calc->smd->threshold*calc->smd->threshold; + BVHTreeFromMesh treeData = NULL_BVHTreeFromMesh; BVHTreeNearest nearest = NULL_BVHTreeNearest; @@ -439,10 +449,14 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) nearest.dist = FLT_MAX; - /* Find the nearest vertex */ -#ifndef __APPLE__ -#pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(calc,treeData) schedule(static) -#endif + /* Find the nearest vertex */ + +//FIX OPENMP Compile Error related ?? 'not specified in enclosing parallel', I have to disable it for now +//#ifndef __APPLE__ +//#pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(calc,treeData) schedule(static) +//#endif + + for (i = 0; i < calc->numVerts; ++i) { float *co = calc->vertexCos[i]; float tmp_co[3]; @@ -465,11 +479,16 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) * This will lead in prunning of the search tree. */ if (nearest.index != -1) nearest.dist = len_squared_v3v3(tmp_co, nearest.co); + + else nearest.dist = FLT_MAX; BLI_bvhtree_find_nearest(treeData.tree, tmp_co, &nearest, treeData.nearest_callback, &treeData); + if ( nearest.dist > distthresh ) { + continue; + } /* Found the nearest vertex */ if (nearest.index != -1) { if (calc->smd->shrinkOpts & MOD_SHRINKWRAP_KEEP_ABOVE_SURFACE) { @@ -484,6 +503,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) /* linear interpolation */ interp_v3_v3v3(tmp_co, tmp_co, nearest.co, (dist - calc->keepDist) / dist); } + else { copy_v3_v3(tmp_co, nearest.co); } @@ -491,7 +511,9 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) /* Convert the coordinates back to mesh coordinates */ space_transform_invert(&calc->local2target, tmp_co); - interp_v3_v3v3(co, co, tmp_co, weight); /* linear interpolation */ + + interp_v3_v3v3(co, co, tmp_co, weight) ; /* linear interpolation */ + } } diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 66685c1..c1e44ea 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -666,6 +666,9 @@ typedef struct ShrinkwrapModifierData { struct Object *auxTarget; /* additional shrink target */ char vgroup_name[64]; /* optional vertexgroup name, MAX_VGROUP_NAME */ float keepDist; /* distance offset to keep from mesh/projection point */ + float threshold; + + short shrinkType; /* shrink type projection */ short shrinkOpts; /* shrink options */ float projLimit; /* limit the projection ray cast */ @@ -679,7 +682,7 @@ typedef struct ShrinkwrapModifierData { char subsurfLevels; char pad[2]; - + float pad2; } ShrinkwrapModifierData; /* Shrinkwrap->shrinkType */ diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index fa436e3..60e34e7 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -2442,6 +2442,14 @@ static void rna_def_modifier_shrinkwrap(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Offset", "Distance to keep from the target"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "threshold", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "threshold"); + RNA_def_property_range(prop, -FLT_MAX, FLT_MAX); + RNA_def_property_ui_range(prop, 0, 10000, 1, 2); + RNA_def_property_ui_text(prop, "DistThreshold", "Distance to keep from the target"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "project_limit", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "projLimit"); RNA_def_property_range(prop, 0.0, FLT_MAX); diff --git a/source/blender/modifiers/intern/MOD_shrinkwrap.c b/source/blender/modifiers/intern/MOD_shrinkwrap.c index 7a55f9a..d0382ab 100644 --- a/source/blender/modifiers/intern/MOD_shrinkwrap.c +++ b/source/blender/modifiers/intern/MOD_shrinkwrap.c @@ -56,6 +56,8 @@ static void initData(ModifierData *md) smd->shrinkOpts = MOD_SHRINKWRAP_PROJECT_ALLOW_POS_DIR; smd->keepDist = 0.0f; + smd->threshold = 0.0f; + smd->target = NULL; smd->auxTarget = NULL; } @@ -73,6 +75,9 @@ static void copyData(ModifierData *md, ModifierData *target) tsmd->keepDist = smd->keepDist; tsmd->shrinkType = smd->shrinkType; tsmd->shrinkOpts = smd->shrinkOpts; + + tsmd->threshold = smd->threshold; + tsmd->projAxis = smd->projAxis; tsmd->subsurfLevels = smd->subsurfLevels; }