Amaranth Addon
[blender-addons-contrib.git] / amaranth / render / border_camera.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 Set Camera Bounds as Render Border
16
17 When in camera view, we can now set the border-render to be the same size
18 of the camera, so we don't render outside the view. Makes faster render
19 preview. Under Specials menu W, when in Camera view.
20 """
21
22 import bpy
23
24
25 class AMTH_VIEW3D_OT_render_border_camera(bpy.types.Operator):
26
27     """Set camera bounds as render border"""
28     bl_idname = "view3d.render_border_camera"
29     bl_label = "Camera as Render Border"
30
31     @classmethod
32     def poll(cls, context):
33         return context.space_data.region_3d.view_perspective == "CAMERA"
34
35     def execute(self, context):
36         render = context.scene.render
37         render.use_border = True
38         render.border_min_x = 0
39         render.border_min_y = 0
40         render.border_max_x = 1
41         render.border_max_y = 1
42
43         return {"FINISHED"}
44
45
46 def button_render_border_camera(self, context):
47     view3d = context.space_data.region_3d
48
49     if view3d.view_perspective == "CAMERA":
50         layout = self.layout
51         layout.separator()
52         layout.operator(AMTH_VIEW3D_OT_render_border_camera.bl_idname,
53                         text="Camera as Render Border",
54                         icon="FULLSCREEN_ENTER")
55
56
57 def register():
58     bpy.utils.register_class(AMTH_VIEW3D_OT_render_border_camera)
59     bpy.types.VIEW3D_MT_object_specials.append(button_render_border_camera)
60
61
62 def unregister():
63     bpy.utils.unregister_class(AMTH_VIEW3D_OT_render_border_camera)
64     bpy.types.VIEW3D_MT_object_specials.remove(button_render_border_camera)