render_toolbox/preferences.py

142 lines
5.4 KiB
Python
Executable File

# SPDX-License-Identifier: GPL-3.0-or-later
import bpy
import os
from bpy.props import (FloatProperty,
BoolProperty,
EnumProperty,
StringProperty,
IntProperty,
PointerProperty,
FloatVectorProperty)
from bpy.app.handlers import persistent
# region Preferences
class RT_prefs(bpy.types.AddonPreferences):
bl_idname = __package__
## path templates
use_env_base_path_templates : BoolProperty(
name="Use Environment Base Path Templates",
description="Use environmenet variables to set base path for file output templates\
\nFollowing env variable are available:\
\nRENDERTOOLBOX_EXR_PATH_TEMPLATE for single base path file output\
\nRENDERTOOLBOX_MULTILAYER_PATH_TEMPLATE for multilayer base path file output",
default=True,
)
base_path_template: StringProperty(
name="Base Path Template",
description="Template for base paths",
default="//render/{node_label}/",
)
base_path_multilayer_template: StringProperty(
name="Base Path Multilayer Template",
description="Template for base paths of multilayer files",
default="//render/{node_label}/{node_label}_",
)
## Tech passes
use_env_technical_passes : BoolProperty(
name="Use Environment Technical Passes",
description="Use environmenet variables to set the technical passes name:\
\nRENDERTOOLBOX_TECH_PASSES",
default=True,
)
tech_passes_names : StringProperty(
name="Tech Passes Names",
description="Comma separated list of tech passes names to use for file output creation (Use lossless EXR 32bit)",
default="uv, normal, depth, position, vector, ao",
)
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
col = layout.column()
col.label(text="Output files path templates:")
col.prop(self, "use_env_base_path_templates", text="Use Environment Base Path Templates")
# col.active = not self.use_env_base_path_templates
col.prop(self, "base_path_template", text="Base Path Template")
col.prop(self, "base_path_multilayer_template", text="Base Path Multilayer Template")
if self.use_env_base_path_templates:
box=col.box()
boxcol = box.column()
env_path_template = os.getenv('RENDERTOOLBOX_EXR_PATH_TEMPLATE')
env_multi_template = os.getenv('RENDERTOOLBOX_MULTILAYER_PATH_TEMPLATE')
if not env_path_template or not env_multi_template:
boxcol.label(text="Environment variables override above templates if set", icon='INFO')
if env_path_template or env_multi_template:
boxcol.label(text="Environment variables found:", icon='CHECKMARK')
if env_path_template:
boxcol.label(text=f"RENDERTOOLBOX_EXR_PATH_TEMPLATE:")
boxcol.label(text=env_path_template)
else:
boxcol.label(text="RENDERTOOLBOX_EXR_PATH_TEMPLATE env not found, using preferences ") # (single base path file output)
if env_multi_template:
boxcol.label(text=f"RENDERTOOLBOX_MULTILAYER_PATH_TEMPLATE:")
boxcol.label(text=env_multi_template)
else:
boxcol.label(text="RENDERTOOLBOX_MULTILAYER_PATH_TEMPLATE env not found, using preferences") # (multilayer base path file output)
layout.separator()
col = layout.column()
col.label(text="Default Separated Technical Passes:")
col.prop(self, "use_env_technical_passes", text="Use Environment Technical Passes")
col.prop(self, "tech_passes_names", text="Technical Passes Names", placeholder="e.g. uv, normal, depth, vector, ...")
if self.use_env_technical_passes:
box=col.box()
boxcol = box.column()
env_tech_pass = os.getenv('RENDERTOOLBOX_TECH_PASSES')
if env_tech_pass:
boxcol.label(text="Environment variable found:", icon='CHECKMARK')
boxcol.label(text=f"RENDERTOOLBOX_TECH_PASSES:")
boxcol.label(text=env_tech_pass)
else:
boxcol.label(text="Environment variable override tech passes names if set", icon='INFO')
boxcol.label(text='RENDERTOOLBOX_TECH_PASSES env not found, using preferences')
# region Handlers
@persistent
def set_render_toolbox_settings(dummy):
## Handler for prefs to scene properties replications
from .properties import reset_scene_path_templates
reset_scene_path_templates()
# region Register
classes = (
RT_prefs,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
# prefs = bpy.context.preferences.addons[__package__].preferences
if not 'set_render_toolbox_settings' in [hand.__name__ for hand in bpy.app.handlers.load_post]:
bpy.app.handlers.load_post.append(set_render_toolbox_settings)
def unregister():
if not 'set_render_toolbox_settings' in [hand.__name__ for hand in bpy.app.handlers.load_post]:
bpy.app.handlers.load_post.remove(set_render_toolbox_settings)
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
# endregion