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