Amaranth Addon
[blender-addons-contrib.git] / amaranth / render / unsimplify.py
1 #  This program is free software; you can redistribute it and/or
2 #  modify it under the terms of the GNU General Public License
3 #  as published by the Free Software Foundation; either version 2
4 #  of the License, or (at your option) any later version.
5 #
6 #  This program is distributed in the hope that it will be useful,
7 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
8 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9 #  GNU General Public License for more details.
10 #
11 #  You should have received a copy of the GNU General Public License
12 #  along with this program; if not, write to the Free Software Foundation,
13 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14 """
15 Unsimplify Render
16
17 Handy option when you want to simplify the 3D View but unsimplify during
18 render. Find it on the Simplify panel under Scene properties.
19 """
20
21 import bpy
22 from amaranth import utils
23
24
25 def init():
26     scene = bpy.types.Scene
27     scene.use_unsimplify_render = bpy.props.BoolProperty(
28         default=False,
29         name="Unsimplify Render",
30         description="Disable Simplify during render")
31     scene.simplify_status = bpy.props.BoolProperty(default=False)
32
33
34 def clear():
35     wm = bpy.context.window_manager
36     for p in ("use_unsimplify_render", "simplify_status"):
37         if wm.get(p):
38             del wm[p]
39
40
41 @bpy.app.handlers.persistent
42 def unsimplify_render_pre(scene):
43     render = scene.render
44     scene.simplify_status = render.use_simplify
45
46     if scene.use_unsimplify_render:
47         render.use_simplify = False
48
49
50 @bpy.app.handlers.persistent
51 def unsimplify_render_post(scene):
52     render = scene.render
53     render.use_simplify = scene.simplify_status
54
55
56 def unsimplify_ui(self, context):
57     scene = bpy.context.scene
58     self.layout.prop(scene, 'use_unsimplify_render')
59
60
61 def register():
62     init()
63     bpy.app.handlers.render_pre.append(unsimplify_render_pre)
64     bpy.app.handlers.render_post.append(unsimplify_render_post)
65     bpy.types.SCENE_PT_simplify.append(unsimplify_ui)
66     if utils.cycles_exists():
67         bpy.types.CyclesScene_PT_simplify.append(unsimplify_ui)
68
69
70 def unregister():
71     clear()
72     bpy.app.handlers.render_pre.remove(unsimplify_render_pre)
73     bpy.app.handlers.render_post.remove(unsimplify_render_post)
74     bpy.types.SCENE_PT_simplify.remove(unsimplify_ui)
75     if utils.cycles_exists():
76         bpy.types.CyclesScene_PT_simplify.remove(unsimplify_ui)