0502ccd3a0fbdd654acdbcb43456245ee2d00c48
[blender.git] / release / scripts / startup / bl_ui / properties_data_lightprobe.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Panel
22
23
24 class DataButtonsPanel:
25     bl_space_type = 'PROPERTIES'
26     bl_region_type = 'WINDOW'
27     bl_context = "data"
28
29     @classmethod
30     def poll(cls, context):
31         engine = context.engine
32         return context.lightprobe and (engine in cls.COMPAT_ENGINES)
33
34
35 class DATA_PT_context_lightprobe(DataButtonsPanel, Panel):
36     bl_label = ""
37     bl_options = {'HIDE_HEADER'}
38     COMPAT_ENGINES = {'BLENDER_EEVEE', 'BLENDER_RENDER'}
39
40     def draw(self, context):
41         layout = self.layout
42
43         ob = context.object
44         probe = context.lightprobe
45         space = context.space_data
46
47         if ob:
48             layout.template_ID(ob, "data")
49         elif probe:
50             layout.template_ID(space, "pin_id")
51
52
53 class DATA_PT_lightprobe(DataButtonsPanel, Panel):
54     bl_label = "Probe"
55     COMPAT_ENGINES = {'BLENDER_EEVEE', 'BLENDER_RENDER'}
56
57     def draw(self, context):
58         layout = self.layout
59         layout.use_property_split = True
60
61         probe = context.lightprobe
62
63 #        layout.prop(probe, "type")
64
65         if probe.type == 'GRID':
66             col = layout.column()
67             col.prop(probe, "influence_distance", text="Distance")
68             col.prop(probe, "falloff")
69             col.prop(probe, "intensity")
70
71             sub = col.column(align=True)
72             sub.prop(probe, "grid_resolution_x", text="Resolution X")
73             sub.prop(probe, "grid_resolution_y", text="Y")
74             sub.prop(probe, "grid_resolution_z", text="Z")
75
76         elif probe.type == 'PLANAR':
77             col = layout.column()
78             col.prop(probe, "influence_distance", text="Distance")
79             col.prop(probe, "falloff")
80         else:
81             col = layout.column()
82             col.prop(probe, "influence_type")
83
84             if probe.influence_type == 'ELIPSOID':
85                 col.prop(probe, "influence_distance", text="Radius")
86             else:
87                 col.prop(probe, "influence_distance", text="Size")
88
89             col.prop(probe, "falloff")
90             col.prop(probe, "intensity")
91
92         sub = col.column(align=True)
93         if probe.type != 'PLANAR':
94             sub.prop(probe, "clip_start", text="Clipping Start")
95         else:
96             sub.prop(probe, "clip_start", text="Clipping Offset")
97
98         if probe.type != 'PLANAR':
99             sub.prop(probe, "clip_end", text="End")
100
101
102 class DATA_PT_lightprobe_visibility(DataButtonsPanel, Panel):
103     bl_label = "Visibility"
104     bl_parent_id = "DATA_PT_lightprobe"
105     COMPAT_ENGINES = {'BLENDER_EEVEE', 'BLENDER_RENDER'}
106
107     def draw(self, context):
108         layout = self.layout
109         layout.use_property_split = True
110
111         probe = context.lightprobe
112
113         col = layout.column()
114
115         if probe.type == 'GRID':
116             col.prop(probe, "visibility_buffer_bias", text="Bias")
117             col.prop(probe, "visibility_bleed_bias", text="Bleed Bias")
118             col.prop(probe, "visibility_blur", text="Blur")
119
120         row = col.row(align=True)
121         row.prop(probe, "visibility_collection")
122         row.prop(probe, "invert_visibility_collection", text="", icon='ARROW_LEFTRIGHT')
123
124
125 class DATA_PT_lightprobe_parallax(DataButtonsPanel, Panel):
126     bl_label = "Custom Parallax"
127     bl_options = {'DEFAULT_CLOSED'}
128     COMPAT_ENGINES = {'BLENDER_EEVEE', 'BLENDER_RENDER'}
129
130     @classmethod
131     def poll(cls, context):
132         engine = context.engine
133         return context.lightprobe and context.lightprobe.type == 'CUBEMAP' and (engine in cls.COMPAT_ENGINES)
134
135     def draw_header(self, context):
136         probe = context.lightprobe
137         self.layout.prop(probe, "use_custom_parallax", text="")
138
139     def draw(self, context):
140         layout = self.layout
141         layout.use_property_split = True
142
143         probe = context.lightprobe
144
145         col = layout.column()
146         col.active = probe.use_custom_parallax
147
148         col.prop(probe, "parallax_type")
149
150         if probe.parallax_type == 'ELIPSOID':
151             col.prop(probe, "parallax_distance", text="Radius")
152         else:
153             col.prop(probe, "parallax_distance", text="Size")
154
155
156 class DATA_PT_lightprobe_display(DataButtonsPanel, Panel):
157     bl_label = "Viewport Display"
158     bl_options = {'DEFAULT_CLOSED'}
159     COMPAT_ENGINES = {'BLENDER_EEVEE', 'BLENDER_RENDER'}
160
161     def draw(self, context):
162         layout = self.layout
163         layout.use_property_split = True
164
165         ob = context.object
166         probe = context.lightprobe
167
168         col = layout.column()
169
170         if probe.type == 'PLANAR':
171             col.prop(ob, "empty_display_size", text="Arrow Size")
172             col.prop(probe, "show_data")
173
174         if probe.type in {'GRID', 'CUBEMAP'}:
175             col.prop(probe, "show_influence")
176             col.prop(probe, "show_clip")
177
178         if probe.type == 'CUBEMAP':
179             sub = col.column()
180             sub.active = probe.use_custom_parallax
181             sub.prop(probe, "show_parallax")
182
183
184 classes = (
185     DATA_PT_context_lightprobe,
186     DATA_PT_lightprobe,
187     DATA_PT_lightprobe_visibility,
188     DATA_PT_lightprobe_parallax,
189     DATA_PT_lightprobe_display,
190 )
191
192 if __name__ == "__main__":  # only for live edit.
193     from bpy.utils import register_class
194     for cls in classes:
195         register_class(cls)