diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-02-28 16:54:51 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-02-28 16:54:51 +0300 |
commit | 4e8bd537c3b7101d1166c70a820a319de215eb17 (patch) | |
tree | 2db94ae982f950ab6b71f19d421b584b72eedfa1 /source/blender/blenkernel | |
parent | bd25e73c540d7fb7f2a3e52994429ed77bebcbd0 (diff) | |
parent | 8b8e16dc2cedd03d0a22f89c9165c76722cc706a (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_scene.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 188 |
2 files changed, 84 insertions, 107 deletions
diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index bb435df136d..bd36bb000b4 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -111,6 +111,9 @@ void BKE_scene_object_base_flag_sync_from_object(struct Base *base); void BKE_scene_set_background(struct Main *bmain, struct Scene *sce); struct Scene *BKE_scene_set_name(struct Main *bmain, const char *name); +struct ToolSettings *BKE_toolsettings_copy(struct ToolSettings *toolsettings, const int flag); +void BKE_toolsettings_free(struct ToolSettings *toolsettings); + void BKE_scene_copy_data(struct Main *bmain, struct Scene *sce_dst, const struct Scene *sce_src, const int flag); struct Scene *BKE_scene_copy(struct Main *bmain, struct Scene *sce, int type); void BKE_scene_groups_relink(struct Scene *sce); diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index f263f23fb92..512ce79e21c 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -151,6 +151,83 @@ static void remove_sequencer_fcurves(Scene *sce) } } +/* flag -- copying options (see BKE_library.h's LIB_ID_COPY_... flags for more). */ +ToolSettings *BKE_toolsettings_copy(ToolSettings *toolsettings, const int flag) +{ + if (toolsettings == NULL) { + return NULL; + } + ToolSettings *ts = MEM_dupallocN(toolsettings); + if (ts->vpaint) { + ts->vpaint = MEM_dupallocN(ts->vpaint); + BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint, flag); + } + if (ts->wpaint) { + ts->wpaint = MEM_dupallocN(ts->wpaint); + BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint, flag); + } + if (ts->sculpt) { + ts->sculpt = MEM_dupallocN(ts->sculpt); + BKE_paint_copy(&ts->sculpt->paint, &ts->sculpt->paint, flag); + } + if (ts->uvsculpt) { + ts->uvsculpt = MEM_dupallocN(ts->uvsculpt); + BKE_paint_copy(&ts->uvsculpt->paint, &ts->uvsculpt->paint, flag); + } + + BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint, flag); + ts->imapaint.paintcursor = NULL; + ts->particle.paintcursor = NULL; + ts->particle.scene = NULL; + ts->particle.object = NULL; + + /* duplicate Grease Pencil Drawing Brushes */ + BLI_listbase_clear(&ts->gp_brushes); + for (bGPDbrush *brush = toolsettings->gp_brushes.first; brush; brush = brush->next) { + bGPDbrush *newbrush = BKE_gpencil_brush_duplicate(brush); + BLI_addtail(&ts->gp_brushes, newbrush); + } + + /* duplicate Grease Pencil interpolation curve */ + ts->gp_interpolate.custom_ipo = curvemapping_copy(ts->gp_interpolate.custom_ipo); + return ts; +} + +void BKE_toolsettings_free(ToolSettings *toolsettings) +{ + if (toolsettings == NULL) { + return; + } + if (toolsettings->vpaint) { + BKE_paint_free(&toolsettings->vpaint->paint); + MEM_freeN(toolsettings->vpaint); + } + if (toolsettings->wpaint) { + BKE_paint_free(&toolsettings->wpaint->paint); + MEM_freeN(toolsettings->wpaint); + } + if (toolsettings->sculpt) { + BKE_paint_free(&toolsettings->sculpt->paint); + MEM_freeN(toolsettings->sculpt); + } + if (toolsettings->uvsculpt) { + BKE_paint_free(&toolsettings->uvsculpt->paint); + MEM_freeN(toolsettings->uvsculpt); + } + BKE_paint_free(&toolsettings->imapaint.paint); + + /* free Grease Pencil Drawing Brushes */ + BKE_gpencil_free_brushes(&toolsettings->gp_brushes); + BLI_freelistN(&toolsettings->gp_brushes); + + /* free Grease Pencil interpolation curve */ + if (toolsettings->gp_interpolate.custom_ipo) { + curvemapping_free(toolsettings->gp_interpolate.custom_ipo); + } + + MEM_freeN(toolsettings); +} + /** * Only copy internal data of Scene ID from source to already allocated/initialized destination. * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs. @@ -223,41 +300,7 @@ void BKE_scene_copy_data(Main *bmain, Scene *sce_dst, const Scene *sce_src, cons curvemapping_copy_data(&sce_dst->r.mblur_shutter_curve, &sce_src->r.mblur_shutter_curve); /* tool settings */ - if (sce_dst->toolsettings != NULL) { - ToolSettings *ts = sce_dst->toolsettings = MEM_dupallocN(sce_dst->toolsettings); - if (ts->vpaint) { - ts->vpaint = MEM_dupallocN(ts->vpaint); - BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint, flag_subdata); - } - if (ts->wpaint) { - ts->wpaint = MEM_dupallocN(ts->wpaint); - BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint, flag_subdata); - } - if (ts->sculpt) { - ts->sculpt = MEM_dupallocN(ts->sculpt); - BKE_paint_copy(&ts->sculpt->paint, &ts->sculpt->paint, flag_subdata); - } - if (ts->uvsculpt) { - ts->uvsculpt = MEM_dupallocN(ts->uvsculpt); - BKE_paint_copy(&ts->uvsculpt->paint, &ts->uvsculpt->paint, flag_subdata); - } - - BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint, flag_subdata); - ts->imapaint.paintcursor = NULL; - ts->particle.paintcursor = NULL; - ts->particle.scene = NULL; - ts->particle.object = NULL; - - /* duplicate Grease Pencil Drawing Brushes */ - BLI_listbase_clear(&ts->gp_brushes); - for (bGPDbrush *brush = sce_src->toolsettings->gp_brushes.first; brush; brush = brush->next) { - bGPDbrush *newbrush = BKE_gpencil_brush_duplicate(brush); - BLI_addtail(&ts->gp_brushes, newbrush); - } - - /* duplicate Grease Pencil interpolation curve */ - ts->gp_interpolate.custom_ipo = curvemapping_copy(ts->gp_interpolate.custom_ipo); - } + sce_dst->toolsettings = BKE_toolsettings_copy(sce_dst->toolsettings, flag_subdata); /* make a private copy of the avicodecdata */ if (sce_src->r.avicodecdata) { @@ -296,7 +339,6 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) /* TODO this should/could most likely be replaced by call to more generic code at some point... * But for now, let's keep it well isolated here. */ if (type == SCE_COPY_EMPTY) { - ToolSettings *ts; ListBase rv; sce_copy = BKE_scene_add(bmain, sce->id.name + 2); @@ -331,46 +373,7 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) curvemapping_copy_data(&sce_copy->r.mblur_shutter_curve, &sce->r.mblur_shutter_curve); /* tool settings */ - sce_copy->toolsettings = MEM_dupallocN(sce->toolsettings); - - ts = sce_copy->toolsettings; - if (ts) { - if (ts->vpaint) { - ts->vpaint = MEM_dupallocN(ts->vpaint); - BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint, 0); - } - if (ts->wpaint) { - ts->wpaint = MEM_dupallocN(ts->wpaint); - BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint, 0); - } - if (ts->sculpt) { - ts->sculpt = MEM_dupallocN(ts->sculpt); - BKE_paint_copy(&ts->sculpt->paint, &ts->sculpt->paint, 0); - } - if (ts->uvsculpt) { - ts->uvsculpt = MEM_dupallocN(ts->uvsculpt); - BKE_paint_copy(&ts->uvsculpt->paint, &ts->uvsculpt->paint, 0); - } - - BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint, 0); - ts->imapaint.paintcursor = NULL; - id_us_plus((ID *)ts->imapaint.stencil); - id_us_plus((ID *)ts->imapaint.clone); - id_us_plus((ID *)ts->imapaint.canvas); - ts->particle.paintcursor = NULL; - ts->particle.scene = NULL; - ts->particle.object = NULL; - - /* duplicate Grease Pencil Drawing Brushes */ - BLI_listbase_clear(&ts->gp_brushes); - for (bGPDbrush *brush = sce->toolsettings->gp_brushes.first; brush; brush = brush->next) { - bGPDbrush *newbrush = BKE_gpencil_brush_duplicate(brush); - BLI_addtail(&ts->gp_brushes, newbrush); - } - - /* duplicate Grease Pencil interpolation curve */ - ts->gp_interpolate.custom_ipo = curvemapping_copy(ts->gp_interpolate.custom_ipo); - } + sce_copy->toolsettings = BKE_toolsettings_copy(sce->toolsettings, 0); /* make a private copy of the avicodecdata */ if (sce->r.avicodecdata) { @@ -492,37 +495,8 @@ void BKE_scene_free_ex(Scene *sce, const bool do_id_user) BLI_freelistN(&sce->markers); BLI_freelistN(&sce->r.views); - if (sce->toolsettings) { - if (sce->toolsettings->vpaint) { - BKE_paint_free(&sce->toolsettings->vpaint->paint); - MEM_freeN(sce->toolsettings->vpaint); - } - if (sce->toolsettings->wpaint) { - BKE_paint_free(&sce->toolsettings->wpaint->paint); - MEM_freeN(sce->toolsettings->wpaint); - } - if (sce->toolsettings->sculpt) { - BKE_paint_free(&sce->toolsettings->sculpt->paint); - MEM_freeN(sce->toolsettings->sculpt); - } - if (sce->toolsettings->uvsculpt) { - BKE_paint_free(&sce->toolsettings->uvsculpt->paint); - MEM_freeN(sce->toolsettings->uvsculpt); - } - BKE_paint_free(&sce->toolsettings->imapaint.paint); - - /* free Grease Pencil Drawing Brushes */ - BKE_gpencil_free_brushes(&sce->toolsettings->gp_brushes); - BLI_freelistN(&sce->toolsettings->gp_brushes); - - /* free Grease Pencil interpolation curve */ - if (sce->toolsettings->gp_interpolate.custom_ipo) { - curvemapping_free(sce->toolsettings->gp_interpolate.custom_ipo); - } - - MEM_freeN(sce->toolsettings); - sce->toolsettings = NULL; - } + BKE_toolsettings_free(sce->toolsettings); + sce->toolsettings = NULL; BKE_scene_free_depsgraph_hash(sce); |