1bd1c507ccf205aaf7868f932100a312e02933b1
[blender.git] / release / ui / buttons_physics_cloth.py
1
2 import bpy
3
4 class PhysicButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
6         __region_type__ = "WINDOW"
7         __context__ = "physics"
8
9         def poll(self, context):
10                 ob = context.object
11                 rd = context.scene.render_data
12                 return (ob and ob.type == 'MESH') and (not rd.use_game_engine)
13                 
14 class PHYSICS_PT_cloth(PhysicButtonsPanel):
15         __label__ = "Cloth"
16
17         def draw(self, context):
18                 layout = self.layout
19                 md = context.cloth
20                 ob = context.object
21
22                 split = layout.split()
23                 split.operator_context = 'EXEC_DEFAULT'
24
25                 if md:
26                         # remove modifier + settings
27                         split.set_context_pointer("modifier", md)
28                         split.itemO("object.modifier_remove", text="Remove")
29
30                         row = split.row(align=True)
31                         row.itemR(md, "render", text="")
32                         row.itemR(md, "realtime", text="")
33                 else:
34                         # add modifier
35                         split.item_enumO("object.modifier_add", "type", 'CLOTH', text="Add")
36                         split.itemL()
37
38                 if md:
39                         cloth = md.settings
40
41                         split = layout.split()
42                         
43                         col = split.column()
44                         col.itemR(cloth, "quality", slider=True)
45                         col.itemL(text="Gravity:")
46                         col.itemR(cloth, "gravity", text="")
47
48                         col.itemR(cloth, "pin_cloth", text="Pin")
49                         colsub = col.column(align=True)
50                         colsub.active = cloth.pin_cloth
51                         colsub.itemR(cloth, "pin_stiffness", text="Stiffness")
52                         colsub.item_pointerR(cloth, "mass_vertex_group", ob, "vertex_groups", text="")
53                         
54                         col = split.column()
55                         col.itemL(text="Presets...")
56                         col.itemL(text="Material:")
57                         colsub = col.column(align=True)
58                         colsub.itemR(cloth, "mass")
59                         colsub.itemR(cloth, "structural_stiffness", text="Structural")
60                         colsub.itemR(cloth, "bending_stiffness", text="Bending")
61                         col.itemL(text="Damping:")
62                         colsub = col.column(align=True)
63                         colsub.itemR(cloth, "spring_damping", text="Spring")
64                         colsub.itemR(cloth, "air_damping", text="Air")
65                         
66                         # Disabled for now
67                         """
68                         if cloth.mass_vertex_group:
69                                 layout.itemL(text="Goal:")
70                         
71                                 col = layout.column_flow()
72                                 col.itemR(cloth, "goal_default", text="Default")
73                                 col.itemR(cloth, "goal_spring", text="Stiffness")
74                                 col.itemR(cloth, "goal_friction", text="Friction")
75                         """
76
77 class PHYSICS_PT_cloth_cache(PhysicButtonsPanel):
78         __label__ = "Cloth Cache"
79         __default_closed__ = True
80
81         def poll(self, context):
82                 return (context.cloth != None)
83
84         def draw(self, context):
85                 layout = self.layout
86
87                 cache = context.cloth.point_cache
88                 
89                 row = layout.row()
90                 row.itemR(cache, "name")
91                 
92                 row = layout.row()
93                 row.itemR(cache, "start_frame")
94                 row.itemR(cache, "end_frame")
95                 
96                 row = layout.row()
97                 
98                 if cache.baked == True:
99                         row.itemO("ptcache.free_bake_cloth", text="Free Bake")
100                 else:
101                         row.item_booleanO("ptcache.cache_cloth", "bake", True, text="Bake")
102                 
103                 subrow = row.row()
104                 subrow.enabled = cache.frames_skipped or cache.outdated
105                 subrow.itemO("ptcache.cache_cloth", text="Calculate to Current Frame")
106                         
107                 row = layout.row()
108                 #row.enabled = particle_panel_enabled(psys)
109                 row.itemO("ptcache.bake_from_cloth_cache", text="Current Cache to Bake")
110                 row.itemR(cache, "step");
111         
112                 row = layout.row()
113                 #row.enabled = particle_panel_enabled(psys)
114                 row.itemR(cache, "quick_cache")
115                 row.itemR(cache, "disk_cache")
116                 
117                 layout.itemL(text=cache.info)
118                 
119                 layout.itemS()
120                 
121                 row = layout.row()
122                 row.itemO("ptcache.bake_all", "bake", True, text="Bake All Dynamics")
123                 row.itemO("ptcache.free_bake_all", text="Free All Bakes")
124                 layout.itemO("ptcache.bake_all", text="Update All Dynamics to current frame")
125                 
126 class PHYSICS_PT_cloth_collision(PhysicButtonsPanel):
127         __label__ = "Cloth Collision"
128         __default_closed__ = True
129
130         def poll(self, context):
131                 return (context.cloth != None)
132         
133         def draw_header(self, context):
134                 layout = self.layout
135                 cloth = context.cloth.collision_settings
136         
137                 layout.itemR(cloth, "enable_collision", text="")
138
139         def draw(self, context):
140                 layout = self.layout
141                 cloth = context.cloth.collision_settings
142                 split = layout.split()
143                 
144                 layout.active = cloth.enable_collision
145                 
146                 col = split.column(align=True)
147                 col.itemR(cloth, "collision_quality", slider=True, text="Quality")
148                 col.itemR(cloth, "min_distance", slider=True, text="Distance")
149                 col.itemR(cloth, "friction")
150                 
151                 col = split.column(align=True)
152                 col.itemR(cloth, "enable_self_collision", text="Self Collision")
153                 col = col.column(align=True)
154                 col.active = cloth.enable_self_collision
155                 col.itemR(cloth, "self_collision_quality", slider=True, text="Quality")
156                 col.itemR(cloth, "self_min_distance", slider=True, text="Distance")
157
158 class PHYSICS_PT_cloth_stiffness(PhysicButtonsPanel):
159         __label__ = "Cloth Stiffness Scaling"
160         __default_closed__ = True
161
162         def poll(self, context):
163                 return (context.cloth != None)
164         
165         def draw_header(self, context):
166                 layout = self.layout
167                 cloth = context.cloth.settings
168         
169                 layout.itemR(cloth, "stiffness_scaling", text="")
170
171         def draw(self, context):
172                 layout = self.layout
173                 ob = context.object
174                 cloth = context.cloth.settings
175                 
176                 layout.active = cloth.stiffness_scaling 
177                 
178                 split = layout.split()
179                 
180                 col = split.column()
181                 col.itemL(text="Structural Stiffness:")
182                 colsub = col.column(align=True)
183                 colsub.itemR(cloth, "structural_stiffness_max", text="Max")
184                 colsub.item_pointerR(cloth, "structural_stiffness_vertex_group", ob, "vertex_groups", text="")
185                 
186                 col = split.column()
187                 col.itemL(text="Bending Stiffness:")
188                 colsub = col.column(align=True)
189                 colsub.itemR(cloth, "bending_stiffness_max", text="Max")
190                 colsub.item_pointerR(cloth, "bending_vertex_group", ob, "vertex_groups", text="")
191                 
192 bpy.types.register(PHYSICS_PT_cloth)
193 bpy.types.register(PHYSICS_PT_cloth_cache)
194 bpy.types.register(PHYSICS_PT_cloth_collision)
195 bpy.types.register(PHYSICS_PT_cloth_stiffness)