Commit: 57414e6d1de53c1c0c32304252a2e790d2fc4786 Author: Jacques Lucke Date: Fri Nov 6 17:22:20 2020 +0100 Branches: master https://developer.blender.org/rB57414e6d1de53c1c0c32304252a2e790d2fc4786
Refactor: move gpencil modifier .blend I/O to blenkernel Ref T76372. =================================================================== M source/blender/blenkernel/BKE_gpencil_modifier.h M source/blender/blenkernel/intern/gpencil_modifier.c M source/blender/blenloader/intern/readfile.c M source/blender/blenloader/intern/writefile.c =================================================================== diff --git a/source/blender/blenkernel/BKE_gpencil_modifier.h b/source/blender/blenkernel/BKE_gpencil_modifier.h index 78a17e3568d..7729d2c53ab 100644 --- a/source/blender/blenkernel/BKE_gpencil_modifier.h +++ b/source/blender/blenkernel/BKE_gpencil_modifier.h @@ -35,6 +35,9 @@ struct Main; struct ModifierUpdateDepsgraphContext; struct Object; struct Scene; +struct BlendWriter; +struct BlendDataReader; +struct BlendLibReader; /* NOTE: bakeModifier() called from UI: * needs to create new data-blocks, hence the need for this. */ struct bGPDframe; @@ -303,6 +306,10 @@ struct bGPDframe *BKE_gpencil_frame_retime_get(struct Depsgraph *depsgraph, struct Object *ob, struct bGPDlayer *gpl); +void BKE_gpencil_modifier_blend_write(struct BlendWriter *writer, struct ListBase *modbase); +void BKE_gpencil_modifier_blend_read_data(struct BlendDataReader *reader, struct ListBase *lb); +void BKE_gpencil_modifier_blend_read_lib(struct BlendLibReader *reader, struct Object *ob); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c index 934791ccc35..be06638ab64 100644 --- a/source/blender/blenkernel/intern/gpencil_modifier.c +++ b/source/blender/blenkernel/intern/gpencil_modifier.c @@ -37,10 +37,12 @@ #include "DNA_gpencil_modifier_types.h" #include "DNA_gpencil_types.h" #include "DNA_meshdata_types.h" +#include "DNA_modifier_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" +#include "BKE_colortools.h" #include "BKE_gpencil.h" #include "BKE_gpencil_geom.h" #include "BKE_gpencil_modifier.h" @@ -55,6 +57,8 @@ #include "MOD_gpencil_modifiertypes.h" +#include "BLO_read_write.h" + #include "CLG_log.h" static CLG_LogRef LOG = {"bke.gpencil_modifier"}; @@ -777,3 +781,159 @@ void BKE_gpencil_modifiers_calc(Depsgraph *depsgraph, Scene *scene, Object *ob) /* Clear any lattice data. */ BKE_gpencil_lattice_clear(ob); } + +void BKE_gpencil_modifier_blend_write(BlendWriter *writer, ListBase *modbase) +{ + if (modbase == NULL) { + return; + } + + LISTBASE_FOREACH (GpencilModifierData *, md, modbase) { + const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info(md->type); + if (mti == NULL) { + return; + } + + BLO_write_struct_by_name(writer, mti->struct_name, md); + + if (md->type == eGpencilModifierType_Thick) { + ThickGpencilModifierData *gpmd = (ThickGpencilModifierData *)md; + + if (gpmd->curve_thickness) { + BKE_curvemapping_blend_write(writer, gpmd->curve_thickness); + } + } + else if (md->type == eGpencilModifierType_Noise) { + NoiseGpencilModifierData *gpmd = (NoiseGpencilModifierData *)md; + + if (gpmd->curve_intensity) { + BKE_curvemapping_blend_write(writer, gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Hook) { + HookGpencilModifierData *gpmd = (HookGpencilModifierData *)md; + + if (gpmd->curfalloff) { + BKE_curvemapping_blend_write(writer, gpmd->curfalloff); + } + } + else if (md->type == eGpencilModifierType_Tint) { + TintGpencilModifierData *gpmd = (TintGpencilModifierData *)md; + if (gpmd->colorband) { + BLO_write_struct(writer, ColorBand, gpmd->colorband); + } + if (gpmd->curve_intensity) { + BKE_curvemapping_blend_write(writer, gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Smooth) { + SmoothGpencilModifierData *gpmd = (SmoothGpencilModifierData *)md; + if (gpmd->curve_intensity) { + BKE_curvemapping_blend_write(writer, gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Color) { + ColorGpencilModifierData *gpmd = (ColorGpencilModifierData *)md; + if (gpmd->curve_intensity) { + BKE_curvemapping_blend_write(writer, gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Opacity) { + OpacityGpencilModifierData *gpmd = (OpacityGpencilModifierData *)md; + if (gpmd->curve_intensity) { + BKE_curvemapping_blend_write(writer, gpmd->curve_intensity); + } + } + } +} + +void BKE_gpencil_modifier_blend_read_data(BlendDataReader *reader, ListBase *lb) +{ + BLO_read_list(reader, lb); + + LISTBASE_FOREACH (GpencilModifierData *, md, lb) { + md->error = NULL; + + /* if modifiers disappear, or for upward compatibility */ + if (NULL == BKE_gpencil_modifier_get_info(md->type)) { + md->type = eModifierType_None; + } + + if (md->type == eGpencilModifierType_Lattice) { + LatticeGpencilModifierData *gpmd = (LatticeGpencilModifierData *)md; + gpmd->cache_data = NULL; + } + else if (md->type == eGpencilModifierType_Hook) { + HookGpencilModifierData *hmd = (HookGpencilModifierData *)md; + + BLO_read_data_address(reader, &hmd->curfalloff); + if (hmd->curfalloff) { + BKE_curvemapping_blend_read(reader, hmd->curfalloff); + } + } + else if (md->type == eGpencilModifierType_Noise) { + NoiseGpencilModifierData *gpmd = (NoiseGpencilModifierData *)md; + + BLO_read_data_address(reader, &gpmd->curve_intensity); + if (gpmd->curve_intensity) { + BKE_curvemapping_blend_read(reader, gpmd->curve_intensity); + /* initialize the curve. Maybe this could be moved to modififer logic */ + BKE_curvemapping_init(gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Thick) { + ThickGpencilModifierData *gpmd = (ThickGpencilModifierData *)md; + + BLO_read_data_address(reader, &gpmd->curve_thickness); + if (gpmd->curve_thickness) { + BKE_curvemapping_blend_read(reader, gpmd->curve_thickness); + BKE_curvemapping_init(gpmd->curve_thickness); + } + } + else if (md->type == eGpencilModifierType_Tint) { + TintGpencilModifierData *gpmd = (TintGpencilModifierData *)md; + BLO_read_data_address(reader, &gpmd->colorband); + BLO_read_data_address(reader, &gpmd->curve_intensity); + if (gpmd->curve_intensity) { + BKE_curvemapping_blend_read(reader, gpmd->curve_intensity); + BKE_curvemapping_init(gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Smooth) { + SmoothGpencilModifierData *gpmd = (SmoothGpencilModifierData *)md; + BLO_read_data_address(reader, &gpmd->curve_intensity); + if (gpmd->curve_intensity) { + BKE_curvemapping_blend_read(reader, gpmd->curve_intensity); + BKE_curvemapping_init(gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Color) { + ColorGpencilModifierData *gpmd = (ColorGpencilModifierData *)md; + BLO_read_data_address(reader, &gpmd->curve_intensity); + if (gpmd->curve_intensity) { + BKE_curvemapping_blend_read(reader, gpmd->curve_intensity); + BKE_curvemapping_init(gpmd->curve_intensity); + } + } + else if (md->type == eGpencilModifierType_Opacity) { + OpacityGpencilModifierData *gpmd = (OpacityGpencilModifierData *)md; + BLO_read_data_address(reader, &gpmd->curve_intensity); + if (gpmd->curve_intensity) { + BKE_curvemapping_blend_read(reader, gpmd->curve_intensity); + BKE_curvemapping_init(gpmd->curve_intensity); + } + } + } +} + +void BKE_gpencil_modifier_blend_read_lib(BlendLibReader *reader, Object *ob) +{ + BKE_gpencil_modifiers_foreach_ID_link(ob, BKE_object_modifiers_lib_link_common, reader); + + /* If linking from a library, clear 'local' library override flag. */ + if (ob->id.lib != NULL) { + LISTBASE_FOREACH (GpencilModifierData *, mod, &ob->greasepencil_modifiers) { + mod->flag &= ~eGpencilModifierFlag_OverrideLibrary_Local; + } + } +} diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index fa1e832c9f8..2b93f5222db 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2745,18 +2745,6 @@ void blo_do_versions_key_uidgen(Key *key) /** \name Read ID: Object * \{ */ -static void lib_link_gpencil_modifiers(BlendLibReader *reader, Object *ob) -{ - BKE_gpencil_modifiers_foreach_ID_link(ob, BKE_object_modifiers_lib_link_common, reader); - - /* If linking from a library, clear 'local' library override flag. */ - if (ob->id.lib != NULL) { - LISTBASE_FOREACH (GpencilModifierData *, mod, &ob->greasepencil_modifiers) { - mod->flag &= ~eGpencilModifierFlag_OverrideLibrary_Local; - } - } -} - static void lib_link_object(BlendLibReader *reader, Object *ob) { bool warn = false; @@ -2911,7 +2899,7 @@ static void lib_link_object(BlendLibReader *reader, Object *ob) BKE_particle_system_blend_read_lib(reader, ob, &ob->id, &ob->particlesystem); BKE_modifier_blend_read_lib(reader, ob); - lib_link_gpencil_modifiers(reader, ob); + BKE_gpencil_modifier_blend_read_lib(reader, ob); BKE_shaderfx_blend_read_lib(reader, ob); if (ob->rigidbody_constraint) { @@ -2988,85 +2976,6 @@ static void direct_link_pose(BlendDataReader *reader, bPose *pose) } } -static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb) -{ - BLO_read_list(reader, lb); - - LISTBASE_FOREACH (GpencilModifierData *, md, lb) { - md->error = NULL; - - /* if modifiers disappear, or for upward compatibility */ - if (NULL == BKE_gpencil_modifier_get_info(md->type)) { - md->type = eModifierType_None; - } - - if (md->type == eGpencilModifierType_Lattice) { - LatticeGpencilModifierData *gpmd = (LatticeGpencilModifierData *)md; - gpmd->cache_data = NULL; - } - else if (md->type == eGpencilModifierType_Hook) { - HookGpencilModifierData *hmd = (HookGpencilModifierData *)md; - - BLO_read_data_address(reader, &hmd->curfalloff); - if (hmd->curfalloff) { - BKE_curvemapping_blend_read(reader, hmd->curfalloff); - } - } - else if (md->type == eGpencilModifierType_Noise) { - NoiseGpencilModifierData *gpmd = @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs