Fix T63427: Annotations don'twork with 2.79 settings

The problem was the colors were not converted and the annotation flag was not enabled.

Note: For Scene data (View3D) there is a convert operator.
This commit is contained in:
Antonio Vazquez 2019-04-09 20:12:21 +02:00
parent 59955a297e
commit 009dbc2bc9
Notes: blender-bot 2023-02-14 06:00:49 +01:00
Referenced by issue #64515, Crashing During Render View and Render
Referenced by issue #63596, Keyframed group inputs bound to index not property
Referenced by issue #63562, Changing group input stack doesn't update group node-tree
Referenced by issue #63557, 2.8 Crashes on the startup
Referenced by issue #63538, Vector transform node with constant input difference in Cycles and Eevee
Referenced by issue #63472, Cursed blend file crashes on F12 render unless SSS is turned off.
Referenced by issue #63468, Volumetrics broken in current compiled version
Referenced by issue #63448, dragging in Image changes the resolution to square
Referenced by issue #63427, Annotations don't work with 2.79 settings
Referenced by issue #63377, "Principled Volume" node not working anymore in EEVEE.
Referenced by issue #61413, Grease Pencil crashes in 32-Bit version
3 changed files with 80 additions and 6 deletions

View File

@ -1069,7 +1069,7 @@ Material *BKE_gpencil_object_material_new(Main *bmain, Object *ob, const char *n
/* Returns the material for a brush with respect to its pinned state. */
Material *BKE_gpencil_object_material_get_from_brush(Object *ob, Brush *brush)
{
if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) {
if ((brush) && (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED)) {
Material *ma = BKE_gpencil_brush_material_get(brush);
return ma;
}
@ -1081,7 +1081,7 @@ Material *BKE_gpencil_object_material_get_from_brush(Object *ob, Brush *brush)
/* Returns the material index for a brush with respect to its pinned state. */
int BKE_gpencil_object_material_get_index_from_brush(Object *ob, Brush *brush)
{
if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) {
if ((brush) && (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED)) {
return BKE_gpencil_object_material_get_index(ob, brush->gpencil_settings->material);
}
else {

View File

@ -564,6 +564,28 @@ static void do_version_collection_propagate_lib_to_children(Collection *collecti
}
}
/** convert old annotations colors */
static void do_versions_fix_annotations(bGPdata *gpd)
{
for (const bGPDpalette *palette = gpd->palettes.first; palette; palette = palette->next) {
for (bGPDpalettecolor *palcolor = palette->colors.first; palcolor; palcolor = palcolor->next) {
/* fix layers */
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
if ((gps->colorname[0] != '\0') &&
(STREQ(gps->colorname, palcolor->info)))
{
/* copy color settings */
copy_v4_v4(gpl->color, palcolor->color);
}
}
}
}
}
}
}
void do_versions_after_linking_280(Main *bmain)
{
bool use_collection_compat_28 = true;
@ -657,6 +679,30 @@ void do_versions_after_linking_280(Main *bmain)
}
}
if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
for (SpaceLink *space = sa->spacedata.first; space; space = space->next) {
if (space->spacetype == SPACE_IMAGE) {
SpaceImage *sima = (SpaceImage *)space;
if ((sima) && (sima->gpd)) {
sima->gpd->flag |= GP_DATA_ANNOTATIONS;
do_versions_fix_annotations(sima->gpd);
}
}
if (space->spacetype == SPACE_CLIP) {
SpaceClip *spclip = (SpaceClip *)space;
MovieClip *clip = spclip->clip;
if ((clip) && (clip->gpd)) {
clip->gpd->flag |= GP_DATA_ANNOTATIONS;
do_versions_fix_annotations(clip->gpd);
}
}
}
}
}
}
/* New workspace design */
if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) {
do_version_workspaces_after_lib_link(bmain);

View File

@ -48,6 +48,9 @@
#include "WM_api.h"
#include "WM_types.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "ED_object.h"
#include "ED_gpencil.h"
@ -94,14 +97,16 @@ static bool gpencil_convert_old_files_poll(bContext *C)
return (int) (scene->gpd != NULL);
}
static int gpencil_convert_old_files_exec(bContext *C, wmOperator *UNUSED(op))
static int gpencil_convert_old_files_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
const bool is_annotation = RNA_boolean_get(op->ptr, "annotation");
bGPdata *gpd = scene->gpd;
/* Convert grease pencil scene datablock to GP object */
if ((scene->gpd) && (view_layer != NULL)) {
if ((!is_annotation) && (view_layer != NULL)) {
Object *ob;
ob = BKE_object_add_for_data(bmain, view_layer, OB_GPENCIL, "GP_Scene", &scene->gpd->id, false);
zero_v3(ob->loc);
@ -161,6 +166,26 @@ static int gpencil_convert_old_files_exec(bContext *C, wmOperator *UNUSED(op))
scene->gpd = NULL;
}
if (is_annotation) {
for (const bGPDpalette *palette = gpd->palettes.first; palette; palette = palette->next) {
for (bGPDpalettecolor *palcolor = palette->colors.first; palcolor; palcolor = palcolor->next) {
/* fix layers */
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
if ((gps->colorname[0] != '\0') &&
(STREQ(gps->colorname, palcolor->info)))
{
/* copy color settings */
copy_v4_v4(gpl->color, palcolor->color);
}
}
}
}
}
}
}
/* notifiers */
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@ -170,9 +195,9 @@ static int gpencil_convert_old_files_exec(bContext *C, wmOperator *UNUSED(op))
void GPENCIL_OT_convert_old_files(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Convert 2.7 Grease Pencil File";
ot->name = "Convert Grease Pencil";
ot->idname = "GPENCIL_OT_convert_old_files";
ot->description = "Convert 2.7x grease pencil files to 2.8";
ot->description = "Convert 2.7x grease pencil files to 2.80";
/* callbacks */
ot->exec = gpencil_convert_old_files_exec;
@ -180,4 +205,7 @@ void GPENCIL_OT_convert_old_files(wmOperatorType *ot)
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* props */
ot->prop = RNA_def_boolean(ot->srna, "annotation", 0, "Annotation", "Convert to Annotations");
}