made scripts pass the pep8 test (though not fully pep8 yet)
[blender-staging.git] / release / scripts / ui / properties_physics_cloth.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 point_cache_ui
10 from properties_physics_common import effector_weights_ui
11
12
13 def cloth_panel_enabled(md):
14     return md.point_cache.baked == False
15
16
17 class PhysicButtonsPanel(bpy.types.Panel):
18     bl_space_type = 'PROPERTIES'
19     bl_region_type = 'WINDOW'
20     bl_context = "physics"
21
22     def poll(self, context):
23         ob = context.object
24         rd = context.scene.render_data
25         return (ob and ob.type == 'MESH') and (not rd.use_game_engine)
26
27
28 class PHYSICS_PT_cloth(PhysicButtonsPanel):
29     bl_label = "Cloth"
30
31     def draw(self, context):
32         layout = self.layout
33
34         md = context.cloth
35         ob = context.object
36
37         split = layout.split()
38         split.operator_context = 'EXEC_DEFAULT'
39
40         if md:
41             # remove modifier + settings
42             split.set_context_pointer("modifier", md)
43             split.itemO("object.modifier_remove", text="Remove")
44
45             row = split.row(align=True)
46             row.itemR(md, "render", text="")
47             row.itemR(md, "realtime", text="")
48         else:
49             # add modifier
50             split.item_enumO("object.modifier_add", "type", 'CLOTH', text="Add")
51             split.itemL()
52
53         if md:
54             cloth = md.settings
55
56             layout.active = cloth_panel_enabled(md)
57
58             split = layout.split()
59
60             col = split.column()
61
62             col.itemL(text="Quality:")
63             col.itemR(cloth, "quality", text="Steps", slider=True)
64
65             col.itemL(text="Material:")
66             sub = col.column(align=True)
67             sub.itemR(cloth, "mass")
68             sub.itemR(cloth, "structural_stiffness", text="Structural")
69             sub.itemR(cloth, "bending_stiffness", text="Bending")
70
71             col = split.column()
72
73             col.itemL(text="Presets:")
74             col.itemL(text="TODO!")
75
76             col.itemL(text="Damping:")
77             sub = col.column(align=True)
78             sub.itemR(cloth, "spring_damping", text="Spring")
79             sub.itemR(cloth, "air_damping", text="Air")
80
81             col.itemR(cloth, "pin_cloth", text="Pin")
82             sub = col.column(align=True)
83             sub.active = cloth.pin_cloth
84             sub.itemR(cloth, "pin_stiffness", text="Stiffness")
85             sub.item_pointerR(cloth, "mass_vertex_group", ob, "vertex_groups", text="")
86
87             # Disabled for now
88             """
89             if cloth.mass_vertex_group:
90                 layout.itemL(text="Goal:")
91
92                 col = layout.column_flow()
93                 col.itemR(cloth, "goal_default", text="Default")
94                 col.itemR(cloth, "goal_spring", text="Stiffness")
95                 col.itemR(cloth, "goal_friction", text="Friction")
96             """
97
98
99 class PHYSICS_PT_cloth_cache(PhysicButtonsPanel):
100     bl_label = "Cloth Cache"
101     bl_default_closed = True
102
103     def poll(self, context):
104         return context.cloth
105
106     def draw(self, context):
107         md = context.cloth
108         point_cache_ui(self, md.point_cache, cloth_panel_enabled(md), 0, 0)
109
110
111 class PHYSICS_PT_cloth_collision(PhysicButtonsPanel):
112     bl_label = "Cloth Collision"
113     bl_default_closed = True
114
115     def poll(self, context):
116         return context.cloth
117
118     def draw_header(self, context):
119         cloth = context.cloth.collision_settings
120
121         self.layout.active = cloth_panel_enabled(context.cloth)
122         self.layout.itemR(cloth, "enable_collision", text="")
123
124     def draw(self, context):
125         layout = self.layout
126
127         cloth = context.cloth.collision_settings
128         md = context.cloth
129
130         layout.active = cloth.enable_collision and cloth_panel_enabled(md)
131
132         split = layout.split()
133
134         col = split.column()
135         col.itemR(cloth, "collision_quality", slider=True, text="Quality")
136         col.itemR(cloth, "min_distance", slider=True, text="Distance")
137         col.itemR(cloth, "friction")
138
139         col = split.column()
140         col.itemR(cloth, "enable_self_collision", text="Self Collision")
141         sub = col.column()
142         sub.active = cloth.enable_self_collision
143         sub.itemR(cloth, "self_collision_quality", slider=True, text="Quality")
144         sub.itemR(cloth, "self_min_distance", slider=True, text="Distance")
145
146
147 class PHYSICS_PT_cloth_stiffness(PhysicButtonsPanel):
148     bl_label = "Cloth Stiffness Scaling"
149     bl_default_closed = True
150
151     def poll(self, context):
152         return context.cloth
153
154     def draw_header(self, context):
155         cloth = context.cloth.settings
156
157         self.layout.active = cloth_panel_enabled(context.cloth)
158         self.layout.itemR(cloth, "stiffness_scaling", text="")
159
160     def draw(self, context):
161         layout = self.layout
162
163         md = context.cloth
164         ob = context.object
165         cloth = context.cloth.settings
166
167         layout.active = cloth.stiffness_scaling and cloth_panel_enabled(md)
168
169         split = layout.split()
170
171         col = split.column()
172         col.itemL(text="Structural Stiffness:")
173         sub = col.column(align=True)
174         sub.itemR(cloth, "structural_stiffness_max", text="Max")
175         sub.item_pointerR(cloth, "structural_stiffness_vertex_group", ob, "vertex_groups", text="")
176
177         col = split.column()
178         col.itemL(text="Bending Stiffness:")
179         sub = col.column(align=True)
180         sub.itemR(cloth, "bending_stiffness_max", text="Max")
181         sub.item_pointerR(cloth, "bending_vertex_group", ob, "vertex_groups", text="")
182
183
184 class PHYSICS_PT_cloth_field_weights(PhysicButtonsPanel):
185     bl_label = "Cloth Field Weights"
186     bl_default_closed = True
187
188     def poll(self, context):
189         return (context.cloth)
190
191     def draw(self, context):
192         cloth = context.cloth.settings
193         effector_weights_ui(self, cloth.effector_weights)
194
195 bpy.types.register(PHYSICS_PT_cloth)
196 bpy.types.register(PHYSICS_PT_cloth_cache)
197 bpy.types.register(PHYSICS_PT_cloth_collision)
198 bpy.types.register(PHYSICS_PT_cloth_stiffness)
199 bpy.types.register(PHYSICS_PT_cloth_field_weights)