Fix Shot_Builder
fails to invoke with correct project root directory
#8
@ -50,6 +50,12 @@ Add-on with miscellaneous tools for animators.
|
||||
|
||||
Author & Maintainer: Demeter Dzadik
|
||||
|
||||
## lighting-overrider
|
||||
|
||||
Add-on to create, manage and apply python overrides in a flexible and reliable way as they are used in the lighting process of the Blender Studio pipeline on a shot and sequence level.
|
||||
|
||||
Author & Maintainer: Simon Thommes
|
||||
|
||||
## blender-svn
|
||||
|
||||
Add-on that is intended as a UI for the SVN (Subversion) file versioning system which we use at the studio. Currently doesn't support check-out, but once a check-out is done, it supports all common SVN operations, including resolving conflicts. The currently opened .blend file must be in an SVN repository for the UI to appear.
|
||||
|
1
lighting_overrider/README.md
Normal file
1
lighting_overrider/README.md
Normal file
@ -0,0 +1 @@
|
||||
System to create, manage and apply python overrides in a flexible and reliable way as they are used in the lighting process of the Blender Studio pipeline.
|
33
lighting_overrider/TODO.txt
Normal file
33
lighting_overrider/TODO.txt
Normal file
@ -0,0 +1,33 @@
|
||||
UI
|
||||
|
||||
- show alerts for items that are not found
|
||||
- automatically select type based on match
|
||||
|
||||
FEATURES
|
||||
|
||||
custom properties
|
||||
- allow rna overriding of custom properties (see geonodes modifiers)
|
||||
|
||||
remove drivers/animation data
|
||||
- properly remove drivers/animation data when creating an rna override
|
||||
|
||||
animated overrides
|
||||
- store animation data in the blend file and write
|
||||
their rna path to json to allow animated/driven overrides
|
||||
|
||||
execution script
|
||||
- auto-generate script from modules
|
||||
|
||||
text data-block
|
||||
- auto-load on file-load if on disk
|
||||
- jump to file in text editor
|
||||
|
||||
settings interaction
|
||||
- show dirty per category
|
||||
|
||||
FIXES
|
||||
|
||||
- library flags for RNA overrides
|
||||
- settings ordering (template)
|
||||
- search invert (template)
|
||||
- auto-mute drivers/fcurves whenever necessary !!
|
26
lighting_overrider/__init__.py
Normal file
26
lighting_overrider/__init__.py
Normal file
@ -0,0 +1,26 @@
|
||||
from . import categories
|
||||
from .categories import *
|
||||
from . import templates, json_io, execution, ui, override_picker
|
||||
|
||||
|
||||
bl_info = {
|
||||
"name": "Lighting Overrider",
|
||||
"author": "Simon Thommes",
|
||||
"version": (1,0),
|
||||
"blender": (3, 0, 0),
|
||||
"location": "3D Viewport > Sidebar > Overrides",
|
||||
"description": "Tool for the Blender Studio to create, manage and store local python overrides of linked data on a shot and sequence level.",
|
||||
"category": "Workflow",
|
||||
}
|
||||
|
||||
modules = [templates]
|
||||
modules += [globals()[mod] for mod in categories.__all__]
|
||||
modules += [json_io, execution, ui, override_picker]
|
||||
|
||||
def register():
|
||||
for m in modules:
|
||||
m.register()
|
||||
|
||||
def unregister():
|
||||
for m in modules:
|
||||
m.unregister()
|
1
lighting_overrider/categories/__init__.py
Normal file
1
lighting_overrider/categories/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
__all__ = [ 'variable_settings', 'motion_blur_settings', 'shader_settings', 'rig_settings', 'rna_overrides' ]
|
253
lighting_overrider/categories/motion_blur_settings.py
Normal file
253
lighting_overrider/categories/motion_blur_settings.py
Normal file
@ -0,0 +1,253 @@
|
||||
from .. import utils
|
||||
from ..templates import *
|
||||
import bpy
|
||||
|
||||
def settings_as_dict(settings):
|
||||
data = {}
|
||||
for setting in settings.motion_blur_settings:
|
||||
data[setting.name] = []
|
||||
return data
|
||||
|
||||
def apply_settings(data):
|
||||
''' Deactivates deformation motion blur for objects in selected collections.
|
||||
'''
|
||||
if not data:
|
||||
return
|
||||
|
||||
list_unique, list_all = utils.split_by_suffix(data.keys(), ':all')
|
||||
|
||||
if 'Master Collection' in data.keys() or 'Scene Collection' in data.keys():
|
||||
for ob in bpy.data.objects:
|
||||
if ob.type == 'CAMERA':
|
||||
continue
|
||||
ob.cycles.use_motion_blur = False
|
||||
return
|
||||
|
||||
for col in bpy.data.collections:
|
||||
for name_col in list_all:
|
||||
if not col.name.startswith(name_col):
|
||||
continue
|
||||
for ob in col.all_objects:
|
||||
if ob.type == 'CAMERA':
|
||||
continue
|
||||
ob.cycles.use_motion_blur = False
|
||||
# unique names
|
||||
if not col.name in list_unique:
|
||||
continue
|
||||
for ob in col.all_objects:
|
||||
if ob.type == 'CAMERA':
|
||||
continue
|
||||
ob.cycles.use_motion_blur = False
|
||||
return
|
||||
|
||||
def load_settings(settings, data):
|
||||
while len(settings.motion_blur_settings) > 0:
|
||||
settings.motion_blur_settings.remove(0)
|
||||
|
||||
for name in data.keys():
|
||||
value = data[name]
|
||||
new_setting = settings.motion_blur_settings.add()
|
||||
new_setting.name = name
|
||||
|
||||
settings.motion_blur_settings_index = min(settings.motion_blur_settings_index, len(settings.motion_blur_settings)-1)
|
||||
return
|
||||
|
||||
class LOR_OT_motion_blur_settings_apply(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.motion_blur_settings_apply"
|
||||
bl_label = "Apply Motion Blur Settings"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
apply_settings(settings_as_dict(settings))
|
||||
utils.kick_evaluation()
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_motion_blur_setting(LOR_subsetting):
|
||||
name: bpy.props.StringProperty(default='Collection Name')
|
||||
pass
|
||||
|
||||
class LOR_OT_motion_blur_settings_initialize(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.motion_blur_settings_init"
|
||||
bl_label = "Add Active Collection"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return bool(context.collection)
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
existing_names = [setting.name for setting in settings.motion_blur_settings]
|
||||
|
||||
active_name = context.collection.name
|
||||
|
||||
if not active_name in existing_names:
|
||||
new_setting = settings.motion_blur_settings.add()
|
||||
new_setting.name = active_name
|
||||
settings.is_dirty = True
|
||||
|
||||
settings.motion_blur_settings_index = len(settings.motion_blur_settings)-1
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class LOR_OT_motion_blur_setting_add(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.motion_blur_setting_add"
|
||||
bl_label = "Add Motion Blur Setting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
new_setting = settings.motion_blur_settings.add()
|
||||
settings.is_dirty = True
|
||||
|
||||
settings.motion_blur_settings_index = len(settings.motion_blur_settings)-1
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_motion_blur_setting_remove(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.motion_blur_setting_remove"
|
||||
bl_label = "Remove Motion Blur Setting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
return len(settings.motion_blur_settings)>0
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
settings.motion_blur_settings.remove(settings.motion_blur_settings_index)
|
||||
settings.is_dirty = True
|
||||
|
||||
if settings.motion_blur_settings_index >= len(settings.motion_blur_settings):
|
||||
settings.motion_blur_settings_index = len(settings.motion_blur_settings)-1
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_UL_motion_blur_settings_list(LOR_UL_settings_list):
|
||||
|
||||
def draw_item(
|
||||
self, context, layout, data, item, icon, active_data, active_propname, index):
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
row = layout.row()
|
||||
col = row.column()
|
||||
row = col.row(align=True)
|
||||
row.label(text='', icon='OUTLINER_COLLECTION')
|
||||
icon = 'WORLD' if item.name.endswith(':all') else 'MESH_CIRCLE'
|
||||
if item.name in ['Master Collection', 'Scene Collection']:
|
||||
icon = 'SHADING_SOLID'
|
||||
row.prop(item, "name", text='', icon=icon, emboss=False)
|
||||
|
||||
col = row.column()
|
||||
if index == settings.motion_blur_settings_index:
|
||||
col.operator("lighting_overrider.motion_blur_setting_remove", icon='X', text="", emboss=False)
|
||||
else:
|
||||
col.label(text='', icon='BLANK1')
|
||||
|
||||
def filter_items(self, context, data, propname):
|
||||
settings = getattr(data, propname)
|
||||
helper_funcs = bpy.types.UI_UL_list
|
||||
|
||||
flt_flags = []
|
||||
flt_neworder = []
|
||||
|
||||
if self.filter_name:
|
||||
flt_flags = helper_funcs.filter_items_by_name(self.filter_name, self.bitflag_filter_item, settings, "name",
|
||||
reverse=self.use_filter_invert)
|
||||
|
||||
return flt_flags, flt_neworder
|
||||
|
||||
class LOR_PT_motion_blur_settings_panel(bpy.types.Panel):
|
||||
bl_parent_id = "LOR_PT_lighting_overrider_panel"
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_region_type = 'UI'
|
||||
bl_label = "Motion Blur Settings"
|
||||
bl_category = 'Overrides'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
self.layout.label(text='', icon='ONIONSKIN_ON')
|
||||
return
|
||||
|
||||
def draw_header_preset(self, context):
|
||||
layout = self.layout
|
||||
col = layout.column()
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
col.enabled = False
|
||||
col.label(text=str(len(settings.motion_blur_settings)))
|
||||
return
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
col_top = layout.column()
|
||||
if not meta_settings.enabled:
|
||||
col_top.enabled = False
|
||||
row = col_top.row()
|
||||
col = row.column()
|
||||
row = col.row()
|
||||
row.operator("lighting_overrider.motion_blur_settings_init", icon='SHADERFX')
|
||||
|
||||
col = row.column()
|
||||
row = col.row(align=True)
|
||||
row.operator("lighting_overrider.motion_blur_setting_add", icon='ADD', text="")
|
||||
row.operator("lighting_overrider.motion_blur_setting_remove", icon='REMOVE', text="")
|
||||
|
||||
row = col_top.row(align=True)
|
||||
col = row.column()
|
||||
col.template_list(
|
||||
"LOR_UL_motion_blur_settings_list",
|
||||
"",
|
||||
settings,
|
||||
"motion_blur_settings",
|
||||
settings,
|
||||
"motion_blur_settings_index",
|
||||
rows=2,
|
||||
)
|
||||
col.operator('lighting_overrider.motion_blur_settings_apply', icon='PLAY')
|
||||
return
|
||||
|
||||
panel_class = LOR_PT_motion_blur_settings_panel
|
||||
|
||||
classes = (
|
||||
LOR_motion_blur_setting,
|
||||
LOR_UL_motion_blur_settings_list,
|
||||
LOR_OT_motion_blur_setting_add,
|
||||
LOR_OT_motion_blur_setting_remove,
|
||||
LOR_OT_motion_blur_settings_initialize,
|
||||
LOR_OT_motion_blur_settings_apply,
|
||||
)
|
||||
|
||||
def register():
|
||||
for c in classes:
|
||||
bpy.utils.register_class(c)
|
||||
|
||||
def unregister():
|
||||
for c in classes:
|
||||
bpy.utils.unregister_class(c)
|
415
lighting_overrider/categories/rig_settings.py
Normal file
415
lighting_overrider/categories/rig_settings.py
Normal file
@ -0,0 +1,415 @@
|
||||
from .. import utils
|
||||
from ..templates import *
|
||||
import bpy
|
||||
|
||||
def settings_as_dict(settings):
|
||||
data = {}
|
||||
for setting in settings.rig_settings:
|
||||
data_sub = {}
|
||||
for subsetting in setting.subsettings:
|
||||
if isinstance(getattr(subsetting, subsetting.type), str):
|
||||
data_sub[subsetting.name] = [getattr(subsetting, subsetting.type), subsetting.type]
|
||||
elif not subsetting.bl_rna.properties[subsetting.type].is_array:
|
||||
data_sub[subsetting.name] = [getattr(subsetting, subsetting.type), subsetting.type]
|
||||
else:
|
||||
data_sub[subsetting.name] = [getattr(subsetting, subsetting.type)[:], subsetting.type]
|
||||
data[setting.specifier] = data_sub
|
||||
return data
|
||||
|
||||
def get_properties_bone(ob, prefix='Properties_'):
|
||||
|
||||
if not ob.type == 'ARMATURE':
|
||||
return None
|
||||
|
||||
for bone in ob.pose.bones:
|
||||
if not bone.name.startswith(prefix):
|
||||
continue
|
||||
return bone
|
||||
return None
|
||||
|
||||
def apply_settings(data):
|
||||
if not data:
|
||||
return
|
||||
|
||||
list_unique, list_all = utils.split_by_suffix(data.keys(), ':all')
|
||||
|
||||
for ob in bpy.data.objects:
|
||||
# find properties bone (first posebone that starts with 'Properties_')
|
||||
if not ob.type == 'ARMATURE':
|
||||
continue
|
||||
bone_prop = get_properties_bone(ob)
|
||||
if not bone_prop:
|
||||
continue
|
||||
|
||||
# group names
|
||||
for name_ob in list_all:
|
||||
if not ob.name.startswith(name_ob):
|
||||
continue
|
||||
for name_set in data[name_ob+':all']:
|
||||
if not name_set in bone_prop:
|
||||
print(f'Warning: Property {name_set} on object {ob.name} not found.')
|
||||
continue
|
||||
data_path = f'pose.bones["{bone_prop.name}"]["{name_set}"]'
|
||||
utils.mute_fcurve(ob, data_path)
|
||||
bone_prop[name_set] = data[name_ob+':all'][name_set][0]
|
||||
|
||||
# unique names
|
||||
if ob.name in list_unique:
|
||||
for name_set in data[ob.name]:
|
||||
if name_set in bone_prop:
|
||||
data_path = f'pose.bones["{bone_prop.name}"]["{name_set}"]'
|
||||
utils.mute_fcurve(ob, data_path)
|
||||
bone_prop[name_set] = data[ob.name][name_set][0]
|
||||
else:
|
||||
print(f'Warning: Property {name_set} on object {ob.name} not found.')
|
||||
return
|
||||
|
||||
def load_settings(settings, data):
|
||||
while len(settings.rig_settings) > 0:
|
||||
settings.rig_settings.remove(0)
|
||||
|
||||
for specifier in data.keys():
|
||||
subsettings_dict = data[specifier]
|
||||
new_setting = settings.rig_settings.add()
|
||||
new_setting.setting_expanded = False
|
||||
new_setting.specifier = specifier
|
||||
for name in subsettings_dict.keys():
|
||||
value = subsettings_dict[name]
|
||||
new_subsetting = new_setting.subsettings.add()
|
||||
new_subsetting.name = name
|
||||
new_subsetting.type = value[1]
|
||||
setattr(new_subsetting, value[1], value[0])
|
||||
|
||||
settings.rig_settings_index = min(settings.rig_settings_index, len(settings.rig_settings)-1)
|
||||
return
|
||||
|
||||
class LOR_OT_rig_settings_apply(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.rig_settings_apply"
|
||||
bl_label = "Apply Rig Settings"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
apply_settings(settings_as_dict(settings))
|
||||
utils.kick_evaluation()
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_rig_setting(LOR_setting):
|
||||
specifier: bpy.props.StringProperty(default='HLP-', update=utils.mark_dirty)
|
||||
|
||||
|
||||
class LOR_OT_rig_settings_initialize(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.rig_settings_init"
|
||||
bl_label = "Initialize from Selection"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return 'ARMATURE' in [ob.type for ob in context.selected_objects]
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
existing_specifiers = [setting.specifier for setting in settings.rig_settings]
|
||||
|
||||
for ob in context.selected_objects:
|
||||
if not ob.type == 'ARMATURE':
|
||||
continue
|
||||
|
||||
bone_prop = get_properties_bone(ob)
|
||||
if not bone_prop:
|
||||
continue
|
||||
|
||||
if not ob.name in existing_specifiers:
|
||||
setting = settings.rig_settings.add()
|
||||
setting.specifier = ob.name
|
||||
else:
|
||||
setting = settings.rig_settings[existing_specifiers.index(ob.name)]
|
||||
|
||||
existing_names = [subsetting.name for subsetting in setting.subsettings]
|
||||
|
||||
for name in list(bone_prop.keys()): #TODO make type identification more fail-safe
|
||||
try:
|
||||
prop_props = bone_prop.id_properties_ui(name)
|
||||
except:
|
||||
continue
|
||||
|
||||
if name in existing_names:
|
||||
continue
|
||||
value = bone_prop[name]
|
||||
type = 'VALUE'
|
||||
if prop_props.as_dict()['subtype'] == 'COLOR':
|
||||
type = 'COLOR'
|
||||
elif prop_props.as_dict()['subtype'] == 'FACTOR':
|
||||
type = 'FACTOR'
|
||||
elif isinstance(bone_prop[name], int):
|
||||
type = 'INTEGER'
|
||||
elif isinstance(value, str):
|
||||
type = 'STRING'
|
||||
else:
|
||||
try:
|
||||
if len(value)==3 and not isinstance(value[0], str):
|
||||
type = 'VECTOR'
|
||||
else:
|
||||
continue
|
||||
except:
|
||||
continue
|
||||
subsetting = setting.subsettings.add()
|
||||
subsetting.name = name
|
||||
subsetting.type = type
|
||||
setattr(subsetting, subsetting.type, value)#TODO pull in settings like min/max
|
||||
settings.is_dirty = True
|
||||
|
||||
settings.rig_settings_index = len(settings.rig_settings)-1
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class LOR_OT_rig_setting_add(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.rig_setting_add"
|
||||
bl_label = "Add Rig Setting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
new_setting = settings.rig_settings.add()
|
||||
settings.is_dirty = True
|
||||
|
||||
settings.rig_settings_index = len(settings.rig_settings)-1
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_rig_setting_remove(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.rig_setting_remove"
|
||||
bl_label = "Remove Rig Setting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
return len(settings.rig_settings)>0
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
settings.rig_settings.remove(settings.rig_settings_index)
|
||||
settings.is_dirty = True
|
||||
|
||||
if settings.rig_settings_index >= len(settings.rig_settings):
|
||||
settings.rig_settings_index = len(settings.rig_settings)-1
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_rig_setting_duplicate(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.rig_setting_duplicate"
|
||||
bl_label = "Duplicate Rig Setting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
return len(settings.rig_settings)>0
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
prev_setting = settings.rig_settings[settings.rig_settings_index]
|
||||
new_setting = settings.rig_settings.add()
|
||||
|
||||
setattr(new_setting, 'specifier', getattr(prev_setting, 'specifier'))
|
||||
for i in range(len(prev_setting.subsettings)):
|
||||
new_setting.subsettings.add()
|
||||
enum_items = [item.identifier for item in prev_setting.subsettings[i].bl_rna.properties['type'].enum_items_static]
|
||||
for prop in ['name', 'type']+enum_items:
|
||||
setattr(new_setting.subsettings[i], prop, getattr(prev_setting.subsettings[i], prop))
|
||||
|
||||
settings.rig_settings_index = len(settings.rig_settings)-1
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_rig_subsetting_add(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.rig_subsetting_add"
|
||||
bl_label = "Add Rig Subsetting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
rig_setting = settings.rig_settings[settings.rig_settings_index]
|
||||
new_subsetting = rig_setting.subsettings.add()
|
||||
settings.is_dirty = True
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_rig_subsetting_remove(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.rig_subsetting_remove"
|
||||
bl_label = "Remove Rig Subsetting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
index: bpy.props.IntProperty(default=-1)
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
rig_setting = settings.rig_settings[settings.rig_settings_index]
|
||||
rig_setting.subsettings.remove(self.index)
|
||||
settings.is_dirty = True
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_UL_rig_settings_list(LOR_UL_settings_list):
|
||||
|
||||
def draw_item(
|
||||
self, context, layout, data, item, icon, active_data, active_propname, index):
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
row = layout.row()
|
||||
col_top = row.column()
|
||||
row = col_top.row()
|
||||
if len(item.subsettings) == 0 and not index == settings.rig_settings_index:
|
||||
toggle = False
|
||||
else:
|
||||
toggle = item.setting_expanded
|
||||
if len(item.subsettings) == 0:
|
||||
row.label(text='', icon='LAYER_USED')
|
||||
else:
|
||||
row.prop(item, 'setting_expanded',
|
||||
icon="TRIA_DOWN" if toggle else "TRIA_RIGHT",
|
||||
icon_only=True, emboss=False
|
||||
)
|
||||
icon = 'WORLD' if item.specifier.endswith(':all') else 'MESH_CIRCLE'
|
||||
row.prop(item, "specifier", text='', icon=icon, emboss=False)
|
||||
|
||||
col = row.column()
|
||||
col.alignment = 'RIGHT'
|
||||
col.enabled = False
|
||||
col.label(text=str(len(item.subsettings)))
|
||||
|
||||
col = row.column()
|
||||
if index == settings.rig_settings_index:
|
||||
col.operator("lighting_overrider.rig_setting_remove", icon='X', text="", emboss=False)
|
||||
else:
|
||||
col.label(text='', icon='BLANK1')
|
||||
|
||||
if toggle:
|
||||
if index == settings.rig_settings_index:
|
||||
col_top = col_top.box()
|
||||
row = col_top.row()
|
||||
col = row.column()
|
||||
|
||||
for i in range(len(item.subsettings)):
|
||||
subsetting = item.subsettings[i]
|
||||
row_sub = col.row()
|
||||
col_sub = row_sub.column()
|
||||
row_sub2 = col_sub.row(align=True)
|
||||
row_sub2.prop(subsetting, "name", text='')
|
||||
row_sub2.prop(subsetting, subsetting.type, text='')
|
||||
col_sub = row_sub.column()
|
||||
row_sub2 = col_sub.row(align=True)
|
||||
row_sub2.prop(subsetting, 'type', text='', icon='THREE_DOTS', icon_only=True, emboss=False)
|
||||
if index == settings.rig_settings_index:
|
||||
row_sub.operator("lighting_overrider.rig_subsetting_remove", icon='REMOVE', text="", emboss=False).index = i
|
||||
|
||||
if index == settings.rig_settings_index:
|
||||
col_top.operator("lighting_overrider.rig_subsetting_add", icon='ADD', text="")
|
||||
|
||||
class LOR_PT_rig_settings_panel(bpy.types.Panel):
|
||||
bl_parent_id = "LOR_PT_lighting_overrider_panel"
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_region_type = 'UI'
|
||||
bl_label = "Rig Settings"
|
||||
bl_category = 'Overrides'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
self.layout.label(text='', icon='ARMATURE_DATA')
|
||||
return
|
||||
|
||||
def draw_header_preset(self, context):
|
||||
layout = self.layout
|
||||
col = layout.column()
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
col.enabled = False
|
||||
col.label(text=str(len(settings.rig_settings)))
|
||||
return
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
col_top = layout.column()
|
||||
if not meta_settings.enabled:
|
||||
col_top.enabled = False
|
||||
row = col_top.row()
|
||||
col = row.column()
|
||||
row = col.row()
|
||||
row.operator("lighting_overrider.rig_settings_init", icon='SHADERFX')
|
||||
|
||||
col = row.column()
|
||||
row = col.row(align=True)
|
||||
row.operator("lighting_overrider.rig_setting_add", icon='ADD', text="")
|
||||
row.operator("lighting_overrider.rig_setting_remove", icon='REMOVE', text="")
|
||||
row.operator("lighting_overrider.rig_setting_duplicate", icon='DUPLICATE', text="")
|
||||
|
||||
row = col_top.row(align=True)
|
||||
col = row.column()
|
||||
col.template_list(
|
||||
"LOR_UL_rig_settings_list",
|
||||
"",
|
||||
settings,
|
||||
"rig_settings",
|
||||
settings,
|
||||
"rig_settings_index",
|
||||
rows=2,
|
||||
)
|
||||
col.operator('lighting_overrider.rig_settings_apply', icon='PLAY')
|
||||
return
|
||||
|
||||
panel_class = LOR_PT_rig_settings_panel
|
||||
|
||||
classes = (
|
||||
LOR_rig_setting,
|
||||
LOR_UL_rig_settings_list,
|
||||
LOR_OT_rig_setting_add,
|
||||
LOR_OT_rig_setting_remove,
|
||||
LOR_OT_rig_setting_duplicate,
|
||||
LOR_OT_rig_settings_initialize,
|
||||
LOR_OT_rig_subsetting_add,
|
||||
LOR_OT_rig_subsetting_remove,
|
||||
LOR_OT_rig_settings_apply,
|
||||
)
|
||||
|
||||
def register():
|
||||
for c in classes:
|
||||
bpy.utils.register_class(c)
|
||||
|
||||
def unregister():
|
||||
for c in classes:
|
||||
bpy.utils.unregister_class(c)
|
271
lighting_overrider/categories/rna_overrides.py
Normal file
271
lighting_overrider/categories/rna_overrides.py
Normal file
@ -0,0 +1,271 @@
|
||||
from .. import utils
|
||||
from ..templates import *
|
||||
import bpy
|
||||
|
||||
import inspect
|
||||
|
||||
def settings_as_dict(settings):
|
||||
data = {}
|
||||
for setting in settings.rna_overrides:
|
||||
if isinstance(getattr(setting, setting.type), str):
|
||||
data[setting.path] = [getattr(setting, setting.type), setting.type, setting.name]
|
||||
elif not setting.bl_rna.properties[setting.type].is_array:
|
||||
data[setting.path] = [getattr(setting, setting.type), setting.type, setting.name]
|
||||
else:
|
||||
data[setting.path] = [getattr(setting, setting.type)[:], setting.type, setting.name]
|
||||
return data
|
||||
|
||||
|
||||
def apply_settings(data):
|
||||
''' Applies custom overrides on specified rna data paths.
|
||||
'''
|
||||
if not data:
|
||||
return
|
||||
|
||||
for path in data:
|
||||
try:
|
||||
if data[path][1] == 'STRING':
|
||||
exec(path+f" = '{data[path][0]}'")
|
||||
else:
|
||||
exec(path+f' = {data[path][0]}')
|
||||
except:
|
||||
print(f'Warning: Failed to assign property {data[path][2]} at {path}')
|
||||
|
||||
|
||||
def load_settings(settings, data):
|
||||
while len(settings.rna_overrides) > 0:
|
||||
settings.rna_overrides.remove(0)
|
||||
|
||||
for path in data.keys():
|
||||
value = data[path]
|
||||
new_setting = settings.rna_overrides.add()
|
||||
new_setting.name = value[2]
|
||||
new_setting.path = path
|
||||
new_setting.type = value[1]
|
||||
setattr(new_setting, value[1], value[0])
|
||||
|
||||
settings.rna_overrides_index = min(settings.rna_overrides_index, len(settings.rna_overrides)-1)
|
||||
|
||||
|
||||
class LOR_OT_rna_overrides_apply(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.rna_overrides_apply"
|
||||
bl_label = "Apply RNA Overrides"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
apply_settings(settings_as_dict(settings))
|
||||
utils.kick_evaluation()
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class LOR_rna_override(LOR_subsetting):
|
||||
name: bpy.props.StringProperty(default='RNA Override')
|
||||
path: bpy.props.StringProperty(default='bpy.data.')
|
||||
|
||||
def add_rna_override(context, add_info = None):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
new_setting = None
|
||||
if add_info:
|
||||
for rna_override in settings.rna_overrides:
|
||||
if rna_override.path == add_info[1]:
|
||||
new_setting = rna_override
|
||||
add_info[0] = new_setting.name
|
||||
if not new_setting:
|
||||
new_setting = settings.rna_overrides.add()
|
||||
settings.is_dirty = True
|
||||
|
||||
if add_info:
|
||||
new_setting.name = add_info[0]
|
||||
new_setting.path = add_info[1]
|
||||
new_setting.type = add_info[3]
|
||||
setattr(new_setting, new_setting.type, add_info[2])
|
||||
|
||||
settings.rna_overrides_index = len(settings.rna_overrides)-1
|
||||
|
||||
|
||||
class LOR_OT_rna_override_add(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.rna_override_add"
|
||||
bl_label = "Add Variable Setting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
add_rna_override(context)
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class LOR_OT_rna_override_remove(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.rna_override_remove"
|
||||
bl_label = "Remove Variable Setting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
return len(settings.rna_overrides)>0
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
settings.rna_overrides.remove(settings.rna_overrides_index)
|
||||
settings.is_dirty = True
|
||||
|
||||
if settings.rna_overrides_index >= len(settings.rna_overrides):
|
||||
settings.rna_overrides_index = len(settings.rna_overrides)-1
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class LOR_OT_rna_override_cleanup(bpy.types.Operator):
|
||||
""" Removes outdated RNA overrides from the list
|
||||
"""
|
||||
bl_idname = "lighting_overrider.rna_override_cleanup"
|
||||
bl_label = "Cleanup RNA Overrides"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
return len(settings.rna_overrides)>0
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
remove_list = []
|
||||
for i, setting in enumerate(settings.rna_overrides):
|
||||
try:
|
||||
eval(setting.path)
|
||||
except:
|
||||
remove_list += [i]
|
||||
continue
|
||||
if remove_list:
|
||||
settings.is_dirty = True
|
||||
for j, i in enumerate(remove_list):
|
||||
settings.rna_overrides.remove(i-j)
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class LOR_UL_rna_overrides_list(LOR_UL_settings_list):
|
||||
|
||||
def draw_item(
|
||||
self, context, layout, data, item, icon, active_data, active_propname, index):
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
row = layout.row()
|
||||
col_top = row.column()
|
||||
row = col_top.row(align=True)
|
||||
row.prop(item, "name", text='', icon='DOT', emboss=False)
|
||||
|
||||
col = row.column()
|
||||
if index == settings.rna_overrides_index:
|
||||
col.operator("lighting_overrider.rna_override_remove", icon='X', text="", emboss=False)
|
||||
else:
|
||||
col.label(text='', icon='BLANK1')
|
||||
|
||||
row = col_top.row(align=True)
|
||||
split = row.split(factor=.7, align=True)
|
||||
split.prop(item, "path", text='')
|
||||
split.prop(item, item.type, text='')
|
||||
row.prop(item, 'type', text='', icon='THREE_DOTS', icon_only=True, emboss=False)
|
||||
if index >= len(settings.rna_overrides)-1:
|
||||
col_top.operator("lighting_overrider.rna_override_add", icon='ADD', text="", emboss=False)
|
||||
|
||||
def filter_items(self, context, data, propname):
|
||||
|
||||
settings = getattr(data, propname)
|
||||
helper_funcs = bpy.types.UI_UL_list
|
||||
|
||||
flt_flags = []
|
||||
flt_neworder = []
|
||||
|
||||
if self.filter_name:
|
||||
flt_flags = helper_funcs.filter_items_by_name(self.filter_name, self.bitflag_filter_item, settings, "name",
|
||||
reverse=self.use_filter_invert)
|
||||
|
||||
return flt_flags, flt_neworder
|
||||
|
||||
|
||||
class LOR_PT_rna_overrides_panel(bpy.types.Panel):
|
||||
bl_parent_id = "LOR_PT_lighting_overrider_panel"
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_region_type = 'UI'
|
||||
bl_label = "RNA Overrides"
|
||||
bl_category = 'Overrides'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
self.layout.label(text='', icon='RNA')
|
||||
return
|
||||
|
||||
def draw_header_preset(self, context):
|
||||
layout = self.layout
|
||||
col = layout.column()
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
col.enabled = False
|
||||
col.label(text=str(len(settings.rna_overrides)))
|
||||
return
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
col_top = layout.column()
|
||||
if not meta_settings.enabled:
|
||||
col_top.enabled = False
|
||||
row = col_top.row(align=True)
|
||||
row.operator("lighting_overrider.rna_override_add", icon='ADD', text="")
|
||||
row.operator("lighting_overrider.rna_override_remove", icon='REMOVE', text="")
|
||||
row.operator("lighting_overrider.rna_override_cleanup", icon='BRUSH_DATA', text="Clean Up")
|
||||
|
||||
row = col_top.row(align=True)
|
||||
col = row.column()
|
||||
col.template_list(
|
||||
"LOR_UL_rna_overrides_list",
|
||||
"",
|
||||
settings,
|
||||
"rna_overrides",
|
||||
settings,
|
||||
"rna_overrides_index",
|
||||
rows=2,
|
||||
)
|
||||
col.operator('lighting_overrider.rna_overrides_apply', icon='PLAY')
|
||||
return
|
||||
|
||||
panel_class = LOR_PT_rna_overrides_panel
|
||||
|
||||
classes = (
|
||||
LOR_rna_override,
|
||||
LOR_UL_rna_overrides_list,
|
||||
LOR_OT_rna_override_add,
|
||||
LOR_OT_rna_override_remove,
|
||||
LOR_OT_rna_overrides_apply,
|
||||
LOR_OT_rna_override_cleanup,
|
||||
)
|
||||
|
||||
def register():
|
||||
for c in classes:
|
||||
bpy.utils.register_class(c)
|
||||
|
||||
def unregister():
|
||||
for c in classes:
|
||||
bpy.utils.unregister_class(c)
|
397
lighting_overrider/categories/shader_settings.py
Normal file
397
lighting_overrider/categories/shader_settings.py
Normal file
@ -0,0 +1,397 @@
|
||||
from .. import utils
|
||||
from ..templates import *
|
||||
import bpy
|
||||
|
||||
def settings_as_dict(settings):
|
||||
data = {}
|
||||
for setting in settings.shader_settings:
|
||||
data_sub = {}
|
||||
for subsetting in setting.subsettings:
|
||||
if isinstance(getattr(subsetting, subsetting.type), str):
|
||||
data_sub[subsetting.name] = [getattr(subsetting, subsetting.type), subsetting.type]
|
||||
elif not subsetting.bl_rna.properties[subsetting.type].is_array:
|
||||
data_sub[subsetting.name] = [getattr(subsetting, subsetting.type), subsetting.type]
|
||||
else:
|
||||
data_sub[subsetting.name] = [getattr(subsetting, subsetting.type)[:], subsetting.type]
|
||||
data[setting.specifier] = data_sub
|
||||
return data
|
||||
|
||||
def apply_settings(data):
|
||||
|
||||
if not data:
|
||||
return
|
||||
|
||||
list_unique, list_all = utils.split_by_suffix(data.keys(), ':all')
|
||||
|
||||
for ob in bpy.data.objects:
|
||||
# group names
|
||||
for name_ob in list_all:
|
||||
if not ob.name.startswith(name_ob):
|
||||
continue
|
||||
for name_set in data[name_ob+':all']:
|
||||
if not name_set in ob:
|
||||
print(f'Warning: Property {name_set} on object {ob.name} not found.')
|
||||
continue
|
||||
ob[name_set] = data[name_ob+':all'][name_set][0]
|
||||
# unique names
|
||||
if ob.name in list_unique:
|
||||
for name_set in data[ob.name]:
|
||||
if name_set in ob:
|
||||
ob[name_set] = data[ob.name][name_set][0]
|
||||
else:
|
||||
print(f'Warning: Property {name_set} on object {ob.name} not found.')
|
||||
return
|
||||
|
||||
|
||||
def load_settings(settings, data):
|
||||
while len(settings.shader_settings) > 0:
|
||||
settings.shader_settings.remove(0)
|
||||
|
||||
for specifier in data.keys():
|
||||
subsettings_dict = data[specifier]
|
||||
new_setting = settings.shader_settings.add()
|
||||
new_setting.setting_expanded = False
|
||||
new_setting.specifier = specifier
|
||||
for name in subsettings_dict.keys():
|
||||
value = subsettings_dict[name]
|
||||
new_subsetting = new_setting.subsettings.add()
|
||||
new_subsetting.name = name
|
||||
new_subsetting.type = value[1]
|
||||
setattr(new_subsetting, value[1], value[0])
|
||||
|
||||
settings.shader_settings_index = min(settings.shader_settings_index, len(settings.shader_settings)-1)
|
||||
return
|
||||
|
||||
class LOR_OT_shader_settings_apply(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.shader_settings_apply"
|
||||
bl_label = "Apply Shader Settings"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
apply_settings(settings_as_dict(settings))
|
||||
utils.kick_evaluation()
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_shader_setting(LOR_setting):
|
||||
specifier: bpy.props.StringProperty(default='HLP-', update=utils.mark_dirty)
|
||||
|
||||
|
||||
class LOR_OT_shader_settings_initialize(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.shader_settings_init"
|
||||
bl_label = "Initialize from Selection"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return len(context.selected_objects) > 0
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
existing_specifiers = [setting.specifier for setting in settings.shader_settings]
|
||||
|
||||
objects = context.selected_objects
|
||||
for ob in context.selected_objects:
|
||||
if not ob.type == 'ARMATURE':
|
||||
continue
|
||||
for child in ob.children:
|
||||
if not (child.name.startswith('HLP-') and 'settings' in child.name):
|
||||
continue
|
||||
if child in objects:
|
||||
continue
|
||||
objects += [child]
|
||||
|
||||
for ob in objects:
|
||||
if ob.type == 'ARMATURE':
|
||||
continue
|
||||
if not ob.name in existing_specifiers:
|
||||
setting = settings.shader_settings.add()
|
||||
setting.specifier = ob.name
|
||||
existing_specifiers += [ob.name]
|
||||
else:
|
||||
setting = settings.shader_settings[existing_specifiers.index(ob.name)]
|
||||
|
||||
existing_names = [subsetting.name for subsetting in setting.subsettings]
|
||||
|
||||
for name in list(ob.keys()):
|
||||
try:
|
||||
prop_props = ob.id_properties_ui(name)
|
||||
except:
|
||||
continue
|
||||
|
||||
if name in existing_names:
|
||||
continue
|
||||
subsetting = setting.subsettings.add()
|
||||
subsetting.name = name
|
||||
value = ob[name]
|
||||
if 'subtype' in prop_props.as_dict().keys():
|
||||
if prop_props.as_dict()['subtype'] == 'COLOR':
|
||||
subsetting.type = 'COLOR'
|
||||
if prop_props.as_dict()['subtype'] == 'FACTOR':
|
||||
subsetting.type = 'FACTOR'
|
||||
elif '__len__' in dir(value):
|
||||
if isinstance(value, str):
|
||||
subsetting.type = 'STRING'
|
||||
elif len(value)==3:
|
||||
subsetting.type = 'VECTOR'
|
||||
else:
|
||||
continue
|
||||
setattr(subsetting, subsetting.type, value)
|
||||
settings.is_dirty = True
|
||||
|
||||
settings.shader_settings_index = len(settings.shader_settings)-1
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class LOR_OT_shader_setting_add(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.shader_setting_add"
|
||||
bl_label = "Add Shader Setting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
new_setting = settings.shader_settings.add()
|
||||
settings.is_dirty = True
|
||||
|
||||
settings.shader_settings_index = len(settings.shader_settings)-1
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_shader_setting_remove(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.shader_setting_remove"
|
||||
bl_label = "Remove Shader Setting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
return len(settings.shader_settings)>0
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
settings.shader_settings.remove(settings.shader_settings_index)
|
||||
settings.is_dirty = True
|
||||
|
||||
if settings.shader_settings_index >= len(settings.shader_settings):
|
||||
settings.shader_settings_index = len(settings.shader_settings)-1
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_shader_setting_duplicate(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.shader_setting_duplicate"
|
||||
bl_label = "Duplicate Shader Setting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
return len(settings.shader_settings)>0
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
prev_setting = settings.shader_settings[settings.shader_settings_index]
|
||||
new_setting = settings.shader_settings.add()
|
||||
|
||||
setattr(new_setting, 'specifier', getattr(prev_setting, 'specifier'))
|
||||
for i in range(len(prev_setting.subsettings)):
|
||||
new_setting.subsettings.add()
|
||||
enum_items = [item.identifier for item in prev_setting.subsettings[i].bl_rna.properties['type'].enum_items_static]
|
||||
for prop in ['name', 'type']+enum_items:
|
||||
setattr(new_setting.subsettings[i], prop, getattr(prev_setting.subsettings[i], prop))
|
||||
|
||||
settings.shader_settings_index = len(settings.shader_settings)-1
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_shader_subsetting_add(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.shader_subsetting_add"
|
||||
bl_label = "Add Shader Subsetting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
shader_setting = settings.shader_settings[settings.shader_settings_index]
|
||||
new_subsetting = shader_setting.subsettings.add()
|
||||
settings.is_dirty = True
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_shader_subsetting_remove(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.shader_subsetting_remove"
|
||||
bl_label = "Remove Shader Subsetting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
index: bpy.props.IntProperty(default=-1)
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
shader_setting = settings.shader_settings[settings.shader_settings_index]
|
||||
shader_setting.subsettings.remove(self.index)
|
||||
settings.is_dirty = True
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_UL_shader_settings_list(LOR_UL_settings_list):
|
||||
|
||||
def draw_item(
|
||||
self, context, layout, data, item, icon, active_data, active_propname, index):
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
row = layout.row()
|
||||
col_top = row.column()
|
||||
row = col_top.row()
|
||||
if len(item.subsettings) == 0 and not index == settings.shader_settings_index:
|
||||
toggle = False
|
||||
else:
|
||||
toggle = item.setting_expanded
|
||||
if len(item.subsettings) == 0:
|
||||
row.label(text='', icon='LAYER_USED')
|
||||
else:
|
||||
row.prop(item, 'setting_expanded',
|
||||
icon="TRIA_DOWN" if toggle else "TRIA_RIGHT",
|
||||
icon_only=True, emboss=False
|
||||
)
|
||||
icon = 'WORLD' if item.specifier.endswith(':all') else 'MESH_CIRCLE'
|
||||
row.prop(item, "specifier", text='', icon=icon, emboss=False)
|
||||
|
||||
col = row.column()
|
||||
col.alignment = 'RIGHT'
|
||||
col.enabled = False
|
||||
col.label(text=str(len(item.subsettings)))
|
||||
|
||||
col = row.column()
|
||||
if index == settings.shader_settings_index:
|
||||
col.operator("lighting_overrider.shader_setting_remove", icon='X', text="", emboss=False)
|
||||
else:
|
||||
col.label(text='', icon='BLANK1')
|
||||
|
||||
if toggle:
|
||||
if index == settings.shader_settings_index:
|
||||
col_top = col_top.box()
|
||||
row = col_top.row()
|
||||
col = row.column()
|
||||
|
||||
for i in range(len(item.subsettings)):
|
||||
subsetting = item.subsettings[i]
|
||||
row_sub = col.row()
|
||||
col_sub = row_sub.column()
|
||||
row_sub2 = col_sub.row(align=True)
|
||||
row_sub2.prop(subsetting, "name", text='')
|
||||
row_sub2.prop(subsetting, subsetting.type, text='')
|
||||
col_sub = row_sub.column()
|
||||
row_sub2 = col_sub.row(align=True)
|
||||
row_sub2.prop(subsetting, 'type', text='', icon='THREE_DOTS', icon_only=True, emboss=False)
|
||||
if index == settings.shader_settings_index:
|
||||
row_sub.operator("lighting_overrider.shader_subsetting_remove", icon='REMOVE', text="", emboss=False).index = i
|
||||
|
||||
if index == settings.shader_settings_index:
|
||||
col_top.operator("lighting_overrider.shader_subsetting_add", icon='ADD', text="")
|
||||
|
||||
class LOR_PT_shader_settings_panel(bpy.types.Panel):
|
||||
bl_parent_id = "LOR_PT_lighting_overrider_panel"
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_region_type = 'UI'
|
||||
bl_label = "Shader Settings"
|
||||
bl_category = 'Overrides'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
layout = self.layout
|
||||
layout.label(text='', icon='NODE_MATERIAL')
|
||||
return
|
||||
|
||||
def draw_header_preset(self, context):
|
||||
layout = self.layout
|
||||
|
||||
col = layout.column()
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
col.enabled = False
|
||||
col.label(text=str(len(settings.shader_settings)))
|
||||
return
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
col_top = layout.column()
|
||||
if not meta_settings.enabled:
|
||||
col_top.enabled = False
|
||||
row = col_top.row()
|
||||
col = row.column()
|
||||
row = col.row()
|
||||
row.operator("lighting_overrider.shader_settings_init", icon='SHADERFX')
|
||||
|
||||
col = row.column()
|
||||
row = col.row(align=True)
|
||||
row.operator("lighting_overrider.shader_setting_add", icon='ADD', text="")
|
||||
row.operator("lighting_overrider.shader_setting_remove", icon='REMOVE', text="")
|
||||
row.operator("lighting_overrider.shader_setting_duplicate", icon='DUPLICATE', text="")
|
||||
|
||||
row = col_top.row(align=True)
|
||||
col = row.column()
|
||||
col.template_list(
|
||||
"LOR_UL_shader_settings_list",
|
||||
"",
|
||||
settings,
|
||||
"shader_settings",
|
||||
settings,
|
||||
"shader_settings_index",
|
||||
rows=2,
|
||||
)
|
||||
col.operator('lighting_overrider.shader_settings_apply', icon='PLAY')
|
||||
return
|
||||
|
||||
panel_class = LOR_PT_shader_settings_panel
|
||||
|
||||
classes = (
|
||||
LOR_shader_setting,
|
||||
LOR_UL_shader_settings_list,
|
||||
LOR_OT_shader_setting_add,
|
||||
LOR_OT_shader_setting_remove,
|
||||
LOR_OT_shader_setting_duplicate,
|
||||
LOR_OT_shader_settings_initialize,
|
||||
LOR_OT_shader_subsetting_add,
|
||||
LOR_OT_shader_subsetting_remove,
|
||||
LOR_OT_shader_settings_apply,
|
||||
)
|
||||
|
||||
def register():
|
||||
for c in classes:
|
||||
bpy.utils.register_class(c)
|
||||
|
||||
def unregister():
|
||||
for c in classes:
|
||||
bpy.utils.unregister_class(c)
|
257
lighting_overrider/categories/variable_settings.py
Normal file
257
lighting_overrider/categories/variable_settings.py
Normal file
@ -0,0 +1,257 @@
|
||||
from .. import utils
|
||||
from ..templates import *
|
||||
import bpy
|
||||
|
||||
def settings_as_dict(settings):
|
||||
data = {}
|
||||
for setting in settings.variable_settings:
|
||||
if isinstance(getattr(setting, setting.type), str):
|
||||
data[setting.name] = [getattr(setting, setting.type), setting.type]
|
||||
elif not setting.bl_rna.properties[setting.type].is_array:
|
||||
data[setting.name] = [getattr(setting, setting.type), setting.type]
|
||||
else:
|
||||
data[setting.name] = [getattr(setting, setting.type)[:], setting.type]
|
||||
return data
|
||||
|
||||
def apply_settings(data):
|
||||
''' Applies settings to according nodes in the variables nodegroup.
|
||||
'''
|
||||
if not data:
|
||||
return
|
||||
|
||||
for ng in bpy.data.node_groups:
|
||||
if not ng.name == 'VAR-settings':
|
||||
continue
|
||||
for name in data:
|
||||
node = ng.nodes.get(name)
|
||||
if node:
|
||||
node.outputs[0].default_value = data[name][0]
|
||||
else:
|
||||
print(f'Warning: Node {set} in variable settings nodegroup not found.')
|
||||
return
|
||||
|
||||
|
||||
def load_settings(settings, data):
|
||||
while len(settings.variable_settings) > 0:
|
||||
settings.variable_settings.remove(0)
|
||||
|
||||
for name in data.keys():
|
||||
value = data[name]
|
||||
new_setting = settings.variable_settings.add()
|
||||
new_setting.name = name
|
||||
new_setting.type = value[1]
|
||||
setattr(new_setting, value[1], value[0])
|
||||
|
||||
settings.variable_settings_index = min(settings.variable_settings_index, len(settings.variable_settings)-1)
|
||||
return
|
||||
|
||||
class LOR_OT_variable_settings_apply(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.variable_settings_apply"
|
||||
bl_label = "Apply Variable Settings"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
apply_settings(settings_as_dict(settings))
|
||||
utils.kick_evaluation()
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_variable_setting(LOR_subsetting):
|
||||
pass
|
||||
|
||||
|
||||
class LOR_OT_variable_settings_initialize(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.variable_settings_init"
|
||||
bl_label = "Initialize from Selection"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return bool(bpy.data.node_groups.get('VAR-settings'))
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
existing_names = [setting.name for setting in settings.variable_settings]
|
||||
|
||||
ng = bpy.data.node_groups.get('VAR-settings')
|
||||
if not ng:
|
||||
return {'CANCELLED'}
|
||||
|
||||
for node in ng.nodes:
|
||||
if node.name in ['Group Input', 'Group Output', 'Math', 'Map Range']+existing_names:
|
||||
continue
|
||||
new_setting = settings.variable_settings.add()
|
||||
new_setting.name = node.name
|
||||
value = node.outputs[0].default_value
|
||||
if '__len__' in dir(value):
|
||||
new_setting.type = 'COLOR'
|
||||
setattr(new_setting, new_setting.type, value[:])
|
||||
else:
|
||||
new_setting.type = 'VALUE'
|
||||
setattr(new_setting, new_setting.type, value)
|
||||
settings.is_dirty = True
|
||||
|
||||
settings.variable_settings_index = len(settings.variable_settings)-1
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class LOR_OT_variable_setting_add(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.variable_setting_add"
|
||||
bl_label = "Add Variable Setting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
new_setting = settings.variable_settings.add()
|
||||
settings.is_dirty = True
|
||||
|
||||
settings.variable_settings_index = len(settings.variable_settings)-1
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_variable_setting_remove(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.variable_setting_remove"
|
||||
bl_label = "Remove Variable Setting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
return len(settings.variable_settings)>0
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
settings.variable_settings.remove(settings.variable_settings_index)
|
||||
settings.is_dirty = True
|
||||
|
||||
if settings.variable_settings_index >= len(settings.variable_settings):
|
||||
settings.variable_settings_index = len(settings.variable_settings)-1
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_UL_variable_settings_list(LOR_UL_settings_list):
|
||||
|
||||
def draw_item(
|
||||
self, context, layout, data, item, icon, active_data, active_propname, index):
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
row = layout.row()
|
||||
col = row.column()
|
||||
row = col.row(align=True)
|
||||
row.prop(item, "name", text='', icon='DOT', emboss=False)
|
||||
row.prop(item, item.type, text='')
|
||||
row.prop(item, 'type', text='', icon='THREE_DOTS', icon_only=True, emboss=False)
|
||||
|
||||
col = row.column()
|
||||
if index == settings.variable_settings_index:
|
||||
col.operator("lighting_overrider.variable_setting_remove", icon='X', text="", emboss=False)
|
||||
else:
|
||||
col.label(text='', icon='BLANK1')
|
||||
|
||||
def filter_items(self, context, data, propname):
|
||||
|
||||
settings = getattr(data, propname)
|
||||
helper_funcs = bpy.types.UI_UL_list
|
||||
|
||||
flt_flags = []
|
||||
flt_neworder = []
|
||||
|
||||
if self.filter_name:
|
||||
flt_flags = helper_funcs.filter_items_by_name(self.filter_name, self.bitflag_filter_item, settings, "name",
|
||||
reverse=self.use_filter_invert)
|
||||
|
||||
return flt_flags, flt_neworder
|
||||
|
||||
class LOR_PT_variable_settings_panel(bpy.types.Panel):
|
||||
bl_parent_id = "LOR_PT_lighting_overrider_panel"
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_region_type = 'UI'
|
||||
bl_label = "Variable Settings"
|
||||
bl_category = 'Overrides'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
layout = self.layout
|
||||
layout.label(text='', icon='LIGHT_SUN')
|
||||
return
|
||||
|
||||
def draw_header_preset(self, context):
|
||||
layout = self.layout
|
||||
col = layout.column()
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
col.enabled = False
|
||||
col.label(text=str(len(settings.variable_settings)))
|
||||
return
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
col_top = layout.column()
|
||||
if not meta_settings.enabled:
|
||||
col_top.enabled = False
|
||||
row = col_top.row()
|
||||
col = row.column()
|
||||
row = col.row()
|
||||
row.operator("lighting_overrider.variable_settings_init", icon='SHADERFX')
|
||||
|
||||
col = row.column()
|
||||
row = col.row(align=True)
|
||||
row.operator("lighting_overrider.variable_setting_add", icon='ADD', text="")
|
||||
row.operator("lighting_overrider.variable_setting_remove", icon='REMOVE', text="")
|
||||
|
||||
row = col_top.row(align=True)
|
||||
col = row.column()
|
||||
col.template_list(
|
||||
"LOR_UL_variable_settings_list",
|
||||
"",
|
||||
settings,
|
||||
"variable_settings",
|
||||
settings,
|
||||
"variable_settings_index",
|
||||
rows=2,
|
||||
)
|
||||
col.operator('lighting_overrider.variable_settings_apply', icon='PLAY')
|
||||
return
|
||||
|
||||
panel_class = LOR_PT_variable_settings_panel
|
||||
|
||||
classes = (
|
||||
LOR_variable_setting,
|
||||
LOR_UL_variable_settings_list,
|
||||
LOR_OT_variable_setting_add,
|
||||
LOR_OT_variable_setting_remove,
|
||||
LOR_OT_variable_settings_initialize,
|
||||
LOR_OT_variable_settings_apply,
|
||||
)
|
||||
|
||||
def register():
|
||||
for c in classes:
|
||||
bpy.utils.register_class(c)
|
||||
|
||||
def unregister():
|
||||
for c in classes:
|
||||
bpy.utils.unregister_class(c)
|
231
lighting_overrider/execution.py
Normal file
231
lighting_overrider/execution.py
Normal file
@ -0,0 +1,231 @@
|
||||
from . import categories
|
||||
from .categories import *
|
||||
from . import utils
|
||||
from .import json_io
|
||||
import bpy
|
||||
import inspect
|
||||
from bpy.app.handlers import persistent
|
||||
|
||||
from . import lighting_overrider_execution
|
||||
|
||||
@persistent
|
||||
def write_execution_script_on_save(dummy):
|
||||
meta_settings = getattr(bpy.context.scene, 'LOR_Settings')
|
||||
if not meta_settings.enabled:
|
||||
return
|
||||
if utils.link_execution_script_from_source(bpy.context):
|
||||
return
|
||||
bpy.ops.lighting_overrider.generate_execution_script()
|
||||
return
|
||||
|
||||
def load_settings(context, name, path=None):
|
||||
''' Return text datablock of the settings specified with a name. If a filepath is specified (re)load from disk.
|
||||
'''
|
||||
meta_settings = getattr(bpy.context.scene, 'LOR_Settings')
|
||||
if not meta_settings:
|
||||
return None
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
if path:
|
||||
path += f'/{name}.settings.json'
|
||||
|
||||
settings_db = bpy.data.texts.get(f'{name}.settings.json')
|
||||
|
||||
if settings_db:
|
||||
force_reload_external(context, settings_db)
|
||||
return settings_from_datablock(settings_db)
|
||||
|
||||
if path:
|
||||
if not os.path.isfile(path):
|
||||
open(path, 'a').close()
|
||||
bpy.ops.text.open(filepath=bpy.path.relpath(path))
|
||||
settings_db = bpy.data.texts.get(f'{name}.settings.json')
|
||||
else:
|
||||
settings_db = bpy.data.texts.new(f'{name}.settings.json')
|
||||
return settings_from_datablock(settings_db)
|
||||
|
||||
def apply_settings(data):
|
||||
|
||||
category_modules = [globals()[mod] for mod in categories.__all__]
|
||||
|
||||
for cat, cat_name in zip(category_modules, categories.__all__):
|
||||
cat.apply_settings(data[cat_name])
|
||||
return
|
||||
|
||||
def generate_execution_script() -> str:
|
||||
|
||||
script = inspect.getsource(lighting_overrider_execution)
|
||||
|
||||
return script
|
||||
|
||||
class LOR_OT_link_execution_script(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.link_execution_script"
|
||||
bl_label = "Link Execution Script"
|
||||
bl_description = "Link execution script from specified source file"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
utils.link_execution_script_from_source(context)
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_generate_execution_script(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.generate_execution_script"
|
||||
bl_label = "Generate Execution Script"
|
||||
bl_description = "Generate script for automatic execution of the overrides based on the JSON settings"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
if not meta_settings.execution_script:
|
||||
text = bpy.data.texts.new('lighting_overrider_execution.py')
|
||||
meta_settings.execution_script = text
|
||||
else:
|
||||
text = meta_settings.execution_script
|
||||
text.from_string(generate_execution_script())
|
||||
text.use_module = True
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
def run_execution_script(context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
if not meta_settings.execution_script:
|
||||
return False
|
||||
script = meta_settings.execution_script
|
||||
exec(script.as_string(), globals())
|
||||
|
||||
return True
|
||||
|
||||
class LOR_OT_run_execution_script(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.run_execution_script"
|
||||
bl_label = "Run Execution Script"
|
||||
bl_description = "Run script for automatic execution of the overrides based on the JSON settings"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
return bool(meta_settings.execution_script)
|
||||
|
||||
def execute(self, context):
|
||||
if not run_execution_script(context):
|
||||
return {'CANCELLED'}
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_reload_libraries(bpy.types.Operator):
|
||||
""" Reloads all libraries to show the fresh file without overrides
|
||||
"""
|
||||
bl_idname = "lighting_overrider.reload_libraries"
|
||||
bl_label = "Reload Libraries"
|
||||
bl_description = "Reload all libraries"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
utils.reload_libraries()
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_reload_run_execution_script(bpy.types.Operator):
|
||||
""" Reloads all libraries and runs the override script to show how the file will look after load
|
||||
"""
|
||||
bl_idname = "lighting_overrider.reload_run_execution_script"
|
||||
bl_label = "Reload Libraries and Run Execution Script"
|
||||
bl_description = "Reload all libraries and run script for automatic execution of the overrides based on the JSON settings"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
return bool(meta_settings.execution_script)
|
||||
|
||||
def execute(self, context):
|
||||
utils.reload_libraries()
|
||||
if not run_execution_script(context):
|
||||
return {'CANCELLED'}
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_apply_JSON(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.apply_json"
|
||||
bl_label = "Apply JSON"
|
||||
bl_description = "Apply settings from specified JSON text datablock"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
return bool(settings.text_datablock)
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
text = settings.text_datablock
|
||||
data = json_io.read_data_from_json(text)
|
||||
|
||||
apply_settings(data)
|
||||
utils.kick_evaluation()
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_write_apply_JSON(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.write_apply_json"
|
||||
bl_label = "Write and Apply JSON"
|
||||
bl_description = "Write and apply settings in specified JSON text datablock"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
return bool(settings.text_datablock)
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
text = settings.text_datablock
|
||||
data = json_io.pack_settings_data(settings)
|
||||
|
||||
json_io.write_data_to_json( text, data)
|
||||
settings.is_dirty = False
|
||||
|
||||
apply_settings(data)
|
||||
utils.kick_evaluation()
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
|
||||
classes = (
|
||||
LOR_OT_apply_JSON,
|
||||
LOR_OT_write_apply_JSON,
|
||||
LOR_OT_link_execution_script,
|
||||
LOR_OT_generate_execution_script,
|
||||
LOR_OT_reload_libraries,
|
||||
LOR_OT_run_execution_script,
|
||||
LOR_OT_reload_run_execution_script,
|
||||
)
|
||||
|
||||
def register():
|
||||
for c in classes:
|
||||
bpy.utils.register_class(c)
|
||||
bpy.app.handlers.save_pre.append(write_execution_script_on_save)
|
||||
|
||||
def unregister():
|
||||
for c in classes:
|
||||
bpy.utils.unregister_class(c)
|
169
lighting_overrider/json_io.py
Normal file
169
lighting_overrider/json_io.py
Normal file
@ -0,0 +1,169 @@
|
||||
import bpy
|
||||
import json
|
||||
from . import categories
|
||||
from .categories import *
|
||||
from . import utils
|
||||
|
||||
class LOR_OT_find_settings(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.find_settings"
|
||||
bl_label = "Find JSON"
|
||||
bl_description = "Find settings datablock for the current sequence or shot as it is referenced in the scene properties"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
sequence_settings_db, shot_settings_db = utils.find_settings(bpy.context)
|
||||
|
||||
if meta_settings.settings_toggle == 'SEQUENCE':
|
||||
meta_settings.sequence_settings.text_datablock = sequence_settings_db
|
||||
elif meta_settings.settings_toggle == 'SHOT':
|
||||
meta_settings.shot_settings.text_datablock = shot_settings_db
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_read_settings(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.read_settings"
|
||||
bl_label = "Read JSON"
|
||||
bl_description = "Read settings from specified text datablock"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
return bool(settings.text_datablock)
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
text = settings.text_datablock
|
||||
|
||||
if not text.is_in_memory:
|
||||
override = context.copy()
|
||||
area_type = override['area'].type
|
||||
override['area'].type = 'TEXT_EDITOR'
|
||||
override['edit_text'] = text
|
||||
bpy.ops.text.reload(override)
|
||||
override['area'].type = area_type
|
||||
|
||||
data = read_data_from_json(text)
|
||||
|
||||
unpack_settings_data(settings, data)
|
||||
settings.is_dirty = False
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_write_settings(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.write_settings"
|
||||
bl_label = "Write JSON"
|
||||
bl_description = "Write settings to specified text datablock"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
return bool(settings.text_datablock)
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
text = settings.text_datablock
|
||||
|
||||
data = pack_settings_data(settings)
|
||||
|
||||
write_data_to_json( text, data)
|
||||
|
||||
if not text.is_in_memory:
|
||||
override = context.copy()
|
||||
area_type = override['area'].type
|
||||
override['area'].type = 'TEXT_EDITOR'
|
||||
override['edit_text'] = text
|
||||
bpy.ops.text.save(override)
|
||||
override['area'].type = area_type
|
||||
settings.is_dirty = False
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
def pack_settings_data(settings) -> dict:
|
||||
|
||||
data = {}
|
||||
|
||||
category_modules = [globals()[mod] for mod in categories.__all__]
|
||||
|
||||
for cat, cat_name in zip(category_modules, categories.__all__):
|
||||
data[cat_name] = cat.settings_as_dict(settings)
|
||||
|
||||
return data
|
||||
|
||||
def unpack_settings_data(settings, data):
|
||||
|
||||
category_modules = [globals()[mod] for mod in categories.__all__]
|
||||
|
||||
for cat, cat_name in zip(category_modules, categories.__all__):
|
||||
if not cat_name in data.keys():
|
||||
continue
|
||||
cat.load_settings(settings, data[cat_name])
|
||||
|
||||
return
|
||||
|
||||
def cleanup_json(string):
|
||||
|
||||
counter = 0
|
||||
open_brackets = 0
|
||||
remove = []
|
||||
for i, char in enumerate(string):
|
||||
#if char == '{':
|
||||
# counter += 1
|
||||
# continue
|
||||
#if counter < 3:
|
||||
# continue
|
||||
if char == '[':
|
||||
open_brackets += 1
|
||||
elif char == ']':
|
||||
open_brackets -= 1
|
||||
if open_brackets:
|
||||
if char == '\n':
|
||||
remove += [i]
|
||||
elif char == ' ' and string[i+1] == ' ':
|
||||
remove += [i]
|
||||
counter = 0
|
||||
for i in remove:
|
||||
i -= counter
|
||||
string = string[:i] + string[i+1:]
|
||||
counter += 1
|
||||
|
||||
return string
|
||||
|
||||
def write_data_to_json(text: bpy.types.Text, data: dict, partial=None):
|
||||
text.clear()
|
||||
text.write(cleanup_json(json.dumps(data, separators=(',', ':'), indent=4)))
|
||||
return
|
||||
|
||||
def read_data_from_json(text: bpy.types.Text):
|
||||
return json.loads(text.as_string())
|
||||
|
||||
|
||||
classes = (
|
||||
LOR_OT_find_settings,
|
||||
LOR_OT_read_settings,
|
||||
LOR_OT_write_settings,
|
||||
)
|
||||
|
||||
def register():
|
||||
for c in classes:
|
||||
bpy.utils.register_class(c)
|
||||
|
||||
def unregister():
|
||||
for c in classes:
|
||||
bpy.utils.unregister_class(c)
|
268
lighting_overrider/lighting_overrider_execution.py
Normal file
268
lighting_overrider/lighting_overrider_execution.py
Normal file
@ -0,0 +1,268 @@
|
||||
import bpy
|
||||
import os
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
def split_by_suffix(list, sfx):
|
||||
with_suffix = [name[:-len(sfx)] for name in list if name.endswith(sfx)]
|
||||
without_suffix = [name for name in list if not name.endswith(sfx)]
|
||||
return without_suffix, with_suffix
|
||||
|
||||
def mute_fcurve(ob, path):
|
||||
if not ob.animation_data:
|
||||
return
|
||||
if not ob.animation_data.action:
|
||||
return
|
||||
fcurve = ob.animation_data.action.fcurves.find(path)
|
||||
if fcurve:
|
||||
fcurve.mute = True
|
||||
return
|
||||
|
||||
def get_properties_bone(ob, prefix='Properties_'):
|
||||
|
||||
if not ob.type == 'ARMATURE':
|
||||
return None
|
||||
|
||||
for bone in ob.pose.bones:
|
||||
if not bone.name.startswith(prefix):
|
||||
continue
|
||||
return bone
|
||||
return None
|
||||
|
||||
def apply_variable_settings(data):
|
||||
''' Applies settings to according nodes in the variables nodegroup.
|
||||
'''
|
||||
if not data:
|
||||
return
|
||||
|
||||
for ng in bpy.data.node_groups:
|
||||
if not ng.name == 'VAR-settings':
|
||||
continue
|
||||
for name in data:
|
||||
node = ng.nodes.get(name)
|
||||
if node:
|
||||
node.outputs[0].default_value = data[name][0]
|
||||
else:
|
||||
print(f'Warning: Node {set} in variable settings nodegroup not found.')
|
||||
return
|
||||
|
||||
def apply_motion_blur_settings(data):
|
||||
''' Deactivates deformation motion blur for objects in selected collections.
|
||||
'''
|
||||
if not data:
|
||||
return
|
||||
|
||||
list_unique, list_all = split_by_suffix(data.keys(), ':all')
|
||||
|
||||
if 'Master Collection' in data.keys() or 'Scene Collection' in data.keys():
|
||||
for ob in bpy.data.objects:
|
||||
if ob.type == 'CAMERA':
|
||||
continue
|
||||
ob.cycles.use_motion_blur = False
|
||||
return
|
||||
|
||||
for col in bpy.data.collections:
|
||||
for name_col in list_all:
|
||||
if not col.name.startswith(name_col):
|
||||
continue
|
||||
for ob in col.all_objects:
|
||||
if ob.type == 'CAMERA':
|
||||
continue
|
||||
ob.cycles.use_motion_blur = False
|
||||
# unique names
|
||||
if not col.name in list_unique:
|
||||
continue
|
||||
for ob in col.all_objects:
|
||||
if ob.type == 'CAMERA':
|
||||
continue
|
||||
ob.cycles.use_motion_blur = False
|
||||
return
|
||||
|
||||
def apply_shader_settings(data):
|
||||
''' Assign shader setting properties to helper objects according to specified names.
|
||||
'''
|
||||
if not data:
|
||||
return
|
||||
|
||||
list_unique, list_all = split_by_suffix(data.keys(), ':all')
|
||||
|
||||
for ob in bpy.data.objects:
|
||||
# group names
|
||||
for name_ob in list_all:
|
||||
if not ob.name.startswith(name_ob):
|
||||
continue
|
||||
for name_set in data[name_ob+':all']:
|
||||
if not name_set in ob:
|
||||
print(f'Warning: Property {name_set} on object {ob.name} not found.')
|
||||
continue
|
||||
ob[name_set] = data[name_ob+':all'][name_set][0]
|
||||
# unique names
|
||||
if ob.name in list_unique:
|
||||
for name_set in data[ob.name]:
|
||||
if name_set in ob:
|
||||
ob[name_set] = data[ob.name][name_set][0]
|
||||
else:
|
||||
print(f'Warning: Property {name_set} on object {ob.name} not found.')
|
||||
return
|
||||
|
||||
def apply_rig_settings(data):
|
||||
''' Assign rig setting properties to property bones according to specified names. Mutes fcurves from evaluation on those overriden properties.
|
||||
'''
|
||||
if not data:
|
||||
return
|
||||
|
||||
list_unique, list_all = split_by_suffix(data.keys(), ':all')
|
||||
|
||||
for ob in bpy.data.objects:
|
||||
# find properties bone (first posebone that starts with 'Properties_')
|
||||
if not ob.type == 'ARMATURE':
|
||||
continue
|
||||
bone_prop = get_properties_bone(ob)
|
||||
if not bone_prop:
|
||||
continue
|
||||
|
||||
# group names
|
||||
for name_ob in list_all:
|
||||
if not ob.name.startswith(name_ob):
|
||||
continue
|
||||
for name_set in data[name_ob+':all']:
|
||||
if not name_set in bone_prop:
|
||||
print(f'Warning: Property {name_set} on object {ob.name} not found.')
|
||||
continue
|
||||
data_path = f'pose.bones["{bone_prop.name}"]["{name_set}"]'
|
||||
mute_fcurve(ob, data_path)
|
||||
bone_prop[name_set] = data[name_ob+':all'][name_set][0]
|
||||
|
||||
# unique names
|
||||
if ob.name in list_unique:
|
||||
for name_set in data[ob.name]:
|
||||
if name_set in bone_prop:
|
||||
data_path = f'pose.bones["{bone_prop.name}"]["{name_set}"]'
|
||||
mute_fcurve(ob, data_path)
|
||||
bone_prop[name_set] = data[ob.name][name_set][0]
|
||||
else:
|
||||
print(f'Warning: Property {name_set} on object {ob.name} not found.')
|
||||
return
|
||||
|
||||
def apply_rna_overrides(data):
|
||||
''' Applies custom overrides on specified rna data paths.
|
||||
'''
|
||||
if not data:
|
||||
return
|
||||
|
||||
for path in data:
|
||||
try:
|
||||
if data[path][1] == 'STRING':
|
||||
exec(path+f" = '{data[path][0]}'")
|
||||
else:
|
||||
exec(path+f' = {data[path][0]}')
|
||||
except:
|
||||
print(f'Warning: Failed to assign property {data[path][2]} at {path}')
|
||||
return
|
||||
|
||||
def apply_settings(data):
|
||||
''' Applies settings by categories using the specified category name and apply function.
|
||||
'''
|
||||
categories = {
|
||||
'variable_settings': apply_variable_settings,
|
||||
'motion_blur_settings': apply_motion_blur_settings,
|
||||
'shader_settings': apply_shader_settings,
|
||||
'rig_settings': apply_rig_settings,
|
||||
'rna_overrides': apply_rna_overrides,
|
||||
}
|
||||
|
||||
for cat in categories:
|
||||
cat_data = data.get(cat)
|
||||
if cat_data:
|
||||
categories[cat](cat_data)
|
||||
return
|
||||
|
||||
def settings_from_datablock(datablock):
|
||||
''' Return the settings dict from the text data-block.
|
||||
'''
|
||||
settings = {}
|
||||
if not datablock:
|
||||
return None
|
||||
if not datablock.as_string():
|
||||
return settings
|
||||
settings = json.loads(datablock.as_string())
|
||||
return settings
|
||||
|
||||
def force_reload_external(context, text):
|
||||
''' Reloads text datablock from disk.
|
||||
'''
|
||||
if not text:
|
||||
return
|
||||
if text.is_in_memory:
|
||||
return
|
||||
if not (text.is_dirty or text.is_modified):
|
||||
return
|
||||
path = text.filepath
|
||||
path = bpy.path.abspath(path)
|
||||
if not os.path.isfile(path):
|
||||
return
|
||||
new_string = open(path, 'r').read()
|
||||
if not text.as_string() == new_string:
|
||||
text.from_string(new_string)
|
||||
return
|
||||
|
||||
def load_settings(context, name, path=None):
|
||||
''' Return text datablock of the settings specified with a name. If a filepath is specified (re)load from disk.
|
||||
'''
|
||||
if path:
|
||||
path += f'/{name}.settings.json'
|
||||
|
||||
settings_db = bpy.data.texts.get(f'{name}.settings.json')
|
||||
|
||||
if settings_db:
|
||||
force_reload_external(context, settings_db)
|
||||
return settings_from_datablock(settings_db)
|
||||
|
||||
if path:
|
||||
if not os.path.isfile(path):
|
||||
open(path, 'a').close()
|
||||
bpy.ops.text.open(filepath=bpy.path.relpath(path))
|
||||
settings_db = bpy.data.texts.get(f'{name}.settings.json')
|
||||
else:
|
||||
settings_db = bpy.data.texts.new(f'{name}.settings.json')
|
||||
return settings_from_datablock(settings_db)
|
||||
|
||||
if __name__=="__main__" or __name__=="lighting_overrider.execution":
|
||||
# Execution
|
||||
context = bpy.context
|
||||
|
||||
sequence_settings = None
|
||||
shot_settings = None
|
||||
|
||||
try:
|
||||
sequence_db = context.scene['LOR_sequence_settings']
|
||||
force_reload_external(context, sequence_db)
|
||||
except:
|
||||
sequence_db = None
|
||||
|
||||
try:
|
||||
shot_db = context.scene['LOR_shot_settings']
|
||||
force_reload_external(context, shot_db)
|
||||
except:
|
||||
shot_db = None
|
||||
|
||||
sequence_settings = settings_from_datablock(sequence_db)
|
||||
shot_settings = settings_from_datablock(shot_db)
|
||||
|
||||
filepath = Path(bpy.context.blend_data.filepath)
|
||||
|
||||
sequence_name, shot_name = filepath.parts[-3:-1]
|
||||
|
||||
sequence_settings_path = filepath.parents[1].as_posix()
|
||||
|
||||
if not sequence_settings:
|
||||
sequence_settings = load_settings(context, sequence_name, sequence_settings_path)
|
||||
if not shot_settings:
|
||||
shot_settings = load_settings(context, shot_name)
|
||||
|
||||
apply_settings(sequence_settings)
|
||||
apply_settings(shot_settings)
|
||||
|
||||
# kick re-evaluation
|
||||
for ob in bpy.data.objects:
|
||||
ob.update_tag()
|
268
lighting_overrider/override_picker.py
Normal file
268
lighting_overrider/override_picker.py
Normal file
@ -0,0 +1,268 @@
|
||||
import bpy
|
||||
import re
|
||||
import idprop
|
||||
from . import utils
|
||||
from .categories import rna_overrides
|
||||
|
||||
from rna_prop_ui import rna_idprop_ui_create
|
||||
|
||||
|
||||
def struct_from_rna_path(rna_path):
|
||||
''' Returns struct object for specified rna path.
|
||||
'''
|
||||
if not '.' in rna_path:
|
||||
return None
|
||||
elements = rna_path.rsplit('.', 1)
|
||||
if '][' in elements[1]:
|
||||
struct_path = f"{elements[0]}.{elements[1]}"
|
||||
else:
|
||||
struct_path = f"{elements[0]}.bl_rna.properties['{elements[1]}']"
|
||||
try:
|
||||
return eval(struct_path)
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
def stylize_name(path):
|
||||
''' Splits words by '_', capitalizes them and separates them with ' '.
|
||||
'''
|
||||
custom_prop = utils.parse_rna_path_for_custom_property(path)
|
||||
if custom_prop:
|
||||
return f"{eval(custom_prop[0]+'.name')}: {custom_prop[1]}"
|
||||
|
||||
path_elements = utils.parse_rna_path_to_elements(path)
|
||||
parent = '.'.join(path_elements[:-1])
|
||||
main = path_elements[-1]
|
||||
try:
|
||||
if main in ['default_value']:
|
||||
return eval(parent).name
|
||||
else:
|
||||
return f"{eval(parent).name}: {' '.join([word.capitalize() for word in main.split('_')])}"
|
||||
except:
|
||||
return ' '.join([word.capitalize() for word in main.split('_')])
|
||||
|
||||
|
||||
class LOR_OT_override_picker(bpy.types.Operator):
|
||||
"""Adds an operator on button mouse hover"""
|
||||
bl_idname = "lighting_overrider.override_picker"
|
||||
bl_label = "Add RNA Override"
|
||||
bl_options = {'UNDO'}
|
||||
|
||||
rna_path: bpy.props.StringProperty(name="Data path to override", default="")
|
||||
override_float: bpy.props.FloatProperty(name="Override", default=0)
|
||||
batch_override: bpy.props.BoolProperty(name="Batch Override", default=False, options={'SKIP_SAVE'})
|
||||
|
||||
init_val = None
|
||||
property = None
|
||||
override = None
|
||||
|
||||
name_string = 'RNA Override'
|
||||
type = 'VALUE'
|
||||
|
||||
_array_path_re = re.compile(r'^(.*)\[[0-9]+\]$')
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
#print(f'poll: {bpy.ops.ui.copy_data_path_button.poll()}')
|
||||
return True
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
property = self.property
|
||||
|
||||
if property is None:
|
||||
return
|
||||
|
||||
col = layout.column()
|
||||
col.scale_y = 1.8
|
||||
col.scale_x = 1.5
|
||||
|
||||
if self.type == 'COLOR':
|
||||
col.template_color_picker(context.scene, 'override', value_slider=True)
|
||||
|
||||
col = layout.column()
|
||||
col.prop(context.scene, 'override')
|
||||
self.override = context.scene['override']
|
||||
|
||||
if self.batch_override:
|
||||
row = layout.row()
|
||||
row.alert = True
|
||||
row.label(text=f'Batch Overriding {len(context.selected_objects)} Objects', icon='DOCUMENTS')
|
||||
|
||||
|
||||
def invoke(self, context, event):
|
||||
|
||||
if not bpy.ops.ui.copy_data_path_button.poll():
|
||||
return {'PASS_THROUGH'}
|
||||
|
||||
clip = context.window_manager.clipboard
|
||||
bpy.ops.ui.copy_data_path_button(full_path=True)
|
||||
rna_path = context.window_manager.clipboard
|
||||
context.window_manager.clipboard = clip
|
||||
|
||||
if rna_path.endswith('name'):
|
||||
print("Warning: Don't override datablock names.")
|
||||
return {'CANCELLED'}
|
||||
|
||||
if not rna_path.startswith('bpy.data.objects'):
|
||||
self.batch_override = False
|
||||
|
||||
# Strip off array indices (f.e. 'a.b.location[0]' -> 'a.b.location')
|
||||
m = self._array_path_re.match(rna_path)
|
||||
if m:
|
||||
rna_path = m.group(1)
|
||||
|
||||
self.rna_path = rna_path
|
||||
|
||||
self.property = struct_from_rna_path(rna_path)
|
||||
|
||||
if self.property is None:
|
||||
print("Warning: No struct was found for given RNA path.")
|
||||
return {'CANCELLED'}
|
||||
|
||||
self.name_string = stylize_name(self.rna_path)
|
||||
|
||||
if 'type' in dir(self.property):
|
||||
# Gather UI data
|
||||
keys = ['description', 'default', 'min', 'max', 'soft_min', 'soft_max', 'step', 'precision', 'subtype']
|
||||
|
||||
vars = {}
|
||||
for key in keys:
|
||||
try:
|
||||
vars[key] = eval(f'self.property.{key}')
|
||||
except:
|
||||
print(f'{key} not in property')
|
||||
|
||||
if self.property.type == 'FLOAT':
|
||||
vars['unit'] = self.property.unit
|
||||
if not self.property.is_array:
|
||||
bpy.types.Scene.override = bpy.props.FloatProperty(name = self.name_string, **vars)
|
||||
else:
|
||||
vars['size'] = self.property.array_length
|
||||
vars['default'] = self.property.default_array[:]
|
||||
if vars['subtype'] == 'COLOR':
|
||||
self.type = 'COLOR'
|
||||
else:
|
||||
self.type = 'VECTOR'
|
||||
bpy.types.Scene.override = bpy.props.FloatVectorProperty(name = self.name_string, **vars)
|
||||
elif self.property.type == 'STRING':
|
||||
bpy.types.Scene.override = bpy.props.StringProperty(name = self.name_string, **vars)
|
||||
self.type = 'STRING'
|
||||
elif self.property.type == 'BOOLEAN':
|
||||
bpy.types.Scene.override = bpy.props.BoolProperty(name = self.name_string, **vars)
|
||||
self.type = 'BOOL'
|
||||
elif self.property.type == 'INT':
|
||||
bpy.types.Scene.override = bpy.props.IntProperty(name = self.name_string, **vars)
|
||||
self.type = 'INTEGER'
|
||||
elif self.property.type == 'ENUM':
|
||||
self.type = 'STRING'
|
||||
items = [(item.identifier, item.name, item.description, item.icon, i) for i, item in enumerate(self.property.enum_items)]
|
||||
vars.pop('subtype', None)
|
||||
bpy.types.Scene.override = bpy.props.EnumProperty(items = items, name = self.name_string, **vars)
|
||||
else:
|
||||
vars = {}
|
||||
custom_prop = utils.parse_rna_path_for_custom_property(self.rna_path)
|
||||
if custom_prop:
|
||||
data_block = eval(custom_prop[0])
|
||||
property_name = custom_prop[1]
|
||||
vars = data_block.id_properties_ui(property_name).as_dict()
|
||||
|
||||
if type(self.property) is float:
|
||||
bpy.types.Scene.override = bpy.props.FloatProperty(name = self.name_string, **vars)
|
||||
elif type(self.property) is idprop.types.IDPropertyArray:
|
||||
bpy.types.Scene.override = bpy.props.FloatVectorProperty(name = self.name_string, size=len(self.property), **vars)
|
||||
if vars['subtype'] in ['COLOR', 'COLOR_GAMMA']:
|
||||
self.type = 'COLOR'
|
||||
else:
|
||||
self.type = 'VECTOR'
|
||||
elif type(self.property) is str:
|
||||
bpy.types.Scene.override = bpy.props.StringProperty(name = self.name_string, **vars)
|
||||
self.type = 'STRING'
|
||||
elif type(self.property) is int:
|
||||
bpy.types.Scene.override = bpy.props.IntProperty(name = self.name_string, **vars)
|
||||
self.type = 'INTEGER'
|
||||
elif type(self.property) == bool:
|
||||
bpy.types.Scene.override = bpy.props.BoolProperty(name = self.name_string, **vars)
|
||||
self.type = 'BOOL'
|
||||
|
||||
# check for custom property
|
||||
|
||||
context.scene.override = eval(rna_path)
|
||||
|
||||
self.override = context.scene.override
|
||||
|
||||
self.init_val = eval(rna_path)
|
||||
|
||||
wm = context.window_manager
|
||||
state = wm.invoke_props_dialog(self)
|
||||
if state in {'FINISHED', 'CANCELLED'}:
|
||||
del context.scene['override']
|
||||
return state
|
||||
else:
|
||||
return state
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
if context.scene.override==self.init_val:
|
||||
del context.scene['override']
|
||||
return {'CANCELLED'}
|
||||
|
||||
exec(self.rna_path+f' = context.scene.override')
|
||||
|
||||
add_info=[self.name_string, self.rna_path, context.scene.override, self.type]
|
||||
rna_overrides.add_rna_override(context, add_info)
|
||||
|
||||
if not self.batch_override:
|
||||
del context.scene['override']
|
||||
return {'FINISHED'}
|
||||
|
||||
for ob in context.selected_objects:
|
||||
path = ']'.join(self.rna_path.split(']')[1:])
|
||||
if ob.library:
|
||||
rna_path = f'bpy.data.objects["{ob.name}", "{ob.library.filepath}"]{path}'
|
||||
else:
|
||||
rna_path = f'bpy.data.objects["{ob.name}"]{path}'
|
||||
|
||||
try:
|
||||
eval(rna_path)
|
||||
except:
|
||||
continue
|
||||
|
||||
exec(rna_path+f' = context.scene.override')
|
||||
name_string = stylize_name(rna_path)
|
||||
add_info = [name_string, rna_path, context.scene.override, self.type]
|
||||
rna_overrides.add_rna_override(context, add_info)
|
||||
|
||||
del context.scene['override']
|
||||
return {'FINISHED'}
|
||||
|
||||
def cancel(self, context):
|
||||
del context.scene['override']
|
||||
return
|
||||
|
||||
|
||||
classes = [
|
||||
LOR_OT_override_picker,
|
||||
]
|
||||
|
||||
def register():
|
||||
for c in classes:
|
||||
bpy.utils.register_class(c)
|
||||
|
||||
wm = bpy.context.window_manager
|
||||
if wm.keyconfigs.addon is not None:
|
||||
km = wm.keyconfigs.addon.keymaps.new(name="User Interface")
|
||||
kmi = km.keymap_items.new("lighting_overrider.override_picker","O", "PRESS",shift=False, ctrl=False)
|
||||
kmi.properties.batch_override = False
|
||||
kmi = km.keymap_items.new("lighting_overrider.override_picker","O", "PRESS",shift=False, ctrl=False, alt=True)
|
||||
kmi.properties.batch_override = True
|
||||
|
||||
def unregister():
|
||||
for c in classes:
|
||||
bpy.utils.unregister_class(c)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
register()
|
71
lighting_overrider/templates.py
Normal file
71
lighting_overrider/templates.py
Normal file
@ -0,0 +1,71 @@
|
||||
import bpy
|
||||
from . import utils
|
||||
|
||||
class LOR_filter_string(bpy.types.PropertyGroup):
|
||||
string: bpy.props.StringProperty(default='')
|
||||
|
||||
class LOR_subsetting(bpy.types.PropertyGroup):
|
||||
name: bpy.props.StringProperty(default='setting', update=utils.mark_dirty)
|
||||
VALUE: bpy.props.FloatProperty('', update=utils.mark_dirty)
|
||||
FACTOR: bpy.props.FloatProperty(subtype='FACTOR', soft_min=0, soft_max=1, update=utils.mark_dirty)
|
||||
INTEGER: bpy.props.IntProperty('', update=utils.mark_dirty)
|
||||
BOOL: bpy.props.BoolProperty('', update=utils.mark_dirty)
|
||||
VECTOR: bpy.props.FloatVectorProperty('', update=utils.mark_dirty)
|
||||
COLOR: bpy.props.FloatVectorProperty(size=4, subtype='COLOR', default=(.5,.5,.5,1), soft_min=0, soft_max=1, update=utils.mark_dirty)
|
||||
STRING: bpy.props.StringProperty('', update=utils.mark_dirty)
|
||||
type: bpy.props.EnumProperty(items=[('VALUE', 'Value', '', '', 0),
|
||||
('FACTOR', 'Factor', '', '', 1),
|
||||
('INTEGER', 'Integer', '', '', 2),
|
||||
('BOOL', 'Boolean', '', '', 3),
|
||||
('VECTOR', 'Vector', '', '', 4),
|
||||
('COLOR', 'Color', '', '', 5),
|
||||
('STRING', 'String', '', '', 6),]
|
||||
, update=utils.mark_dirty)
|
||||
|
||||
class LOR_setting(bpy.types.PropertyGroup):
|
||||
specifier: bpy.props.StringProperty('', update=utils.mark_dirty)
|
||||
subsettings: bpy.props.CollectionProperty(type=LOR_subsetting)
|
||||
setting_expanded: bpy.props.BoolProperty(default=True)
|
||||
|
||||
class LOR_UL_settings_list(bpy.types.UIList):
|
||||
|
||||
filter_strings: bpy.props.CollectionProperty(type=LOR_filter_string)
|
||||
|
||||
def filter_items(self, context, data, propname):
|
||||
|
||||
settings = getattr(data, propname)
|
||||
helper_funcs = bpy.types.UI_UL_list
|
||||
|
||||
flt_flags = []
|
||||
flt_neworder = []
|
||||
|
||||
while not len(self.filter_strings) == len(settings):
|
||||
if len(self.filter_strings) < len(settings):
|
||||
self.filter_strings.add()
|
||||
else:
|
||||
self.filter_strings.remove(0)
|
||||
|
||||
if self.filter_name:
|
||||
for i, set in enumerate(settings):
|
||||
self.filter_strings[i].string = ' '.join([subset.name for subset in set.subsettings]).lower()
|
||||
self.filter_strings[i].string = ' '.join([set.specifier, self.filter_strings[i].string])
|
||||
flt_flags = helper_funcs.filter_items_by_name(self.filter_name.lower(), self.bitflag_filter_item, self.filter_strings, "string",
|
||||
reverse=self.use_filter_invert)
|
||||
|
||||
return flt_flags, flt_neworder
|
||||
|
||||
|
||||
classes = (
|
||||
LOR_subsetting,
|
||||
LOR_setting,
|
||||
LOR_filter_string,
|
||||
LOR_UL_settings_list,
|
||||
)
|
||||
|
||||
def register():
|
||||
for c in classes:
|
||||
bpy.utils.register_class(c)
|
||||
|
||||
def unregister():
|
||||
for c in classes:
|
||||
bpy.utils.unregister_class(c)
|
248
lighting_overrider/ui.py
Normal file
248
lighting_overrider/ui.py
Normal file
@ -0,0 +1,248 @@
|
||||
from . import categories
|
||||
from .categories import *
|
||||
from . import utils
|
||||
import bpy
|
||||
from bpy.app.handlers import persistent
|
||||
from pathlib import Path
|
||||
|
||||
@persistent
|
||||
def init_on_load(dummy):
|
||||
|
||||
if not bpy.data.is_saved:
|
||||
return
|
||||
|
||||
context = bpy.context
|
||||
meta_settings = getattr(context.scene, 'LOR_Settings')
|
||||
if not meta_settings:
|
||||
return
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
filepath = Path(bpy.context.blend_data.filepath)
|
||||
sequence_name, shot_name, file_name = filepath.parts[-3:]
|
||||
|
||||
meta_settings.sequence_settings.name = sequence_name
|
||||
meta_settings.shot_settings.name = shot_name
|
||||
|
||||
if file_name.endswith('.lighting.blend'):
|
||||
meta_settings.enabled = True
|
||||
|
||||
if not meta_settings.enabled:
|
||||
return
|
||||
|
||||
if not meta_settings.execution_script:
|
||||
execution_script = bpy.data.texts.get('lighting_overrider_execution.py')
|
||||
if not execution_script:
|
||||
pass
|
||||
meta_settings.execution_script = execution_script
|
||||
|
||||
if not bpy.context.blend_data.filepath:
|
||||
return
|
||||
|
||||
sequence_settings_db, shot_settings_db = utils.find_settings(bpy.context)
|
||||
if not meta_settings.sequence_settings.text_datablock:
|
||||
meta_settings.sequence_settings.text_datablock = sequence_settings_db
|
||||
if not meta_settings.shot_settings.text_datablock:
|
||||
meta_settings.shot_settings.text_datablock = shot_settings_db
|
||||
|
||||
#utils.reload_settings(context) #TODO: Fix loading settings on file load
|
||||
|
||||
return
|
||||
|
||||
@persistent
|
||||
def store_ref_on_save(dummy):
|
||||
meta_settings = getattr(bpy.context.scene, 'LOR_Settings')
|
||||
bpy.context.scene['LOR_sequence_settings'] = meta_settings.sequence_settings.text_datablock
|
||||
bpy.context.scene['LOR_shot_settings'] = meta_settings.shot_settings.text_datablock
|
||||
return
|
||||
|
||||
class LOR_OT_toggle_enabled(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.toggle_enabled"
|
||||
bl_label = "Toggle Lighting Overrider Addon"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
meta_settings.enabled = not meta_settings.enabled
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_OT_text_db_add(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "lighting_overrider.text_db_add"
|
||||
bl_label = "Add Text Datablock"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
name = f'{settings.name}.settings.json' if settings.name else f'{meta_settings.settings_toggle.lower()}_settings.json'
|
||||
text_db = bpy.data.texts.new(name)
|
||||
settings.text_datablock = text_db
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class LOR_SettingsGroup(bpy.types.PropertyGroup):
|
||||
name: bpy.props.StringProperty()
|
||||
text_datablock: bpy.props.PointerProperty(
|
||||
type = bpy.types.Text,
|
||||
name = "Settings JSON",
|
||||
description = "Text datablock that contains the full settings information"
|
||||
)
|
||||
is_dirty: bpy.props.BoolProperty(default=False)
|
||||
|
||||
variable_settings: bpy.props.CollectionProperty(type=variable_settings.LOR_variable_setting)
|
||||
variable_settings_index: bpy.props.IntProperty()
|
||||
motion_blur_settings: bpy.props.CollectionProperty(type=variable_settings.LOR_variable_setting)
|
||||
motion_blur_settings_index: bpy.props.IntProperty()
|
||||
shader_settings: bpy.props.CollectionProperty(type=shader_settings.LOR_shader_setting)
|
||||
shader_settings_index: bpy.props.IntProperty()
|
||||
rig_settings: bpy.props.CollectionProperty(type=rig_settings.LOR_rig_setting)
|
||||
rig_settings_index: bpy.props.IntProperty()
|
||||
rna_overrides: bpy.props.CollectionProperty(type=rna_overrides.LOR_rna_override)
|
||||
rna_overrides_index: bpy.props.IntProperty()
|
||||
|
||||
class LOR_MetaSettings(bpy.types.PropertyGroup):
|
||||
enabled: bpy.props.BoolProperty(default=False)
|
||||
shot_settings: bpy.props.PointerProperty(type=LOR_SettingsGroup)
|
||||
sequence_settings: bpy.props.PointerProperty(type=LOR_SettingsGroup)
|
||||
settings_toggle: bpy.props.EnumProperty(default='SHOT',
|
||||
items= [('SEQUENCE', 'Sequence Settings', 'Manage override settings for the current sequence', '', 0),
|
||||
('SHOT', 'Shot Settings', 'Manage override settings for the current shot', '', 1),]
|
||||
)
|
||||
execution_script: bpy.props.PointerProperty(
|
||||
type = bpy.types.Text,
|
||||
name = "Execution Script",
|
||||
description = "Text datablock with script that automatically applies the saved settings on file-load"
|
||||
)
|
||||
execution_script_source: bpy.props.StringProperty(default='//../../../lib/scripts/load_settings.blend')#TODO expose in addon settings
|
||||
|
||||
class LOR_PT_lighting_overrider_panel(bpy.types.Panel):
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_region_type = 'UI'
|
||||
bl_label = "Lighting Overrider"
|
||||
bl_category = 'Overrides'
|
||||
|
||||
def draw_header(self, context):
|
||||
self.layout.label(text='', icon='LIBRARY_DATA_OVERRIDE')
|
||||
return
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = utils.get_settings(meta_settings)
|
||||
|
||||
enabled = meta_settings.enabled
|
||||
|
||||
text = 'Lighting Overrider Active' if enabled else 'Lighting Overrider Inactive'
|
||||
icon = 'CHECKBOX_HLT' if enabled else 'CHECKBOX_DEHLT'
|
||||
layout.operator('lighting_overrider.toggle_enabled', text=text, icon=icon, depress=enabled)
|
||||
|
||||
col_main = layout.column()
|
||||
if not meta_settings.enabled:
|
||||
col_main.enabled = False
|
||||
|
||||
col = col_main.column()
|
||||
|
||||
box = col.box()
|
||||
row = box.row(align=True)
|
||||
row.prop(meta_settings, 'execution_script')
|
||||
if not meta_settings.execution_script:
|
||||
if utils.executions_script_source_exists(context):
|
||||
row.operator('lighting_overrider.link_execution_script', icon='LINKED', text='')
|
||||
else:
|
||||
row.operator('lighting_overrider.generate_execution_script', icon='FILE_CACHE', text='')
|
||||
#row.operator('lighting_overrider.reload_libraries', icon='FILE_REFRESH', text='')#TODO reload libraries accurately (bug?)
|
||||
row.operator('lighting_overrider.run_execution_script', icon='PLAY', text='')
|
||||
#row = box.row()
|
||||
#row.operator('lighting_overrider.reload_run_execution_script', icon='CHECKMARK')
|
||||
if not meta_settings.execution_script:
|
||||
col_warn = box.column()
|
||||
col_warn.alert = True
|
||||
row = col_warn.row()
|
||||
row.label(text=f'No execution script referenced!', icon='ERROR')
|
||||
row = col_warn.row()
|
||||
row.label(text=f'Without the execution script overrides will not be applied on file-load!', icon='BLANK1')
|
||||
|
||||
col.separator(factor=2.0)
|
||||
|
||||
|
||||
row = col.row()
|
||||
row.prop(meta_settings, 'settings_toggle', expand=True)
|
||||
col.alignment = 'CENTER'
|
||||
col.label(text=f"{meta_settings.settings_toggle.capitalize()} Name: {settings.name if settings.name else 'UNKNOWN'}")
|
||||
|
||||
col = col_main.column()
|
||||
col.label(text=settings.bl_rna.properties['text_datablock'].name)
|
||||
row = col.row(align=True)
|
||||
try:
|
||||
linked_settings = context.scene[f'LOR_{meta_settings.settings_toggle.lower()}_settings']
|
||||
except:
|
||||
linked_settings = None
|
||||
if settings.text_datablock not in [linked_settings, None]:
|
||||
row.alert = True
|
||||
row.prop(settings, 'text_datablock', text='', expand=True)
|
||||
if not settings.text_datablock or row.alert:
|
||||
row.operator('lighting_overrider.find_settings', text='', icon='VIEWZOOM')
|
||||
if not settings.text_datablock:
|
||||
row.operator('lighting_overrider.text_db_add', text='', icon='FILE_NEW')
|
||||
else:
|
||||
# mark whether JSON file is internal or external
|
||||
row.label(text='', icon = 'FILE_ARCHIVE' if settings.text_datablock.is_in_memory else 'FILE')
|
||||
|
||||
row = col.row(align=True)
|
||||
flag1 = False
|
||||
flag2 = False
|
||||
if settings.text_datablock:
|
||||
if settings.text_datablock.is_dirty:
|
||||
flag1 = True
|
||||
if settings.text_datablock.is_modified:
|
||||
flag2 = True
|
||||
flag = (flag1 or flag2) and not settings.text_datablock.is_in_memory
|
||||
row.alert = flag or settings.is_dirty
|
||||
icon = 'FILE_TICK'if flag else 'IMPORT'
|
||||
text = 'Write and Save JSON' if flag else 'Write JSON'
|
||||
row.operator('lighting_overrider.write_settings', icon=icon, text=text)
|
||||
icon = 'FILE_REFRESH'if flag else 'EXPORT'
|
||||
text = 'Reload and Read JSON' if flag else 'Read JSON'
|
||||
row.operator('lighting_overrider.read_settings', icon=icon, text=text)
|
||||
|
||||
row = col.row(align=True)
|
||||
row.alert = settings.is_dirty
|
||||
operator = 'lighting_overrider.write_apply_json' if settings.is_dirty else 'lighting_overrider.apply_json'
|
||||
icon = 'TEMP' if settings.is_dirty else 'PLAY'
|
||||
row.operator(operator, icon=icon)
|
||||
|
||||
return
|
||||
|
||||
classes = [
|
||||
LOR_SettingsGroup,
|
||||
LOR_MetaSettings,
|
||||
LOR_OT_text_db_add,
|
||||
LOR_OT_toggle_enabled,
|
||||
LOR_PT_lighting_overrider_panel,
|
||||
]
|
||||
|
||||
category_modules = [globals()[mod] for mod in categories.__all__]
|
||||
for cat in category_modules:
|
||||
classes += [cat.panel_class]
|
||||
|
||||
def register():
|
||||
for c in classes:
|
||||
bpy.utils.register_class(c)
|
||||
bpy.types.Scene.LOR_Settings = bpy.props.PointerProperty(type=LOR_MetaSettings)
|
||||
bpy.app.handlers.load_post.append(init_on_load)
|
||||
bpy.app.handlers.save_pre.append(store_ref_on_save)
|
||||
|
||||
def unregister():
|
||||
for c in classes:
|
||||
bpy.utils.unregister_class(c)
|
||||
del bpy.types.Scene.LOR_Settings
|
||||
bpy.app.handlers.load_post.remove(init_on_load)
|
||||
bpy.app.handlers.save_pre.remove(store_ref_on_save)
|
||||
|
||||
#if __name__ == "__main__":
|
||||
# register()
|
160
lighting_overrider/utils.py
Normal file
160
lighting_overrider/utils.py
Normal file
@ -0,0 +1,160 @@
|
||||
import os
|
||||
import bpy
|
||||
from pathlib import Path
|
||||
|
||||
def executions_script_source_exists(context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
path = meta_settings.execution_script_source
|
||||
path = bpy.path.abspath(path)
|
||||
return os.path.isfile(path)
|
||||
|
||||
def link_execution_script_from_source(context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
if not executions_script_source_exists:
|
||||
print(f'Warning: Execution script source file not found')
|
||||
return False
|
||||
with bpy.data.libraries.load(meta_settings.execution_script_source, link=True, relative=True) as (data_from, data_to):
|
||||
data_to.texts = ["lighting_overrider_execution.py"]
|
||||
meta_settings.execution_script = bpy.data.texts["lighting_overrider_execution.py", meta_settings.execution_script_source]
|
||||
return
|
||||
|
||||
def find_settings(context):
|
||||
meta_settings = getattr(context.scene, 'LOR_Settings')
|
||||
if meta_settings:
|
||||
sequence_name = meta_settings.sequence_settings.name
|
||||
shot_name = meta_settings.shot_settings.name
|
||||
|
||||
try:
|
||||
sequence_settings_db = context.scene['LOR_sequence_settings']
|
||||
except:
|
||||
sequence_settings_db = None
|
||||
|
||||
try:
|
||||
shot_settings_db = context.scene['LOR_shot_settings']
|
||||
except:
|
||||
shot_settings_db = None
|
||||
|
||||
if not sequence_settings_db:
|
||||
sequence_settings_db = bpy.data.texts.get(f'{sequence_name}.settings.json')
|
||||
if not shot_settings_db:
|
||||
shot_settings_db = bpy.data.texts.get(f'{shot_name}.settings.json')
|
||||
|
||||
if not sequence_settings_db:
|
||||
filepath = Path(bpy.context.blend_data.filepath)
|
||||
path = filepath.parents[1].as_posix()+f'/{sequence_name}.settings.json'
|
||||
if not os.path.isfile(path):
|
||||
open(path, 'a').close()
|
||||
bpy.ops.text.open(filepath=bpy.path.relpath(path))
|
||||
if not shot_settings_db:
|
||||
shot_settings_db = bpy.data.texts.new(f'{shot_name}.settings.json')
|
||||
|
||||
return sequence_settings_db, shot_settings_db
|
||||
|
||||
def get_settings(meta_settings):
|
||||
''' Returns the currently active settings group.
|
||||
'''
|
||||
if meta_settings.settings_toggle == 'SHOT':
|
||||
settings = meta_settings.shot_settings
|
||||
elif meta_settings.settings_toggle == 'SEQUENCE':
|
||||
settings = meta_settings.sequence_settings
|
||||
return settings
|
||||
|
||||
def mark_dirty(self, context):
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
settings = get_settings(meta_settings)
|
||||
|
||||
if settings.is_dirty:
|
||||
return
|
||||
settings.is_dirty = True
|
||||
return
|
||||
|
||||
def mute_fcurve(ob, path):
|
||||
if not ob.animation_data:
|
||||
return
|
||||
if not ob.animation_data.action:
|
||||
return
|
||||
fcurve = ob.animation_data.action.fcurves.find(path)
|
||||
if fcurve:
|
||||
fcurve.mute = True
|
||||
return
|
||||
|
||||
def reload_libraries():
|
||||
for lib in bpy.data.libraries:
|
||||
lib.reload()
|
||||
return
|
||||
|
||||
def reload_settings(context):#TODO find a way to run this on load_post handler
|
||||
meta_settings = context.scene.LOR_Settings
|
||||
for settings in [meta_settings.sequence_settings, meta_settings.shot_settings]:
|
||||
if not settings.text_datablock:
|
||||
continue
|
||||
if settings.text_datablock.is_in_memory:
|
||||
continue
|
||||
override = context.copy()
|
||||
if not override['area']:
|
||||
return
|
||||
area_type = override['area'].type
|
||||
override['area'].type = 'TEXT_EDITOR'
|
||||
override['edit_text'] = settings.text_datablock
|
||||
bpy.ops.text.reload(override)
|
||||
override['area'].type = area_type
|
||||
return
|
||||
|
||||
def get_instances_across_all_libraries(name, path) -> list:#TODO
|
||||
|
||||
|
||||
return
|
||||
|
||||
def kick_evaluation(objects=None):
|
||||
if not objects:
|
||||
objects = bpy.data.objects
|
||||
for ob in objects:
|
||||
ob.update_tag()
|
||||
return
|
||||
|
||||
def split_by_suffix(list, sfx):
|
||||
with_suffix = [name[:-len(sfx)] for name in list if name.endswith(sfx)]
|
||||
without_suffix = [name for name in list if not name.endswith(sfx)]
|
||||
return without_suffix, with_suffix
|
||||
|
||||
def parse_rna_path_to_elements(rna_path, delimiter='.'):
|
||||
''' Returns the element strings of an RNA path split by '.' delimiter, disregarding any delimiter in a string within the path.
|
||||
'''
|
||||
if not delimiter in rna_path:
|
||||
return [rna_path]
|
||||
|
||||
parse = rna_path
|
||||
|
||||
# replace escape chars with whitespaces
|
||||
parse_elements = parse.split(r'\\')
|
||||
parse = ' '.join(parse_elements)
|
||||
|
||||
parse_elements = parse.split('\\')
|
||||
parse = parse_elements[0]
|
||||
for el in parse_elements[1:]:
|
||||
parse += ' '
|
||||
parse += el[1:]
|
||||
|
||||
# replace strings within path with whitespaces
|
||||
parse_elements = parse.split('"')
|
||||
parse = parse_elements[0]
|
||||
for el1, el2 in zip(parse_elements[1::2], parse_elements[2::2]):
|
||||
parse += '"'+' '*len(el1)+'"'
|
||||
parse += el2
|
||||
|
||||
parse_elements = parse.split(delimiter)
|
||||
|
||||
elements = []
|
||||
for el in parse_elements:
|
||||
elements += [rna_path[:len(el)]]
|
||||
rna_path = rna_path[len(el)+len(delimiter):]
|
||||
|
||||
return elements
|
||||
|
||||
def parse_rna_path_for_custom_property(rna_path):
|
||||
''' Returns the rna path of the datablock and the name of the custom property for an rna path that describes a custom property.
|
||||
'''
|
||||
if not '][' in rna_path:
|
||||
return False
|
||||
parse_elements = parse_rna_path_to_elements(rna_path, delimiter='][')
|
||||
return parse_elements[0]+']', '"'.join(parse_elements[1].split('"')[1:-1])
|
Loading…
Reference in New Issue
Block a user