diff options
author | Jacques Lucke <jacques@blender.org> | 2020-09-10 16:50:50 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-09-10 16:50:50 +0300 |
commit | 7f4799a18931a1b9f8edd970cd4bb30bf1577d40 (patch) | |
tree | e4166930ea2e29ea37d2ea659d9d043b2ea2b67f /source/blender | |
parent | 8e4cc07547a7d3d5474de31ae27ac9d62bf35e9f (diff) |
Refactor: move Brush .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/brush.c | 167 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 124 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 51 |
3 files changed, 166 insertions, 176 deletions
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index b35d2b199aa..ffd51f136a4 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -52,6 +52,8 @@ #include "RE_render_ext.h" /* RE_texture_evaluate */ +#include "BLO_read_write.h" + static void brush_init_data(ID *id) { Brush *brush = (Brush *)id; @@ -196,6 +198,163 @@ static void brush_foreach_id(ID *id, LibraryForeachIDData *data) BKE_texture_mtex_foreach_id(data, &brush->mask_mtex); } +static void brush_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Brush *brush = (Brush *)id; + if (brush->id.us > 0 || BLO_write_is_undo(writer)) { + BLO_write_id_struct(writer, Brush, id_address, &brush->id); + BKE_id_blend_write(writer, &brush->id); + + if (brush->curve) { + BKE_curvemapping_blend_write(writer, brush->curve); + } + + if (brush->gpencil_settings) { + BLO_write_struct(writer, BrushGpencilSettings, brush->gpencil_settings); + + if (brush->gpencil_settings->curve_sensitivity) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_sensitivity); + } + if (brush->gpencil_settings->curve_strength) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_strength); + } + if (brush->gpencil_settings->curve_jitter) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_jitter); + } + if (brush->gpencil_settings->curve_rand_pressure) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_pressure); + } + if (brush->gpencil_settings->curve_rand_strength) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_strength); + } + if (brush->gpencil_settings->curve_rand_uv) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_uv); + } + if (brush->gpencil_settings->curve_rand_hue) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_hue); + } + if (brush->gpencil_settings->curve_rand_saturation) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_saturation); + } + if (brush->gpencil_settings->curve_rand_value) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_value); + } + } + if (brush->gradient) { + BLO_write_struct(writer, ColorBand, brush->gradient); + } + } +} + +static void brush_blend_read_data(BlendDataReader *reader, ID *id) +{ + Brush *brush = (Brush *)id; + + /* fallof curve */ + BLO_read_data_address(reader, &brush->curve); + + BLO_read_data_address(reader, &brush->gradient); + + if (brush->curve) { + BKE_curvemapping_blend_read(reader, brush->curve); + } + else { + BKE_brush_curve_preset(brush, CURVE_PRESET_SHARP); + } + + /* grease pencil */ + BLO_read_data_address(reader, &brush->gpencil_settings); + if (brush->gpencil_settings != NULL) { + BLO_read_data_address(reader, &brush->gpencil_settings->curve_sensitivity); + BLO_read_data_address(reader, &brush->gpencil_settings->curve_strength); + BLO_read_data_address(reader, &brush->gpencil_settings->curve_jitter); + + BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_pressure); + BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_strength); + BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_uv); + BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_hue); + BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_saturation); + BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_value); + + if (brush->gpencil_settings->curve_sensitivity) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_sensitivity); + } + + if (brush->gpencil_settings->curve_strength) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_strength); + } + + if (brush->gpencil_settings->curve_jitter) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_jitter); + } + + if (brush->gpencil_settings->curve_rand_pressure) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_pressure); + } + + if (brush->gpencil_settings->curve_rand_strength) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_strength); + } + + if (brush->gpencil_settings->curve_rand_uv) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_uv); + } + + if (brush->gpencil_settings->curve_rand_hue) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_hue); + } + + if (brush->gpencil_settings->curve_rand_saturation) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_saturation); + } + + if (brush->gpencil_settings->curve_rand_value) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_value); + } + } + + brush->preview = NULL; + brush->icon_imbuf = NULL; +} + +static void brush_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Brush *brush = (Brush *)id; + + /* brush->(mask_)mtex.obj is ignored on purpose? */ + BLO_read_id_address(reader, brush->id.lib, &brush->mtex.tex); + BLO_read_id_address(reader, brush->id.lib, &brush->mask_mtex.tex); + BLO_read_id_address(reader, brush->id.lib, &brush->clone.image); + BLO_read_id_address(reader, brush->id.lib, &brush->toggle_brush); + BLO_read_id_address(reader, brush->id.lib, &brush->paint_curve); + + /* link default grease pencil palette */ + if (brush->gpencil_settings != NULL) { + if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) { + BLO_read_id_address(reader, brush->id.lib, &brush->gpencil_settings->material); + + if (!brush->gpencil_settings->material) { + brush->gpencil_settings->flag &= ~GP_BRUSH_MATERIAL_PINNED; + } + } + else { + brush->gpencil_settings->material = NULL; + } + } +} + +static void brush_blend_read_expand(BlendExpander *expander, ID *id) +{ + Brush *brush = (Brush *)id; + BLO_expand(expander, brush->mtex.tex); + BLO_expand(expander, brush->mask_mtex.tex); + BLO_expand(expander, brush->clone.image); + BLO_expand(expander, brush->paint_curve); + if (brush->gpencil_settings != NULL) { + BLO_expand(expander, brush->gpencil_settings->material); + } +} + IDTypeInfo IDType_ID_BR = { .id_code = ID_BR, .id_filter = FILTER_ID_BR, @@ -213,10 +372,10 @@ IDTypeInfo IDType_ID_BR = { .foreach_id = brush_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = brush_blend_write, + .blend_read_data = brush_blend_read_data, + .blend_read_lib = brush_blend_read_lib, + .blend_read_expand = brush_blend_read_expand, }; static RNG *brush_rng; diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 139f049533f..969a28e6b82 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2478,108 +2478,6 @@ static void direct_link_id_common( /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read ID: Brush - * \{ */ - -/* library brush linking after fileread */ -static void lib_link_brush(BlendLibReader *reader, Brush *brush) -{ - /* brush->(mask_)mtex.obj is ignored on purpose? */ - BLO_read_id_address(reader, brush->id.lib, &brush->mtex.tex); - BLO_read_id_address(reader, brush->id.lib, &brush->mask_mtex.tex); - BLO_read_id_address(reader, brush->id.lib, &brush->clone.image); - BLO_read_id_address(reader, brush->id.lib, &brush->toggle_brush); - BLO_read_id_address(reader, brush->id.lib, &brush->paint_curve); - - /* link default grease pencil palette */ - if (brush->gpencil_settings != NULL) { - if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) { - BLO_read_id_address(reader, brush->id.lib, &brush->gpencil_settings->material); - - if (!brush->gpencil_settings->material) { - brush->gpencil_settings->flag &= ~GP_BRUSH_MATERIAL_PINNED; - } - } - else { - brush->gpencil_settings->material = NULL; - } - } -} - -static void direct_link_brush(BlendDataReader *reader, Brush *brush) -{ - /* brush itself has been read */ - - /* fallof curve */ - BLO_read_data_address(reader, &brush->curve); - - BLO_read_data_address(reader, &brush->gradient); - - if (brush->curve) { - BKE_curvemapping_blend_read(reader, brush->curve); - } - else { - BKE_brush_curve_preset(brush, CURVE_PRESET_SHARP); - } - - /* grease pencil */ - BLO_read_data_address(reader, &brush->gpencil_settings); - if (brush->gpencil_settings != NULL) { - BLO_read_data_address(reader, &brush->gpencil_settings->curve_sensitivity); - BLO_read_data_address(reader, &brush->gpencil_settings->curve_strength); - BLO_read_data_address(reader, &brush->gpencil_settings->curve_jitter); - - BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_pressure); - BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_strength); - BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_uv); - BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_hue); - BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_saturation); - BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_value); - - if (brush->gpencil_settings->curve_sensitivity) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_sensitivity); - } - - if (brush->gpencil_settings->curve_strength) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_strength); - } - - if (brush->gpencil_settings->curve_jitter) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_jitter); - } - - if (brush->gpencil_settings->curve_rand_pressure) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_pressure); - } - - if (brush->gpencil_settings->curve_rand_strength) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_strength); - } - - if (brush->gpencil_settings->curve_rand_uv) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_uv); - } - - if (brush->gpencil_settings->curve_rand_hue) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_hue); - } - - if (brush->gpencil_settings->curve_rand_saturation) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_saturation); - } - - if (brush->gpencil_settings->curve_rand_value) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_value); - } - } - - brush->preview = NULL; - brush->icon_imbuf = NULL; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read Animation (legacy for version patching) * \{ */ @@ -7297,9 +7195,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_AR: direct_link_armature(&reader, (bArmature *)id); break; - case ID_BR: - direct_link_brush(&reader, (Brush *)id); - break; case ID_PA: direct_link_particlesettings(&reader, (ParticleSettings *)id); break; @@ -7337,6 +7232,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_MC: case ID_PAL: case ID_PC: + case ID_BR: /* Do nothing. Handled by IDTypeInfo callback. */ break; } @@ -7975,9 +7871,6 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_PA: lib_link_particlesettings(&reader, (ParticleSettings *)id); break; - case ID_BR: - lib_link_brush(&reader, (Brush *)id); - break; case ID_GR: lib_link_collection(&reader, (Collection *)id); break; @@ -8046,6 +7939,7 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_MC: case ID_PAL: case ID_PC: + case ID_BR: /* Do nothing. Handled by IDTypeInfo callback. */ break; } @@ -8742,17 +8636,6 @@ static void expand_texture(BlendExpander *expander, Tex *tex) BLO_expand(expander, tex->ipo); // XXX deprecated - old animation system } -static void expand_brush(BlendExpander *expander, Brush *brush) -{ - BLO_expand(expander, brush->mtex.tex); - BLO_expand(expander, brush->mask_mtex.tex); - BLO_expand(expander, brush->clone.image); - BLO_expand(expander, brush->paint_curve); - if (brush->gpencil_settings != NULL) { - BLO_expand(expander, brush->gpencil_settings->material); - } -} - static void expand_material(BlendExpander *expander, Material *ma) { BLO_expand(expander, ma->ipo); // XXX deprecated - old animation system @@ -9243,9 +9126,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) case ID_GR: expand_collection(&expander, (Collection *)id); break; - case ID_BR: - expand_brush(&expander, (Brush *)id); - break; case ID_IP: expand_ipo(&expander, (Ipo *)id); // XXX deprecated - old animation system break; diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 95e86efdc39..8efc181cbfc 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2436,53 +2436,6 @@ static void write_probe(BlendWriter *writer, LightProbe *prb, const void *id_add } } -static void write_brush(BlendWriter *writer, Brush *brush, const void *id_address) -{ - if (brush->id.us > 0 || BLO_write_is_undo(writer)) { - BLO_write_id_struct(writer, Brush, id_address, &brush->id); - BKE_id_blend_write(writer, &brush->id); - - if (brush->curve) { - BKE_curvemapping_blend_write(writer, brush->curve); - } - - if (brush->gpencil_settings) { - BLO_write_struct(writer, BrushGpencilSettings, brush->gpencil_settings); - - if (brush->gpencil_settings->curve_sensitivity) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_sensitivity); - } - if (brush->gpencil_settings->curve_strength) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_strength); - } - if (brush->gpencil_settings->curve_jitter) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_jitter); - } - if (brush->gpencil_settings->curve_rand_pressure) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_pressure); - } - if (brush->gpencil_settings->curve_rand_strength) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_strength); - } - if (brush->gpencil_settings->curve_rand_uv) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_uv); - } - if (brush->gpencil_settings->curve_rand_hue) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_hue); - } - if (brush->gpencil_settings->curve_rand_saturation) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_saturation); - } - if (brush->gpencil_settings->curve_rand_value) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_value); - } - } - if (brush->gradient) { - BLO_write_struct(writer, ColorBand, brush->gradient); - } - } -} - static void write_mask(BlendWriter *writer, Mask *mask, const void *id_address) { if (mask->id.us > 0 || BLO_write_is_undo(writer)) { @@ -3014,9 +2967,6 @@ static bool write_file_handle(Main *mainvar, case ID_PA: write_particlesettings(&writer, (ParticleSettings *)id_buffer, id); break; - case ID_BR: - write_brush(&writer, (Brush *)id_buffer, id); - break; case ID_GD: write_gpencil(&writer, (bGPdata *)id_buffer, id); break; @@ -3045,6 +2995,7 @@ static bool write_file_handle(Main *mainvar, case ID_MC: case ID_PC: case ID_PAL: + case ID_BR: /* Do nothing, handled in IDTypeInfo callback. */ break; case ID_LI: |