EditMesh: extract restore logic out of EDBM_redo_state_free
Split mesh restore logic into a new function: `EDBM_redo_state_restore_and_free`.
This commit is contained in:
parent
d27db03444
commit
dac81ad71b
|
@ -27,6 +27,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "BLI_compiler_attrs.h"
|
||||
|
||||
struct ARegion;
|
||||
struct BMBVHTree;
|
||||
struct BMEdge;
|
||||
|
@ -455,12 +457,14 @@ typedef struct BMBackup {
|
|||
struct BMesh *bmcopy;
|
||||
} BMBackup;
|
||||
|
||||
/* save a copy of the bmesh for restoring later */
|
||||
struct BMBackup EDBM_redo_state_store(struct BMEditMesh *em);
|
||||
/* restore a bmesh from backup */
|
||||
void EDBM_redo_state_restore(struct BMBackup, struct BMEditMesh *em, int recalctess);
|
||||
/* delete the backup, optionally flushing it to an editmesh */
|
||||
void EDBM_redo_state_free(struct BMBackup *, struct BMEditMesh *em, int recalctess);
|
||||
void EDBM_redo_state_restore(struct BMBackup *backup, struct BMEditMesh *em, bool recalc_looptri)
|
||||
ATTR_NONNULL(1, 2);
|
||||
void EDBM_redo_state_restore_and_free(struct BMBackup *backup,
|
||||
struct BMEditMesh *em,
|
||||
bool recalc_looptri) ATTR_NONNULL(1, 2);
|
||||
void EDBM_redo_state_free(struct BMBackup *backup) ATTR_NONNULL(1);
|
||||
|
||||
/* *** meshtools.c *** */
|
||||
int ED_mesh_join_objects_exec(struct bContext *C, struct wmOperator *op);
|
||||
|
|
|
@ -347,7 +347,7 @@ static bool edbm_bevel_calc(wmOperator *op)
|
|||
|
||||
/* revert to original mesh */
|
||||
if (opdata->is_modal) {
|
||||
EDBM_redo_state_restore(opdata->ob_store[ob_index].mesh_backup, em, false);
|
||||
EDBM_redo_state_restore(&opdata->ob_store[ob_index].mesh_backup, em, false);
|
||||
}
|
||||
|
||||
const int material = CLAMPIS(material_init, -1, obedit->totcol - 1);
|
||||
|
@ -436,7 +436,7 @@ static void edbm_bevel_exit(bContext *C, wmOperator *op)
|
|||
View3D *v3d = CTX_wm_view3d(C);
|
||||
ARegion *region = CTX_wm_region(C);
|
||||
for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) {
|
||||
EDBM_redo_state_free(&opdata->ob_store[ob_index].mesh_backup, NULL, false);
|
||||
EDBM_redo_state_free(&opdata->ob_store[ob_index].mesh_backup);
|
||||
}
|
||||
ED_region_draw_cb_exit(region->type, opdata->draw_handle_pixel);
|
||||
if (v3d) {
|
||||
|
@ -456,7 +456,7 @@ static void edbm_bevel_cancel(bContext *C, wmOperator *op)
|
|||
for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) {
|
||||
Object *obedit = opdata->ob_store[ob_index].ob;
|
||||
BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
||||
EDBM_redo_state_free(&opdata->ob_store[ob_index].mesh_backup, em, true);
|
||||
EDBM_redo_state_restore_and_free(&opdata->ob_store[ob_index].mesh_backup, em, true);
|
||||
EDBM_update(obedit->data,
|
||||
&(const struct EDBMUpdate_Params){
|
||||
.calc_looptri = false,
|
||||
|
|
|
@ -67,7 +67,7 @@ typedef struct {
|
|||
|
||||
/* Aligned with objects array. */
|
||||
struct {
|
||||
BMBackup mesh;
|
||||
BMBackup mesh_backup;
|
||||
bool is_valid;
|
||||
bool is_dirty;
|
||||
} * backup;
|
||||
|
@ -160,7 +160,7 @@ static int mesh_bisect_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|||
|
||||
if (em->bm->totedgesel != 0) {
|
||||
opdata->backup[ob_index].is_valid = true;
|
||||
opdata->backup[ob_index].mesh = EDBM_redo_state_store(em);
|
||||
opdata->backup[ob_index].mesh_backup = EDBM_redo_state_store(em);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ static void edbm_bisect_exit(bContext *C, BisectData *opdata)
|
|||
|
||||
for (int ob_index = 0; ob_index < opdata->backup_len; ob_index++) {
|
||||
if (opdata->backup[ob_index].is_valid) {
|
||||
EDBM_redo_state_free(&opdata->backup[ob_index].mesh, NULL, false);
|
||||
EDBM_redo_state_free(&opdata->backup[ob_index].mesh_backup);
|
||||
}
|
||||
}
|
||||
MEM_freeN(opdata->backup);
|
||||
|
@ -301,7 +301,7 @@ static int mesh_bisect_exec(bContext *C, wmOperator *op)
|
|||
|
||||
if (opdata != NULL) {
|
||||
if (opdata->backup[ob_index].is_dirty) {
|
||||
EDBM_redo_state_restore(opdata->backup[ob_index].mesh, em, false);
|
||||
EDBM_redo_state_restore(&opdata->backup[ob_index].mesh_backup, em, false);
|
||||
opdata->backup[ob_index].is_dirty = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -209,7 +209,7 @@ static void edbm_inset_exit(bContext *C, wmOperator *op)
|
|||
View3D *v3d = CTX_wm_view3d(C);
|
||||
ARegion *region = CTX_wm_region(C);
|
||||
for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) {
|
||||
EDBM_redo_state_free(&opdata->ob_store[ob_index].mesh_backup, NULL, false);
|
||||
EDBM_redo_state_free(&opdata->ob_store[ob_index].mesh_backup);
|
||||
}
|
||||
ED_region_draw_cb_exit(region->type, opdata->draw_handle_pixel);
|
||||
if (v3d) {
|
||||
|
@ -235,7 +235,7 @@ static void edbm_inset_cancel(bContext *C, wmOperator *op)
|
|||
for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) {
|
||||
Object *obedit = opdata->ob_store[ob_index].ob;
|
||||
BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
||||
EDBM_redo_state_free(&opdata->ob_store[ob_index].mesh_backup, em, true);
|
||||
EDBM_redo_state_restore_and_free(&opdata->ob_store[ob_index].mesh_backup, em, true);
|
||||
EDBM_update(obedit->data,
|
||||
&(const struct EDBMUpdate_Params){
|
||||
.calc_looptri = false,
|
||||
|
@ -276,7 +276,7 @@ static bool edbm_inset_calc(wmOperator *op)
|
|||
BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
||||
|
||||
if (opdata->is_modal) {
|
||||
EDBM_redo_state_restore(opdata->ob_store[ob_index].mesh_backup, em, false);
|
||||
EDBM_redo_state_restore(&opdata->ob_store[ob_index].mesh_backup, em, false);
|
||||
}
|
||||
|
||||
if (use_individual) {
|
||||
|
|
|
@ -1284,7 +1284,7 @@ static bool edbm_connect_vert_pair(BMEditMesh *em, struct Mesh *me, wmOperator *
|
|||
}
|
||||
else if (failure) {
|
||||
len = 0;
|
||||
EDBM_redo_state_free(&em_backup, em, true);
|
||||
EDBM_redo_state_restore_and_free(&em_backup, em, true);
|
||||
em_backup_free = false;
|
||||
}
|
||||
else {
|
||||
|
@ -1302,7 +1302,7 @@ static bool edbm_connect_vert_pair(BMEditMesh *em, struct Mesh *me, wmOperator *
|
|||
}
|
||||
|
||||
if (em_backup_free) {
|
||||
EDBM_redo_state_free(&em_backup, NULL, false);
|
||||
EDBM_redo_state_free(&em_backup);
|
||||
}
|
||||
}
|
||||
MEM_freeN(verts);
|
||||
|
|
|
@ -68,6 +68,9 @@
|
|||
* just as the undo stack would.
|
||||
* So leaving this as an interface for further work */
|
||||
|
||||
/**
|
||||
* Save a copy of the #BMesh for restoring later.
|
||||
*/
|
||||
BMBackup EDBM_redo_state_store(BMEditMesh *em)
|
||||
{
|
||||
BMBackup backup;
|
||||
|
@ -75,44 +78,43 @@ BMBackup EDBM_redo_state_store(BMEditMesh *em)
|
|||
return backup;
|
||||
}
|
||||
|
||||
void EDBM_redo_state_restore(BMBackup backup, BMEditMesh *em, int recalctess)
|
||||
void EDBM_redo_state_restore(BMBackup *backup, BMEditMesh *em, bool recalc_looptri)
|
||||
{
|
||||
BMesh *tmpbm;
|
||||
if (!em || !backup.bmcopy) {
|
||||
return;
|
||||
}
|
||||
|
||||
BM_mesh_data_free(em->bm);
|
||||
tmpbm = BM_mesh_copy(backup.bmcopy);
|
||||
tmpbm = BM_mesh_copy(backup->bmcopy);
|
||||
*em->bm = *tmpbm;
|
||||
MEM_freeN(tmpbm);
|
||||
tmpbm = NULL;
|
||||
|
||||
if (recalctess) {
|
||||
if (recalc_looptri) {
|
||||
BKE_editmesh_looptri_calc(em);
|
||||
}
|
||||
}
|
||||
|
||||
void EDBM_redo_state_free(BMBackup *backup, BMEditMesh *em, int recalctess)
|
||||
/**
|
||||
* Delete the backup, flushing it to an edit-mesh.
|
||||
*/
|
||||
void EDBM_redo_state_restore_and_free(BMBackup *backup, BMEditMesh *em, bool recalc_looptri)
|
||||
{
|
||||
if (em && backup->bmcopy) {
|
||||
BM_mesh_data_free(em->bm);
|
||||
*em->bm = *backup->bmcopy;
|
||||
}
|
||||
else if (backup->bmcopy) {
|
||||
BM_mesh_data_free(backup->bmcopy);
|
||||
}
|
||||
|
||||
if (backup->bmcopy) {
|
||||
MEM_freeN(backup->bmcopy);
|
||||
}
|
||||
BM_mesh_data_free(em->bm);
|
||||
*em->bm = *backup->bmcopy;
|
||||
MEM_freeN(backup->bmcopy);
|
||||
backup->bmcopy = NULL;
|
||||
|
||||
if (recalctess && em) {
|
||||
if (recalc_looptri) {
|
||||
BKE_editmesh_looptri_calc(em);
|
||||
}
|
||||
}
|
||||
|
||||
void EDBM_redo_state_free(BMBackup *backup)
|
||||
{
|
||||
if (backup->bmcopy) {
|
||||
BM_mesh_data_free(backup->bmcopy);
|
||||
MEM_freeN(backup->bmcopy);
|
||||
}
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
|
Loading…
Reference in New Issue