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