From 37809e15e63ddcfc1531038fed2459ab990f6b9e Mon Sep 17 00:00:00 2001 From: Pullusb Date: Wed, 22 Sep 2021 18:35:52 +0200 Subject: [PATCH] set opacity skip masks 0.3.5: feat: set full opacity -> skip chosen prefix (MA by default) --- CHANGELOG.md | 4 +++ OP_check_scene.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++ OP_setup_layers.py | 30 +++++++++++------ __init__.py | 2 +- ui.py | 6 ++-- 5 files changed, 108 insertions(+), 14 deletions(-) create mode 100644 OP_check_scene.py diff --git a/CHANGELOG.md b/CHANGELOG.md index dca3889..2c75b80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ Activate / deactivate layer opaticty according to prefix Activate / deactivate all masks using MA layers --> +0.3.5: + +feat: set full opacity -> skip chosen prefix (MA by default) + 0.3.4: feat: swap cams button, code copied from `bg_plane_manager` diff --git a/OP_check_scene.py b/OP_check_scene.py new file mode 100644 index 0000000..a831c2c --- /dev/null +++ b/OP_check_scene.py @@ -0,0 +1,80 @@ +import bpy +from . import fn + +## not used, replaced by "setup_layers.py" +class GPEXP_OT_check_render_scene(bpy.types.Operator): + bl_idname = "gp.check_render_scene" + bl_label = "Check render scene" + bl_description = "Auto check render scene" + bl_options = {"REGISTER"} # , "UNDO" + + # clear_unused_view_layers : bpy.props.BoolProperty(name="Clear unused view layers", + # description="Delete view layer that aren't used in the nodetree anymore", + # default=True) + + @classmethod + def poll(cls, context): + return True + + def invoke(self, context, event): + return self.execute(context) + return context.window_manager.invoke_props_dialog(self) + + def draw(self, context): + layout = self.layout + # layout.prop(self, 'clear_unused_view_layers') + + def execute(self, context): + gp_objs = [o for o in context.scene.objects if o.type == 'GPENCIL'] + + + # TODO create a list to disaply everything in a message box ? + + for ob in pool: + layers = ob.data.layers + for l in layers: + used = False + if l.mask_layers: + print(f'-> masks') + state = '' if l.use_mask_layer else ' (disabled)' + print(f'{ob.name} > {l.info}{state}:') + used = True + for ml in l.mask_layers: + mlstate = ' (disabled)' if ml.hide else '' + mlinvert = ' <>' if ml.invert else '' + print(f' - {ml.info}{mlstate}{mlinvert}') + + if l.opacity != 1: + print(f'-> opacity {l.opacity}') + used = True + + if l.use_lights: + print(f'-> use lights !') + used = True + if l.blend_mode != 'REGULAR': + print(f'-> blend mode "{l.blend_mode}" !') + used = True + + if used: + print() + + # render = bpy.data.scenes.get('Render') + # if not render: + # print('SKIP, no Render scene') + # return {"CANCELLED"} + + return {"FINISHED"} + + + +classes=( +GPEXP_OT_check_render_scene, +) + +def register(): + for cls in classes: + bpy.utils.register_class(cls) + +def unregister(): + for cls in reversed(classes): + bpy.utils.unregister_class(cls) \ No newline at end of file diff --git a/OP_setup_layers.py b/OP_setup_layers.py index 61a33b4..196732e 100644 --- a/OP_setup_layers.py +++ b/OP_setup_layers.py @@ -20,7 +20,7 @@ class GPEXP_OT_layers_state(bpy.types.Operator): # (that way compo artists can re-affect opacity quickly or at least have a reminder) all_objects : BoolProperty(name='On All Object', - default=False, description='On All object, else use selected objects') # , options={'SKIP_SAVE'} + default=True, description='On All object, else use selected objects') # , options={'SKIP_SAVE'} set_full_opacity : BoolProperty(name='Set Full Opacity', default=True, description='Check/Set full opacity') # , options={'SKIP_SAVE'} @@ -30,6 +30,9 @@ class GPEXP_OT_layers_state(bpy.types.Operator): set_blend_mode : BoolProperty(name='Set Regular Blend Mode', default=True, description='Check/Set blend mode to regular') # , options={'SKIP_SAVE'} + + opacity_exclude_list : StringProperty(name='Skip', + default='MA', description='Skip prefixes from this list when changing opacity\nSeparate multiple value with a comma (ex: MA,IN)') # , options={'SKIP_SAVE'} @classmethod def poll(cls, context): @@ -48,7 +51,10 @@ class GPEXP_OT_layers_state(bpy.types.Operator): layout.prop(self, 'all_objects') layout.separator() layout.label(text='Set (or only perform a check):') - layout.prop(self, 'set_full_opacity') + row = layout.row() + row.prop(self, 'set_full_opacity') + if self.set_full_opacity: + row.prop(self, 'opacity_exclude_list') layout.prop(self, 'set_use_lights') layout.prop(self, 'set_blend_mode') # layout.prop(self, 'clear_unused_view_layers') @@ -79,14 +85,18 @@ class GPEXP_OT_layers_state(bpy.types.Operator): # print(f'{ml.info}{mlstate}{mlinvert}') if l.opacity != 1: - - full_opacity_state = '' if self.set_full_opacity else ' (check only)' - mess = f'{l.info} : opacity {l.opacity:.2f} >> 1.0{full_opacity_state}' - print(mess) - changes.append(mess) - if self.set_full_opacity: - l.opacity = 1.0 - used = True + # TODO Skip zeroed opacity ? + # check if there is an exclusion word + if any(x.strip() + '_' in l.info for x in self.opacity_exclude_list.strip(',').split(',') if x): + print(f'Skipped layer : {l.info}') + else: + full_opacity_state = '' if self.set_full_opacity else ' (check only)' + mess = f'{l.info} : opacity {l.opacity:.2f} >> 1.0{full_opacity_state}' + print(mess) + changes.append(mess) + if self.set_full_opacity: + l.opacity = 1.0 + used = True if l.use_lights: diff --git a/__init__.py b/__init__.py index 0437efc..1793a6d 100644 --- a/__init__.py +++ b/__init__.py @@ -2,7 +2,7 @@ bl_info = { "name": "GP Render", "description": "Organise export of gp layers through compositor output", "author": "Samuel Bernou", - "version": (0, 3, 4), + "version": (0, 3, 5), "blender": (2, 93, 0), "location": "View3D", "warning": "", diff --git a/ui.py b/ui.py index 6be032d..cb8a76b 100644 --- a/ui.py +++ b/ui.py @@ -16,8 +16,6 @@ class GPEXP_PT_gp_node_ui(Panel): layout.operator('gp.render_scene_switch', icon='SCENE_DATA', text='Switch Scene') scn = context.scene - if not scn.use_nodes or not scn.node_tree: - return ## Camera swapping row = layout.row() @@ -27,11 +25,13 @@ class GPEXP_PT_gp_node_ui(Panel): else: text = f'None' # Cam: - layout.separator() # if cam and cam_name == 'draw_cam': # cam_name = f'{cam.parent.name} > {cam_name}' row.operator("gp.swap_render_cams", text=text, icon='OUTLINER_OB_CAMERA') + if not scn.use_nodes or not scn.node_tree: + return + layout.separator() # TODO : add advanced bool checkbox to hide some options from the user col = layout.column(align=True)