Render: Add operators to add all used or remove all unused lightgroups
These operators build a list of all lightgroups that are used by the view layer's scene and either add all used lightgroups that are not part of the view layer yet or remove all lightgroups in the view layer that are not being used. Differential Revision: https://developer.blender.org/D14596
This commit is contained in:
parent
0b05e0b97e
commit
2e77a8f974
Notes:
blender-bot
2023-02-14 02:27:56 +01:00
Referenced by issue #97796, Regression: alpha clipped materials render fuzzy (exactly like alpha hashed materials)
|
@ -1,7 +1,7 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
# <pep8 compliant>
|
||||
from bpy.types import Panel, UIList
|
||||
from bpy.types import Menu, Panel, UIList
|
||||
|
||||
|
||||
class VIEWLAYER_UL_aov(UIList):
|
||||
|
@ -138,7 +138,7 @@ class ViewLayerAOVPanel(ViewLayerButtonsPanel, Panel):
|
|||
row = layout.row()
|
||||
col = row.column()
|
||||
col.template_list("VIEWLAYER_UL_aov", "aovs", view_layer,
|
||||
"aovs", view_layer, "active_aov_index", rows=2)
|
||||
"aovs", view_layer, "active_aov_index", rows=3)
|
||||
|
||||
col = row.column()
|
||||
sub = col.column(align=True)
|
||||
|
@ -187,6 +187,16 @@ class VIEWLAYER_PT_layer_passes_cryptomatte(ViewLayerCryptomattePanel, Panel):
|
|||
COMPAT_ENGINES = {'BLENDER_EEVEE'}
|
||||
|
||||
|
||||
class VIEWLAYER_MT_lightgroup_sync(Menu):
|
||||
bl_label = "Lightgroup Sync"
|
||||
|
||||
def draw(self, _context):
|
||||
layout = self.layout
|
||||
|
||||
layout.operator("scene.view_layer_add_used_lightgroups", icon='ADD')
|
||||
layout.operator("scene.view_layer_remove_unused_lightgroups", icon='REMOVE')
|
||||
|
||||
|
||||
class ViewLayerLightgroupsPanel(ViewLayerButtonsPanel, Panel):
|
||||
bl_label = "Light Groups"
|
||||
|
||||
|
@ -201,12 +211,14 @@ class ViewLayerLightgroupsPanel(ViewLayerButtonsPanel, Panel):
|
|||
row = layout.row()
|
||||
col = row.column()
|
||||
col.template_list("UI_UL_list", "lightgroups", view_layer,
|
||||
"lightgroups", view_layer, "active_lightgroup_index", rows=2)
|
||||
"lightgroups", view_layer, "active_lightgroup_index", rows=3)
|
||||
|
||||
col = row.column()
|
||||
sub = col.column(align=True)
|
||||
sub.operator("scene.view_layer_add_lightgroup", icon='ADD', text="")
|
||||
sub.operator("scene.view_layer_remove_lightgroup", icon='REMOVE', text="")
|
||||
sub.separator()
|
||||
sub.menu("VIEWLAYER_MT_lightgroup_sync", icon='DOWNARROW_HLT', text="")
|
||||
|
||||
|
||||
class VIEWLAYER_PT_layer_passes_lightgroups(ViewLayerLightgroupsPanel):
|
||||
|
@ -215,6 +227,7 @@ class VIEWLAYER_PT_layer_passes_lightgroups(ViewLayerLightgroupsPanel):
|
|||
|
||||
|
||||
classes = (
|
||||
VIEWLAYER_MT_lightgroup_sync,
|
||||
VIEWLAYER_PT_layer,
|
||||
VIEWLAYER_PT_layer_passes,
|
||||
VIEWLAYER_PT_eevee_layer_passes_data,
|
||||
|
|
|
@ -35,6 +35,8 @@ void SCENE_OT_view_layer_add_aov(struct wmOperatorType *ot);
|
|||
void SCENE_OT_view_layer_remove_aov(struct wmOperatorType *ot);
|
||||
void SCENE_OT_view_layer_add_lightgroup(struct wmOperatorType *ot);
|
||||
void SCENE_OT_view_layer_remove_lightgroup(struct wmOperatorType *ot);
|
||||
void SCENE_OT_view_layer_add_used_lightgroups(struct wmOperatorType *ot);
|
||||
void SCENE_OT_view_layer_remove_unused_lightgroups(struct wmOperatorType *ot);
|
||||
|
||||
void SCENE_OT_light_cache_bake(struct wmOperatorType *ot);
|
||||
void SCENE_OT_light_cache_free(struct wmOperatorType *ot);
|
||||
|
|
|
@ -41,6 +41,8 @@ void ED_operatortypes_render()
|
|||
WM_operatortype_append(SCENE_OT_view_layer_remove_aov);
|
||||
WM_operatortype_append(SCENE_OT_view_layer_add_lightgroup);
|
||||
WM_operatortype_append(SCENE_OT_view_layer_remove_lightgroup);
|
||||
WM_operatortype_append(SCENE_OT_view_layer_add_used_lightgroups);
|
||||
WM_operatortype_append(SCENE_OT_view_layer_remove_unused_lightgroups);
|
||||
|
||||
WM_operatortype_append(SCENE_OT_render_view_add);
|
||||
WM_operatortype_append(SCENE_OT_render_view_remove);
|
||||
|
|
|
@ -1216,6 +1216,114 @@ void SCENE_OT_view_layer_remove_lightgroup(wmOperatorType *ot)
|
|||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name View Layer Add Used Lightgroups Operator
|
||||
* \{ */
|
||||
|
||||
static GSet *get_used_lightgroups(Scene *scene)
|
||||
{
|
||||
GSet *used_lightgroups = BLI_gset_str_new(__func__);
|
||||
|
||||
FOREACH_SCENE_OBJECT_BEGIN (scene, ob) {
|
||||
if (ob->lightgroup && ob->lightgroup->name[0]) {
|
||||
BLI_gset_add(used_lightgroups, ob->lightgroup->name);
|
||||
}
|
||||
}
|
||||
FOREACH_SCENE_OBJECT_END;
|
||||
|
||||
if (scene->world && scene->world->lightgroup && scene->world->lightgroup->name[0]) {
|
||||
BLI_gset_add(used_lightgroups, scene->world->lightgroup->name);
|
||||
}
|
||||
|
||||
return used_lightgroups;
|
||||
}
|
||||
|
||||
static int view_layer_add_used_lightgroups_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
|
||||
GSet *used_lightgroups = get_used_lightgroups(scene);
|
||||
GSET_FOREACH_BEGIN (const char *, used_lightgroup, used_lightgroups) {
|
||||
if (!BLI_findstring(
|
||||
&view_layer->lightgroups, used_lightgroup, offsetof(ViewLayerLightgroup, name))) {
|
||||
BKE_view_layer_add_lightgroup(view_layer, used_lightgroup);
|
||||
}
|
||||
}
|
||||
GSET_FOREACH_END();
|
||||
BLI_gset_free(used_lightgroups, nullptr);
|
||||
|
||||
if (scene->nodetree) {
|
||||
ntreeCompositUpdateRLayers(scene->nodetree);
|
||||
}
|
||||
|
||||
DEG_id_tag_update(&scene->id, 0);
|
||||
DEG_relations_tag_update(CTX_data_main(C));
|
||||
WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void SCENE_OT_view_layer_add_used_lightgroups(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name = "Add Used Lightgroups";
|
||||
ot->idname = "SCENE_OT_view_layer_add_used_lightgroups";
|
||||
ot->description = "Add all used Light Groups";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = view_layer_add_used_lightgroups_exec;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name View Layer Remove Unussed Lightgroups Operator
|
||||
* \{ */
|
||||
|
||||
static int view_layer_remove_unused_lightgroups_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
|
||||
GSet *used_lightgroups = get_used_lightgroups(scene);
|
||||
LISTBASE_FOREACH_MUTABLE (ViewLayerLightgroup *, lightgroup, &view_layer->lightgroups) {
|
||||
if (!BLI_gset_haskey(used_lightgroups, lightgroup->name)) {
|
||||
BKE_view_layer_remove_lightgroup(view_layer, lightgroup);
|
||||
}
|
||||
}
|
||||
BLI_gset_free(used_lightgroups, nullptr);
|
||||
|
||||
if (scene->nodetree) {
|
||||
ntreeCompositUpdateRLayers(scene->nodetree);
|
||||
}
|
||||
|
||||
DEG_id_tag_update(&scene->id, 0);
|
||||
DEG_relations_tag_update(CTX_data_main(C));
|
||||
WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void SCENE_OT_view_layer_remove_unused_lightgroups(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name = "Remove Unused Lightgroups";
|
||||
ot->idname = "SCENE_OT_view_layer_remove_unused_lightgroups";
|
||||
ot->description = "Remove all unused Light Groups";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = view_layer_remove_unused_lightgroups_exec;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Light Cache Bake Operator
|
||||
* \{ */
|
||||
|
|
Loading…
Reference in New Issue