2.5 Physic Buttons:
[blender-staging.git] / release / ui / buttons_physic_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                 return (ob and ob.type == 'MESH')
12                 
13 class PHYSICS_PT_cloth(PhysicButtonsPanel):
14         __idname__ = "PHYSICS_PT_cloth"
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_OT_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_OT_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.itemR(cloth, "gravity")
46
47                         subcol = col.column(align=True)
48                         subcol.itemR(cloth, "mass")
49                         subcol.item_pointerR(cloth, "mass_vertex_group", ob, "vertex_groups", text="")
50
51                         col = split.column()
52                         col.itemL(text="Stiffness:")
53                         col.itemR(cloth, "structural_stiffness", text="Structural")
54                         col.itemR(cloth, "bending_stiffness", text="Bending")
55                         col.itemL(text="Damping:")
56                         col.itemR(cloth, "spring_damping", text="Spring")
57                         col.itemR(cloth, "air_damping", text="Air")
58                         
59                         # Disabled for now
60                         """
61                         if cloth.mass_vertex_group:
62                                 layout.itemL(text="Goal:")
63                         
64                                 col = layout.column_flow()
65                                 col.itemR(cloth, "goal_default", text="Default")
66                                 col.itemR(cloth, "goal_spring", text="Stiffness")
67                                 col.itemR(cloth, "goal_friction", text="Friction")
68                         """
69
70 class PHYSICS_PT_cloth_cache(PhysicButtonsPanel):
71         __idname__= "PHYSICS_PT_cloth_cache"
72         __label__ = "Cloth Cache"
73         __default_closed__ = True
74
75         def poll(self, context):
76                 return (context.cloth != None)
77
78         def draw(self, context):
79                 layout = self.layout
80
81                 cache = context.cloth.point_cache
82                 
83                 row = layout.row()
84                 row.itemR(cache, "name")
85                 
86                 row = layout.row()
87                 row.itemR(cache, "start_frame")
88                 row.itemR(cache, "end_frame")
89                 
90                 row = layout.row()
91                 
92                 if cache.baked == True:
93                         row.itemO("PTCACHE_OT_free_bake_cloth", text="Free Bake")
94                 else:
95                         row.item_booleanO("PTCACHE_OT_cache_cloth", "bake", True, text="Bake")
96                 
97                 subrow = row.row()
98                 subrow.enabled = cache.frames_skipped or cache.outdated
99                 subrow.itemO("PTCACHE_OT_cache_cloth", text="Calculate to Current Frame")
100                         
101                 row = layout.row()
102                 #row.enabled = particle_panel_enabled(psys)
103                 row.itemO("PTCACHE_OT_bake_from_cloth_cache", text="Current Cache to Bake")
104                 row.itemR(cache, "step");
105         
106                 row = layout.row()
107                 #row.enabled = particle_panel_enabled(psys)
108                 row.itemR(cache, "quick_cache")
109                 row.itemR(cache, "disk_cache")
110                 
111                 layout.itemL(text=cache.info)
112                 
113                 layout.itemS()
114                 
115                 row = layout.row()
116                 row.itemO("PTCACHE_OT_bake_all", "bake", True, text="Bake All Dynamics")
117                 row.itemO("PTCACHE_OT_free_bake_all", text="Free All Bakes")
118                 layout.itemO("PTCACHE_OT_bake_all", text="Update All Dynamics to current frame")
119                 
120 class PHYSICS_PT_cloth_collision(PhysicButtonsPanel):
121         __idname__ = "PHYSICS_PT_clothcollision"
122         __label__ = "Cloth Collision"
123
124         def poll(self, context):
125                 return (context.cloth != None)
126         
127         def draw_header(self, context):
128                 layout = self.layout
129                 cloth = context.cloth.collision_settings
130         
131                 layout.itemR(cloth, "enable_collision", text="")
132
133         def draw(self, context):
134                 layout = self.layout
135                 cloth = context.cloth.collision_settings
136                 
137                 layout.active = cloth.enable_collision  
138                 
139                 col = layout.column_flow()
140                 col.itemR(cloth, "collision_quality", slider=True)
141                 col.itemR(cloth, "friction")
142                 col.itemR(cloth, "min_distance", text="MinDistance")
143                 
144                 
145                 layout.itemR(cloth, "enable_self_collision", text="Self Collision")
146                 
147                 col = layout.column_flow()
148                 col.active = cloth.enable_self_collision
149                 col.itemR(cloth, "self_collision_quality", slider=True)
150                 col.itemR(cloth, "self_min_distance", text="MinDistance")
151
152 class PHYSICS_PT_cloth_stiffness(PhysicButtonsPanel):
153         __idname__ = "PHYSICS_PT_stiffness"
154         __label__ = "Cloth Stiffness Scaling"
155
156         def poll(self, context):
157                 return (context.cloth != None)
158         
159         def draw_header(self, context):
160                 layout = self.layout
161                 cloth = context.cloth.settings
162         
163                 layout.itemR(cloth, "stiffness_scaling", text="")
164
165         def draw(self, context):
166                 layout = self.layout
167                 ob = context.object
168                 cloth = context.cloth.settings
169                 
170                 layout.active = cloth.stiffness_scaling 
171                 
172                 split = layout.split()
173                 
174                 sub = split.column(align=True)
175                 sub.itemL(text="Structural Stiffness:")
176                 sub.item_pointerR(cloth, "structural_stiffness_vertex_group", ob, "vertex_groups", text="")
177                 sub.itemR(cloth, "structural_stiffness_max", text="Max")
178                 
179                 sub = split.column(align=True)
180                 sub.itemL(text="Bending Stiffness:")
181                 sub.item_pointerR(cloth, "bending_vertex_group", ob, "vertex_groups", text="")
182                 sub.itemR(cloth, "bending_stiffness_max", text="Max")
183                 
184 bpy.types.register(PHYSICS_PT_cloth)
185 bpy.types.register(PHYSICS_PT_cloth_cache)
186 bpy.types.register(PHYSICS_PT_cloth_collision)
187 bpy.types.register(PHYSICS_PT_cloth_stiffness)
188