GPv3: Minor Refactor of conversion code.
Essentially move the Object-handling logic also into `bke::greasepencil::convert::`. This code will also be needed for automatic conversion on fileread etc. It also helps to keep all the conversion logic in one place (especially since there is going to be way more done at object level - modifiers, animation, etc.). Pull Request: https://projects.blender.org/blender/blender/pulls/118384
This commit is contained in:
@@ -729,7 +729,9 @@ namespace convert {
|
||||
void legacy_gpencil_frame_to_grease_pencil_drawing(const bGPDframe &gpf,
|
||||
const ListBase &vertex_group_names,
|
||||
GreasePencilDrawing &r_drawing);
|
||||
void legacy_gpencil_to_grease_pencil(Main &main, GreasePencil &grease_pencil, bGPdata &gpd);
|
||||
void legacy_gpencil_to_grease_pencil(Main &bmain, GreasePencil &grease_pencil, bGPdata &gpd);
|
||||
|
||||
void legacy_gpencil_object(Main &bmain, Object &object);
|
||||
|
||||
} // namespace convert
|
||||
} // namespace greasepencil
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
#include "BKE_curves.hh"
|
||||
#include "BKE_deform.hh"
|
||||
#include "BKE_grease_pencil.hh"
|
||||
#include "BKE_lib_id.hh"
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_object.hh"
|
||||
|
||||
#include "BLI_color.hh"
|
||||
#include "BLI_listbase.h"
|
||||
@@ -334,4 +336,24 @@ void legacy_gpencil_to_grease_pencil(Main &bmain, GreasePencil &grease_pencil, b
|
||||
BKE_id_materials_copy(&bmain, &gpd.id, &grease_pencil.id);
|
||||
}
|
||||
|
||||
void legacy_gpencil_object(Main &bmain, Object &object)
|
||||
{
|
||||
bGPdata *gpd = static_cast<bGPdata *>(object.data);
|
||||
|
||||
GreasePencil *new_grease_pencil = static_cast<GreasePencil *>(
|
||||
BKE_id_new(&bmain, ID_GP, gpd->id.name + 2));
|
||||
object.data = new_grease_pencil;
|
||||
object.type = OB_GREASE_PENCIL;
|
||||
|
||||
/* NOTE: Could also use #BKE_id_free_us, to also free the legacy GP if not used anymore? */
|
||||
id_us_min(&gpd->id);
|
||||
/* No need to increase usercount of `new_grease_pencil`, since ID creation already set it
|
||||
* to 1. */
|
||||
|
||||
legacy_gpencil_to_grease_pencil(bmain, *new_grease_pencil, *gpd);
|
||||
|
||||
BKE_object_free_derived_caches(&object);
|
||||
BKE_object_free_modifiers(&object, 0);
|
||||
}
|
||||
|
||||
} // namespace blender::bke::greasepencil::convert
|
||||
|
||||
@@ -3222,8 +3222,6 @@ static int object_convert_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
ob->flag |= OB_DONE;
|
||||
|
||||
bGPdata *gpd = static_cast<bGPdata *>(ob->data);
|
||||
|
||||
if (keep_original) {
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
@@ -3231,21 +3229,7 @@ static int object_convert_exec(bContext *C, wmOperator *op)
|
||||
newob = ob;
|
||||
}
|
||||
|
||||
GreasePencil *new_grease_pencil = static_cast<GreasePencil *>(
|
||||
BKE_id_new(bmain, ID_GP, gpd->id.name + 2));
|
||||
newob->data = new_grease_pencil;
|
||||
newob->type = OB_GREASE_PENCIL;
|
||||
|
||||
/* NOTE: Could also use #BKE_id_free_us, to also free the legacy GP if not used anymore? */
|
||||
id_us_min(&gpd->id);
|
||||
/* No need to increase usercount of `new_grease_pencil`, since ID creation already set it
|
||||
* to 1. */
|
||||
|
||||
bke::greasepencil::convert::legacy_gpencil_to_grease_pencil(
|
||||
*bmain, *new_grease_pencil, *gpd);
|
||||
|
||||
BKE_object_free_derived_caches(newob);
|
||||
BKE_object_free_modifiers(newob, 0);
|
||||
bke::greasepencil::convert::legacy_gpencil_object(*bmain, *newob);
|
||||
}
|
||||
else if (target == OB_CURVES) {
|
||||
ob->flag |= OB_DONE;
|
||||
|
||||
Reference in New Issue
Block a user