New point cache file format:
[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                 layout.set_context_pointer("PointCache", cache)
89                 
90                 row = layout.row()
91                 row.template_list(cache, "point_cache_list", cache, "active_point_cache_index")
92                 col = row.column(align=True)
93                 col.itemO("ptcache.add_new", icon="ICON_ZOOMIN", text="")
94                 col.itemO("ptcache.remove", icon="ICON_ZOOMOUT", text="")
95                 
96                 row = layout.row()
97                 row.itemR(cache, "name")
98                 
99                 row = layout.row()
100                 row.itemR(cache, "start_frame")
101                 row.itemR(cache, "end_frame")
102                 
103                 row = layout.row()
104                 
105                 if cache.baked == True:
106                         row.itemO("ptcache.free_bake", text="Free Bake")
107                 else:
108                         row.item_booleanO("ptcache.bake", "bake", True, text="Bake")
109                 
110                 subrow = row.row()
111                 subrow.enabled = cache.frames_skipped or cache.outdated
112                 subrow.itemO("ptcache.bake", "bake", False, text="Calculate to Current Frame")
113                         
114                 row = layout.row()
115                 #row.enabled = particle_panel_enabled(psys)
116                 row.itemO("ptcache.bake_from_cache", text="Current Cache to Bake")
117                 row.itemR(cache, "step");
118         
119                 row = layout.row()
120                 #row.enabled = particle_panel_enabled(psys)
121                 row.itemR(cache, "quick_cache")
122                 row.itemR(cache, "disk_cache")
123                 
124                 layout.itemL(text=cache.info)
125                 
126                 layout.itemS()
127                 
128                 row = layout.row()
129                 row.itemO("ptcache.bake_all", "bake", True, text="Bake All Dynamics")
130                 row.itemO("ptcache.free_bake_all", text="Free All Bakes")
131                 layout.itemO("ptcache.bake_all", "bake", False, text="Update All Dynamics to current frame")
132                 
133 class PHYSICS_PT_cloth_collision(PhysicButtonsPanel):
134         __label__ = "Cloth Collision"
135         __default_closed__ = True
136
137         def poll(self, context):
138                 return (context.cloth != None)
139         
140         def draw_header(self, context):
141                 layout = self.layout
142                 cloth = context.cloth.collision_settings
143         
144                 layout.itemR(cloth, "enable_collision", text="")
145
146         def draw(self, context):
147                 layout = self.layout
148                 cloth = context.cloth.collision_settings
149                 split = layout.split()
150                 
151                 layout.active = cloth.enable_collision
152                 
153                 col = split.column(align=True)
154                 col.itemR(cloth, "collision_quality", slider=True, text="Quality")
155                 col.itemR(cloth, "min_distance", slider=True, text="Distance")
156                 col.itemR(cloth, "friction")
157                 
158                 col = split.column(align=True)
159                 col.itemR(cloth, "enable_self_collision", text="Self Collision")
160                 col = col.column(align=True)
161                 col.active = cloth.enable_self_collision
162                 col.itemR(cloth, "self_collision_quality", slider=True, text="Quality")
163                 col.itemR(cloth, "self_min_distance", slider=True, text="Distance")
164
165 class PHYSICS_PT_cloth_stiffness(PhysicButtonsPanel):
166         __label__ = "Cloth Stiffness Scaling"
167         __default_closed__ = True
168
169         def poll(self, context):
170                 return (context.cloth != None)
171         
172         def draw_header(self, context):
173                 layout = self.layout
174                 cloth = context.cloth.settings
175         
176                 layout.itemR(cloth, "stiffness_scaling", text="")
177
178         def draw(self, context):
179                 layout = self.layout
180                 ob = context.object
181                 cloth = context.cloth.settings
182                 
183                 layout.active = cloth.stiffness_scaling 
184                 
185                 split = layout.split()
186                 
187                 col = split.column()
188                 col.itemL(text="Structural Stiffness:")
189                 colsub = col.column(align=True)
190                 colsub.itemR(cloth, "structural_stiffness_max", text="Max")
191                 colsub.item_pointerR(cloth, "structural_stiffness_vertex_group", ob, "vertex_groups", text="")
192                 
193                 col = split.column()
194                 col.itemL(text="Bending Stiffness:")
195                 colsub = col.column(align=True)
196                 colsub.itemR(cloth, "bending_stiffness_max", text="Max")
197                 colsub.item_pointerR(cloth, "bending_vertex_group", ob, "vertex_groups", text="")
198                 
199 bpy.types.register(PHYSICS_PT_cloth)
200 bpy.types.register(PHYSICS_PT_cloth_cache)
201 bpy.types.register(PHYSICS_PT_cloth_collision)
202 bpy.types.register(PHYSICS_PT_cloth_stiffness)