gp_render/OP_setup_layers.py

217 lines
8.4 KiB
Python
Raw Normal View History

import bpy
from bpy.props import (FloatProperty,
BoolProperty,
EnumProperty,
StringProperty,
IntProperty)
from . import fn
class GPEXP_OT_layers_state(bpy.types.Operator):
bl_idname = "gp.layers_state"
bl_label = "Set Layers State"
bl_description = "Display state of layer that migh need adjustement"
bl_options = {"REGISTER"} # , "UNDO"
# clear_unused_view_layers :BoolProperty(name="Clear unused view layers",
# description="Delete view layer that aren't used in the nodetree anymore",
# default=True)
# TODO : (optional) export layer opacity to json and/or text
# (that way compo artists can re-affect opacity quickly or at least have a reminder)
all_objects : BoolProperty(name='On All Object',
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'}
set_use_lights : BoolProperty(name='Disable Use Light',
default=True, description='Check/Set use lights disabling') # , options={'SKIP_SAVE'}
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):
return context.object and context.object.type == 'GPENCIL'
def invoke(self, context, event):
# self.ctrl=event.ctrl
# self.alt=event.alt
if event.alt:
self.all_objects=True
# return self.execute(context)
return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
layout = self.layout
layout.prop(self, 'all_objects')
layout.separator()
layout.label(text='Set (or only perform a check):')
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')
def execute(self, context):
if self.all_objects:
pool = [o for o in context.scene.objects if o.type == 'GPENCIL']
else:
pool = [o for o in context.selected_objects if o.type == 'GPENCIL']
# pool = [context.object]
changes = []
for ob in pool:
changes.append(f'>> {ob.name}')
layers = ob.data.layers
for l in layers:
used = False
## mask check
# 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:
# 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:
use_lights_state = '' if self.set_use_lights else ' (check only)'
mess = f'{l.info} : disable use lights{use_lights_state}'
print(mess)
changes.append(mess)
if self.set_use_lights:
l.use_lights = False
used = True
if l.blend_mode != 'REGULAR':
blend_mode_state = '' if self.set_blend_mode else ' (check only)'
mess = f'{l.info} : blend mode "{l.blend_mode}" >> regular{blend_mode_state}'
print(mess)
changes.append(mess)
if self.set_blend_mode:
l.blend_mode = 'REGULAR'
used = True
if used:
print()
if changes:
changes.append('')
fn.show_message_box(_message=changes, _title="Layers Check Report", _icon='INFO')
# render = bpy.data.scenes.get('Render')
# if not render:
# print('SKIP, no Render scene')
# return {"CANCELLED"}
return {"FINISHED"}
class GPEXP_OT_lower_layers_name(bpy.types.Operator):
bl_idname = "gp.lower_layers_name"
bl_label = "Normalize Layers Name"
bl_description = "Make the object and layers name lowercase with dashed converted to underscore (without touching layer prefix and suffix)"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
return context.object and context.object.type == 'GPENCIL'
all_objects : BoolProperty(name='On All Object',
default=False, description='On All object, else use selected objects') # , options={'SKIP_SAVE'}
object_name : BoolProperty(name='Normalize Object Name',
default=True, description='Make the object name lowercase') # , options={'SKIP_SAVE'}
layer_name : BoolProperty(name='Normalize Layers Names',
default=True, description='Make the layers name lowercase') # , options={'SKIP_SAVE'}
# dash_to_undescore : BoolProperty(name='Dash To Underscore',
# default=True, description='Make the layers name lowercase') # , options={'SKIP_SAVE'}
def invoke(self, context, event):
# self.ctrl=event.ctrl
# self.alt=event.alt
if event.alt:
self.all_objects=True
# return self.execute(context)
return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
layout = self.layout
layout.prop(self, 'all_objects')
if self.all_objects:
gp_ct = len([o for o in context.scene.objects if o.type == 'GPENCIL'])
else:
gp_ct = len([o for o in context.selected_objects if o.type == 'GPENCIL'])
layout.label(text=f'{gp_ct} to lower-case')
layout.separator()
layout.label(text=f'Choose what to rename:')
layout.prop(self, 'object_name')
layout.prop(self, 'layer_name')
# if self.layer_name:
# box = layout.box()
# box.prop(self, 'dash_to_undescore')
if not self.object_name and not self.layer_name:
layout.label(text=f'At least one choice!', icon='ERROR')
def execute(self, context):
if self.all_objects:
pool = [o for o in context.scene.objects if o.type == 'GPENCIL']
else:
pool = [o for o in context.selected_objects if o.type == 'GPENCIL']
for ob in pool:
if self.object_name:
rename_data = ob.name == ob.data.name
ob.name = ob.name.lower().replace('-', '_')
if rename_data:
ob.data.name = ob.name
if self.layer_name:
for l in ob.data.layers:
# if self.dash_to_undescore:
l.info = l.info.replace('-', '_')
fn.normalize_layer_name(l) # default : lower=True, dash_to_underscore=self.dash_to_undescore
return {"FINISHED"}
classes=(
GPEXP_OT_layers_state,
GPEXP_OT_lower_layers_name
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)