diff options
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/layer.c | 148 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.cc | 12 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/world.c | 12 |
3 files changed, 172 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index ccff4dbed03..c99bf885074 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -266,6 +266,8 @@ void BKE_view_layer_free_ex(ViewLayer *view_layer, const bool do_id_user) BLI_freelistN(&view_layer->drawdata); BLI_freelistN(&view_layer->aovs); view_layer->active_aov = NULL; + BLI_freelistN(&view_layer->lightgroups); + view_layer->active_lightgroup = NULL; MEM_SAFE_FREE(view_layer->stats); @@ -428,6 +430,29 @@ static void layer_aov_copy_data(ViewLayer *view_layer_dst, } } +static void layer_lightgroup_copy_data(ViewLayer *view_layer_dst, + const ViewLayer *view_layer_src, + ListBase *lightgroups_dst, + const ListBase *lightgroups_src) +{ + if (lightgroups_src != NULL) { + BLI_duplicatelist(lightgroups_dst, lightgroups_src); + } + + ViewLayerLightgroup *lightgroup_dst = lightgroups_dst->first; + const ViewLayerLightgroup *lightgroup_src = lightgroups_src->first; + + while (lightgroup_dst != NULL) { + BLI_assert(lightgroup_src); + if (lightgroup_src == view_layer_src->active_lightgroup) { + view_layer_dst->active_lightgroup = lightgroup_dst; + } + + lightgroup_dst = lightgroup_dst->next; + lightgroup_src = lightgroup_src->next; + } +} + static void layer_collections_copy_data(ViewLayer *view_layer_dst, const ViewLayer *view_layer_src, ListBase *layer_collections_dst, @@ -496,6 +521,10 @@ void BKE_view_layer_copy_data(Scene *scene_dst, layer_aov_copy_data( view_layer_dst, view_layer_src, &view_layer_dst->aovs, &view_layer_src->aovs); + BLI_listbase_clear(&view_layer_dst->lightgroups); + layer_lightgroup_copy_data( + view_layer_dst, view_layer_src, &view_layer_dst->lightgroups, &view_layer_src->lightgroups); + if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { id_us_plus((ID *)view_layer_dst->mat_override); } @@ -2256,6 +2285,9 @@ void BKE_view_layer_blend_write(BlendWriter *writer, ViewLayer *view_layer) LISTBASE_FOREACH (ViewLayerAOV *, aov, &view_layer->aovs) { BLO_write_struct(writer, ViewLayerAOV, aov); } + LISTBASE_FOREACH (ViewLayerLightgroup *, lightgroup, &view_layer->lightgroups) { + BLO_write_struct(writer, ViewLayerLightgroup, lightgroup); + } write_layer_collections(writer, &view_layer->layer_collections); } @@ -2294,6 +2326,9 @@ void BKE_view_layer_blend_read_data(BlendDataReader *reader, ViewLayer *view_lay BLO_read_list(reader, &view_layer->aovs); BLO_read_data_address(reader, &view_layer->active_aov); + BLO_read_list(reader, &view_layer->lightgroups); + BLO_read_data_address(reader, &view_layer->active_lightgroup); + BLI_listbase_clear(&view_layer->drawdata); view_layer->object_bases_array = NULL; view_layer->object_bases_hash = NULL; @@ -2471,4 +2506,117 @@ ViewLayer *BKE_view_layer_find_with_aov(struct Scene *scene, struct ViewLayerAOV return NULL; } +/* -------------------------------------------------------------------- */ +/** \name Light Groups + * \{ */ + +static void viewlayer_lightgroup_make_name_unique(ViewLayer *view_layer, + ViewLayerLightgroup *lightgroup) +{ + /* Don't allow dots, it's incompatible with OpenEXR convention to store channels + * as "layer.pass.channel". */ + BLI_str_replace_char(lightgroup->name, '.', '_'); + BLI_uniquename(&view_layer->lightgroups, + lightgroup, + DATA_("Lightgroup"), + '_', + offsetof(ViewLayerLightgroup, name), + sizeof(lightgroup->name)); +} + +static void viewlayer_lightgroup_active_set(ViewLayer *view_layer, ViewLayerLightgroup *lightgroup) +{ + if (lightgroup != NULL) { + BLI_assert(BLI_findindex(&view_layer->lightgroups, lightgroup) != -1); + view_layer->active_lightgroup = lightgroup; + } + else { + view_layer->active_lightgroup = NULL; + } +} + +struct ViewLayerLightgroup *BKE_view_layer_add_lightgroup(struct ViewLayer *view_layer) +{ + ViewLayerLightgroup *lightgroup; + lightgroup = MEM_callocN(sizeof(ViewLayerLightgroup), __func__); + BLI_strncpy(lightgroup->name, DATA_("Lightgroup"), sizeof(lightgroup->name)); + BLI_addtail(&view_layer->lightgroups, lightgroup); + viewlayer_lightgroup_active_set(view_layer, lightgroup); + viewlayer_lightgroup_make_name_unique(view_layer, lightgroup); + return lightgroup; +} + +void BKE_view_layer_remove_lightgroup(ViewLayer *view_layer, ViewLayerLightgroup *lightgroup) +{ + BLI_assert(BLI_findindex(&view_layer->lightgroups, lightgroup) != -1); + BLI_assert(lightgroup != NULL); + if (view_layer->active_lightgroup == lightgroup) { + if (lightgroup->next) { + viewlayer_lightgroup_active_set(view_layer, lightgroup->next); + } + else { + viewlayer_lightgroup_active_set(view_layer, lightgroup->prev); + } + } + BLI_freelinkN(&view_layer->lightgroups, lightgroup); +} + +void BKE_view_layer_set_active_lightgroup(ViewLayer *view_layer, ViewLayerLightgroup *lightgroup) +{ + viewlayer_lightgroup_active_set(view_layer, lightgroup); +} + +ViewLayer *BKE_view_layer_find_with_lightgroup(struct Scene *scene, + struct ViewLayerLightgroup *lightgroup) +{ + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { + if (BLI_findindex(&view_layer->lightgroups, lightgroup) != -1) { + return view_layer; + } + } + return NULL; +} + +void BKE_view_layer_rename_lightgroup(ViewLayer *view_layer, + ViewLayerLightgroup *lightgroup, + const char *name) +{ + BLI_strncpy_utf8(lightgroup->name, name, sizeof(lightgroup->name)); + viewlayer_lightgroup_make_name_unique(view_layer, lightgroup); +} + +void BKE_lightgroup_membership_get(struct LightgroupMembership *lgm, char *name) +{ + if (lgm != NULL) { + BLI_strncpy(name, lgm->name, sizeof(lgm->name)); + } + else { + name[0] = '\0'; + } +} + +int BKE_lightgroup_membership_length(struct LightgroupMembership *lgm) +{ + if (lgm != NULL) { + return strlen(lgm->name); + } + return 0; +} + +void BKE_lightgroup_membership_set(struct LightgroupMembership **lgm, const char *name) +{ + if (name[0] != '\0') { + if (*lgm == NULL) { + *lgm = MEM_callocN(sizeof(LightgroupMembership), __func__); + } + BLI_strncpy((*lgm)->name, name, sizeof((*lgm)->name)); + } + else { + if (*lgm != NULL) { + MEM_freeN(*lgm); + *lgm = NULL; + } + } +} + /** \} */ diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc index c00a403d5e9..833e6f882f1 100644 --- a/source/blender/blenkernel/intern/object.cc +++ b/source/blender/blenkernel/intern/object.cc @@ -260,6 +260,10 @@ static void object_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const in else { ob_dst->preview = nullptr; } + + if (ob_src->lightgroup) { + ob_dst->lightgroup = (LightgroupMembership *)MEM_dupallocN(ob_src->lightgroup); + } } static void object_free_data(ID *id) @@ -310,6 +314,8 @@ static void object_free_data(ID *id) } BKE_previewimg_free(&ob->preview); + + MEM_SAFE_FREE(ob->lightgroup); } static void library_foreach_modifiersForeachIDLink(void *user_data, @@ -584,6 +590,10 @@ static void object_blend_write(BlendWriter *writer, ID *id, const void *id_addre BLO_write_struct_list(writer, LinkData, &ob->pc_ids); BKE_previewimg_blend_write(writer, ob->preview); + + if (ob->lightgroup) { + BLO_write_struct(writer, LightgroupMembership, ob->lightgroup); + } } /* XXX deprecated - old animation system */ @@ -800,6 +810,8 @@ static void object_blend_read_data(BlendDataReader *reader, ID *id) BLO_read_data_address(reader, &ob->preview); BKE_previewimg_blend_read(reader, ob->preview); + + BLO_read_data_address(reader, &ob->lightgroup); } /* XXX deprecated - old animation system */ diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index ac8b18f3395..cc3ee06f539 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -59,6 +59,8 @@ static void world_free_data(ID *id) BKE_icon_id_delete((struct ID *)wrld); BKE_previewimg_free(&wrld->preview); + + MEM_SAFE_FREE(wrld->lightgroup); } static void world_init_data(ID *id) @@ -107,6 +109,10 @@ static void world_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int else { wrld_dst->preview = NULL; } + + if (wrld_src->lightgroup) { + wrld_dst->lightgroup = (LightgroupMembership *)MEM_dupallocN(wrld_src->lightgroup); + } } static void world_foreach_id(ID *id, LibraryForeachIDData *data) @@ -142,6 +148,10 @@ static void world_blend_write(BlendWriter *writer, ID *id, const void *id_addres } BKE_previewimg_blend_write(writer, wrld->preview); + + if (wrld->lightgroup) { + BLO_write_struct(writer, LightgroupMembership, wrld->lightgroup); + } } static void world_blend_read_data(BlendDataReader *reader, ID *id) @@ -153,6 +163,8 @@ static void world_blend_read_data(BlendDataReader *reader, ID *id) BLO_read_data_address(reader, &wrld->preview); BKE_previewimg_blend_read(reader, wrld->preview); BLI_listbase_clear(&wrld->gpumaterial); + + BLO_read_data_address(reader, &wrld->lightgroup); } static void world_blend_read_lib(BlendLibReader *reader, ID *id) |