forked from bartvdbraak/blender
py api: add Object.update_from_editmode(),
Useful for python exporters to avoid toggling editmode on export, moved into own function ED_object_editmode_load(obedit).
This commit is contained in:
parent
fa0e2603f5
commit
401fdf5065
@ -130,6 +130,7 @@ void ED_object_toggle_modes(struct bContext *C, int mode);
|
||||
#define EM_IGNORE_LAYER 16
|
||||
void ED_object_exit_editmode(struct bContext *C, int flag);
|
||||
void ED_object_enter_editmode(struct bContext *C, int flag);
|
||||
bool ED_object_editmode_load(struct Object *obedit);
|
||||
|
||||
void ED_object_location_from_view(struct bContext *C, float loc[3]);
|
||||
void ED_object_rotation_from_view(struct bContext *C, float rot[3]);
|
||||
|
@ -127,7 +127,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
|
||||
second_life = RNA_boolean_get(op->ptr, "second_life");
|
||||
|
||||
/* get editmode results */
|
||||
ED_object_exit_editmode(C, 0); /* 0 = does not exit editmode */
|
||||
ED_object_editmode_load(CTX_data_edit_object(C));
|
||||
|
||||
if (collada_export(CTX_data_scene(C),
|
||||
filepath,
|
||||
|
@ -572,7 +572,7 @@ static void init_bake_internal(BakeRender *bkr, bContext *C)
|
||||
bScreen *sc = CTX_wm_screen(C);
|
||||
|
||||
/* get editmode results */
|
||||
ED_object_exit_editmode(C, 0); /* 0 = does not exit editmode */
|
||||
ED_object_editmode_load(CTX_data_edit_object(C));
|
||||
|
||||
bkr->sa = sc ? BKE_screen_find_big_area(sc, SPACE_IMAGE, 10) : NULL; /* can be NULL */
|
||||
bkr->main = CTX_data_main(C);
|
||||
|
@ -312,25 +312,22 @@ void OBJECT_OT_hide_render_set(wmOperatorType *ot)
|
||||
|
||||
/* ******************* toggle editmode operator ***************** */
|
||||
|
||||
void ED_object_exit_editmode(bContext *C, int flag)
|
||||
/**
|
||||
* Load EditMode data back into the object,
|
||||
* optionally freeing the editmode data.
|
||||
*/
|
||||
static bool ED_object_editmode_load_ex(Object *obedit, const bool freedata)
|
||||
{
|
||||
/* Note! only in exceptional cases should 'EM_DO_UNDO' NOT be in the flag */
|
||||
if (obedit == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
Object *obedit = CTX_data_edit_object(C);
|
||||
int freedata = flag & EM_FREEDATA;
|
||||
|
||||
if (obedit == NULL) return;
|
||||
|
||||
if (flag & EM_WAITCURSOR) waitcursor(1);
|
||||
if (obedit->type == OB_MESH) {
|
||||
Mesh *me = obedit->data;
|
||||
|
||||
// if (EM_texFaceCheck())
|
||||
|
||||
if (me->edit_btmesh->bm->totvert > MESH_MAX_VERTS) {
|
||||
error("Too many vertices");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
EDBM_mesh_load(obedit);
|
||||
@ -367,6 +364,29 @@ void ED_object_exit_editmode(bContext *C, int flag)
|
||||
if (freedata) free_editMball(obedit);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ED_object_editmode_load(Object *obedit)
|
||||
{
|
||||
return ED_object_editmode_load_ex(obedit, false);
|
||||
}
|
||||
|
||||
void ED_object_exit_editmode(bContext *C, int flag)
|
||||
{
|
||||
/* Note! only in exceptional cases should 'EM_DO_UNDO' NOT be in the flag */
|
||||
/* Note! if 'EM_FREEDATA' isn't in the flag, use ED_object_editmode_load directly */
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
Object *obedit = CTX_data_edit_object(C);
|
||||
const bool freedata = (flag & EM_FREEDATA) != 0;
|
||||
|
||||
if (flag & EM_WAITCURSOR) waitcursor(1);
|
||||
|
||||
if (ED_object_editmode_load_ex(obedit, freedata) == false) {
|
||||
if (flag & EM_WAITCURSOR) waitcursor(0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* freedata only 0 now on file saves and render */
|
||||
if (freedata) {
|
||||
ListBase pidlist;
|
||||
@ -391,12 +411,12 @@ void ED_object_exit_editmode(bContext *C, int flag)
|
||||
if (flag & EM_DO_UNDO)
|
||||
ED_undo_push(C, "Editmode");
|
||||
|
||||
if (flag & EM_WAITCURSOR) waitcursor(0);
|
||||
|
||||
WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
|
||||
|
||||
obedit->mode &= ~OB_MODE_EDIT;
|
||||
}
|
||||
|
||||
if (flag & EM_WAITCURSOR) waitcursor(0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -542,7 +542,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even
|
||||
BKE_sequencer_cache_cleanup();
|
||||
|
||||
/* get editmode results */
|
||||
ED_object_exit_editmode(C, 0); /* 0 = does not exit editmode */
|
||||
ED_object_editmode_load(CTX_data_edit_object(C));
|
||||
|
||||
// store spare
|
||||
// get view3d layer, local layer, make this nice api call to render
|
||||
|
@ -391,6 +391,14 @@ void rna_Object_dm_info(struct Object *ob, int type, char *result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int rna_Object_update_from_editmode(Object *ob)
|
||||
{
|
||||
if (ob->mode & OB_MODE_EDIT) {
|
||||
return ED_object_editmode_load(ob);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif /* NDEBUG */
|
||||
|
||||
#else /* RNA_RUNTIME */
|
||||
@ -567,6 +575,11 @@ void RNA_api_object(StructRNA *srna)
|
||||
RNA_def_property_flag(parm, PROP_THICK_WRAP); /* needed for string return value */
|
||||
RNA_def_function_output(func, parm);
|
||||
#endif /* NDEBUG */
|
||||
|
||||
func = RNA_def_function(srna, "update_from_editmode", "rna_Object_update_from_editmode");
|
||||
RNA_def_function_ui_description(func, "Load the objects edit-mode data intp the object data");
|
||||
parm = RNA_def_boolean(func, "result", 0, "", "Success");
|
||||
RNA_def_function_return(func, parm);
|
||||
}
|
||||
|
||||
|
||||
|
@ -830,7 +830,7 @@ int wm_file_write(bContext *C, const char *target, int fileflags, ReportList *re
|
||||
packAll(G.main, reports);
|
||||
}
|
||||
|
||||
ED_object_exit_editmode(C, EM_DO_UNDO);
|
||||
ED_object_editmode_load(CTX_data_edit_object(C));
|
||||
ED_sculpt_force_update(C);
|
||||
|
||||
/* don't forget not to return without! */
|
||||
|
Loading…
Reference in New Issue
Block a user