COW: Edit Mesh: Do not copy the looptris pointer

No functional changes.

Differential Revision: https://developer.blender.org/D7173
This commit is contained in:
Germano Cavalcante 2020-03-23 09:30:26 -03:00
parent bceb91ffd2
commit 64982e213f
Notes: blender-bot 2023-02-14 09:19:09 +01:00
Referenced by commit b701af328a, Revert "COW: Edit Mesh: Do not copy the looptris pointer"
8 changed files with 26 additions and 13 deletions

View File

@ -613,6 +613,7 @@ void update_mesh_edit_mode_pointers(const ID *id_orig, ID *id_cow)
return;
}
mesh_cow->edit_mesh = (BMEditMesh *)MEM_dupallocN(mesh_orig->edit_mesh);
mesh_cow->edit_mesh->looptris = nullptr;
mesh_cow->edit_mesh->mesh_eval_cage = nullptr;
mesh_cow->edit_mesh->mesh_eval_final = nullptr;
}
@ -994,6 +995,7 @@ void discard_mesh_edit_mode_pointers(ID *id_cow)
if (mesh_cow->edit_mesh == nullptr) {
return;
}
BLI_assert(mesh_cow->edit_mesh->looptris == nullptr);
BKE_editmesh_free_derivedmesh(mesh_cow->edit_mesh);
MEM_freeN(mesh_cow->edit_mesh);
mesh_cow->edit_mesh = nullptr;

View File

