Gp modifier to unified modifier

master
pullusb 2024-11-11 18:44:35 +01:00
parent 0160b4eae4
commit 94fc926f7a
4 changed files with 25 additions and 83 deletions

View File

@ -181,20 +181,12 @@ class GPTB_OT_file_checker(bpy.types.Operator):
if fix.list_gp_mod_vis_conflict: if fix.list_gp_mod_vis_conflict:
mod_viz_ct = 0 mod_viz_ct = 0
for o in context.scene.objects: for o in context.scene.objects:
if o.type == 'GREASEPENCIL': for m in o.modifiers:
for m in o.grease_pencil_modifiers: if m.show_viewport != m.show_render:
if m.show_viewport != m.show_render: vp = 'Yes' if m.show_viewport else 'No'
vp = 'Yes' if m.show_viewport else 'No' rd = 'Yes' if m.show_render else 'No'
rd = 'Yes' if m.show_render else 'No' mod_viz_ct += 1
mod_viz_ct += 1 print(f'{o.name} - modifier {m.name}: viewport {vp} != render {rd}')
print(f'{o.name} - GP modifier {m.name}: viewport {vp} != render {rd}')
else:
for m in o.modifiers:
if m.show_viewport != m.show_render:
vp = 'Yes' if m.show_viewport else 'No'
rd = 'Yes' if m.show_render else 'No'
mod_viz_ct += 1
print(f'{o.name} - modifier {m.name}: viewport {vp} != render {rd}')
if mod_viz_ct: if mod_viz_ct:
problems.append(['gp.list_modifier_visibility', f'{mod_viz_ct} modifiers visibility conflicts (details in console)', 'MODIFIER_DATA']) problems.append(['gp.list_modifier_visibility', f'{mod_viz_ct} modifiers visibility conflicts (details in console)', 'MODIFIER_DATA'])
@ -203,11 +195,11 @@ class GPTB_OT_file_checker(bpy.types.Operator):
if fix.list_broken_mod_targets: if fix.list_broken_mod_targets:
for o in [o for o in bpy.context.scene.objects if o.type == 'GREASEPENCIL']: for o in [o for o in bpy.context.scene.objects if o.type == 'GREASEPENCIL']:
lay_name_list = [l.name for l in o.data.layers] lay_name_list = [l.name for l in o.data.layers]
for m in o.grease_pencil_modifiers: for m in o.modifiers:
if not hasattr(m, 'layer'): if not hasattr(m, 'layer_filter'):
continue continue
if m.layer != '' and not m.layer in lay_name_list: if m.layer_filter != '' and not m.layer_filter in lay_name_list:
mess = f'Broken modifier layer target: {o.name} > {m.name} > {m.layer}' mess = f'Broken modifier layer target: {o.name} > {m.name} > {m.layer_filter}'
print(mess) print(mess)
problems.append(mess) problems.append(mess)
@ -562,46 +554,6 @@ class GPTB_OT_list_object_visibility(bpy.types.Operator):
# self.report({'INFO'}, f"No Object visibility conflict on current scene") # self.report({'INFO'}, f"No Object visibility conflict on current scene")
# return {'FINISHED'} # return {'FINISHED'}
## Only GP modifier
'''
class GPTB_OT_list_modifier_visibility(bpy.types.Operator):
bl_idname = "gp.list_modifier_visibility"
bl_label = "List GP Modifiers Visibility Conflicts"
bl_description = "List Modifier visibility conflicts, when viewport and render have different values"
bl_options = {"REGISTER"}
def invoke(self, context, event):
self.ob_list = []
for o in context.scene.objects:
if o.type != 'GREASEPENCIL':
continue
if not len(o.grease_pencil_modifiers):
continue
mods = []
for m in o.grease_pencil_modifiers:
if m.show_viewport != m.show_render:
if not mods:
self.ob_list.append([o, mods])
mods.append(m)
return context.window_manager.invoke_props_dialog(self, width=250)
def draw(self, context):
layout = self.layout
for o in self.ob_list:
layout.label(text=o[0].name, icon='OUTLINER_OB_GREASEPENCIL')
for m in o[1]:
row = layout.row()
row.label(text='')
row.label(text=m.name, icon='MODIFIER_ON')
row.prop(m, 'show_viewport', text='', emboss=False) # invert_checkbox=True
row.prop(m, 'show_render', text='', emboss=False) # invert_checkbox=True
def execute(self, context):
return {'FINISHED'}
'''
## not exposed in UI, Check is performed in Check file (can be called in popped menu) ## not exposed in UI, Check is performed in Check file (can be called in popped menu)
class GPTB_OT_list_modifier_visibility(bpy.types.Operator): class GPTB_OT_list_modifier_visibility(bpy.types.Operator):
bl_idname = "gp.list_modifier_visibility" bl_idname = "gp.list_modifier_visibility"
@ -612,24 +564,14 @@ class GPTB_OT_list_modifier_visibility(bpy.types.Operator):
def invoke(self, context, event): def invoke(self, context, event):
self.ob_list = [] self.ob_list = []
for o in context.scene.objects: for o in context.scene.objects:
if o.type == 'GREASEPENCIL': if not len(o.modifiers):
if not len(o.grease_pencil_modifiers): continue
continue mods = []
mods = [] for m in o.modifiers:
for m in o.grease_pencil_modifiers: if m.show_viewport != m.show_render:
if m.show_viewport != m.show_render: if not mods:
if not mods: self.ob_list.append([o, mods, "OUTLINER_OB_" + o.type])
self.ob_list.append([o, mods, 'OUTLINER_OB_GREASEPENCIL']) mods.append(m)
mods.append(m)
else:
if not len(o.modifiers):
continue
mods = []
for m in o.modifiers:
if m.show_viewport != m.show_render:
if not mods:
self.ob_list.append([o, mods, "OUTLINER_OB_" + o.type])
mods.append(m)
self.ob_list.sort(key=lambda x: x[2]) # regroup by objects type (this or x[0] for object name) self.ob_list.sort(key=lambda x: x[2]) # regroup by objects type (this or x[0] for object name)
return context.window_manager.invoke_props_dialog(self, width=250) return context.window_manager.invoke_props_dialog(self, width=250)

