From def1c3eb4b5c2926431a1c975839e7719f06b38e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 15 May 2018 13:26:40 +0200 Subject: =?UTF-8?q?Particle=20System:=20ported=20most=20DerivedMesh=20?= =?UTF-8?q?=E2=86=92=20Mesh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are a few places where DerivedMesh is still used, most notably when calling the (not yet ported) cloth simulation. There is also still the use of Object.derivedDeform and Object.derivedFinal. Those places are marked with a TODO. Some functions in the editors module were copied to accept Mesh. Those already had 'mesh' in the name; the copies are suffixed with '__real_mesh' for easy renaming later when the DM-based functionality is removed. --- source/blender/editors/mesh/meshtools.c | 118 +++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) (limited to 'source/blender/editors/mesh/meshtools.c') diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 83458127820..9b86f904161 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -707,6 +707,30 @@ int ED_mesh_mirror_topo_table( return 0; } +/* mode is 's' start, or 'e' end, or 'u' use */ +/* if end, ob can be NULL */ +/* note, is supposed return -1 on error, which callers are currently checking for, but is not used so far */ +int ED_mesh_mirror_topo_table__real_mesh( + Object *ob, Mesh *mesh, char mode) +{ + if (mode == 'u') { /* use table */ + if (ED_mesh_mirrtopo_recalc_check__real_mesh(ob->data, mesh, &mesh_topo_store)) { + ED_mesh_mirror_topo_table__real_mesh(ob, mesh, 's'); + } + } + else if (mode == 's') { /* start table */ + ED_mesh_mirrtopo_init__real_mesh(ob->data, mesh, &mesh_topo_store, false); + } + else if (mode == 'e') { /* end table */ + ED_mesh_mirrtopo_free(&mesh_topo_store); + } + else { + BLI_assert(0); + } + + return 0; +} + /** \} */ @@ -742,6 +766,38 @@ int mesh_get_x_mirror_vert(Object *ob, DerivedMesh *dm, int index, const bool us } } +static int mesh_get_x_mirror_vert_spatial__real_mesh(Object *ob, Mesh *mesh, int index) +{ + Mesh *me = ob->data; + MVert *mvert = mesh ? mesh->mvert : me->mvert; + float vec[3]; + + mvert = &mvert[index]; + vec[0] = -mvert->co[0]; + vec[1] = mvert->co[1]; + vec[2] = mvert->co[2]; + + return ED_mesh_mirror_spatial_table__real_mesh(ob, NULL, mesh, vec, 'u'); +} + +static int mesh_get_x_mirror_vert_topo__real_mesh(Object *ob, Mesh *mesh, int index) +{ + if (ED_mesh_mirror_topo_table__real_mesh(ob, mesh, 'u') == -1) + return -1; + + return mesh_topo_store.index_lookup[index]; +} + +int mesh_get_x_mirror_vert__real_mesh(Object *ob, Mesh *mesh, int index, const bool use_topology) +{ + if (use_topology) { + return mesh_get_x_mirror_vert_topo__real_mesh(ob, mesh, index); + } + else { + return mesh_get_x_mirror_vert_spatial__real_mesh(ob, mesh, index); + } +} + static BMVert *editbmesh_get_x_mirror_vert_spatial(Object *ob, BMEditMesh *em, const float co[3]) { float vec[3]; @@ -991,7 +1047,67 @@ int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em, DerivedMesh *dm) BLI_ghash_free(fhash, NULL, NULL); MEM_freeN(mirrorverts); - + + return mirrorfaces; +} + +/* This is a Mesh-based copy of mesh_get_x_mirror_faces() */ +int *mesh_get_x_mirror_faces__real_mesh(Object *ob, BMEditMesh *em, Mesh *mesh) +{ + Mesh *me = ob->data; + MVert *mv, *mvert; + MFace mirrormf, *mf, *hashmf, *mface; + GHash *fhash; + int *mirrorverts, *mirrorfaces; + + BLI_assert(em == NULL); /* Does not work otherwise, currently... */ + + const bool use_topology = (me->editflag & ME_EDIT_MIRROR_TOPO) != 0; + const int totvert = mesh ? mesh->totvert : me->totvert; + const int totface = mesh ? mesh->totface : me->totface; + int a; + + mirrorverts = MEM_callocN(sizeof(int) * totvert, "MirrorVerts"); + mirrorfaces = MEM_callocN(sizeof(int) * 2 * totface, "MirrorFaces"); + + mvert = mesh ? mesh->mvert : me->mvert; + mface = mesh ? mesh->mface : me->mface; + + ED_mesh_mirror_spatial_table__real_mesh(ob, em, mesh, NULL, 's'); + + for (a = 0, mv = mvert; a < totvert; a++, mv++) + mirrorverts[a] = mesh_get_x_mirror_vert__real_mesh(ob, mesh, a, use_topology); + + ED_mesh_mirror_spatial_table__real_mesh(ob, em, mesh, NULL, 'e'); + + fhash = BLI_ghash_new_ex(mirror_facehash, mirror_facecmp, "mirror_facehash gh", me->totface); + for (a = 0, mf = mface; a < totface; a++, mf++) + BLI_ghash_insert(fhash, mf, mf); + + for (a = 0, mf = mface; a < totface; a++, mf++) { + mirrormf.v1 = mirrorverts[mf->v3]; + mirrormf.v2 = mirrorverts[mf->v2]; + mirrormf.v3 = mirrorverts[mf->v1]; + mirrormf.v4 = (mf->v4) ? mirrorverts[mf->v4] : 0; + + /* make sure v4 is not 0 if a quad */ + if (mf->v4 && mirrormf.v4 == 0) { + SWAP(unsigned int, mirrormf.v1, mirrormf.v3); + SWAP(unsigned int, mirrormf.v2, mirrormf.v4); + } + + hashmf = BLI_ghash_lookup(fhash, &mirrormf); + if (hashmf) { + mirrorfaces[a * 2] = hashmf - mface; + mirrorfaces[a * 2 + 1] = mirror_facerotation(&mirrormf, hashmf); + } + else + mirrorfaces[a * 2] = -1; + } + + BLI_ghash_free(fhash, NULL, NULL); + MEM_freeN(mirrorverts); + return mirrorfaces; } -- cgit v1.2.3 From ddf2a5828215cdd77a93fcbf2041f600349f8e55 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 1 Jun 2018 14:29:22 +0200 Subject: Mesh: Replace DM for mesh w/ wpaint vertex picking --- source/blender/editors/mesh/meshtools.c | 46 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'source/blender/editors/mesh/meshtools.c') diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 9b86f904161..802922ab799 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -1154,21 +1154,22 @@ bool ED_mesh_pick_face(bContext *C, Object *ob, const int mval[2], unsigned int static void ed_mesh_pick_face_vert__mpoly_find( /* context */ struct ARegion *ar, const float mval[2], - /* mesh data */ - DerivedMesh *dm, MPoly *mp, MLoop *mloop, + /* mesh data (evaluated) */ + const MPoly *mp, + const MVert *mvert, const MLoop *mloop, /* return values */ float *r_len_best, int *r_v_idx_best) { const MLoop *ml; int j = mp->totloop; for (ml = &mloop[mp->loopstart]; j--; ml++) { - float co[3], sco[2], len; + float sco[2]; const int v_idx = ml->v; - dm->getVertCo(dm, v_idx, co); + const float *co = mvert[v_idx].co; if (ED_view3d_project_float_object(ar, co, sco, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { - len = len_manhattan_v2v2(mval, sco); - if (len < *r_len_best) { - *r_len_best = len; + const float len_test = len_manhattan_v2v2(mval, sco); + if (len_test < *r_len_best) { + *r_len_best = len_test; *r_v_idx_best = v_idx; } } @@ -1191,7 +1192,7 @@ bool ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], unsigned struct ARegion *ar = CTX_wm_region(C); /* derived mesh to find deformed locations */ - DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); + Mesh *me_eval = mesh_get_eval_final(depsgraph, scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); int v_idx_best = ORIGINDEX_NONE; @@ -1199,36 +1200,38 @@ bool ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], unsigned const float mval_f[2] = {UNPACK2(mval)}; float len_best = FLT_MAX; - MPoly *dm_mpoly; - MLoop *dm_mloop; - unsigned int dm_mpoly_tot; + MPoly *me_eval_mpoly; + MLoop *me_eval_mloop; + MVert *me_eval_mvert; + unsigned int me_eval_mpoly_len; const int *index_mp_to_orig; - dm_mpoly = dm->getPolyArray(dm); - dm_mloop = dm->getLoopArray(dm); + me_eval_mpoly = me_eval->mpoly; + me_eval_mloop = me_eval->mloop; + me_eval_mvert = me_eval->mvert; - dm_mpoly_tot = dm->getNumPolys(dm); + me_eval_mpoly_len = me_eval->totpoly; - index_mp_to_orig = dm->getPolyDataArray(dm, CD_ORIGINDEX); + index_mp_to_orig = CustomData_get_layer(&me_eval->pdata, CD_ORIGINDEX); /* tag all verts using this face */ if (index_mp_to_orig) { unsigned int i; - for (i = 0; i < dm_mpoly_tot; i++) { + for (i = 0; i < me_eval_mpoly_len; i++) { if (index_mp_to_orig[i] == poly_index) { ed_mesh_pick_face_vert__mpoly_find( ar, mval_f, - dm, &dm_mpoly[i], dm_mloop, + &me_eval_mpoly[i], me_eval_mvert, me_eval_mloop, &len_best, &v_idx_best); } } } else { - if (poly_index < dm_mpoly_tot) { + if (poly_index < me_eval_mpoly_len) { ed_mesh_pick_face_vert__mpoly_find( ar, mval_f, - dm, &dm_mpoly[poly_index], dm_mloop, + &me_eval_mpoly[poly_index], me_eval_mvert, me_eval_mloop, &len_best, &v_idx_best); } } @@ -1236,15 +1239,12 @@ bool ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], unsigned /* map 'dm -> me' index if possible */ if (v_idx_best != ORIGINDEX_NONE) { const int *index_mv_to_orig; - - index_mv_to_orig = dm->getVertDataArray(dm, CD_ORIGINDEX); + index_mv_to_orig = CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX); if (index_mv_to_orig) { v_idx_best = index_mv_to_orig[v_idx_best]; } } - dm->release(dm); - if ((v_idx_best != ORIGINDEX_NONE) && (v_idx_best < me->totvert)) { *index = v_idx_best; return true; -- cgit v1.2.3 From 44505b38df557a5711703613685a1dec9fc2c3d9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 4 Jun 2018 09:31:30 +0200 Subject: Cleanup: strip trailing space in editors --- source/blender/editors/mesh/meshtools.c | 104 ++++++++++++++++---------------- 1 file changed, 52 insertions(+), 52 deletions(-) (limited to 'source/blender/editors/mesh/meshtools.c') diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index d3d29b61182..6953473a792 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -282,13 +282,13 @@ int join_mesh_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_WARNING, "Cannot join while in edit mode"); return OPERATOR_CANCELLED; } - + /* ob is the object we are adding geometry to */ if (!ob || ob->type != OB_MESH) { BKE_report(op->reports, RPT_WARNING, "Active object is not a mesh"); return OPERATOR_CANCELLED; } - + /* count & check */ CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) { @@ -300,23 +300,23 @@ int join_mesh_exec(bContext *C, wmOperator *op) totloop += me->totloop; totpoly += me->totpoly; totmat += base->object->totcol; - + if (base->object == ob) ok = true; - + /* check for shapekeys */ if (me->key) haskey++; } } CTX_DATA_END; - - /* that way the active object is always selected */ + + /* that way the active object is always selected */ if (ok == false) { BKE_report(op->reports, RPT_WARNING, "Active object is not a selected mesh"); return OPERATOR_CANCELLED; } - + /* only join meshes if there are verts to join, there aren't too many, and we only had one mesh selected */ me = (Mesh *)ob->data; key = me->key; @@ -325,7 +325,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_WARNING, "No mesh data to join"); return OPERATOR_CANCELLED; } - + if (totvert > MESH_MAX_VERTS) { BKE_reportf(op->reports, RPT_WARNING, "Joining results in %d vertices, limit is %ld", totvert, MESH_MAX_VERTS); return OPERATOR_CANCELLED; @@ -340,23 +340,23 @@ int join_mesh_exec(bContext *C, wmOperator *op) matmap = MEM_callocN(sizeof(*matmap) * totmat, "join_mesh matmap"); } totcol = ob->totcol; - + /* obact materials in new main array, is nicer start! */ for (a = 0; a < ob->totcol; a++) { matar[a] = give_current_material(ob, a + 1); id_us_plus((ID *)matar[a]); /* increase id->us : will be lowered later */ } - + /* - if destination mesh had shapekeys, move them somewhere safe, and set up placeholders * with arrays that are large enough to hold shapekey data for all meshes - * - if destination mesh didn't have shapekeys, but we encountered some in the meshes we're + * - if destination mesh didn't have shapekeys, but we encountered some in the meshes we're * joining, set up a new keyblock and assign to the mesh */ if (key) { /* make a duplicate copy that will only be used here... (must remember to free it!) */ nkey = BKE_key_copy(bmain, key); - + /* for all keys in old block, clear data-arrays */ for (kb = key->block.first; kb; kb = kb->next) { if (kb->data) MEM_freeN(kb->data); @@ -369,14 +369,14 @@ int join_mesh_exec(bContext *C, wmOperator *op) key = me->key = BKE_key_add((ID *)me); key->type = KEY_RELATIVE; } - + /* first pass over objects - copying materials and vertexgroups across */ CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) { /* only act if a mesh, and not the one we're joining to */ if ((ob != base->object) && (base->object->type == OB_MESH)) { me = base->object->data; - + /* Join this object's vertex groups to the base one's */ for (dg = base->object->defbase.first; dg; dg = dg->next) { /* See if this group exists in the object (if it doesn't, add it to the end) */ @@ -388,8 +388,8 @@ int join_mesh_exec(bContext *C, wmOperator *op) } if (ob->defbase.first && ob->actdef == 0) ob->actdef = 1; - - + + if (me->totvert) { /* Add this object's materials to the base one's if they don't exist already (but only if limits not exceeded yet) */ if (totcol < MAXMAT) { @@ -413,7 +413,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) } } } - + /* if this mesh has shapekeys, check if destination mesh already has matching entries too */ if (me->key && key) { /* for remapping KeyBlock.relative */ @@ -475,7 +475,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) edgeofs = 0; loopofs = 0; polyofs = 0; - + /* inverse transform for all selected meshes in this object */ invert_m4_m4(imat, ob->obmat); @@ -516,10 +516,10 @@ int join_mesh_exec(bContext *C, wmOperator *op) } } CTX_DATA_END; - + /* return to mesh we're merging to */ me = ob->data; - + CustomData_free(&me->vdata, me->totvert); CustomData_free(&me->edata, me->totedge); CustomData_free(&me->ldata, me->totloop); @@ -540,7 +540,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) /* update normals in case objects with non-uniform scale are joined */ BKE_mesh_calc_normals(me); - + /* old material array */ for (a = 1; a <= ob->totcol; a++) { ma = ob->mat[a - 1]; @@ -567,13 +567,13 @@ int join_mesh_exec(bContext *C, wmOperator *op) /* other mesh users */ test_all_objects_materials(bmain, (ID *)me); - + /* free temp copy of destination shapekeys (if applicable) */ if (nkey) { /* We can assume nobody is using that ID currently. */ BKE_libblock_free_ex(bmain, nkey, false, false); } - + /* ensure newly inserted keys are time sorted */ if (key && (key->type != KEY_RELATIVE)) { BKE_key_sort(key); @@ -593,7 +593,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) /*********************** JOIN AS SHAPES ***************************/ -/* Append selected meshes vertex locations as shapes of the active mesh, +/* Append selected meshes vertex locations as shapes of the active mesh, * return 0 if no join is made (error) and 1 of the join is done */ int join_mesh_shapes_exec(bContext *C, wmOperator *op) @@ -606,14 +606,14 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) Key *key = me->key; KeyBlock *kb; bool ok = false, nonequal_verts = false; - + CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) { if (base->object == ob) continue; - + if (base->object->type == OB_MESH) { selme = (Mesh *)base->object->data; - + if (selme->totvert == me->totvert) ok = true; else @@ -621,7 +621,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) } } CTX_DATA_END; - + if (!ok) { if (nonequal_verts) BKE_report(op->reports, RPT_WARNING, "Selected meshes must have equal numbers of vertices"); @@ -629,7 +629,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_WARNING, "No additional selected meshes with equal vertex count to join"); return OPERATOR_CANCELLED; } - + if (key == NULL) { key = me->key = BKE_key_add((ID *)me); key->type = KEY_RELATIVE; @@ -638,32 +638,32 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) kb = BKE_keyblock_add(key, NULL); BKE_keyblock_convert_from_mesh(me, kb); } - + /* now ready to add new keys from selected meshes */ CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) { if (base->object == ob) continue; - + if (base->object->type == OB_MESH) { selme = (Mesh *)base->object->data; - + if (selme->totvert == me->totvert) { dm = mesh_get_derived_deform(scene, base->object, CD_MASK_BAREMESH); - + if (!dm) continue; - + kb = BKE_keyblock_add(key, base->object->id.name + 2); - + DM_to_meshkey(dm, me, kb); - + dm->release(dm); } } } CTX_DATA_END; - + WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); - + return OPERATOR_FINISHED; } @@ -707,12 +707,12 @@ static int mesh_get_x_mirror_vert_spatial(Object *ob, DerivedMesh *dm, int index Mesh *me = ob->data; MVert *mvert = dm ? dm->getVertArray(dm) : me->mvert; float vec[3]; - + mvert = &mvert[index]; vec[0] = -mvert->co[0]; vec[1] = mvert->co[1]; vec[2] = mvert->co[2]; - + return ED_mesh_mirror_spatial_table(ob, NULL, dm, vec, 'u'); } @@ -738,7 +738,7 @@ static BMVert *editbmesh_get_x_mirror_vert_spatial(Object *ob, BMEditMesh *em, c { float vec[3]; int i; - + /* ignore nan verts */ if ((isfinite(co[0]) == false) || (isfinite(co[1]) == false) || @@ -746,11 +746,11 @@ static BMVert *editbmesh_get_x_mirror_vert_spatial(Object *ob, BMEditMesh *em, c { return NULL; } - + vec[0] = -co[0]; vec[1] = co[1]; vec[2] = co[2]; - + i = ED_mesh_mirror_spatial_table(ob, em, NULL, vec, 'u'); if (i != -1) { return BM_vert_at_index(em->bm, i); @@ -767,14 +767,14 @@ static BMVert *editbmesh_get_x_mirror_vert_topo(Object *ob, struct BMEditMesh *e if (index == -1) { BMIter iter; BMVert *v; - + index = 0; BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { if (v == eve) break; index++; } - + if (index == em->bm->totvert) { return NULL; } @@ -785,7 +785,7 @@ static BMVert *editbmesh_get_x_mirror_vert_topo(Object *ob, struct BMEditMesh *e if (poinval != -1) return (BMVert *)(poinval); return NULL; -} +} BMVert *editbmesh_get_x_mirror_vert(Object *ob, struct BMEditMesh *em, BMVert *eve, const float co[3], int index, const bool use_topology) { @@ -857,19 +857,19 @@ static float *editmesh_get_mirror_uv(BMEditMesh *em, int axis, float *uv, float { BMIter iter; BMFace *efa; - + BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { uv_poly_center(efa, cent, cd_loop_uv_offset); - + if ( (fabsf(cent[0] - cent_vec[0]) < 0.001f) && (fabsf(cent[1] - cent_vec[1]) < 0.001f) ) { BMIter liter; BMLoop *l; - + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { MLoopUV *luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); if ( (fabsf(luv->uv[0] - vec[0]) < 0.001f) && (fabsf(luv->uv[1] - vec[1]) < 0.001f) ) { return luv->uv; - + } } } @@ -918,7 +918,7 @@ static int mirror_facerotation(MFace *a, MFace *b) else if (a->v2 == b->v1 && a->v3 == b->v2 && a->v1 == b->v3) return 2; } - + return -1; } @@ -983,7 +983,7 @@ int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em, DerivedMesh *dm) BLI_ghash_free(fhash, NULL, NULL); MEM_freeN(mirrorverts); - + return mirrorfaces; } -- cgit v1.2.3 From ce6db959c7d96792edad3a6d606e3662a4ef0798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 5 Jun 2018 16:58:08 +0200 Subject: Moved function declarations from BKE_DerivedMesh.h to BKE_mesh_runtime.h The function definitions still reside in DerivedMesh.c. Once we're done porting all the DerivedMesh use to Mesh, we'll move the still-relevant functions to mesh_runtime.c. This move is now cumbersome due to shared statically-declared utility functions in DerivedMesh.c --- source/blender/editors/mesh/meshtools.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender/editors/mesh/meshtools.c') diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 786b27ee816..41e1ca13b79 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -54,6 +54,7 @@ #include "BKE_library.h" #include "BKE_main.h" #include "BKE_mesh.h" +#include "BKE_mesh_runtime.h" #include "BKE_material.h" #include "BKE_object.h" #include "BKE_object_deform.h" -- cgit v1.2.3 From be57cf9b2a0e1be577211839487cacd288886c1a Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 12 Jun 2018 12:53:27 +0200 Subject: Cleanup: remove moar G.main from BKE area. --- source/blender/editors/mesh/meshtools.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source/blender/editors/mesh/meshtools.c') diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 6953473a792..8980e1830cf 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -366,7 +366,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) } else if (haskey) { /* add a new key-block and add to the mesh */ - key = me->key = BKE_key_add((ID *)me); + key = me->key = BKE_key_add(bmain, (ID *)me); key->type = KEY_RELATIVE; } @@ -598,6 +598,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) int join_mesh_shapes_exec(bContext *C, wmOperator *op) { + Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); Mesh *me = (Mesh *)ob->data; @@ -631,7 +632,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) } if (key == NULL) { - key = me->key = BKE_key_add((ID *)me); + key = me->key = BKE_key_add(bmain, (ID *)me); key->type = KEY_RELATIVE; /* first key added, so it was the basis. initialize it with the existing mesh */ -- cgit v1.2.3 From 9c6522706125794201173207d0caecae0be0b484 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 13 Jun 2018 15:26:59 +0200 Subject: Tag object/scene for selection update from operators Before that depsgraph tagging was done from inside notifier listener in viewport. This had the following issues: - If there are no viewports, selection tag was not done. Causing possible issues when object becomes visible. - Required special trickery to detect which data to tag for update. - Was causing crash when transforming/selecting markers in clip editor. This is because selecting marker needed to poke viewport to redraw, since selected bundles will be displayed differently in viewport. --- source/blender/editors/mesh/meshtools.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source/blender/editors/mesh/meshtools.c') diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 146bcc742e5..6c8de1a481e 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -593,6 +593,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA); + DEG_id_tag_update(&scene->id, DEG_TAG_SELECT_UPDATE); WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); return OPERATOR_FINISHED; @@ -671,6 +672,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) } CTX_DATA_END; + DEG_id_tag_update(&scene->id, DEG_TAG_SELECT_UPDATE); WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); return OPERATOR_FINISHED; -- cgit v1.2.3 From 31d916210c4e70e8c2dcb54fe0d4d2ba6940842f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 21 Jun 2018 18:24:32 +0200 Subject: Cleanup: remove DM from 'join as shape' operator. Also deduplicated the 'mesh as shapekey' code, we had kind of two funcs doing the same thing here... --- source/blender/editors/mesh/meshtools.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source/blender/editors/mesh/meshtools.c') diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 6c8de1a481e..4549c0bccbf 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -612,7 +612,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) Depsgraph *depsgraph = CTX_data_depsgraph(C); Mesh *me = (Mesh *)ob->data; Mesh *selme = NULL; - DerivedMesh *dm = NULL; + Mesh *me_deformed = NULL; Key *key = me->key; KeyBlock *kb; bool ok = false, nonequal_verts = false; @@ -646,7 +646,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) /* first key added, so it was the basis. initialize it with the existing mesh */ kb = BKE_keyblock_add(key, NULL); - BKE_keyblock_convert_from_mesh(me, kb); + BKE_keyblock_convert_from_mesh(me, key, kb); } /* now ready to add new keys from selected meshes */ @@ -658,15 +658,15 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) selme = (Mesh *)base->object->data; if (selme->totvert == me->totvert) { - dm = mesh_get_derived_deform(depsgraph, scene, base->object, CD_MASK_BAREMESH); + me_deformed = mesh_get_eval_deform(depsgraph, scene, base->object, CD_MASK_BAREMESH); - if (!dm) continue; + if (!me_deformed) { + continue; + } kb = BKE_keyblock_add(key, base->object->id.name + 2); - DM_to_meshkey(dm, me, kb); - - dm->release(dm); + BKE_mesh_runtime_eval_to_meshkey(me_deformed, me, kb); } } } -- cgit v1.2.3 From d6eac9d78710902f94a8e914845d10ecf680f42f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 21 Jun 2018 18:38:37 +0200 Subject: Cleanup: ED_mesh_pick_vert: DM -> me_eval. --- source/blender/editors/mesh/meshtools.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'source/blender/editors/mesh/meshtools.c') diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 4549c0bccbf..3595a918406 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -54,6 +54,7 @@ #include "BKE_library.h" #include "BKE_main.h" #include "BKE_mesh.h" +#include "BKE_mesh_iterators.h" #include "BKE_mesh_runtime.h" #include "BKE_material.h" #include "BKE_object.h" @@ -1322,7 +1323,7 @@ bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int } else { /* derived mesh to find deformed locations */ - DerivedMesh *dm = mesh_get_derived_final(vc.depsgraph, vc.scene, ob, CD_MASK_BAREMESH); + Mesh *me_eval = mesh_get_eval_final(vc.depsgraph, vc.scene, ob, CD_MASK_BAREMESH); ARegion *ar = vc.ar; RegionView3D *rv3d = ar->regiondata; @@ -1334,7 +1335,7 @@ bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int ED_view3d_init_mats_rv3d(ob, rv3d); - if (dm == NULL) { + if (me_eval == NULL) { return false; } @@ -1345,9 +1346,7 @@ bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int data.len_best = FLT_MAX; data.v_idx_best = -1; - dm->foreachMappedVert(dm, ed_mesh_pick_vert__mapFunc, &data, DM_FOREACH_NOP); - - dm->release(dm); + BKE_mesh_foreach_mapped_vert(me_eval, ed_mesh_pick_vert__mapFunc, &data, MESH_FOREACH_NOP); if (data.v_idx_best == -1) { return false; -- cgit v1.2.3 From c111eb0e9927ecfafd1173fc31dac4f04389e31e Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 21 Jun 2018 19:05:10 +0200 Subject: Cleanup: get rid of dual DM/Mesh versions of mirror topology code. Easy to switch to only use (evaluated) mesh instead! --- source/blender/editors/mesh/meshtools.c | 159 +++++--------------------------- 1 file changed, 21 insertions(+), 138 deletions(-) (limited to 'source/blender/editors/mesh/meshtools.c') diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 3595a918406..537056cd1ba 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -34,9 +34,10 @@ #include "MEM_guardedalloc.h" -#include "DNA_mesh_types.h" #include "DNA_key_types.h" #include "DNA_material_types.h" +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" #include "DNA_modifier_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" @@ -49,7 +50,6 @@ #include "BKE_context.h" #include "BKE_deform.h" -#include "BKE_DerivedMesh.h" #include "BKE_key.h" #include "BKE_library.h" #include "BKE_main.h" @@ -691,40 +691,15 @@ static MirrTopoStore_t mesh_topo_store = {NULL, -1. - 1, -1}; /* mode is 's' start, or 'e' end, or 'u' use */ /* if end, ob can be NULL */ /* note, is supposed return -1 on error, which callers are currently checking for, but is not used so far */ -int ED_mesh_mirror_topo_table( - Object *ob, DerivedMesh *dm, char mode) -{ - if (mode == 'u') { /* use table */ - if (ED_mesh_mirrtopo_recalc_check(ob->data, dm, &mesh_topo_store)) { - ED_mesh_mirror_topo_table(ob, dm, 's'); - } - } - else if (mode == 's') { /* start table */ - ED_mesh_mirrtopo_init(ob->data, dm, &mesh_topo_store, false); - } - else if (mode == 'e') { /* end table */ - ED_mesh_mirrtopo_free(&mesh_topo_store); - } - else { - BLI_assert(0); - } - - return 0; -} - -/* mode is 's' start, or 'e' end, or 'u' use */ -/* if end, ob can be NULL */ -/* note, is supposed return -1 on error, which callers are currently checking for, but is not used so far */ -int ED_mesh_mirror_topo_table__real_mesh( - Object *ob, Mesh *mesh, char mode) +int ED_mesh_mirror_topo_table(Object *ob, Mesh *me_eval, char mode) { if (mode == 'u') { /* use table */ - if (ED_mesh_mirrtopo_recalc_check__real_mesh(ob->data, mesh, &mesh_topo_store)) { - ED_mesh_mirror_topo_table__real_mesh(ob, mesh, 's'); + if (ED_mesh_mirrtopo_recalc_check(ob->data, me_eval, &mesh_topo_store)) { + ED_mesh_mirror_topo_table(ob, me_eval, 's'); } } else if (mode == 's') { /* start table */ - ED_mesh_mirrtopo_init__real_mesh(ob->data, mesh, &mesh_topo_store, false); + ED_mesh_mirrtopo_init(ob->data, me_eval, &mesh_topo_store, false); } else if (mode == 'e') { /* end table */ ED_mesh_mirrtopo_free(&mesh_topo_store); @@ -739,39 +714,7 @@ int ED_mesh_mirror_topo_table__real_mesh( /** \} */ -static int mesh_get_x_mirror_vert_spatial(Object *ob, DerivedMesh *dm, int index) -{ - Mesh *me = ob->data; - MVert *mvert = dm ? dm->getVertArray(dm) : me->mvert; - float vec[3]; - - mvert = &mvert[index]; - vec[0] = -mvert->co[0]; - vec[1] = mvert->co[1]; - vec[2] = mvert->co[2]; - - return ED_mesh_mirror_spatial_table(ob, NULL, dm, vec, 'u'); -} - -static int mesh_get_x_mirror_vert_topo(Object *ob, DerivedMesh *dm, int index) -{ - if (ED_mesh_mirror_topo_table(ob, dm, 'u') == -1) - return -1; - - return mesh_topo_store.index_lookup[index]; -} - -int mesh_get_x_mirror_vert(Object *ob, DerivedMesh *dm, int index, const bool use_topology) -{ - if (use_topology) { - return mesh_get_x_mirror_vert_topo(ob, dm, index); - } - else { - return mesh_get_x_mirror_vert_spatial(ob, dm, index); - } -} - -static int mesh_get_x_mirror_vert_spatial__real_mesh(Object *ob, Mesh *mesh, int index) +static int mesh_get_x_mirror_vert_spatial(Object *ob, Mesh *mesh, int index) { Mesh *me = ob->data; MVert *mvert = mesh ? mesh->mvert : me->mvert; @@ -782,24 +725,24 @@ static int mesh_get_x_mirror_vert_spatial__real_mesh(Object *ob, Mesh *mesh, int vec[1] = mvert->co[1]; vec[2] = mvert->co[2]; - return ED_mesh_mirror_spatial_table__real_mesh(ob, NULL, mesh, vec, 'u'); + return ED_mesh_mirror_spatial_table(ob, NULL, mesh, vec, 'u'); } -static int mesh_get_x_mirror_vert_topo__real_mesh(Object *ob, Mesh *mesh, int index) +static int mesh_get_x_mirror_vert_topo(Object *ob, Mesh *mesh, int index) { - if (ED_mesh_mirror_topo_table__real_mesh(ob, mesh, 'u') == -1) + if (ED_mesh_mirror_topo_table(ob, mesh, 'u') == -1) return -1; return mesh_topo_store.index_lookup[index]; } -int mesh_get_x_mirror_vert__real_mesh(Object *ob, Mesh *mesh, int index, const bool use_topology) +int mesh_get_x_mirror_vert(Object *ob, Mesh *me_eval, int index, const bool use_topology) { if (use_topology) { - return mesh_get_x_mirror_vert_topo__real_mesh(ob, mesh, index); + return mesh_get_x_mirror_vert_topo(ob, me_eval, index); } else { - return mesh_get_x_mirror_vert_spatial__real_mesh(ob, mesh, index); + return mesh_get_x_mirror_vert_spatial(ob, me_eval, index); } } @@ -996,68 +939,8 @@ static bool mirror_facecmp(const void *a, const void *b) return (mirror_facerotation((MFace *)a, (MFace *)b) == -1); } -/* BMESH_TODO, convert to MPoly (functions above also) */ -int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em, DerivedMesh *dm) -{ - Mesh *me = ob->data; - MVert *mv, *mvert; - MFace mirrormf, *mf, *hashmf, *mface; - GHash *fhash; - int *mirrorverts, *mirrorfaces; - - BLI_assert(em == NULL); /* Does not work otherwise, currently... */ - - const bool use_topology = (me->editflag & ME_EDIT_MIRROR_TOPO) != 0; - const int totvert = dm ? dm->getNumVerts(dm) : me->totvert; - const int totface = dm ? dm->getNumTessFaces(dm) : me->totface; - int a; - - mirrorverts = MEM_callocN(sizeof(int) * totvert, "MirrorVerts"); - mirrorfaces = MEM_callocN(sizeof(int) * 2 * totface, "MirrorFaces"); - - mvert = dm ? dm->getVertArray(dm) : me->mvert; - mface = dm ? dm->getTessFaceArray(dm) : me->mface; - - ED_mesh_mirror_spatial_table(ob, em, dm, NULL, 's'); - - for (a = 0, mv = mvert; a < totvert; a++, mv++) - mirrorverts[a] = mesh_get_x_mirror_vert(ob, dm, a, use_topology); - - ED_mesh_mirror_spatial_table(ob, em, dm, NULL, 'e'); - - fhash = BLI_ghash_new_ex(mirror_facehash, mirror_facecmp, "mirror_facehash gh", me->totface); - for (a = 0, mf = mface; a < totface; a++, mf++) - BLI_ghash_insert(fhash, mf, mf); - - for (a = 0, mf = mface; a < totface; a++, mf++) { - mirrormf.v1 = mirrorverts[mf->v3]; - mirrormf.v2 = mirrorverts[mf->v2]; - mirrormf.v3 = mirrorverts[mf->v1]; - mirrormf.v4 = (mf->v4) ? mirrorverts[mf->v4] : 0; - - /* make sure v4 is not 0 if a quad */ - if (mf->v4 && mirrormf.v4 == 0) { - SWAP(unsigned int, mirrormf.v1, mirrormf.v3); - SWAP(unsigned int, mirrormf.v2, mirrormf.v4); - } - - hashmf = BLI_ghash_lookup(fhash, &mirrormf); - if (hashmf) { - mirrorfaces[a * 2] = hashmf - mface; - mirrorfaces[a * 2 + 1] = mirror_facerotation(&mirrormf, hashmf); - } - else - mirrorfaces[a * 2] = -1; - } - - BLI_ghash_free(fhash, NULL, NULL); - MEM_freeN(mirrorverts); - - return mirrorfaces; -} - /* This is a Mesh-based copy of mesh_get_x_mirror_faces() */ -int *mesh_get_x_mirror_faces__real_mesh(Object *ob, BMEditMesh *em, Mesh *mesh) +int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em, Mesh *me_eval) { Mesh *me = ob->data; MVert *mv, *mvert; @@ -1068,22 +951,22 @@ int *mesh_get_x_mirror_faces__real_mesh(Object *ob, BMEditMesh *em, Mesh *mesh) BLI_assert(em == NULL); /* Does not work otherwise, currently... */ const bool use_topology = (me->editflag & ME_EDIT_MIRROR_TOPO) != 0; - const int totvert = mesh ? mesh->totvert : me->totvert; - const int totface = mesh ? mesh->totface : me->totface; + const int totvert = me_eval ? me_eval->totvert : me->totvert; + const int totface = me_eval ? me_eval->totface : me->totface; int a; mirrorverts = MEM_callocN(sizeof(int) * totvert, "MirrorVerts"); mirrorfaces = MEM_callocN(sizeof(int) * 2 * totface, "MirrorFaces"); - mvert = mesh ? mesh->mvert : me->mvert; - mface = mesh ? mesh->mface : me->mface; + mvert = me_eval ? me_eval->mvert : me->mvert; + mface = me_eval ? me_eval->mface : me->mface; - ED_mesh_mirror_spatial_table__real_mesh(ob, em, mesh, NULL, 's'); + ED_mesh_mirror_spatial_table(ob, em, me_eval, NULL, 's'); for (a = 0, mv = mvert; a < totvert; a++, mv++) - mirrorverts[a] = mesh_get_x_mirror_vert__real_mesh(ob, mesh, a, use_topology); + mirrorverts[a] = mesh_get_x_mirror_vert(ob, me_eval, a, use_topology); - ED_mesh_mirror_spatial_table__real_mesh(ob, em, mesh, NULL, 'e'); + ED_mesh_mirror_spatial_table(ob, em, me_eval, NULL, 'e'); fhash = BLI_ghash_new_ex(mirror_facehash, mirror_facecmp, "mirror_facehash gh", me->totface); for (a = 0, mf = mface; a < totface; a++, mf++) -- cgit v1.2.3