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