b61f2172d94b1a6daa2fce5cc9c80692af228c3c
[blender.git] / release / scripts / ui / properties_physics_field.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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22 from properties_physics_common import basic_force_field_settings_ui
23 from properties_physics_common import basic_force_field_falloff_ui
24
25
26 class PhysicButtonsPanel(bpy.types.Panel):
27     bl_space_type = 'PROPERTIES'
28     bl_region_type = 'WINDOW'
29     bl_context = "physics"
30
31     def poll(self, context):
32         rd = context.scene.render_data
33         return (context.object) and (not rd.use_game_engine)
34
35
36 class PHYSICS_PT_field(PhysicButtonsPanel):
37     bl_label = "Force Fields"
38
39     def draw(self, context):
40         layout = self.layout
41
42         ob = context.object
43         field = ob.field
44
45         split = layout.split(percentage=0.2)
46         split.itemL(text="Type:")
47         split.itemR(field, "type", text="")
48
49         if field.type not in ('NONE', 'GUIDE', 'TEXTURE'):
50             split = layout.split(percentage=0.2)
51             #split = layout.row()
52             split.itemL(text="Shape:")
53             split.itemR(field, "shape", text="")
54
55         split = layout.split()
56
57         if field.type == 'NONE':
58             return # nothing to draw
59         elif field.type == 'GUIDE':
60             col = split.column()
61             col.itemR(field, "guide_minimum")
62             col.itemR(field, "guide_free")
63             col.itemR(field, "falloff_power")
64             col.itemR(field, "guide_path_add")
65
66             col = split.column()
67             col.itemL(text="Clumping:")
68             col.itemR(field, "guide_clump_amount")
69             col.itemR(field, "guide_clump_shape")
70
71             row = layout.row()
72             row.itemR(field, "use_max_distance")
73             sub = row.row()
74             sub.active = field.use_max_distance
75             sub.itemR(field, "maximum_distance")
76
77             layout.itemS()
78
79             layout.itemR(field, "guide_kink_type")
80             if (field.guide_kink_type != "NONE"):
81                 layout.itemR(field, "guide_kink_axis")
82
83                 flow = layout.column_flow()
84                 flow.itemR(field, "guide_kink_frequency")
85                 flow.itemR(field, "guide_kink_shape")
86                 flow.itemR(field, "guide_kink_amplitude")
87
88         elif field.type == 'TEXTURE':
89             col = split.column()
90             col.itemR(field, "strength")
91             col.itemR(field, "texture", text="")
92             col.itemR(field, "texture_mode", text="")
93             col.itemR(field, "texture_nabla")
94
95             col = split.column()
96             col.itemR(field, "use_coordinates")
97             col.itemR(field, "root_coordinates")
98             col.itemR(field, "force_2d")
99         else:
100             basic_force_field_settings_ui(self, field)
101
102         if field.type not in ('NONE', 'GUIDE'):
103
104             layout.itemL(text="Falloff:")
105             layout.itemR(field, "falloff_type", expand=True)
106
107             basic_force_field_falloff_ui(self, field)
108
109             if field.falloff_type == 'CONE':
110                 layout.itemS()
111
112                 split = layout.split(percentage=0.35)
113
114                 col = split.column()
115                 col.itemL(text="Angular:")
116                 col.itemR(field, "use_radial_min", text="Use Minimum")
117                 col.itemR(field, "use_radial_max", text="Use Maximum")
118
119                 col = split.column()
120                 col.itemR(field, "radial_falloff", text="Power")
121
122                 sub = col.column()
123                 sub.active = field.use_radial_min
124                 sub.itemR(field, "radial_minimum", text="Angle")
125
126                 sub = col.column()
127                 sub.active = field.use_radial_max
128                 sub.itemR(field, "radial_maximum", text="Angle")
129
130             elif field.falloff_type == 'TUBE':
131                 layout.itemS()
132
133                 split = layout.split(percentage=0.35)
134
135                 col = split.column()
136                 col.itemL(text="Radial:")
137                 col.itemR(field, "use_radial_min", text="Use Minimum")
138                 col.itemR(field, "use_radial_max", text="Use Maximum")
139
140                 col = split.column()
141                 col.itemR(field, "radial_falloff", text="Power")
142
143                 sub = col.column()
144                 sub.active = field.use_radial_min
145                 sub.itemR(field, "radial_minimum", text="Distance")
146
147                 sub = col.column()
148                 sub.active = field.use_radial_max
149                 sub.itemR(field, "radial_maximum", text="Distance")
150
151
152 class PHYSICS_PT_collision(PhysicButtonsPanel):
153     bl_label = "Collision"
154     #bl_default_closed = True
155
156     def poll(self, context):
157         ob = context.object
158         rd = context.scene.render_data
159         return (ob and ob.type == 'MESH') and (not rd.use_game_engine)
160
161     def draw(self, context):
162         layout = self.layout
163
164         md = context.collision
165
166         split = layout.split()
167         split.operator_context = 'EXEC_DEFAULT'
168
169         if md:
170             # remove modifier + settings
171             split.set_context_pointer("modifier", md)
172             split.itemO("object.modifier_remove", text="Remove")
173             col = split.column()
174
175             #row = split.row(align=True)
176             #row.itemR(md, "render", text="")
177             #row.itemR(md, "realtime", text="")
178
179             coll = md.settings
180
181         else:
182             # add modifier
183             split.item_enumO("object.modifier_add", "type", 'COLLISION', text="Add")
184             split.itemL()
185
186             coll = None
187
188         if coll:
189             settings = context.object.collision
190
191             layout.active = settings.enabled
192
193             split = layout.split()
194
195             col = split.column()
196             col.itemL(text="Particle:")
197             col.itemR(settings, "permeability", slider=True)
198             col.itemL(text="Particle Damping:")
199             sub = col.column(align=True)
200             sub.itemR(settings, "damping_factor", text="Factor", slider=True)
201             sub.itemR(settings, "random_damping", text="Random", slider=True)
202
203             col.itemL(text="Soft Body and Cloth:")
204             sub = col.column(align=True)
205             sub.itemR(settings, "outer_thickness", text="Outer", slider=True)
206             sub.itemR(settings, "inner_thickness", text="Inner", slider=True)
207
208             layout.itemL(text="Force Fields:")
209             layout.itemR(settings, "absorption", text="Absorption")
210
211             col = split.column()
212             col.itemL(text="")
213             col.itemR(settings, "kill_particles")
214             col.itemL(text="Particle Friction:")
215             sub = col.column(align=True)
216             sub.itemR(settings, "friction_factor", text="Factor", slider=True)
217             sub.itemR(settings, "random_friction", text="Random", slider=True)
218             col.itemL(text="Soft Body Damping:")
219             col.itemR(settings, "damping", text="Factor", slider=True)
220
221 bpy.types.register(PHYSICS_PT_field)
222 bpy.types.register(PHYSICS_PT_collision)