diff options
Diffstat (limited to 'source/blender/blenloader/intern')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 223 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_270.c | 97 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_280.c | 447 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_defaults.c | 55 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 61 |
5 files changed, 613 insertions, 270 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 6cf8c968ed4..01ab4c0603a 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -3609,23 +3609,23 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree) } #if 0 - if (ntree->previews) { - bNodeInstanceHash *new_previews = BKE_node_instance_hash_new("node previews"); - bNodeInstanceHashIterator iter; - - NODE_INSTANCE_HASH_ITER(iter, ntree->previews) { - bNodePreview *preview = BKE_node_instance_hash_iterator_get_value(&iter); - if (preview) { - bNodePreview *new_preview = newimaadr(fd, preview); - if (new_preview) { - bNodeInstanceKey key = BKE_node_instance_hash_iterator_get_key(&iter); - BKE_node_instance_hash_insert(new_previews, key, new_preview); - } - } - } - BKE_node_instance_hash_free(ntree->previews, NULL); - ntree->previews = new_previews; - } + if (ntree->previews) { + bNodeInstanceHash* new_previews = BKE_node_instance_hash_new("node previews"); + bNodeInstanceHashIterator iter; + + NODE_INSTANCE_HASH_ITER(iter, ntree->previews) { + bNodePreview* preview = BKE_node_instance_hash_iterator_get_value(&iter); + if (preview) { + bNodePreview* new_preview = newimaadr(fd, preview); + if (new_preview) { + bNodeInstanceKey key = BKE_node_instance_hash_iterator_get_key(&iter); + BKE_node_instance_hash_insert(new_previews, key, new_preview); + } + } + } + BKE_node_instance_hash_free(ntree->previews, NULL); + ntree->previews = new_previews; + } #else /* XXX TODO */ ntree->previews = NULL; @@ -4084,10 +4084,10 @@ static void direct_link_text(FileData *fd, Text *text) text->compiled = NULL; #if 0 - if (text->flags & TXT_ISEXT) { - BKE_text_reload(text); - } - /* else { */ + if (text->flags & TXT_ISEXT) { + BKE_text_reload(text); + } + /* else { */ #endif link_list(fd, &text->lines); @@ -5071,7 +5071,7 @@ static void lib_link_object(FileData *fd, Main *bmain, Object *ob) * some leaked memory rather then crashing immediately * while bad this _is_ an exceptional case - campbell */ #if 0 - BKE_pose_free(ob->pose); + BKE_pose_free(ob->pose); #else MEM_freeN(ob->pose); #endif @@ -5540,15 +5540,15 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb, Object *ob) else if (md->type == eModifierType_Collision) { CollisionModifierData *collmd = (CollisionModifierData *)md; #if 0 - // TODO: CollisionModifier should use pointcache - // + have proper reset events before enabling this - collmd->x = newdataadr(fd, collmd->x); - collmd->xnew = newdataadr(fd, collmd->xnew); - collmd->mfaces = newdataadr(fd, collmd->mfaces); - - collmd->current_x = MEM_calloc_arrayN(collmd->numverts, sizeof(MVert), "current_x"); - collmd->current_xnew = MEM_calloc_arrayN(collmd->numverts, sizeof(MVert), "current_xnew"); - collmd->current_v = MEM_calloc_arrayN(collmd->numverts, sizeof(MVert), "current_v"); + // TODO: CollisionModifier should use pointcache + // + have proper reset events before enabling this + collmd->x = newdataadr(fd, collmd->x); + collmd->xnew = newdataadr(fd, collmd->xnew); + collmd->mfaces = newdataadr(fd, collmd->mfaces); + + collmd->current_x = MEM_calloc_arrayN(collmd->numverts, sizeof(MVert), "current_x"); + collmd->current_xnew = MEM_calloc_arrayN(collmd->numverts, sizeof(MVert), "current_xnew"); + collmd->current_v = MEM_calloc_arrayN(collmd->numverts, sizeof(MVert), "current_v"); #endif collmd->x = NULL; @@ -5752,16 +5752,66 @@ static void direct_link_gpencil_modifiers(FileData *fd, ListBase *lb) direct_link_curvemapping(fd, hmd->curfalloff); } } + else if (md->type == eGpencilModifierType_Noise) { + NoiseGpencilModifierData *gpmd = (NoiseGpencilModifierData *)md; + + gpmd->curve_intensity = newdataadr(fd, gpmd->curve_intensity); + if (gpmd->curve_intensity) { + direct_link_curvemapping(fd, gpmd->curve_intensity); + /* initialize the curve. Maybe this could be moved to modififer logic */ + BKE_curvemapping_initialize(gpmd->curve_intensity); + } + } else if (md->type == eGpencilModifierType_Thick) { ThickGpencilModifierData *gpmd = (ThickGpencilModifierData *)md; gpmd->curve_thickness = newdataadr(fd, gpmd->curve_thickness); if (gpmd->curve_thickness) { direct_link_curvemapping(fd, gpmd->curve_thickness); - /* initialize the curve. Maybe this could be moved to modififer logic */ BKE_curvemapping_initialize(gpmd->curve_thickness); } } + else if (md->type == eGpencilModifierType_Vertexcolor) { + VertexcolorGpencilModifierData *gpmd = (VertexcolorGpencilModifierData *)md; + gpmd->colorband = newdataadr(fd, gpmd->colorband); + gpmd->curve_intensity = newdataadr(fd, gpmd->curve_intensity); + if (gpmd->curve_intensity) { + direct_link_curvemapping(fd, gpmd->curve_intensity); + BKE_curvemapping_initialize(gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Smooth) { + SmoothGpencilModifierData *gpmd = (SmoothGpencilModifierData *)md; + gpmd->curve_intensity = newdataadr(fd, gpmd->curve_intensity); + if (gpmd->curve_intensity) { + direct_link_curvemapping(fd, gpmd->curve_intensity); + BKE_curvemapping_initialize(gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Color) { + ColorGpencilModifierData *gpmd = (ColorGpencilModifierData *)md; + gpmd->curve_intensity = newdataadr(fd, gpmd->curve_intensity); + if (gpmd->curve_intensity) { + direct_link_curvemapping(fd, gpmd->curve_intensity); + BKE_curvemapping_initialize(gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Tint) { + TintGpencilModifierData *gpmd = (TintGpencilModifierData *)md; + gpmd->curve_intensity = newdataadr(fd, gpmd->curve_intensity); + if (gpmd->curve_intensity) { + direct_link_curvemapping(fd, gpmd->curve_intensity); + BKE_curvemapping_initialize(gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Opacity) { + OpacityGpencilModifierData *gpmd = (OpacityGpencilModifierData *)md; + gpmd->curve_intensity = newdataadr(fd, gpmd->curve_intensity); + if (gpmd->curve_intensity) { + direct_link_curvemapping(fd, gpmd->curve_intensity); + BKE_curvemapping_initialize(gpmd->curve_intensity); + } + } } } @@ -6333,6 +6383,15 @@ static void lib_link_scene(FileData *fd, Main *UNUSED(bmain), Scene *sce) if (sce->toolsettings->gp_paint) { link_paint(fd, sce, &sce->toolsettings->gp_paint->paint); } + if (sce->toolsettings->gp_vertexpaint) { + link_paint(fd, sce, &sce->toolsettings->gp_vertexpaint->paint); + } + if (sce->toolsettings->gp_sculptpaint) { + link_paint(fd, sce, &sce->toolsettings->gp_sculptpaint->paint); + } + if (sce->toolsettings->gp_weightpaint) { + link_paint(fd, sce, &sce->toolsettings->gp_weightpaint->paint); + } if (sce->toolsettings->sculpt) { sce->toolsettings->sculpt->gravity_object = newlibadr( @@ -6615,6 +6674,9 @@ static void direct_link_scene(FileData *fd, Scene *sce) direct_link_paint_helper(fd, sce, (Paint **)&sce->toolsettings->wpaint); direct_link_paint_helper(fd, sce, (Paint **)&sce->toolsettings->uvsculpt); direct_link_paint_helper(fd, sce, (Paint **)&sce->toolsettings->gp_paint); + direct_link_paint_helper(fd, sce, (Paint **)&sce->toolsettings->gp_vertexpaint); + direct_link_paint_helper(fd, sce, (Paint **)&sce->toolsettings->gp_sculptpaint); + direct_link_paint_helper(fd, sce, (Paint **)&sce->toolsettings->gp_weightpaint); direct_link_paint(fd, sce, &sce->toolsettings->imapaint.paint); @@ -6895,7 +6957,7 @@ static void lib_link_gpencil(FileData *fd, Main *UNUSED(bmain), bGPdata *gpd) { /* Relink all data-lock linked by GP data-lock */ /* Layers */ - for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { /* Layer -> Parent References */ gpl->parent = newlibadr(fd, gpd->id.lib, gpl->parent); } @@ -6909,9 +6971,6 @@ static void lib_link_gpencil(FileData *fd, Main *UNUSED(bmain), bGPdata *gpd) /* relinks grease-pencil data - used for direct_link and old file linkage */ static void direct_link_gpencil(FileData *fd, bGPdata *gpd) { - bGPDlayer *gpl; - bGPDframe *gpf; - bGPDstroke *gps; bGPDpalette *palette; /* we must firstly have some grease-pencil data to link! */ @@ -6929,6 +6988,7 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd) gpd->flag &= ~GP_DATA_STROKE_EDITMODE; gpd->flag &= ~GP_DATA_STROKE_SCULPTMODE; gpd->flag &= ~GP_DATA_STROKE_WEIGHTMODE; + gpd->flag &= ~GP_DATA_STROKE_VERTEXMODE; } /* init stroke buffer */ @@ -6952,7 +7012,7 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd) /* relink layers */ link_list(fd, &gpd->layers); - for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { /* relink frames */ link_list(fd, &gpl->frames); @@ -6960,24 +7020,24 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd) gpl->runtime.icon_id = 0; - for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { + /* Relink masks. */ + link_list(fd, &gpl->mask_layers); + + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { /* relink strokes (and their points) */ link_list(fd, &gpf->strokes); - for (gps = gpf->strokes.first; gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { /* relink stroke points array */ gps->points = newdataadr(fd, gps->points); + /* Relink geometry*/ + gps->triangles = newdataadr(fd, gps->triangles); /* relink weight data */ if (gps->dvert) { gps->dvert = newdataadr(fd, gps->dvert); direct_link_dverts(fd, gps->totpoints, gps->dvert); } - - /* the triangulation is not saved, so need to be recalculated */ - gps->triangles = NULL; - gps->tot_triangles = 0; - gps->flag |= GP_STROKE_RECALC_GEOMETRY; } } } @@ -7198,10 +7258,10 @@ static void direct_link_area(FileData *fd, ScrArea *area) * so sacrifice a few old files for now to avoid crashes with new files! * committed: r28002 */ #if 0 - sima->gpd = newdataadr(fd, sima->gpd); - if (sima->gpd) { - direct_link_gpencil(fd, sima->gpd); - } + sima->gpd = newdataadr(fd, sima->gpd); + if (sima->gpd) { + direct_link_gpencil(fd, sima->gpd); + } #endif } else if (sl->spacetype == SPACE_NODE) { @@ -7232,10 +7292,10 @@ static void direct_link_area(FileData *fd, ScrArea *area) * simple return NULL here (sergey) */ #if 0 - if (sseq->gpd) { - sseq->gpd = newdataadr(fd, sseq->gpd); - direct_link_gpencil(fd, sseq->gpd); - } + if (sseq->gpd) { + sseq->gpd = newdataadr(fd, sseq->gpd); + direct_link_gpencil(fd, sseq->gpd); + } #endif sseq->scopes.reference_ibuf = NULL; sseq->scopes.zebra_ibuf = NULL; @@ -7906,11 +7966,11 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map, sima->iuser.scene = NULL; #if 0 - /* Those are allocated and freed by space code, no need to handle them here. */ - MEM_SAFE_FREE(sima->scopes.waveform_1); - MEM_SAFE_FREE(sima->scopes.waveform_2); - MEM_SAFE_FREE(sima->scopes.waveform_3); - MEM_SAFE_FREE(sima->scopes.vecscope); + /* Those are allocated and freed by space code, no need to handle them here. */ + MEM_SAFE_FREE(sima->scopes.waveform_1); + MEM_SAFE_FREE(sima->scopes.waveform_2); + MEM_SAFE_FREE(sima->scopes.waveform_3); + MEM_SAFE_FREE(sima->scopes.vecscope); #endif sima->scopes.ok = 0; @@ -8281,8 +8341,8 @@ static void direct_link_speaker(FileData *fd, Speaker *spk) direct_link_animdata(fd, spk->adt); #if 0 - spk->sound = newdataadr(fd, spk->sound); - direct_link_sound(fd, spk->sound); + spk->sound = newdataadr(fd, spk->sound); + direct_link_sound(fd, spk->sound); #endif } @@ -8905,12 +8965,12 @@ static BHead *read_data_into_oldnewmap(FileData *fd, BHead *bhead, const char *a while (bhead && bhead->code == DATA) { void *data; #if 0 - /* XXX DUMB DEBUGGING OPTION TO GIVE NAMES for guarded malloc errors */ - short *sp = fd->filesdna->structs[bhead->SDNAnr]; - char *tmp = malloc(100); - allocname = fd->filesdna->types[sp[0]]; - strcpy(tmp, allocname); - data = read_struct(fd, bhead, tmp); + /* XXX DUMB DEBUGGING OPTION TO GIVE NAMES for guarded malloc errors */ + short* sp = fd->filesdna->structs[bhead->SDNAnr]; + char* tmp = malloc(100); + allocname = fd->filesdna->types[sp[0]]; + strcpy(tmp, allocname); + data = read_struct(fd, bhead, tmp); #else data = read_struct(fd, bhead, allocname); #endif @@ -9309,11 +9369,6 @@ static void do_versions_userdef(FileData *fd, BlendFileData *bfd) user->walk_navigation.teleport_time = 0.2f; /* s */ } - /* grease pencil multisamples */ - if (!DNA_struct_elem_find(fd->filesdna, "UserDef", "short", "gpencil_multisamples")) { - user->gpencil_multisamples = 4; - } - /* tablet pressure threshold */ if (!DNA_struct_elem_find(fd->filesdna, "UserDef", "float", "pressure_threshold_max")) { user->pressure_threshold_max = 1.0f; @@ -9722,7 +9777,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath) bhead = read_libblock(fd, libmain, bhead, 0, true, NULL); } break; - /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ + /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ case ID_SCRN: bhead->code = ID_SCR; /* pass on to default */ @@ -9877,7 +9932,7 @@ static BHead *find_previous_lib(FileData *fd, BHead *bhead) static BHead *find_bhead(FileData *fd, void *old) { #if 0 - BHead *bhead; + BHead* bhead; #endif struct BHeadSort *bhs, bhs_s; @@ -9897,11 +9952,11 @@ static BHead *find_bhead(FileData *fd, void *old) } #if 0 - for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) { - if (bhead->old == old) { - return bhead; - } - } + for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) { + if (bhead->old == old) { + return bhead; + } + } #endif return NULL; @@ -10032,9 +10087,9 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old) /* Commented because this can print way too much. */ #if 0 - if (G.debug & G_DEBUG) { - printf("expand_doit: already linked: %s lib: %s\n", id->name, lib->name); - } + if (G.debug & G_DEBUG) { + printf("expand_doit: already linked: %s lib: %s\n", id->name, lib->name); + } #endif } @@ -10870,7 +10925,7 @@ static void expand_linestyle(FileData *fd, Main *mainvar, FreestyleLineStyle *li static void expand_gpencil(FileData *fd, Main *mainvar, bGPdata *gpd) { - for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { expand_doit(fd, mainvar, gpl->parent); } @@ -11813,9 +11868,9 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) /* Does this library have any more linked data-blocks we need to read? */ if (has_linked_ids_to_read(mainptr)) { #if 0 - printf("Reading linked data-blocks from %s (%s)\n", - mainptr->curlib->id.name, - mainptr->curlib->name); + printf("Reading linked data-blocks from %s (%s)\n", + mainptr->curlib->id.name, + mainptr->curlib->name); #endif /* Open file if it has not been done yet. */ diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index df946168056..4500de7bbec 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1116,80 +1116,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) if (!MAIN_VERSION_ATLEAST(bmain, 276, 4)) { for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { ToolSettings *ts = scene->toolsettings; - - if (ts->gp_sculpt.brush[0].size == 0) { - GP_Sculpt_Settings *gset = &ts->gp_sculpt; - GP_Sculpt_Data *brush; - - brush = &gset->brush[GP_SCULPT_TYPE_SMOOTH]; - brush->size = 25; - brush->strength = 0.3f; - brush->flag = GP_SCULPT_FLAG_USE_FALLOFF | GP_SCULPT_FLAG_SMOOTH_PRESSURE; - - brush = &gset->brush[GP_SCULPT_TYPE_THICKNESS]; - brush->size = 25; - brush->strength = 0.5f; - brush->flag = GP_SCULPT_FLAG_USE_FALLOFF; - - brush = &gset->brush[GP_SCULPT_TYPE_GRAB]; - brush->size = 50; - brush->strength = 0.3f; - brush->flag = GP_SCULPT_FLAG_USE_FALLOFF; - - brush = &gset->brush[GP_SCULPT_TYPE_PUSH]; - brush->size = 25; - brush->strength = 0.3f; - brush->flag = GP_SCULPT_FLAG_USE_FALLOFF; - - brush = &gset->brush[GP_SCULPT_TYPE_TWIST]; - brush->size = 50; - brush->strength = 0.3f; // XXX? - brush->flag = GP_SCULPT_FLAG_USE_FALLOFF; - - brush = &gset->brush[GP_SCULPT_TYPE_PINCH]; - brush->size = 50; - brush->strength = 0.5f; // XXX? - brush->flag = GP_SCULPT_FLAG_USE_FALLOFF; - - brush = &gset->brush[GP_SCULPT_TYPE_RANDOMIZE]; - brush->size = 25; - brush->strength = 0.5f; - brush->flag = GP_SCULPT_FLAG_USE_FALLOFF; - - brush = &gset->brush[GP_SCULPT_TYPE_CLONE]; - brush->size = 50; - brush->strength = 1.0f; - } - if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "gpencil_v3d_align")) { -#if 0 /* XXX: Cannot do this, as we get random crashes... */ - if (scene->gpd) { - bGPdata *gpd = scene->gpd; - - /* Copy over the settings stored in the GP data-block linked to the scene, - * for minimal disruption. */ - ts->gpencil_v3d_align = 0; - - if (gpd->flag & GP_DATA_VIEWALIGN) { - ts->gpencil_v3d_align |= GP_PROJECT_VIEWSPACE; - } - if (gpd->flag & GP_DATA_DEPTH_VIEW) { - ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_VIEW; - } - if (gpd->flag & GP_DATA_DEPTH_STROKE) { - ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE; - } - - if (gpd->flag & GP_DATA_DEPTH_STROKE_ENDPOINTS) { - ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE_ENDPOINTS; - } - } - else { - /* Default to cursor for all standard 3D views */ - ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE; - } -#endif - ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE; ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE; ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE; @@ -1203,7 +1130,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) /* Ensure that the datablock's onion-skinning toggle flag * stays in sync with the status of the actual layers */ - for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { if (gpl->flag & GP_LAYER_ONIONSKIN) { enabled = true; } @@ -1424,22 +1351,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) if (!MAIN_VERSION_ATLEAST(bmain, 277, 3)) { /* ------- init of grease pencil initialization --------------- */ if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "bGPDpalettecolor", "*palcolor")) { - for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { - ToolSettings *ts = scene->toolsettings; - /* initialize use position for sculpt brushes */ - ts->gp_sculpt.flag |= GP_SCULPT_SETT_FLAG_APPLY_POSITION; - - /* new strength sculpt brush */ - if (ts->gp_sculpt.brush[0].size >= 11) { - GP_Sculpt_Settings *gset = &ts->gp_sculpt; - GP_Sculpt_Data *brush; - - brush = &gset->brush[GP_SCULPT_TYPE_STRENGTH]; - brush->size = 25; - brush->strength = 0.5f; - brush->flag = GP_SCULPT_FLAG_USE_FALLOFF; - } - } /* Convert Grease Pencil to new palettes/brushes * Loop all strokes and create the palette and all colors */ @@ -1447,7 +1358,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) if (BLI_listbase_is_empty(&gpd->palettes)) { /* create palette */ bGPDpalette *palette = BKE_gpencil_palette_addnew(gpd, "GP_Palette"); - for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { /* create color using layer name */ bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_addnew(palette, gpl->info); if (palcolor != NULL) { @@ -1475,8 +1386,8 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) ARRAY_SET_ITEMS(gpl->tintcolor, 0.0f, 0.0f, 0.0f, 0.0f); /* flush relevant layer-settings to strokes */ - for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { - for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { /* set stroke to palette and force recalculation */ BLI_strncpy(gps->colorname, gpl->info, sizeof(gps->colorname)); gps->thickness = gpl->thickness; diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index e29c4f8658f..2035ee3590f 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -52,6 +52,7 @@ #include "DNA_rigidbody_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" +#include "DNA_shader_fx_types.h" #include "DNA_view3d_types.h" #include "DNA_genfile.h" #include "DNA_workspace_types.h" @@ -63,6 +64,7 @@ #include "DNA_world_types.h" #include "BKE_animsys.h" +#include "BKE_brush.h" #include "BKE_cloth.h" #include "BKE_collection.h" #include "BKE_constraint.h" @@ -71,6 +73,8 @@ #include "BKE_fcurve.h" #include "BKE_freestyle.h" #include "BKE_global.h" +#include "BKE_gpencil.h" +#include "BKE_gpencil_modifier.h" #include "BKE_idprop.h" #include "BKE_key.h" #include "BKE_lib_id.h" @@ -573,7 +577,7 @@ 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) { + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { /* unlock/unhide layer */ gpl->flag &= ~GP_LAYER_LOCKED; gpl->flag &= ~GP_LAYER_HIDE; @@ -582,8 +586,8 @@ static void do_versions_fix_annotations(bGPdata *gpd) /* disable tint */ gpl->tintcolor[3] = 0.0f; - for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { - for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { if ((gps->colorname[0] != '\0') && (STREQ(gps->colorname, palcolor->info))) { /* copy color settings */ copy_v4_v4(gpl->color, palcolor->color); @@ -1057,6 +1061,48 @@ static void do_version_curvemapping_walker(Main *bmain, void (*callback)(CurveMa callback(gpmd->curfalloff); } } + else if (md->type == eGpencilModifierType_Noise) { + NoiseGpencilModifierData *gpmd = (NoiseGpencilModifierData *)md; + + if (gpmd->curve_intensity) { + callback(gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Vertexcolor) { + VertexcolorGpencilModifierData *gpmd = (VertexcolorGpencilModifierData *)md; + + if (gpmd->curve_intensity) { + callback(gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Smooth) { + SmoothGpencilModifierData *gpmd = (SmoothGpencilModifierData *)md; + + if (gpmd->curve_intensity) { + callback(gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Color) { + ColorGpencilModifierData *gpmd = (ColorGpencilModifierData *)md; + + if (gpmd->curve_intensity) { + callback(gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Opacity) { + OpacityGpencilModifierData *gpmd = (OpacityGpencilModifierData *)md; + + if (gpmd->curve_intensity) { + callback(gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Tint) { + TintGpencilModifierData *gpmd = (TintGpencilModifierData *)md; + + if (gpmd->curve_intensity) { + callback(gpmd->curve_intensity); + } + } } } @@ -1554,7 +1600,7 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports)) if (gpd == NULL) { continue; } - for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { if (STREQ(gpl->info, "RulerData3D")) { gpl->flag |= GP_LAYER_IS_RULER; break; @@ -1588,6 +1634,34 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports)) } } + if (!MAIN_VERSION_ATLEAST(bmain, 282, 2)) { + /* Init all Vertex/Sculpt and Weight Paint brushes. */ + Brush *brush = BLI_findstring(&bmain->brushes, "Pencil", offsetof(ID, name) + 2); + for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { + ToolSettings *ts = scene->toolsettings; + + BKE_brush_gpencil_vertex_presets(bmain, ts); + BKE_brush_gpencil_sculpt_presets(bmain, ts); + BKE_brush_gpencil_weight_presets(bmain, ts); + + /* Ensure new Paint modes. */ + BKE_paint_ensure_from_paintmode(scene, PAINT_MODE_GPENCIL); + BKE_paint_ensure_from_paintmode(scene, PAINT_MODE_VERTEX_GPENCIL); + BKE_paint_ensure_from_paintmode(scene, PAINT_MODE_SCULPT_GPENCIL); + BKE_paint_ensure_from_paintmode(scene, PAINT_MODE_WEIGHT_GPENCIL); + + /* Set default Draw brush. */ + if (brush != NULL) { + Paint *paint = &ts->gp_paint->paint; + BKE_paint_brush_set(paint, brush); + /* Enable cursor by default. */ + paint->flags |= PAINT_SHOW_BRUSH; + } + /* Ensure Palette by default. */ + BKE_gpencil_palette_ensure(bmain, scene); + } + } + /** * Versioning code until next subversion bump goes here. * @@ -1774,36 +1848,6 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) #endif { - /* Grease pencil sculpt and paint cursors */ - if (!DNA_struct_elem_find(fd->filesdna, "GP_Sculpt_Settings", "int", "weighttype")) { - for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { - /* sculpt brushes */ - GP_Sculpt_Settings *gset = &scene->toolsettings->gp_sculpt; - if (gset) { - gset->weighttype = GP_SCULPT_TYPE_WEIGHT; - } - } - } - - { - float curcolor_add[3], curcolor_sub[3]; - ARRAY_SET_ITEMS(curcolor_add, 1.0f, 0.6f, 0.6f); - ARRAY_SET_ITEMS(curcolor_sub, 0.6f, 0.6f, 1.0f); - GP_Sculpt_Data *gp_brush; - - for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { - ToolSettings *ts = scene->toolsettings; - /* sculpt brushes */ - GP_Sculpt_Settings *gset = &ts->gp_sculpt; - for (int i = 0; i < GP_SCULPT_TYPE_MAX; i++) { - gp_brush = &gset->brush[i]; - gp_brush->flag |= GP_SCULPT_FLAG_ENABLE_CURSOR; - copy_v3_v3(gp_brush->curcolor_add, curcolor_add); - copy_v3_v3(gp_brush->curcolor_sub, curcolor_sub); - } - } - } - /* Init grease pencil edit line color */ if (!DNA_struct_elem_find(fd->filesdna, "bGPdata", "float", "line_color[4]")) { for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) { @@ -1866,8 +1910,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (!MAIN_VERSION_ATLEAST(bmain, 280, 3)) { /* init grease pencil grids and paper */ - if (!DNA_struct_elem_find( - fd->filesdna, "gp_paper_opacity", "float", "gpencil_paper_color[3]")) { + if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "gpencil_paper_color[3]")) { for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) { for (ScrArea *area = screen->areabase.first; area; area = area->next) { for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) { @@ -2621,7 +2664,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } if (!DNA_struct_elem_find(fd->filesdna, "bGPDlayer", "short", "line_change")) { for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) { - for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { gpl->line_change = gpl->thickness; if ((gpl->thickness < 1) || (gpl->thickness > 10)) { gpl->thickness = 3; @@ -2953,34 +2996,13 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) /* grease pencil main material show switches */ for (Material *mat = bmain->materials.first; mat; mat = mat->id.next) { if (mat->gp_style) { - mat->gp_style->flag |= GP_STYLE_STROKE_SHOW; - mat->gp_style->flag |= GP_STYLE_FILL_SHOW; + mat->gp_style->flag |= GP_MATERIAL_STROKE_SHOW; + mat->gp_style->flag |= GP_MATERIAL_FILL_SHOW; } } } if (!MAIN_VERSION_ATLEAST(bmain, 280, 33)) { - /* Grease pencil reset sculpt brushes after struct rename */ - if (!DNA_struct_elem_find(fd->filesdna, "GP_Sculpt_Settings", "int", "weighttype")) { - float curcolor_add[3], curcolor_sub[3]; - ARRAY_SET_ITEMS(curcolor_add, 1.0f, 0.6f, 0.6f); - ARRAY_SET_ITEMS(curcolor_sub, 0.6f, 0.6f, 1.0f); - - for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { - /* sculpt brushes */ - GP_Sculpt_Settings *gset = &scene->toolsettings->gp_sculpt; - if (gset) { - for (int i = 0; i < GP_SCULPT_TYPE_MAX; i++) { - GP_Sculpt_Data *gp_brush = &gset->brush[i]; - gp_brush->size = 30; - gp_brush->strength = 0.5f; - gp_brush->flag = GP_SCULPT_FLAG_USE_FALLOFF | GP_SCULPT_FLAG_ENABLE_CURSOR; - copy_v3_v3(gp_brush->curcolor_add, curcolor_add); - copy_v3_v3(gp_brush->curcolor_sub, curcolor_sub); - } - } - } - } if (!DNA_struct_elem_find(fd->filesdna, "SceneEEVEE", "float", "overscan")) { for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { @@ -3214,7 +3236,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) /* init Annotations onion skin */ if (!DNA_struct_elem_find(fd->filesdna, "bGPDlayer", "int", "gstep")) { for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) { - for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { ARRAY_SET_ITEMS(gpl->gcolor_prev, 0.302f, 0.851f, 0.302f); ARRAY_SET_ITEMS(gpl->gcolor_next, 0.250f, 0.1f, 1.0f); } @@ -3420,20 +3442,6 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } } - /* Grease pencil target weight */ - if (!DNA_struct_elem_find(fd->filesdna, "GP_Sculpt_Settings", "float", "weight")) { - for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { - /* sculpt brushes */ - GP_Sculpt_Settings *gset = &scene->toolsettings->gp_sculpt; - if (gset) { - for (int i = 0; i < GP_SCULPT_TYPE_MAX; i++) { - GP_Sculpt_Data *gp_brush = &gset->brush[i]; - gp_brush->weight = 1.0f; - } - } - } - } - /* Grease pencil cutter/select segment intersection threshold */ if (!DNA_struct_elem_find(fd->filesdna, "GP_Sculpt_Settings", "float", "isect_threshold")) { for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { @@ -3653,7 +3661,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (gpd->flag & GP_DATA_ANNOTATIONS) { continue; } - for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { /* default channel color */ ARRAY_SET_ITEMS(gpl->color, 0.2f, 0.2f, 0.2f); } @@ -3744,26 +3752,24 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } /* init grease pencil brush gradients */ - if (!DNA_struct_elem_find(fd->filesdna, "BrushGpencilSettings", "float", "gradient_f")) { + if (!DNA_struct_elem_find(fd->filesdna, "BrushGpencilSettings", "float", "hardeness")) { for (Brush *brush = bmain->brushes.first; brush; brush = brush->id.next) { if (brush->gpencil_settings != NULL) { BrushGpencilSettings *gp = brush->gpencil_settings; - gp->gradient_f = 1.0f; - gp->gradient_s[0] = 1.0f; - gp->gradient_s[1] = 1.0f; + gp->hardeness = 1.0f; + copy_v2_fl(gp->aspect_ratio, 1.0f); } } } /* init grease pencil stroke gradients */ - if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "float", "gradient_f")) { + if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "float", "hardeness")) { for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) { - 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) { - gps->gradient_f = 1.0f; - gps->gradient_s[0] = 1.0f; - gps->gradient_s[1] = 1.0f; + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { + gps->hardeness = 1.0f; + copy_v2_fl(gps->aspect_ratio, 1.0f); } } } @@ -4217,7 +4223,6 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } } - /* Fix wrong 3D viewport copying causing corrupt pointers (T69974). */ for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) { for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { @@ -4507,6 +4512,272 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } } + if (!MAIN_VERSION_ATLEAST(bmain, 283, 7)) { + /* Init default Grease Pencil Vertex paint mix factor for Viewport. */ + if (!DNA_struct_elem_find( + fd->filesdna, "View3DOverlay", "float", "gpencil_vertex_paint_opacity")) { + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->overlay.gpencil_vertex_paint_opacity = 1.0f; + } + } + } + } + } + + /* Update Grease Pencil after drawing engine and code refactor. + * It uses the seed variable of Array modifier to avoid double patching for + * files created with a development version. */ + if (!DNA_struct_elem_find(fd->filesdna, "ArrayGpencilModifierData", "int", "seed")) { + /* Init new Grease Pencil Paint tools. */ + { + LISTBASE_FOREACH (Brush *, brush, &bmain->brushes) { + if (brush->gpencil_settings != NULL) { + brush->gpencil_vertex_tool = brush->gpencil_settings->brush_type; + brush->gpencil_sculpt_tool = brush->gpencil_settings->brush_type; + brush->gpencil_weight_tool = brush->gpencil_settings->brush_type; + } + } + + BKE_paint_toolslots_init_from_main(bmain); + } + + LISTBASE_FOREACH (Material *, mat, &bmain->materials) { + MaterialGPencilStyle *gp_style = mat->gp_style; + if (gp_style == NULL) { + continue; + } + /* Fix Grease Pencil Material colors to Linear. */ + srgb_to_linearrgb_v4(gp_style->stroke_rgba, gp_style->stroke_rgba); + srgb_to_linearrgb_v4(gp_style->fill_rgba, gp_style->fill_rgba); + + /* Move old gradient variables to texture. */ + if (gp_style->fill_style == GP_MATERIAL_FILL_STYLE_GRADIENT) { + gp_style->texture_angle = gp_style->gradient_angle; + copy_v2_v2(gp_style->texture_scale, gp_style->gradient_scale); + copy_v2_v2(gp_style->texture_offset, gp_style->gradient_shift); + } + /* Set Checker material as Solid. This fill mode has been removed and replaced + * by textures. */ + if (gp_style->fill_style == GP_MATERIAL_FILL_STYLE_CHECKER) { + gp_style->fill_style = GP_MATERIAL_FILL_STYLE_SOLID; + } + /* Update Alpha channel for texture opacity. */ + if (gp_style->fill_style == GP_MATERIAL_FILL_STYLE_TEXTURE) { + gp_style->fill_rgba[3] *= gp_style->texture_opacity; + } + /* Stroke stencil mask to mix = 1. */ + if (gp_style->flag & GP_MATERIAL_STROKE_PATTERN) { + gp_style->mix_stroke_factor = 1.0f; + gp_style->flag &= ~GP_MATERIAL_STROKE_PATTERN; + } + /* Mix disabled, set mix factor to 0. */ + else if ((gp_style->flag & GP_MATERIAL_STROKE_TEX_MIX) == 0) { + gp_style->mix_stroke_factor = 0.0f; + } + } + + /* Fix Grease Pencil VFX and modifiers. */ + LISTBASE_FOREACH (Object *, ob, &bmain->objects) { + if (ob->type != OB_GPENCIL) { + continue; + } + + /* VFX. */ + LISTBASE_FOREACH (ShaderFxData *, fx, &ob->shader_fx) { + switch (fx->type) { + case eShaderFxType_Colorize: { + ColorizeShaderFxData *vfx = (ColorizeShaderFxData *)fx; + if (ELEM(vfx->mode, eShaderFxColorizeMode_GrayScale, eShaderFxColorizeMode_Sepia)) { + vfx->factor = 1.0f; + } + srgb_to_linearrgb_v4(vfx->low_color, vfx->low_color); + srgb_to_linearrgb_v4(vfx->high_color, vfx->high_color); + break; + } + case eShaderFxType_Pixel: { + PixelShaderFxData *vfx = (PixelShaderFxData *)fx; + srgb_to_linearrgb_v4(vfx->rgba, vfx->rgba); + break; + } + case eShaderFxType_Rim: { + RimShaderFxData *vfx = (RimShaderFxData *)fx; + srgb_to_linearrgb_v3_v3(vfx->rim_rgb, vfx->rim_rgb); + srgb_to_linearrgb_v3_v3(vfx->mask_rgb, vfx->mask_rgb); + break; + } + case eShaderFxType_Shadow: { + ShadowShaderFxData *vfx = (ShadowShaderFxData *)fx; + srgb_to_linearrgb_v4(vfx->shadow_rgba, vfx->shadow_rgba); + break; + } + case eShaderFxType_Glow: { + GlowShaderFxData *vfx = (GlowShaderFxData *)fx; + srgb_to_linearrgb_v3_v3(vfx->glow_color, vfx->glow_color); + vfx->glow_color[3] = 1.0f; + srgb_to_linearrgb_v3_v3(vfx->select_color, vfx->select_color); + vfx->blur[1] = vfx->blur[0]; + break; + } + default: + break; + } + } + + /* Modifiers. */ + LISTBASE_FOREACH (GpencilModifierData *, md, &ob->greasepencil_modifiers) { + switch ((GpencilModifierType)md->type) { + case eGpencilModifierType_Array: { + ArrayGpencilModifierData *mmd = (ArrayGpencilModifierData *)md; + mmd->seed = 1; + if ((mmd->offset[0] != 0.0f) || (mmd->offset[1] != 0.0f) || + (mmd->offset[2] != 0.0f)) { + mmd->flag |= GP_ARRAY_USE_OFFSET; + } + if ((mmd->shift[0] != 0.0f) || (mmd->shift[1] != 0.0f) || (mmd->shift[2] != 0.0f)) { + mmd->flag |= GP_ARRAY_USE_OFFSET; + } + if (mmd->object != NULL) { + mmd->flag |= GP_ARRAY_USE_OB_OFFSET; + } + break; + } + case eGpencilModifierType_Noise: { + NoiseGpencilModifierData *mmd = (NoiseGpencilModifierData *)md; + mmd->factor /= 25.0f; + mmd->factor_thickness = mmd->factor; + mmd->factor_strength = mmd->factor; + mmd->factor_uvs = mmd->factor; + mmd->noise_scale = (mmd->flag & GP_NOISE_FULL_STROKE) ? 0.0f : 1.0f; + + if (mmd->curve_intensity == NULL) { + mmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + if (mmd->curve_intensity) { + BKE_curvemapping_initialize(mmd->curve_intensity); + } + } + break; + } + case eGpencilModifierType_Tint: { + TintGpencilModifierData *mmd = (TintGpencilModifierData *)md; + srgb_to_linearrgb_v3_v3(mmd->rgb, mmd->rgb); + if (mmd->curve_intensity == NULL) { + mmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + if (mmd->curve_intensity) { + BKE_curvemapping_initialize(mmd->curve_intensity); + } + } + break; + } + case eGpencilModifierType_Smooth: { + SmoothGpencilModifierData *mmd = (SmoothGpencilModifierData *)md; + if (mmd->curve_intensity == NULL) { + mmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + if (mmd->curve_intensity) { + BKE_curvemapping_initialize(mmd->curve_intensity); + } + } + break; + } + case eGpencilModifierType_Opacity: { + OpacityGpencilModifierData *mmd = (OpacityGpencilModifierData *)md; + if (mmd->curve_intensity == NULL) { + mmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + if (mmd->curve_intensity) { + BKE_curvemapping_initialize(mmd->curve_intensity); + } + } + break; + } + case eGpencilModifierType_Color: { + ColorGpencilModifierData *mmd = (ColorGpencilModifierData *)md; + if (mmd->curve_intensity == NULL) { + mmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + if (mmd->curve_intensity) { + BKE_curvemapping_initialize(mmd->curve_intensity); + } + } + break; + } + case eGpencilModifierType_Thick: { + if (!DNA_struct_elem_find( + fd->filesdna, "ThickGpencilModifierData", "float", "thickness_fac")) { + ThickGpencilModifierData *mmd = (ThickGpencilModifierData *)md; + mmd->thickness_fac = mmd->thickness; + } + break; + } + case eGpencilModifierType_Multiply: { + MultiplyGpencilModifierData *mmd = (MultiplyGpencilModifierData *)md; + mmd->fading_opacity = 1.0 - mmd->fading_opacity; + break; + } + case eGpencilModifierType_Subdiv: { + const short simple = (1 << 0); + SubdivGpencilModifierData *mmd = (SubdivGpencilModifierData *)md; + if (mmd->flag & simple) { + mmd->flag &= ~simple; + mmd->type = GP_SUBDIV_SIMPLE; + } + break; + } + case eGpencilModifierType_Vertexcolor: { + VertexcolorGpencilModifierData *mmd = (VertexcolorGpencilModifierData *)md; + if (mmd->curve_intensity == NULL) { + mmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + if (mmd->curve_intensity) { + BKE_curvemapping_initialize(mmd->curve_intensity); + } + } + break; + } + default: + break; + } + } + } + + /* Fix Layers Colors and Vertex Colors to Linear. + * Also set lights to on for layers. */ + LISTBASE_FOREACH (bGPdata *, gpd, &bmain->gpencils) { + if (gpd->flag & GP_DATA_ANNOTATIONS) { + continue; + } + /* Onion colors. */ + srgb_to_linearrgb_v3_v3(gpd->gcolor_prev, gpd->gcolor_prev); + srgb_to_linearrgb_v3_v3(gpd->gcolor_next, gpd->gcolor_next); + /* Z-depth Offset. */ + gpd->zdepth_offset = 0.150f; + + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + gpl->flag |= GP_LAYER_USE_LIGHTS; + srgb_to_linearrgb_v4(gpl->tintcolor, gpl->tintcolor); + gpl->vertex_paint_opacity = 1.0f; + + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { + /* Set initial opacity for fill color. */ + gps->fill_opacity_fac = 1.0f; + + /* Calc geometry data because in old versions this data was not saved. */ + BKE_gpencil_stroke_geometry_update(gps); + + srgb_to_linearrgb_v4(gps->vert_color_fill, gps->vert_color_fill); + int i; + bGPDspoint *pt; + for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { + srgb_to_linearrgb_v4(pt->vert_color, pt->vert_color); + } + } + } + } + } + } + } + /** * Versioning code until next subversion bump goes here. * diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c index 00276f9c4a9..f0127330b1b 100644 --- a/source/blender/blenloader/intern/versioning_defaults.c +++ b/source/blender/blenloader/intern/versioning_defaults.c @@ -44,10 +44,12 @@ #include "BKE_appdir.h" #include "BKE_brush.h" #include "BKE_colortools.h" +#include "BKE_gpencil.h" #include "BKE_layer.h" #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_mesh.h" +#include "BKE_material.h" #include "BKE_node.h" #include "BKE_paint.h" #include "BKE_screen.h" @@ -235,6 +237,13 @@ static void blo_update_defaults_screen(bScreen *screen, /* Enable Sliders. */ saction->flag |= SACTION_SLIDERS; } + else if (sa->spacetype == SPACE_VIEW3D) { + View3D *v3d = sa->spacedata.first; + /* Set Material Color by default. */ + v3d->shading.color_type = V3D_SHADING_MATERIAL_COLOR; + /* Enable Annotations. */ + v3d->flag2 |= V3D_SHOW_ANNOTATION; + } } } } @@ -583,7 +592,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) } } - if (app_template && STREQ(app_template, "2D_Animation")) { + /* New grease pencil brushes and vertex paint setup. */ + { /* Update Grease Pencil brushes. */ Brush *brush; @@ -617,8 +627,49 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) BKE_id_delete(bmain, brush); } + /* Rename and fix materials. */ + if (app_template && STREQ(app_template, "2D_Animation")) { + Material *ma = NULL; + rename_id_for_versioning(bmain, ID_MA, "Black", "Solid Stroke"); + rename_id_for_versioning(bmain, ID_MA, "Red", "Squares Stroke"); + rename_id_for_versioning(bmain, ID_MA, "Grey", "Solid Fill"); + rename_id_for_versioning(bmain, ID_MA, "Black Dots", "Dots Stroke"); + + /* Dots Stroke. */ + ma = BLI_findstring(&bmain->materials, "Dots Stroke", offsetof(ID, name) + 2); + if (ma == NULL) { + ma = BKE_gpencil_material_add(bmain, "Dots Stroke"); + } + ma->gp_style->mode = GP_MATERIAL_MODE_DOT; + + /* Squares Stroke. */ + ma = BLI_findstring(&bmain->materials, "Squares Stroke", offsetof(ID, name) + 2); + if (ma == NULL) { + ma = BKE_gpencil_material_add(bmain, "Squares Stroke"); + } + ma->gp_style->mode = GP_MATERIAL_MODE_SQUARE; + + /* Change Solid Fill settings. */ + ma = BLI_findstring(&bmain->materials, "Solid Fill", offsetof(ID, name) + 2); + if (ma != NULL) { + ma->gp_style->flag &= ~GP_MATERIAL_STROKE_SHOW; + } + } + /* Reset all grease pencil brushes. */ Scene *scene = bmain->scenes.first; - BKE_brush_gpencil_presets(bmain, scene->toolsettings); + BKE_brush_gpencil_paint_presets(bmain, scene->toolsettings); + + /* Ensure new Paint modes. */ + BKE_paint_ensure_from_paintmode(scene, PAINT_MODE_VERTEX_GPENCIL); + BKE_paint_ensure_from_paintmode(scene, PAINT_MODE_SCULPT_GPENCIL); + BKE_paint_ensure_from_paintmode(scene, PAINT_MODE_WEIGHT_GPENCIL); + + /* Enable cursor. */ + GpPaint *gp_paint = scene->toolsettings->gp_paint; + gp_paint->paint.flags |= PAINT_SHOW_BRUSH; + + /* Ensure Palette by default. */ + BKE_gpencil_palette_ensure(bmain, scene); } } diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 0c9363043ee..81df00ebdef 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1830,6 +1830,13 @@ static void write_gpencil_modifiers(WriteData *wd, ListBase *modbase) write_curvemapping(wd, gpmd->curve_thickness); } } + else if (md->type == eGpencilModifierType_Noise) { + NoiseGpencilModifierData *gpmd = (NoiseGpencilModifierData *)md; + + if (gpmd->curve_intensity) { + write_curvemapping(wd, gpmd->curve_intensity); + } + } else if (md->type == eGpencilModifierType_Hook) { HookGpencilModifierData *gpmd = (HookGpencilModifierData *)md; @@ -1837,6 +1844,39 @@ static void write_gpencil_modifiers(WriteData *wd, ListBase *modbase) write_curvemapping(wd, gpmd->curfalloff); } } + else if (md->type == eGpencilModifierType_Vertexcolor) { + VertexcolorGpencilModifierData *gpmd = (VertexcolorGpencilModifierData *)md; + if (gpmd->colorband) { + writestruct(wd, DATA, ColorBand, 1, gpmd->colorband); + } + if (gpmd->curve_intensity) { + write_curvemapping(wd, gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Smooth) { + SmoothGpencilModifierData *gpmd = (SmoothGpencilModifierData *)md; + if (gpmd->curve_intensity) { + write_curvemapping(wd, gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Color) { + ColorGpencilModifierData *gpmd = (ColorGpencilModifierData *)md; + if (gpmd->curve_intensity) { + write_curvemapping(wd, gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Opacity) { + OpacityGpencilModifierData *gpmd = (OpacityGpencilModifierData *)md; + if (gpmd->curve_intensity) { + write_curvemapping(wd, gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Tint) { + TintGpencilModifierData *gpmd = (TintGpencilModifierData *)md; + if (gpmd->curve_intensity) { + write_curvemapping(wd, gpmd->curve_intensity); + } + } } } @@ -2546,6 +2586,18 @@ static void write_scene(WriteData *wd, Scene *sce) writestruct(wd, DATA, GpPaint, 1, tos->gp_paint); write_paint(wd, &tos->gp_paint->paint); } + if (tos->gp_vertexpaint) { + writestruct(wd, DATA, GpVertexPaint, 1, tos->gp_vertexpaint); + write_paint(wd, &tos->gp_vertexpaint->paint); + } + if (tos->gp_sculptpaint) { + writestruct(wd, DATA, GpSculptPaint, 1, tos->gp_sculptpaint); + write_paint(wd, &tos->gp_sculptpaint->paint); + } + if (tos->gp_weightpaint) { + writestruct(wd, DATA, GpWeightPaint, 1, tos->gp_weightpaint); + write_paint(wd, &tos->gp_weightpaint->paint); + } /* write grease-pencil custom ipo curve to file */ if (tos->gp_interpolate.custom_ipo) { write_curvemapping(wd, tos->gp_interpolate.custom_ipo); @@ -2741,14 +2793,17 @@ static void write_gpencil(WriteData *wd, bGPdata *gpd) /* write grease-pencil layers to file */ writelist(wd, DATA, bGPDlayer, &gpd->layers); - for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + /* Write mask list. */ + writelist(wd, DATA, bGPDlayer_Mask, &gpl->mask_layers); /* write this layer's frames to file */ writelist(wd, DATA, bGPDframe, &gpl->frames); - for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { /* write strokes */ writelist(wd, DATA, bGPDstroke, &gpf->strokes); - for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { writestruct(wd, DATA, bGPDspoint, gps->totpoints, gps->points); + writestruct(wd, DATA, bGPDtriangle, gps->tot_triangles, gps->triangles); write_dverts(wd, gps->totpoints, gps->dvert); } } |