WIP: GPv3: Convert legacy objects on file load #108671
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_gpencil_legacy_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_space_types.h"
|
||||
|
@ -39,6 +40,7 @@
|
|||
#include "BKE_colorband.h"
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_grease_pencil.hh"
|
||||
#include "BKE_idtype.h"
|
||||
#include "BKE_ipo.h"
|
||||
#include "BKE_keyconfig.h"
|
||||
|
@ -897,6 +899,35 @@ static void setup_app_data(bContext *C,
|
|||
BKE_lib_override_library_main_hierarchy_root_ensure(bmain);
|
||||
}
|
||||
|
||||
/* Convert all `OB_GPENCIL_LEGACY` to `OB_GREASE_PENCIL`. */
|
||||
if (mode != LOAD_UNDO && U.experimental.use_grease_pencil_version3 &&
|
||||
!blendfile_or_libraries_versions_atleast(bmain, 400, 3))
|
||||
|
||||
{
|
||||
LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
|
||||
Bastien Montagne
commented
Thish whole block should be its own function in GP BKE code, not exposed like that in generic readfile code. Thish whole block should be its own function in GP BKE code, not exposed like that in generic readfile code.
|
||||
if (ob->type == OB_GPENCIL_LEGACY) {
|
||||
BKE_reportf(reports->reports,
|
||||
RPT_WARNING,
|
||||
"Found legacy grease pencil object (%s), converting to new data type. Expect "
|
||||
"loss of data!",
|
||||
ob->id.name + 2);
|
||||
bGPdata *gpd = static_cast<bGPdata *>(ob->data);
|
||||
|
||||
GreasePencil *new_grease_pencil = static_cast<GreasePencil *>(
|
||||
BKE_id_new(bmain, ID_GP, ob->id.name + 2));
|
||||
blender::bke::greasepencil::convert::legacy_gpencil_to_grease_pencil(
|
||||
*bmain, *new_grease_pencil, *gpd);
|
||||
|
||||
id_us_min(&gpd->id);
|
||||
Bastien Montagne
commented
You probably want to delete these old bGPdata IDs when they have no more users. Another thing to consider here is what to do in case more than one GP object use the same bGPdata obdata. In fact, I think what you should rather do here is loop over bGPdata IDs, make a new version of each, remap ID pointers, and then go over all GP objects to update their types? You probably want to delete these old bGPdata IDs when they have no more users.
Another thing to consider here is what to do in case more than one GP object use the same bGPdata obdata.
In fact, I think what you should rather do here is loop over bGPdata IDs, make a new version of each, remap ID pointers, and then go over all GP objects to update their types?
|
||||
ob->data = new_grease_pencil;
|
||||
ob->type = OB_GREASE_PENCIL;
|
||||
|
||||
if (ob->mode == OB_MODE_EDIT_GPENCIL) {
|
||||
ob->mode = OB_MODE_EDIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmain->recovered = false;
|
||||
|
||||
/* startup.blend or recovered startup */
|
||||
|
|
Loading…
Reference in New Issue
This is most likely wrong, since user can still produce 'old' GP data currently in main?