diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-12 01:01:38 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-12 01:07:44 +0300 |
commit | cfbd605567f48229a923df382baf6db98fbafc61 (patch) | |
tree | d4218c49672047d6c3b37517034660b3b5dcd966 /source/blender/editors/mesh | |
parent | 71a57a37b2eebbed53b5335019287b4df9c30519 (diff) | |
parent | 7212ebd09f9720883581221be923ae5e97ff5d76 (diff) |
Merge branch 'master' into blender2.8
Conflicts:
intern/cycles/blender/addon/ui.py
source/blender/blenkernel/BKE_particle.h
source/blender/blenkernel/intern/dynamicpaint.c
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/particle_distribute.c
source/blender/blenkernel/intern/texture.c
source/blender/editors/object/object_add.c
source/blender/editors/object/object_relations.c
source/blender/editors/physics/particle_edit.c
source/blender/editors/physics/particle_object.c
source/blender/editors/transform/transform_snap_object.c
Diffstat (limited to 'source/blender/editors/mesh')
-rw-r--r-- | source/blender/editors/mesh/editmesh_extrude.c | 3 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_rip.c | 3 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_select.c | 6 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_tools.c | 205 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_undo.c | 6 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_utils.c | 35 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_data.c | 6 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_ops.c | 1 | ||||
-rw-r--r-- | source/blender/editors/mesh/meshtools.c | 17 |
10 files changed, 242 insertions, 41 deletions
diff --git a/source/blender/editors/mesh/editmesh_extrude.c b/source/blender/editors/mesh/editmesh_extrude.c index 1dfb1cddd2c..d4c49833c2c 100644 --- a/source/blender/editors/mesh/editmesh_extrude.c +++ b/source/blender/editors/mesh/editmesh_extrude.c @@ -287,8 +287,7 @@ static int edbm_extrude_repeat_exec(bContext *C, wmOperator *op) short a; /* dvec */ - normalize_v3_v3(dvec, rv3d->persinv[2]); - mul_v3_fl(dvec, offs); + normalize_v3_v3_length(dvec, rv3d->persinv[2], offs); /* base correction */ copy_m3_m4(bmat, obedit->obmat); diff --git a/source/blender/editors/mesh/editmesh_rip.c b/source/blender/editors/mesh/editmesh_rip.c index 8868827a11f..e3e5863dc0e 100644 --- a/source/blender/editors/mesh/editmesh_rip.c +++ b/source/blender/editors/mesh/editmesh_rip.c @@ -153,8 +153,7 @@ static float edbm_rip_edge_side_measure( ED_view3d_project_float_v2_m4(ar, e->v2->co, e_v2_co, projectMat); sub_v2_v2v2(vec, cent, mid); - normalize_v2(vec); - mul_v2_fl(vec, 0.01f); + normalize_v2_length(vec, 0.01f); /* rather then adding to both verts, subtract from the mouse */ sub_v2_v2v2(fmval_tweak, fmval, vec); diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index 84ae35fae6e..5d5731a7e16 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -2453,7 +2453,7 @@ static void select_linked_delimit_begin(BMesh *bm, int delimit) const bool is_walk_ok = ( (select_linked_delimit_test(e, delimit, &delimit_data) == false)); - BMO_elem_flag_set(bm, e, BMO_ELE_TAG, is_walk_ok); + BMO_edge_flag_set(bm, e, BMO_ELE_TAG, is_walk_ok); } } } @@ -2496,7 +2496,7 @@ static int edbm_select_linked_exec(bContext *C, wmOperator *op) if (delimit) { BMEdge *e; BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { - if (!BMO_elem_flag_test(bm, e, BMO_ELE_TAG)) { + if (!BMO_edge_flag_test(bm, e, BMO_ELE_TAG)) { BM_elem_flag_disable(e->v1, BM_ELEM_TAG); BM_elem_flag_disable(e->v2, BM_ELEM_TAG); } @@ -2552,7 +2552,7 @@ static int edbm_select_linked_exec(bContext *C, wmOperator *op) BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { BM_elem_flag_set( e, BM_ELEM_TAG, - (BM_elem_flag_test(e, BM_ELEM_SELECT) && BMO_elem_flag_test(bm, e, BMO_ELE_TAG))); + (BM_elem_flag_test(e, BM_ELEM_SELECT) && BMO_edge_flag_test(bm, e, BMO_ELE_TAG))); } } else { diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index efe179790da..3a7a8fb883b 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -49,6 +49,7 @@ #include "BKE_material.h" #include "BKE_context.h" +#include "BKE_deform.h" #include "BKE_depsgraph.h" #include "BKE_report.h" #include "BKE_texture.h" @@ -79,6 +80,8 @@ #include "mesh_intern.h" /* own include */ +#include "bmesh_tools.h" + #define USE_FACE_CREATE_SEL_EXTEND static int edbm_subdivide_exec(bContext *C, wmOperator *op) @@ -2910,7 +2913,7 @@ static int edbm_knife_cut_exec(bContext *C, wmOperator *op) } } - BMO_elem_flag_set(bm, be, ELE_EDGE_CUT, is_cut); + BMO_edge_flag_set(bm, be, ELE_EDGE_CUT, is_cut); } @@ -2982,7 +2985,9 @@ static Base *mesh_separate_tagged(Main *bmain, Scene *scene, Base *base_old, BMe Object *obedit = base_old->object; BMesh *bm_new; - bm_new = BM_mesh_create(&bm_mesh_allocsize_default); + bm_new = BM_mesh_create( + &bm_mesh_allocsize_default, + &((struct BMeshCreateParams){.use_toolflags = true,})); BM_mesh_elem_toolflags_ensure(bm_new); /* needed for 'duplicate' bmo */ CustomData_copy(&bm_old->vdata, &bm_new->vdata, CD_MASK_BMESH, CD_CALLOC, 0); @@ -3290,11 +3295,13 @@ static int edbm_separate_exec(bContext *C, wmOperator *op) Object *ob = base_iter->object; if (ob->type == OB_MESH) { Mesh *me = ob->data; - if (me->id.lib == NULL) { + if (!ID_IS_LINKED_DATABLOCK(me)) { BMesh *bm_old = NULL; int retval_iter = 0; - bm_old = BM_mesh_create(&bm_mesh_allocsize_default); + bm_old = BM_mesh_create( + &bm_mesh_allocsize_default, + &((struct BMeshCreateParams){.use_toolflags = true,})); BM_mesh_bm_from_me(bm_old, me, (&(struct BMeshFromMeshParams){0})); @@ -3975,6 +3982,196 @@ void MESH_OT_tris_convert_to_quads(wmOperatorType *ot) join_triangle_props(ot); } + +/* -------------------------------------------------------------------- */ + +/** \name Decimate + * + * \note The function to decimate is intended for use as a modifier, + * while its handy allow access as a tool - this does cause access to be a little awkward + * (passing selection as weights for eg). + * + * \{ */ + +static int edbm_decimate_exec(bContext *C, wmOperator *op) +{ + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = BKE_editmesh_from_object(obedit); + BMesh *bm = em->bm; + + const float ratio = RNA_float_get(op->ptr, "ratio"); + bool use_vertex_group = RNA_boolean_get(op->ptr, "use_vertex_group"); + const float vertex_group_factor = RNA_float_get(op->ptr, "vertex_group_factor"); + const bool invert_vertex_group = RNA_boolean_get(op->ptr, "invert_vertex_group"); + const bool use_symmetry = RNA_boolean_get(op->ptr, "use_symmetry"); + const float symmetry_eps = 0.00002f; + const int symmetry_axis = use_symmetry ? RNA_enum_get(op->ptr, "symmetry_axis") : -1; + + /* nop */ + if (ratio == 1.0f) { + return OPERATOR_FINISHED; + } + + float *vweights = MEM_mallocN(sizeof(*vweights) * bm->totvert, __func__); + { + const int cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT); + const int defbase_act = obedit->actdef - 1; + + if (use_vertex_group && (cd_dvert_offset == -1)) { + BKE_report(op->reports, RPT_WARNING, "No active vertex group"); + use_vertex_group = false; + } + + BMIter iter; + BMVert *v; + int i; + BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) { + float weight = 0.0f; + if (BM_elem_flag_test(v, BM_ELEM_SELECT)) { + if (use_vertex_group) { + const MDeformVert *dv = BM_ELEM_CD_GET_VOID_P(v, cd_dvert_offset); + weight = defvert_find_weight(dv, defbase_act); + if (invert_vertex_group) { + weight = 1.0 - weight; + } + } + else { + weight = 1.0f; + } + } + + vweights[i] = weight; + BM_elem_index_set(v, i); /* set_inline */ + } + bm->elem_index_dirty &= ~BM_VERT; + } + + float ratio_adjust; + + if ((bm->totface == bm->totfacesel) || (ratio == 0.0f)) { + ratio_adjust = ratio; + } + else { + /** + * Calculate a new ratio based on faces that could be remoevd during decimation. + * needed so 0..1 has a meaningful range when operating on the selection. + * + * This doesn't have to be totally accurate, + * but needs to be greater than the number of selected faces + */ + + int totface_basis = 0; + int totface_adjacent = 0; + BMIter iter; + BMFace *f; + BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { + /* count faces during decimation, ngons are triangulated */ + const int f_len = f->len > 4 ? (f->len - 2) : 1; + totface_basis += f_len; + + BMLoop *l_iter, *l_first; + l_iter = l_first = BM_FACE_FIRST_LOOP(f); + do { + if (vweights[BM_elem_index_get(l_iter->v)] != 0.0f) { + totface_adjacent += f_len; + break; + } + } while ((l_iter = l_iter->next) != l_first); + } + + ratio_adjust = ratio; + ratio_adjust = 1.0f - ratio_adjust; + ratio_adjust *= (float)totface_adjacent / (float)totface_basis; + ratio_adjust = 1.0f - ratio_adjust; + } + + BM_mesh_decimate_collapse( + em->bm, ratio_adjust, vweights, vertex_group_factor, false, + symmetry_axis, symmetry_eps); + + MEM_freeN(vweights); + + { + short selectmode = em->selectmode; + if ((selectmode & (SCE_SELECT_VERTEX | SCE_SELECT_EDGE)) == 0) { + /* ensure we flush edges -> faces */ + selectmode |= SCE_SELECT_EDGE; + } + EDBM_selectmode_flush_ex(em, selectmode); + } + + EDBM_update_generic(em, true, true); + + return OPERATOR_FINISHED; +} + + +static bool edbm_decimate_check(bContext *UNUSED(C), wmOperator *UNUSED(op)) +{ + return true; +} + + +static void edbm_decimate_ui(bContext *UNUSED(C), wmOperator *op) +{ + uiLayout *layout = op->layout, *box, *row, *col; + PointerRNA ptr; + + RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); + + uiItemR(layout, &ptr, "ratio", 0, NULL, ICON_NONE); + + box = uiLayoutBox(layout); + uiItemR(box, &ptr, "use_vertex_group", 0, NULL, ICON_NONE); + col = uiLayoutColumn(box, false); + uiLayoutSetActive(col, RNA_boolean_get(&ptr, "use_vertex_group")); + uiItemR(col, &ptr, "vertex_group_factor", 0, NULL, ICON_NONE); + uiItemR(col, &ptr, "invert_vertex_group", 0, NULL, ICON_NONE); + + box = uiLayoutBox(layout); + uiItemR(box, &ptr, "use_symmetry", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, true); + uiLayoutSetActive(row, RNA_boolean_get(&ptr, "use_symmetry")); + uiItemR(row, &ptr, "symmetry_axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE); +} + + +void MESH_OT_decimate(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Decimate Geometry"; + ot->idname = "MESH_OT_decimate"; + ot->description = "Simplify geometry by collapsing edges"; + + /* api callbacks */ + ot->exec = edbm_decimate_exec; + ot->check = edbm_decimate_check; + ot->ui = edbm_decimate_ui; + ot->poll = ED_operator_editmesh; + + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* Note, keep in sync with 'rna_def_modifier_decimate' */ + RNA_def_float(ot->srna, "ratio", 1.0f, 0.0f, 1.0f, "Ratio", "", 0.0f, 1.0f); + + RNA_def_boolean(ot->srna, "use_vertex_group", false, "Vertex Group", + "Use active vertex group as an influence"); + RNA_def_float(ot->srna, "vertex_group_factor", 1.0f, 0.0f, 1000.0f, "Weight", + "Vertex group strength", 0.0f, 10.0f); + RNA_def_boolean(ot->srna, "invert_vertex_group", false, "Invert", + "Invert vertex group influence"); + + RNA_def_boolean(ot->srna, "use_symmetry", false, "Symmetry", + "Maintain symmetry on an axis"); + + RNA_def_enum(ot->srna, "symmetry_axis", rna_enum_axis_xyz_items, 1, "Axis", "Axis of symmetry"); +} + +/** \} */ + + /* -------------------------------------------------------------------- */ /* Dissolve */ diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c index 62656d75b9a..c9814d189a4 100644 --- a/source/blender/editors/mesh/editmesh_undo.c +++ b/source/blender/editors/mesh/editmesh_undo.c @@ -114,7 +114,7 @@ static struct { TaskPool *task_pool; #endif -} um_arraystore = {NULL}; +} um_arraystore = {{NULL}}; static void um_arraystore_cd_compact( struct CustomData *cdata, const size_t data_len, @@ -563,7 +563,9 @@ static void undoMesh_to_editbtMesh(void *um_v, void *em_v, void *obdata) EDBM_mesh_free(em); - bm = BM_mesh_create(&allocsize); + bm = BM_mesh_create( + &allocsize, + &((struct BMeshCreateParams){.use_toolflags = true,})); BM_mesh_bm_from_me( bm, &um->me, (&(struct BMeshFromMeshParams){ diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index 99be37845ee..4fc61e0912e 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -354,7 +354,9 @@ void EDBM_mesh_make(ToolSettings *ts, Object *ob, const bool add_key_index) BKE_mesh_convert_mfaces_to_mpolys(me); } - bm = BKE_mesh_to_bmesh(me, ob, add_key_index); + bm = BKE_mesh_to_bmesh( + me, ob, add_key_index, + &((struct BMeshCreateParams){.use_toolflags = true,})); if (me->edit_btmesh) { /* this happens when switching shape keys */ @@ -399,10 +401,25 @@ void EDBM_mesh_load(Object *ob) BKE_mesh_tessface_calc(me); #endif - /* free derived mesh. usually this would happen through depsgraph but there + /* Free derived mesh. usually this would happen through depsgraph but there * are exceptions like file save that will not cause this, and we want to - * avoid ending up with an invalid derived mesh then */ - BKE_object_free_derived_caches(ob); + * avoid ending up with an invalid derived mesh then. + * + * Do it for all objects which shares the same mesh datablock, since their + * derived meshes might also be referencing data which was just freed, + * + * Annoying enough, but currently seems most efficient way to avoid access + * of freed data on scene update, especially in cases when there are dependency + * cycles. + */ + for (Object *other_object = G.main->object.first; + other_object != NULL; + other_object = other_object->id.next) + { + if (other_object->data == ob->data) { + BKE_object_free_derived_caches(other_object); + } + } } /** @@ -1423,13 +1440,9 @@ bool BMBVH_EdgeVisible(struct BMBVHTree *tree, BMEdge *e, ARegion *ar, View3D *v sub_v3_v3v3(dir2, origin, co2); sub_v3_v3v3(dir3, origin, co3); - normalize_v3(dir1); - normalize_v3(dir2); - normalize_v3(dir3); - - mul_v3_fl(dir1, epsilon); - mul_v3_fl(dir2, epsilon); - mul_v3_fl(dir3, epsilon); + normalize_v3_length(dir1, epsilon); + normalize_v3_length(dir2, epsilon); + normalize_v3_length(dir3, epsilon); /* offset coordinates slightly along view vectors, to avoid * hitting the faces that own the edge.*/ diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index e0ddc017e93..772bb1bd308 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -511,7 +511,7 @@ static int layers_poll(bContext *C) { Object *ob = ED_object_context(C); ID *data = (ob) ? ob->data : NULL; - return (ob && !ob->id.lib && ob->type == OB_MESH && data && !data->lib); + return (ob && !ID_IS_LINKED_DATABLOCK(ob) && ob->type == OB_MESH && data && !ID_IS_LINKED_DATABLOCK(data)); } static int mesh_uv_texture_add_exec(bContext *C, wmOperator *UNUSED(op)) @@ -759,7 +759,7 @@ static int mesh_customdata_mask_clear_poll(bContext *C) return false; } - if (me->id.lib == NULL) { + if (!ID_IS_LINKED_DATABLOCK(me)) { CustomData *data = GET_CD_DATA(me, vdata); if (CustomData_has_layer(data, CD_PAINT_MASK)) { return true; @@ -813,7 +813,7 @@ static int mesh_customdata_skin_state(bContext *C) if (ob && ob->type == OB_MESH) { Mesh *me = ob->data; - if (me->id.lib == NULL) { + if (!ID_IS_LINKED_DATABLOCK(me)) { CustomData *data = GET_CD_DATA(me, vdata); return CustomData_has_layer(data, CD_MVERT_SKIN); } diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index 08b4d1aee45..300b21a052d 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -216,6 +216,7 @@ void MESH_OT_fill_holes(struct wmOperatorType *ot); void MESH_OT_beautify_fill(struct wmOperatorType *ot); void MESH_OT_quads_convert_to_tris(struct wmOperatorType *ot); void MESH_OT_tris_convert_to_quads(struct wmOperatorType *ot); +void MESH_OT_decimate(struct wmOperatorType *ot); void MESH_OT_dissolve_verts(struct wmOperatorType *ot); void MESH_OT_dissolve_edges(struct wmOperatorType *ot); void MESH_OT_dissolve_faces(struct wmOperatorType *ot); diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c index 2853ae3a84c..697a92f36d1 100644 --- a/source/blender/editors/mesh/mesh_ops.c +++ b/source/blender/editors/mesh/mesh_ops.c @@ -106,6 +106,7 @@ void ED_operatortypes_mesh(void) WM_operatortype_append(MESH_OT_beautify_fill); WM_operatortype_append(MESH_OT_quads_convert_to_tris); WM_operatortype_append(MESH_OT_tris_convert_to_quads); + WM_operatortype_append(MESH_OT_decimate); WM_operatortype_append(MESH_OT_dissolve_verts); WM_operatortype_append(MESH_OT_dissolve_edges); WM_operatortype_append(MESH_OT_dissolve_faces); diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 1b2d4b7c130..b26989113d4 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -172,7 +172,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) */ if (key) { /* make a duplicate copy that will only be used here... (must remember to free it!) */ - nkey = BKE_key_copy(key); + nkey = BKE_key_copy(bmain, key); /* for all keys in old block, clear data-arrays */ for (kb = key->block.first; kb; kb = kb->next) { @@ -540,7 +540,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) if (matmap) MEM_freeN(matmap); /* other mesh users */ - test_object_materials(bmain, (ID *)me); + test_all_objects_materials(bmain, (ID *)me); /* free temp copy of destination shapekeys (if applicable) */ if (nkey) { @@ -564,21 +564,10 @@ int join_mesh_exec(bContext *C, wmOperator *op) BKE_key_sort(key); } - DAG_relations_tag_update(bmain); // removed objects, need to rebuild dag -#if 0 - ED_object_editmode_enter(C, EM_WAITCURSOR); - ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO); -#else - /* toggle editmode using lower level functions so this can be called from python */ - EDBM_mesh_make(scene->toolsettings, ob, false); - EDBM_mesh_load(ob); - EDBM_mesh_free(me->edit_btmesh); - MEM_freeN(me->edit_btmesh); - me->edit_btmesh = NULL; DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA); -#endif + WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); return OPERATOR_FINISHED; |