Skip to content
Snippets Groups Projects
render_gui.py 19.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • Maurice Raybaud's avatar
    Maurice Raybaud committed
    # ##### 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>
    
    """User interface for rendering parameters"""
    
    import bpy
    from sys import platform  # really import here, as in render.py?
    
    # Or todo: handle this more crossplatform using QTpovray for Linux for instance
    # from os.path import isfile
    from bl_operators.presets import AddPresetBase
    from bpy.utils import register_class, unregister_class
    from bpy.props import EnumProperty
    from bpy.types import Operator, Menu, Panel
    
    
    # Example of wrapping every class 'as is'
    from bl_ui import properties_output
    
    for member in dir(properties_output):
        subclass = getattr(properties_output, member)
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
        try:
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            subclass.COMPAT_ENGINES.add('POVRAY_RENDER')
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
        except BaseException as e:
            print(e.__doc__)
            print('An exception occurred: {}'.format(e))
            pass
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    del properties_output
    
    from bl_ui import properties_freestyle
    
    for member in dir(properties_freestyle):
        subclass = getattr(properties_freestyle, member)
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
        try:
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            if not (subclass.bl_space_type == 'PROPERTIES' and subclass.bl_context == "render"):
                subclass.COMPAT_ENGINES.add('POVRAY_RENDER')
                # subclass.bl_parent_id = "RENDER_PT_POV_filter"
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
        except BaseException as e:
            print(e.__doc__)
            print('An exception occurred: {}'.format(e))
            pass
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    del properties_freestyle
    
    from bl_ui import properties_view_layer
    
    for member in dir(properties_view_layer):
        subclass = getattr(properties_view_layer, member)
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
        try:
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            subclass.COMPAT_ENGINES.add('POVRAY_RENDER')
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
        except BaseException as e:
            print(e.__doc__)
            print('An exception occurred: {}'.format(e))
            pass
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
    del properties_view_layer
    
    # Use some of the existing buttons.
    from bl_ui import properties_render
    
    # DEPRECATED#properties_render.RENDER_PT_render.COMPAT_ENGINES.add('POVRAY_RENDER')
    # DEPRECATED#properties_render.RENDER_PT_dimensions.COMPAT_ENGINES.add('POVRAY_RENDER')
    # properties_render.RENDER_PT_antialiasing.COMPAT_ENGINES.add('POVRAY_RENDER')
    # TORECREATE##DEPRECATED#properties_render.RENDER_PT_shading.COMPAT_ENGINES.add('POVRAY_RENDER')
    # DEPRECATED#properties_render.RENDER_PT_output.COMPAT_ENGINES.add('POVRAY_RENDER')
    del properties_render
    
    
    def check_render_freestyle_svg():
        """Test if Freestyle SVG Exporter addon is activated
    
        This addon is currently used to generate the SVG lines file
        when Freestyle is enabled alongside POV
        """
        if "render_freestyle_svg" in bpy.context.preferences.addons.keys():
            return True
        return False
    
    
    class RenderButtonsPanel:
        """Use this class to define buttons from the render tab of
        properties window."""
    
        bl_space_type = 'PROPERTIES'
        bl_region_type = 'WINDOW'
        bl_context = "render"
        COMPAT_ENGINES = {'POVRAY_RENDER'}
    
        @classmethod
        def poll(cls, context):
            rd = context.scene.render
            return rd.engine in cls.COMPAT_ENGINES
    
    
    class RENDER_PT_POV_export_settings(RenderButtonsPanel, Panel):
        """Use this class to define pov ini settingss buttons."""
    
        bl_options = {'DEFAULT_CLOSED'}
        bl_label = "Auto Start"
        COMPAT_ENGINES = {'POVRAY_RENDER'}
    
        def draw_header(self, context):
            scene = context.scene
            if scene.pov.tempfiles_enable:
                self.layout.prop(scene.pov, "tempfiles_enable", text="", icon='AUTO')
            else:
                self.layout.prop(scene.pov, "tempfiles_enable", text="", icon='CONSOLE')
    
        def draw(self, context):
    
            layout = self.layout
    
            scene = context.scene
    
            layout.active = scene.pov.max_trace_level != 0
            split = layout.split()
    
            col = split.column()
            col.label(text="Command line options:")
            col.prop(scene.pov, "command_line_switches", text="", icon='RIGHTARROW')
            split = layout.split()
    
            # layout.active = not scene.pov.tempfiles_enable
            if not scene.pov.tempfiles_enable:
                split.prop(scene.pov, "deletefiles_enable", text="Delete files")
                split.prop(scene.pov, "pov_editor", text="POV Editor")
    
                col = layout.column()
                col.prop(scene.pov, "scene_name", text="Name")
                col.prop(scene.pov, "scene_path", text="Path to files")
                # col.prop(scene.pov, "scene_path", text="Path to POV-file")
                # col.prop(scene.pov, "renderimage_path", text="Path to image")
    
                split = layout.split()
                split.prop(scene.pov, "indentation_character", text="Indent")
                if scene.pov.indentation_character == 'SPACE':
                    split.prop(scene.pov, "indentation_spaces", text="Spaces")
    
                row = layout.row()
                row.prop(scene.pov, "comments_enable", text="Comments")
                row.prop(scene.pov, "list_lf_enable", text="Line breaks in lists")
    
    
    class RENDER_PT_POV_render_settings(RenderButtonsPanel, Panel):
        """Use this class to define pov render settings buttons."""
    
        bl_label = "Global Settings"
        bl_icon = 'SETTINGS'
        bl_options = {'DEFAULT_CLOSED'}
        COMPAT_ENGINES = {'POVRAY_RENDER'}
    
        def draw_header(self, context):
            scene = context.scene
            if scene.pov.global_settings_advanced:
                self.layout.prop(scene.pov, "global_settings_advanced", text="", icon='SETTINGS')
            else:
                self.layout.prop(scene.pov, "global_settings_advanced", text="", icon='PREFERENCES')
    
        def draw(self, context):
            layout = self.layout
    
            scene = context.scene
            # rd = context.scene.render
            # layout.active = (scene.pov.max_trace_level != 0)
    
            if not platform.startswith('win'):
                layout.prop(scene.pov, "sdl_window_enable", text="POV-Ray SDL Window")
    
            col = layout.column()
            col.label(text="Main Path Tracing:")
            col.prop(scene.pov, "max_trace_level", text="Ray Depth")
            align = True
            layout.active = scene.pov.global_settings_advanced
            row = layout.row(align=align)
            row.prop(scene.pov, "adc_bailout")
            row = layout.row(align=align)
            row.prop(scene.pov, "ambient_light")
            row = layout.row(align=align)
            row.prop(scene.pov, "irid_wavelength")
            row = layout.row(align=align)
            row.prop(scene.pov, "number_of_waves")
            row = layout.row(align=align)
            row.prop(scene.pov, "noise_generator")
    
            split = layout.split()
            split.label(text="Shading:")
            split = layout.split()
    
            row = split.row(align=align)
            row.prop(scene.pov, "use_shadows")
            row.prop(scene.pov, "alpha_mode")
    
    
    class RENDER_PT_POV_photons(RenderButtonsPanel, Panel):
        """Use this class to define pov photons buttons."""
    
        bl_label = "Photons"
        bl_options = {'DEFAULT_CLOSED'}
        COMPAT_ENGINES = {'POVRAY_RENDER'}
    
        # def draw_header(self, context):
        # self.layout.label(icon='SETTINGS')
    
        def draw_header(self, context):
            scene = context.scene
            if scene.pov.photon_enable:
                self.layout.prop(scene.pov, "photon_enable", text="", icon='PMARKER_ACT')
            else:
                self.layout.prop(scene.pov, "photon_enable", text="", icon='PMARKER')
    
        def draw(self, context):
            scene = context.scene
            layout = self.layout
            layout.active = scene.pov.photon_enable
            col = layout.column()
            # col.label(text="Global Photons:")
            col.prop(scene.pov, "photon_max_trace_level", text="Photon Depth")
    
            split = layout.split()
    
            col = split.column()
            col.prop(scene.pov, "photon_spacing", text="Spacing")
            col.prop(scene.pov, "photon_gather_min")
    
            col = split.column()
            col.prop(scene.pov, "photon_adc_bailout", text="Photon ADC")
            col.prop(scene.pov, "photon_gather_max")
    
            box = layout.box()
            box.label(text='Photon Map File:')
            row = box.row()
            row.prop(scene.pov, "photon_map_file_save_load", expand=True)
            if scene.pov.photon_map_file_save_load in {'save'}:
                box.prop(scene.pov, "photon_map_dir")
                box.prop(scene.pov, "photon_map_filename")
            if scene.pov.photon_map_file_save_load in {'load'}:
                box.prop(scene.pov, "photon_map_file")
            # end main photons
    
    
    class RENDER_PT_POV_antialias(RenderButtonsPanel, Panel):
        """Use this class to define pov antialiasing buttons."""
    
        bl_label = "Anti-Aliasing"
        bl_options = {'DEFAULT_CLOSED'}
        COMPAT_ENGINES = {'POVRAY_RENDER'}
    
        def draw_header(self, context):
            prefs = bpy.context.preferences.addons[__package__].preferences
            scene = context.scene
            if prefs.branch_feature_set_povray != 'uberpov' and scene.pov.antialias_method == '2':
                self.layout.prop(scene.pov, "antialias_enable", text="", icon='ERROR')
            elif scene.pov.antialias_enable:
                self.layout.prop(scene.pov, "antialias_enable", text="", icon='ANTIALIASED')
            else:
                self.layout.prop(scene.pov, "antialias_enable", text="", icon='ALIASED')
    
        def draw(self, context):
            prefs = bpy.context.preferences.addons[__package__].preferences
            layout = self.layout
            scene = context.scene
    
            layout.active = scene.pov.antialias_enable
    
            row = layout.row()
            row.prop(scene.pov, "antialias_method", text="")
    
            if prefs.branch_feature_set_povray != 'uberpov' and scene.pov.antialias_method == '2':
                col = layout.column()
                col.alignment = 'CENTER'
                col.label(text="Stochastic Anti Aliasing is")
                col.label(text="Only Available with UberPOV")
                col.label(text="Feature Set in User Preferences.")
                col.label(text="Using Type 2 (recursive) instead")
            else:
                row.prop(scene.pov, "jitter_enable", text="Jitter")
    
                split = layout.split()
                col = split.column()
                col.prop(scene.pov, "antialias_depth", text="AA Depth")
                sub = split.column()
                sub.prop(scene.pov, "jitter_amount", text="Jitter Amount")
                if scene.pov.jitter_enable:
                    sub.enabled = True
                else:
                    sub.enabled = False
    
                row = layout.row()
                row.prop(scene.pov, "antialias_threshold", text="AA Threshold")
                row.prop(scene.pov, "antialias_gamma", text="AA Gamma")
    
                if prefs.branch_feature_set_povray == 'uberpov':
                    row = layout.row()
                    row.prop(scene.pov, "antialias_confidence", text="AA Confidence")
                    if scene.pov.antialias_method == '2':
                        row.enabled = True
                    else:
                        row.enabled = False
    
    
    class RENDER_PT_POV_radiosity(RenderButtonsPanel, Panel):
        """Use this class to define pov radiosity buttons."""
    
        bl_label = "Diffuse Radiosity"
        bl_options = {'DEFAULT_CLOSED'}
        COMPAT_ENGINES = {'POVRAY_RENDER'}
    
        def draw_header(self, context):
            scene = context.scene
            if scene.pov.radio_enable:
                self.layout.prop(scene.pov, "radio_enable", text="", icon='OUTLINER_OB_LIGHTPROBE')
            else:
                self.layout.prop(scene.pov, "radio_enable", text="", icon='LIGHTPROBE_CUBEMAP')
    
        def draw(self, context):
            layout = self.layout
    
            scene = context.scene
    
            layout.active = scene.pov.radio_enable
    
            split = layout.split()
    
            col = split.column()
            col.prop(scene.pov, "radio_count", text="Rays")
            col.prop(scene.pov, "radio_recursion_limit", text="Recursions")
    
            split.prop(scene.pov, "radio_error_bound", text="Error Bound")
    
            layout.prop(scene.pov, "radio_display_advanced")
    
            if scene.pov.radio_display_advanced:
                split = layout.split()
    
                col = split.column()
                col.prop(scene.pov, "radio_adc_bailout", slider=True)
                col.prop(scene.pov, "radio_minimum_reuse", text="Min Reuse")
                col.prop(scene.pov, "radio_gray_threshold", slider=True)
                col.prop(scene.pov, "radio_pretrace_start", slider=True)
                col.prop(scene.pov, "radio_low_error_factor", slider=True)
    
                col = split.column()
                col.prop(scene.pov, "radio_brightness")
                col.prop(scene.pov, "radio_maximum_reuse", text="Max Reuse")
                col.prop(scene.pov, "radio_nearest_count")
                col.prop(scene.pov, "radio_pretrace_end", slider=True)
    
                col = layout.column()
                col.label(text="Estimation Influence:")
                col.prop(scene.pov, "radio_always_sample")
                col.prop(scene.pov, "radio_normal")
                col.prop(scene.pov, "radio_media")
                col.prop(scene.pov, "radio_subsurface")
    
    
    class POV_RADIOSITY_MT_presets(Menu):
        """Use this class to define pov radiosity presets menu."""
    
        bl_label = "Radiosity Presets"
        preset_subdir = "pov/radiosity"
        preset_operator = "script.execute_preset"
        draw = bpy.types.Menu.draw_preset
    
    
    class RENDER_OT_POV_radiosity_add_preset(AddPresetBase, Operator):
        """Use this class to define pov radiosity add presets button"""
    
        '''Add a Radiosity Preset'''
        bl_idname = "scene.radiosity_preset_add"
        bl_label = "Add Radiosity Preset"
        preset_menu = "POV_RADIOSITY_MT_presets"
    
        # variable used for all preset values
        preset_defines = ["scene = bpy.context.scene"]
    
        # properties to store in the preset
        preset_values = [
            "scene.pov.radio_display_advanced",
            "scene.pov.radio_adc_bailout",
            "scene.pov.radio_always_sample",
            "scene.pov.radio_brightness",
            "scene.pov.radio_count",
            "scene.pov.radio_error_bound",
            "scene.pov.radio_gray_threshold",
            "scene.pov.radio_low_error_factor",
            "scene.pov.radio_media",
            "scene.pov.radio_subsurface",
            "scene.pov.radio_minimum_reuse",
            "scene.pov.radio_maximum_reuse",
            "scene.pov.radio_nearest_count",
            "scene.pov.radio_normal",
            "scene.pov.radio_recursion_limit",
            "scene.pov.radio_pretrace_start",
            "scene.pov.radio_pretrace_end",
        ]
    
        # where to store the preset
        preset_subdir = "pov/radiosity"
    
    
    # Draw into an existing panel
    def rad_panel_func(self, context):
        """Display radiosity presets rolldown menu"""
        layout = self.layout
    
        row = layout.row(align=True)
        row.menu(POV_RADIOSITY_MT_presets.__name__, text=POV_RADIOSITY_MT_presets.bl_label)
        row.operator(RENDER_OT_POV_radiosity_add_preset.bl_idname, text="", icon='ADD')
        row.operator(
            RENDER_OT_POV_radiosity_add_preset.bl_idname, text="", icon='REMOVE'
        ).remove_active = True
    
    
    ###############################################################################
    # Freestyle
    ###############################################################################
    # import addon_utils
    # addon_utils.paths()[0]
    # addon_utils.modules()
    # mod.bl_info['name'] == 'Freestyle SVG Exporter':
    bpy.utils.script_paths("addons")
    # render_freestyle_svg = os.path.join(bpy.utils.script_paths("addons"), "render_freestyle_svg.py")
    
    render_freestyle_svg = bpy.context.preferences.addons.get('render_freestyle_svg')
    # mpath=addon_utils.paths()[0].render_freestyle_svg
    # import mpath
    # from mpath import render_freestyle_svg #= addon_utils.modules(['Freestyle SVG Exporter'])
    # from scripts\\addons import render_freestyle_svg
    if check_render_freestyle_svg():
        '''
        snippetsWIP
        import myscript
        import importlib
    
        importlib.reload(myscript)
        myscript.main()
        '''
        for member in dir(render_freestyle_svg):
            subclass = getattr(render_freestyle_svg, member)
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            try:
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                subclass.COMPAT_ENGINES.add('POVRAY_RENDER')
                if subclass.bl_idname == "RENDER_PT_SVGExporterPanel":
                    subclass.bl_parent_id = "RENDER_PT_POV_filter"
                    subclass.bl_options = {'HIDE_HEADER'}
                    # subclass.bl_order = 11
                    print(subclass.bl_info)
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            except BaseException as e:
                print(e.__doc__)
                print('An exception occurred: {}'.format(e))
                pass
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        # del render_freestyle_svg.RENDER_PT_SVGExporterPanel.bl_parent_id
    
    
    class RENDER_PT_POV_filter(RenderButtonsPanel, Panel):
        """Use this class to invoke stuff like Freestyle UI."""
    
        bl_label = "Freestyle"
        bl_options = {'DEFAULT_CLOSED'}
        COMPAT_ENGINES = {'POVRAY_RENDER'}
    
        @classmethod
        def poll(cls, context):
            with_freestyle = bpy.app.build_options.freestyle
            engine = context.scene.render.engine
            return with_freestyle and engine == 'POVRAY_RENDER'
    
        def draw_header(self, context):
    
            # scene = context.scene
            rd = context.scene.render
            layout = self.layout
    
            if rd.use_freestyle:
                layout.prop(rd, "use_freestyle", text="", icon='LINE_DATA')
    
            else:
                layout.prop(rd, "use_freestyle", text="", icon='OUTLINER_OB_IMAGE')
    
        def draw(self, context):
            rd = context.scene.render
            layout = self.layout
            layout.active = rd.use_freestyle
            layout.use_property_split = True
            layout.use_property_decorate = False  # No animation.
            flow = layout.grid_flow(
                row_major=True, columns=0, even_columns=True, even_rows=False, align=True
            )
    
            flow.prop(rd, "line_thickness_mode", expand=True)
    
            if rd.line_thickness_mode == 'ABSOLUTE':
                flow.prop(rd, "line_thickness")
    
            # Warning if the Freestyle SVG Exporter addon is not enabled
            if not check_render_freestyle_svg():
                # col = box.column()
                layout.label(text="Please enable Freestyle SVG Exporter addon", icon="INFO")
                # layout.separator()
                layout.operator(
                    "preferences.addon_show",
                    text="Go to Render: Freestyle SVG Exporter addon",
                    icon="PREFERENCES",
                ).module = "render_freestyle_svg"
    
    
    ##class RENDER_PT_povray_baking(RenderButtonsPanel, Panel):
    ##    bl_label = "Baking"
    ##    COMPAT_ENGINES = {'POVRAY_RENDER'}
    ##
    ##    def draw_header(self, context):
    ##        scene = context.scene
    ##
    ##        self.layout.prop(scene.pov, "baking_enable", text="")
    ##
    ##    def draw(self, context):
    ##        layout = self.layout
    ##
    ##        scene = context.scene
    ##        rd = scene.render
    ##
    ##        layout.active = scene.pov.baking_enable
    
    
    classes = (
        RENDER_PT_POV_export_settings,
        RENDER_PT_POV_render_settings,
        RENDER_PT_POV_photons,
        RENDER_PT_POV_antialias,
        RENDER_PT_POV_radiosity,
        RENDER_PT_POV_filter,
        # RENDER_PT_povray_baking,
        POV_RADIOSITY_MT_presets,
        RENDER_OT_POV_radiosity_add_preset,
    )
    
    
    def register():
        for cls in classes:
            register_class(cls)
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
        RENDER_PT_POV_radiosity.prepend(rad_panel_func)
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
    
    def unregister():
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
        RENDER_PT_POV_radiosity.remove(rad_panel_func)
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
        for cls in reversed(classes):
            unregister_class(cls)