View File

@ -475,7 +475,7 @@ class GPTB_OT_toggle_hide_gp_modifier(Operator):
for o in pool: for o in pool:
if o.type != 'GREASEPENCIL': if o.type != 'GREASEPENCIL':
continue continue
for m in o.grease_pencil_modifiers: for m in o.modifier:
# skip modifier that are not visible in render # skip modifier that are not visible in render
if not m.show_render: if not m.show_render:
continue continue

View File

@ -78,11 +78,11 @@ def layer_name_build(layer, prefix='', desc='', suffix=''):
# maybe a more elegant way exists to find all objects users ? # maybe a more elegant way exists to find all objects users ?
# update Gpencil modifier targets # update Gpencil modifier targets
for mod in ob_user.grease_pencil_modifiers: for mod in ob_user.modifier:
if not hasattr(mod, 'layer'): if not hasattr(mod, 'layer_filter'):
continue continue
if mod.layer == old: if mod.layer_filter == old:
mod.layer = new mod.layer_filter = new
""" """
def layer_name_build(layer, prefix='', prefix2='', desc='', suffix=''): def layer_name_build(layer, prefix='', prefix2='', desc='', suffix=''):

View File

@ -1221,7 +1221,7 @@ def all_object_modifier_enabled(objects) -> bool:
for o in objects: for o in objects:
if o.type != 'GREASEPENCIL': if o.type != 'GREASEPENCIL':
continue continue
for m in o.grease_pencil_modifiers: for m in o.modifier:
if m.show_render and not m.show_viewport: if m.show_render and not m.show_viewport:
return False return False
@ -1325,7 +1325,7 @@ def gp_modifier_status(objects) -> tuple((str, str)):
## Skip hided object ## Skip hided object
if o.hide_get() and o.hide_render: if o.hide_get() and o.hide_render:
continue continue
for m in o.grease_pencil_modifiers: for m in o.modifier:
if m.show_render and not m.show_viewport: if m.show_render and not m.show_viewport:
off_count += 1 off_count += 1
else: else: