/usr/share/blender/scripts/addons/yafaray/ot/yafaray_presets.py is in yafaray-exporter 0.1.2+really0.1.2~beta5-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | # ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
import bpy
from bpy.types import Operator
import os
import sys
from bpy.path import clean_name, display_name
from bpy_types import StructRNA, _GenericUI, RNAMeta
def yaf_preset_find(name, preset_path, disp_name=False):
if not name:
return None
if display_name:
filename = ""
for fn in os.listdir(preset_path):
if fn.endswith(".py") and name == display_name(fn):
filename = fn
break
else:
filename = name + ".py"
if filename:
filepath = os.path.join(preset_path, filename)
if os.path.exists(filepath):
return filepath
class YAF_AddPresetBase():
bl_options = {'REGISTER'} # only because invoke_props_popup requires.
name = bpy.props.StringProperty(name="Name", description="Name of the preset, used to make the path name", maxlen=64, default="")
remove_active = bpy.props.BoolProperty(default=False, options={'HIDDEN'})
def execute(self, context):
if hasattr(self, "pre_cb"):
self.pre_cb(context)
preset_menu_class = getattr(bpy.types, self.preset_menu)
if not self.remove_active:
if not self.name:
return {'FINISHED'}
filename = clean_name(self.name)
target_path = os.path.join(sys.path[0], "yafaray", "presets", self.preset_subdir)
if not target_path:
self.report({'WARNING'}, "Failed to create presets path")
return {'CANCELLED'}
filepath = os.path.join(target_path, filename) + ".py"
if hasattr(self, "add"):
self.add(context, filepath)
else:
file_preset = open(filepath, 'w')
file_preset.write("import bpy\n")
if hasattr(self, "preset_defines"):
for rna_path in self.preset_defines:
exec(rna_path)
file_preset.write("%s\n" % rna_path)
file_preset.write("\n")
for rna_path in self.preset_values:
value = eval(rna_path)
if type(value) == float: # formatting of the floating point values
value = round(value, 4)
if str(value).startswith('Color'): # formatting of the Color Vectors (r,g,b)
r, g, b = round(value.r, 3), round(value.g, 3), round(value.b, 3)
file_preset.write("%s = %r, %r, %r\n" % (rna_path, r, g, b))
else:
try: # convert thin wrapped sequences to simple lists to repr()
value = value[:]
except:
pass
file_preset.write("%s = %r\n" % (rna_path, value))
file_preset.close()
preset_menu_class.bl_label = display_name(filename)
else:
preset_active = preset_menu_class.bl_label
target_path = os.path.join(sys.path[0], "yafaray", "presets", self.preset_subdir)
filepath = yaf_preset_find(preset_active, target_path)
if not filepath:
filepath = yaf_preset_find(preset_active, target_path, disp_name=True)
if not filepath:
return {'CANCELLED'}
if hasattr(self, "remove"):
self.remove(context, filepath)
else:
try:
os.remove(filepath)
except:
import traceback
print("No Preset there to remove...")
# XXX stupid: Print bl_label on menu selector...
preset_menu_class.bl_label = self.bl_label
if hasattr(self, "post_cb"):
self.post_cb(context)
return {'FINISHED'}
def check(self, context):
self.name = clean_name(self.name)
def invoke(self, context, event):
if not self.remove_active:
wm = context.window_manager
return wm.invoke_props_dialog(self)
else:
return self.execute(context)
class YAFARAY_OT_presets_renderset(YAF_AddPresetBase, Operator):
'''Add a Yafaray Render Preset'''
bl_idname = "yafaray.preset_add"
bl_label = "Yafaray Render Presets"
preset_menu = "YAFARAY_MT_presets_render"
preset_defines = [
"scene = bpy.context.scene"
]
preset_values = [
"scene.render.use_color_management",
"scene.gs_ray_depth",
"scene.gs_shadow_depth",
"scene.gs_threads",
"scene.gs_gamma",
"scene.gs_gamma_input",
"scene.gs_tile_size",
"scene.gs_tile_order",
"scene.gs_auto_threads",
"scene.gs_clay_render",
"scene.gs_draw_params",
"scene.gs_custom_string",
"scene.gs_premult",
"scene.gs_transp_shad",
"scene.gs_clamp_rgb",
"scene.gs_show_sam_pix",
"scene.gs_z_channel",
"scene.gs_type_render",
"scene.intg_light_method",
"scene.intg_use_caustics",
"scene.intg_photons",
"scene.intg_caustic_mix",
"scene.intg_caustic_depth",
"scene.intg_caustic_radius",
"scene.intg_use_AO",
"scene.intg_AO_samples",
"scene.intg_AO_distance",
"scene.intg_AO_color",
"scene.intg_bounces",
"scene.intg_diffuse_radius",
"scene.intg_cPhotons",
"scene.intg_search",
"scene.intg_final_gather",
"scene.intg_fg_bounces",
"scene.intg_fg_samples",
"scene.intg_show_map",
"scene.intg_caustic_method",
"scene.intg_path_samples",
"scene.intg_no_recursion",
"scene.intg_debug_type",
"scene.intg_show_perturbed_normals",
"scene.intg_pm_ire",
"scene.intg_pass_num",
"scene.intg_times",
"scene.intg_photon_radius",
"scene.AA_min_samples",
"scene.AA_inc_samples",
"scene.AA_passes",
"scene.AA_threshold",
"scene.AA_pixelwidth",
"scene.AA_filter_type"
]
preset_subdir = "render"
class Yafaray_Menu(StructRNA, _GenericUI, metaclass=RNAMeta): # Yafaray's own Preset Menu drawing: search method for files changed
__slots__ = ()
def path_menu(self, searchpaths, operator, props_default={}):
layout = self.layout
# hard coded to set the operators 'filepath' to the filename.
import os
import bpy.utils
layout = self.layout
if not searchpaths:
layout.label("* Missing Paths *")
# collect paths
files = []
for directory in searchpaths:
files.extend([(f, os.path.join(directory, f)) for f in os.listdir(directory)])
files.sort()
for f, filepath in files:
if f.startswith("."):
continue
preset_name = display_name(f)
props = layout.operator(operator, text=preset_name)
for attr, value in props_default.items():
setattr(props, attr, value)
props.filepath = filepath
if operator == "script.execute_preset":
props.menu_idname = self.bl_idname
def draw_preset(self, context):
"""Define these on the subclass
- preset_operator
- preset_subdir
"""
search_path = [os.path.join(sys.path[0], "yafaray", "presets", self.preset_subdir)]
self.path_menu(search_path, self.preset_operator)
|