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