diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_opdefines.c | 1 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operators.h | 18 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_subdivide.c | 45 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_loopcut.c | 10 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_tools.c | 3 |
5 files changed, 61 insertions, 16 deletions
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index c872fb92a2a..587696268b1 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -969,6 +969,7 @@ static BMOpDefine bmo_subdivide_edges_def = { /* slots_in */ {{"edges", BMO_OP_SLOT_ELEMENT_BUF, {BM_EDGE}}, {"smooth", BMO_OP_SLOT_FLT}, + {"smooth_falloff", BMO_OP_SLOT_INT}, /* SUBD_FALLOFF_ROOT and friends */ {"fractal", BMO_OP_SLOT_FLT}, {"along_normal", BMO_OP_SLOT_FLT}, {"cuts", BMO_OP_SLOT_INT}, diff --git a/source/blender/bmesh/intern/bmesh_operators.h b/source/blender/bmesh/intern/bmesh_operators.h index ff0fc285dc3..e169bf740de 100644 --- a/source/blender/bmesh/intern/bmesh_operators.h +++ b/source/blender/bmesh/intern/bmesh_operators.h @@ -39,6 +39,15 @@ enum { SUBD_STRAIGHT_CUT }; +/* aligned with PROP_SMOOTH and friends */ +enum { + SUBD_FALLOFF_SMOOTH = 0, + SUBD_FALLOFF_SPHERE, + SUBD_FALLOFF_ROOT, + SUBD_FALLOFF_SHARP, + SUBD_FALLOFF_LIN, +}; + enum { SUBDIV_SELECT_ORIG, SUBDIV_SELECT_INNER, @@ -107,12 +116,13 @@ extern const int bmo_opdefines_total; /*------specific operator helper functions-------*/ void BM_mesh_esubdivide(BMesh *bm, const char edge_hflag, - float smooth, float fractal, float along_normal, - int numcuts, - int seltype, int cornertype, + const float smooth, const short smooth_falloff, + const float fractal, const float along_normal, + const int numcuts, + const int seltype, const int cornertype, const short use_single_edge, const short use_grid_fill, const short use_only_quads, - int seed); + const int seed); #include "intern/bmesh_operator_api_inline.h" diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index 157dbef6057..2a75c77f33b 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -44,6 +44,7 @@ typedef struct SubDParams { int numcuts; float smooth; + int smooth_falloff; float fractal; float along_normal; //int beauty; @@ -159,7 +160,7 @@ static void alter_co(BMesh *bm, BMVert *v, BMEdge *UNUSED(origed), const SubDPar } else if (params->use_smooth) { /* we calculate an offset vector vec1[], to be added to *co */ - float len, nor[3], nor1[3], nor2[3], smooth = params->smooth; + float len, nor[3], nor1[3], nor2[3], val; sub_v3_v3v3(nor, vsta->co, vend->co); len = 0.5f * normalize_v3(nor); @@ -176,9 +177,28 @@ static void alter_co(BMesh *bm, BMVert *v, BMEdge *UNUSED(origed), const SubDPar madd_v3_v3fl(tvec, nor2, fac); /* falloff for multi subdivide */ - smooth *= sqrtf(fabsf(1.0f - 2.0f * fabsf(0.5f - perc))); + val = fabsf(1.0f - 2.0f * fabsf(0.5f - perc)); - mul_v3_fl(tvec, smooth * len); + switch (params->smooth_falloff) { + case SUBD_FALLOFF_SMOOTH: + val = 3.0f * val * val - 2.0f * val * val * val; + break; + case SUBD_FALLOFF_SPHERE: + val = sqrtf(2.0f * val - val * val); + break; + case SUBD_FALLOFF_ROOT: + val = sqrtf(val); + break; + case SUBD_FALLOFF_SHARP: + val = val * val; + break; + case SUBD_FALLOFF_LIN: + break; + default: + BLI_assert(0); + } + + mul_v3_fl(tvec, params->smooth * val * len); add_v3_v3(co, tvec); } @@ -757,13 +777,14 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) BLI_array_declare(verts); float smooth, fractal, along_normal; bool use_sphere, use_single_edge, use_grid_fill, use_only_quads; - int cornertype, skey, seed, i, j, matched, a, b, numcuts, totesel; + int cornertype, skey, seed, i, j, matched, a, b, numcuts, totesel, smooth_falloff; BMO_slot_buffer_flag_enable(bm, op->slots_in, "edges", BM_EDGE, SUBD_SPLIT); numcuts = BMO_slot_int_get(op->slots_in, "cuts"); seed = BMO_slot_int_get(op->slots_in, "seed"); smooth = BMO_slot_float_get(op->slots_in, "smooth"); + smooth_falloff = BMO_slot_int_get(op->slots_in, "smooth_falloff"); fractal = BMO_slot_float_get(op->slots_in, "fractal"); along_normal = BMO_slot_float_get(op->slots_in, "along_normal"); cornertype = BMO_slot_int_get(op->slots_in, "quad_corner_type"); @@ -822,6 +843,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) params.slot_edge_percents = BMO_slot_get(op->slots_in, "edge_percents"); params.slot_custom_patterns = BMO_slot_get(op->slots_in, "custom_patterns"); params.smooth = smooth; + params.smooth_falloff = smooth_falloff; params.seed = seed; params.fractal = fractal; params.along_normal = along_normal; @@ -1142,26 +1164,29 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) /* editmesh-emulating function */ void BM_mesh_esubdivide(BMesh *bm, const char edge_hflag, - float smooth, float fractal, float along_normal, - int numcuts, - int seltype, int cornertype, + const float smooth, const short smooth_falloff, + const float fractal, const float along_normal, + const int numcuts, + const int seltype, const int cornertype, const short use_single_edge, const short use_grid_fill, const short use_only_quads, - int seed) + const int seed) { BMOperator op; /* use_sphere isnt exposed here since its only used for new primitives */ BMO_op_initf(bm, &op, BMO_FLAG_DEFAULTS, "subdivide_edges edges=%he " - "smooth=%f fractal=%f along_normal=%f " + "smooth=%f smooth_falloff=%i " + "fractal=%f along_normal=%f " "cuts=%i " "quad_corner_type=%i " "use_single_edge=%b use_grid_fill=%b " "use_only_quads=%b " "seed=%i", edge_hflag, - smooth, fractal, along_normal, + smooth, smooth_falloff, + fractal, along_normal, numcuts, cornertype, use_single_edge, use_grid_fill, diff --git a/source/blender/editors/mesh/editmesh_loopcut.c b/source/blender/editors/mesh/editmesh_loopcut.c index 68a5809bc2e..bfd94a2ecf4 100644 --- a/source/blender/editors/mesh/editmesh_loopcut.c +++ b/source/blender/editors/mesh/editmesh_loopcut.c @@ -53,6 +53,7 @@ #include "RNA_access.h" #include "RNA_define.h" +#include "RNA_enum_types.h" #include "WM_api.h" #include "WM_types.h" @@ -276,6 +277,7 @@ static void ringsel_finish(bContext *C, wmOperator *op) RingSelOpData *lcd = op->customdata; const int cuts = RNA_int_get(op->ptr, "number_cuts"); const float smoothness = 0.292f * RNA_float_get(op->ptr, "smoothness"); + const int smooth_falloff = RNA_enum_get(op->ptr, "falloff"); #ifdef BMW_EDGERING_NGON const bool use_only_quads = false; #else @@ -293,7 +295,7 @@ static void ringsel_finish(bContext *C, wmOperator *op) * Note though that it will break edgeslide in this specific case. * See [#31939]. */ BM_mesh_esubdivide(em->bm, BM_ELEM_SELECT, - smoothness, 0.0f, 0.0f, + smoothness, smooth_falloff, 0.0f, 0.0f, cuts, SUBDIV_SELECT_LOOPCUT, SUBD_PATH, 0, true, use_only_quads, 0); @@ -650,6 +652,12 @@ void MESH_OT_loopcut(wmOperatorType *ot) "Smoothness", "Smoothness factor", -SUBD_SMOOTH_MAX, SUBD_SMOOTH_MAX); RNA_def_property_flag(prop, PROP_SKIP_SAVE); + prop = RNA_def_property(ot->srna, "falloff", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, proportional_falloff_curve_only_items); + RNA_def_property_enum_default(prop, PROP_ROOT); + RNA_def_property_ui_text(prop, "Falloff", "Falloff type the feather"); + RNA_def_property_translation_context(prop, BLF_I18NCONTEXT_ID_CURVE); /* Abusing id_curve :/ */ + prop = RNA_def_int(ot->srna, "edge_index", -1, -1, INT_MAX, "Number of Cuts", "", 0, INT_MAX); RNA_def_property_flag(prop, PROP_HIDDEN); } diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 4a63212793c..a80a940b117 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -90,7 +90,8 @@ static int edbm_subdivide_exec(bContext *C, wmOperator *op) } BM_mesh_esubdivide(em->bm, BM_ELEM_SELECT, - smooth, fractal, along_normal, + smooth, SUBD_FALLOFF_ROOT, + fractal, along_normal, cuts, SUBDIV_SELECT_ORIG, RNA_enum_get(op->ptr, "quadcorner"), RNA_boolean_get(op->ptr, "quadtri"), true, false, |