@ -66,6 +66,8 @@
#include "ED_mesh.h"
#include "ED_uvedit.h"
#include "DEG_depsgraph_query.h"
#include "draw_cache_impl.h"
#include "draw_cache_inline.h"
@ -102,7 +104,7 @@ typedef struct MeshRenderData {
/* HACK not supposed to be there but it's needed. */
struct MeshBatchCache *cache;
/** Edit Mesh */
BMEditMesh *edit_bmesh;
BMEditMesh *edit_bmesh_orig;
BMesh *bm;
EditMeshData *edit_data;
int *v_origindex, *e_origindex, *p_origindex;
@ -149,7 +151,7 @@ static MeshRenderData *mesh_render_data_create(Mesh *me,
if (is_editmode) {
BLI_assert(me->edit_mesh->mesh_eval_cage && me->edit_mesh->mesh_eval_final);
mr->bm = me->edit_mesh->bm;
mr->edit_bmesh = me->edit_mesh;
mr->edit_bmesh_orig = ((Mesh *)DEG_get_original_id(&me->id))->edit_mesh;
mr->edit_data = me->runtime.edit_data;
mr->me = (do_final) ? me->edit_mesh->mesh_eval_final : me->edit_mesh->mesh_eval_cage;
bool use_mapped = !do_uvedit && mr->me && !mr->me->runtime.is_original;
@ -159,7 +161,7 @@ static MeshRenderData *mesh_render_data_create(Mesh *me,
BM_mesh_elem_index_ensure(mr->bm, bm_ensure_types);
BM_mesh_elem_table_ensure(mr->bm, bm_ensure_types & ~BM_LOOP);
mr->efa_act_uv = EDBM_uv_active_face_get(mr->edit_bmesh, false, false);
mr->efa_act_uv = EDBM_uv_active_face_get(mr->edit_bmesh_orig, false, false);
mr->efa_act = BM_mesh_active_face_get(mr->bm, false, true);
mr->eed_act = BM_mesh_active_edge_get(mr->bm);
mr->eve_act = BM_mesh_active_vert_get(mr->bm);
@ -190,7 +192,7 @@ static MeshRenderData *mesh_render_data_create(Mesh *me,
}
else {
mr->me = me;
mr->edit_bmesh = NULL;
mr->edit_bmesh_orig = NULL;
mr->extract_type = MR_EXTRACT_MESH;
}
@ -316,7 +318,7 @@ static MeshRenderData *mesh_render_data_create(Mesh *me,
}
if ((iter_type & MR_ITER_LOOPTRI) || (data_flag & MR_DATA_LOOPTRI)) {
/* Edit mode ensures this is valid, no need to calculate. */
BLI_assert((bm->totloop == 0) || (mr->edit_bmesh->looptris != NULL));
BLI_assert((bm->totloop == 0) || (mr->edit_bmesh_orig->looptris != NULL));
}
if (iter_type & (MR_ITER_LEDGE | MR_ITER_LVERT)) {
int elem_id;
@ -1902,7 +1904,7 @@ static void extract_tan_ex(const MeshRenderData *mr, GPUVertBuf *vbo, const bool
short tangent_mask = 0;
bool calc_active_tangent = false;
if (mr->extract_type == MR_EXTRACT_BMESH) {
BKE_editmesh_loop_tangent_calc(mr->edit_bmesh,
BKE_editmesh_loop_tangent_calc(mr->edit_bmesh_orig,
calc_active_tangent,
tangent_names,
tan_len,
@ -3257,7 +3259,7 @@ static void statvis_calc_overhang(const MeshRenderData *mr, float *r_overhang)
const float min = statvis->overhang_min / (float)M_PI;
const float max = statvis->overhang_max / (float)M_PI;
const char axis = statvis->overhang_axis;
BMEditMesh *em = mr->edit_bmesh;
BMEditMesh *em = mr->edit_bmesh_orig;
BMIter iter;
BMesh *bm = em->bm;
BMFace *f;
@ -3326,7 +3328,7 @@ static void statvis_calc_thickness(const MeshRenderData *mr, float *r_thickness)
const float eps_offset = 0.00002f; /* values <= 0.00001 give errors */
/* cheating to avoid another allocation */
float *face_dists = r_thickness + (mr->loop_len - mr->poly_len);
BMEditMesh *em = mr->edit_bmesh;
BMEditMesh *em = mr->edit_bmesh_orig;
const float scale = 1.0f / mat4_to_scale(mr->obmat);
const MeshStatVis *statvis = &mr->toolsettings->statvis;
const float min = statvis->thickness_min * scale;
@ -3481,7 +3483,7 @@ static bool bvh_overlap_cb(void *userdata, int index_a, int index_b, int UNUSED(
static void statvis_calc_intersect(const MeshRenderData *mr, float *r_intersect)
{
BMEditMesh *em = mr->edit_bmesh;
BMEditMesh *em = mr->edit_bmesh_orig;
for (int l = 0; l < mr->loop_len; l++) {
r_intersect[l] = -1.0f;
@ -3560,7 +3562,7 @@ BLI_INLINE float distort_remap(float fac, float min, float UNUSED(max), float mi
static void statvis_calc_distort(const MeshRenderData *mr, float *r_distort)
{
BMEditMesh *em = mr->edit_bmesh;
BMEditMesh *em = mr->edit_bmesh_orig;
const MeshStatVis *statvis = &mr->toolsettings->statvis;
const float min = statvis->distort_min;
const float max = statvis->distort_max;
@ -3649,7 +3651,7 @@ BLI_INLINE float sharp_remap(float fac, float min, float UNUSED(max), float minm
static void statvis_calc_sharp(const MeshRenderData *mr, float *r_sharp)
{
BMEditMesh *em = mr->edit_bmesh;
BMEditMesh *em = mr->edit_bmesh_orig;
const MeshStatVis *statvis = &mr->toolsettings->statvis;
const float min = statvis->sharp_min;
const float max = statvis->sharp_max;
@ -3747,7 +3749,7 @@ static void statvis_calc_sharp(const MeshRenderData *mr, float *r_sharp)
static void extract_mesh_analysis_finish(const MeshRenderData *mr, void *buf, void *UNUSED(data))
{
BLI_assert(mr->edit_bmesh);
BLI_assert(mr->edit_bmesh_orig);
GPUVertBuf *vbo = buf;
float *l_weight = (float *)vbo->data;
@ -4410,7 +4412,7 @@ BLI_INLINE void mesh_extract_iter(const MeshRenderData *mr,
if (iter_type & MR_ITER_LOOPTRI) {
int t_end = min_ii(mr->tri_len, end);
for (int t = start; t < t_end; t++) {
BMLoop **elt = &mr->edit_bmesh->looptris[t][0];
BMLoop **elt = &mr->edit_bmesh_orig->looptris[t][0];
extract->iter_looptri_bm(mr, t, elt, user_data);
}
}

View File

@ -40,6 +40,7 @@
#include "BKE_undo_system.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
#include "ED_mesh.h"
#include "ED_object.h"
@ -600,6 +601,7 @@ static void undomesh_to_editmesh(UndoMesh *um, Object *ob, BMEditMesh *em, Key *
.active_shapekey = um->shapenr,
}));
BLI_assert(DEG_is_original_object(ob));
em_tmp = BKE_editmesh_create(bm, true);
*em = *em_tmp;

View File

@ -82,6 +82,7 @@
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_query.h"
#include "ED_anim_api.h"
#include "ED_armature.h"
@ -618,6 +619,7 @@ bool ED_object_editmode_enter_ex(Main *bmain, Scene *scene, Object *ob, int flag
em = BKE_editmesh_from_object(ob);
if (LIKELY(em)) {
BLI_assert(DEG_is_original_object(ob));
/* order doesn't matter */
EDBM_mesh_normals_update(em);
BKE_editmesh_looptri_calc(em);

View File

@ -351,6 +351,7 @@ static bool object_hook_index_array(Main *bmain,
em = me->edit_mesh;
BLI_assert(DEG_is_original_object(obedit));
EDBM_mesh_normals_update(em);
BKE_editmesh_looptri_calc(em);

View File

@ -151,6 +151,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
em = me->edit_mesh;
BLI_assert(DEG_is_original_object(obedit));
EDBM_mesh_normals_update(em);
BKE_editmesh_looptri_calc(em);

View File

@ -855,6 +855,7 @@ static void recalcData_objects(TransInfo *t)
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
DEG_id_tag_update(tc->obedit->data, 0); /* sets recalc flags */
BLI_assert(DEG_is_original_object(tc->obedit));
BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
EDBM_mesh_normals_update(em);
BKE_editmesh_looptri_calc(em);

View File

@ -314,6 +314,7 @@ const EnumPropertyItem rna_enum_object_axis_items[] = {
# include "DEG_depsgraph.h"
# include "DEG_depsgraph_build.h"
# include "DEG_depsgraph_query.h"
# include "ED_curve.h"
# include "ED_lattice.h"
@ -442,6 +443,7 @@ static void rna_Object_active_shape_update(Main *bmain, Scene *UNUSED(scene), Po
DEG_id_tag_update(&me->id, 0);
BLI_assert(DEG_is_original_object(ob));
EDBM_mesh_normals_update(em);
BKE_editmesh_looptri_calc(em);
break;