properties_physics_softbody.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18. # <pep8 compliant>
  19. from bpy.types import (
  20. Panel,
  21. )
  22. from bl_ui.properties_physics_common import (
  23. point_cache_ui,
  24. effector_weights_ui,
  25. )
  26. COMPAT_OB_TYPES = {'MESH', 'LATTICE', 'CURVE', 'SURFACE', 'FONT'}
  27. def softbody_panel_enabled(md):
  28. return (md.point_cache.is_baked is False)
  29. class PhysicButtonsPanel:
  30. bl_space_type = 'PROPERTIES'
  31. bl_region_type = 'WINDOW'
  32. bl_context = "physics"
  33. @classmethod
  34. def poll(cls, context):
  35. ob = context.object
  36. return ob and ob.type in COMPAT_OB_TYPES and context.engine in cls.COMPAT_ENGINES and context.soft_body
  37. class PHYSICS_PT_softbody(PhysicButtonsPanel, Panel):
  38. bl_label = "Soft Body"
  39. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  40. def draw(self, context):
  41. layout = self.layout
  42. layout.use_property_split = True
  43. md = context.soft_body
  44. softbody = md.settings
  45. layout.prop(softbody, "collision_collection")
  46. class PHYSICS_PT_softbody_object(PhysicButtonsPanel, Panel):
  47. bl_label = "Object"
  48. bl_parent_id = 'PHYSICS_PT_softbody'
  49. bl_options = {'DEFAULT_CLOSED'}
  50. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  51. def draw(self, context):
  52. layout = self.layout
  53. layout.use_property_split = True
  54. md = context.soft_body
  55. softbody = md.settings
  56. ob = context.object
  57. layout.enabled = softbody_panel_enabled(md)
  58. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  59. col = flow.column()
  60. col.prop(softbody, "friction")
  61. col.separator()
  62. col = flow.column()
  63. col.prop(softbody, "mass")
  64. col.prop_search(softbody, "vertex_group_mass", ob, "vertex_groups", text="Control Point")
  65. class PHYSICS_PT_softbody_simulation(PhysicButtonsPanel, Panel):
  66. bl_label = "Simulation"
  67. bl_parent_id = 'PHYSICS_PT_softbody'
  68. bl_options = {'DEFAULT_CLOSED'}
  69. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  70. def draw(self, context):
  71. layout = self.layout
  72. layout.use_property_split = True
  73. md = context.soft_body
  74. softbody = md.settings
  75. layout.enabled = softbody_panel_enabled(md)
  76. layout.prop(softbody, "speed")
  77. class PHYSICS_PT_softbody_cache(PhysicButtonsPanel, Panel):
  78. bl_label = "Cache"
  79. bl_parent_id = 'PHYSICS_PT_softbody'
  80. bl_options = {'DEFAULT_CLOSED'}
  81. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  82. def draw(self, context):
  83. md = context.soft_body
  84. point_cache_ui(self, md.point_cache, softbody_panel_enabled(md), 'SOFTBODY')
  85. class PHYSICS_PT_softbody_goal(PhysicButtonsPanel, Panel):
  86. bl_label = "Goal"
  87. bl_parent_id = 'PHYSICS_PT_softbody'
  88. bl_options = {'DEFAULT_CLOSED'}
  89. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  90. def draw_header(self, context):
  91. softbody = context.soft_body.settings
  92. self.layout.active = softbody_panel_enabled(context.soft_body)
  93. self.layout.prop(softbody, "use_goal", text="")
  94. def draw(self, context):
  95. layout = self.layout
  96. layout.use_property_split = True
  97. md = context.soft_body
  98. softbody = md.settings
  99. ob = context.object
  100. layout.active = softbody.use_goal and softbody_panel_enabled(md)
  101. layout.prop_search(softbody, "vertex_group_goal", ob, "vertex_groups", text="Vertex Group")
  102. class PHYSICS_PT_softbody_goal_strengths(PhysicButtonsPanel, Panel):
  103. bl_label = "Strengths"
  104. bl_parent_id = 'PHYSICS_PT_softbody_goal'
  105. bl_options = {'DEFAULT_CLOSED'}
  106. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  107. def draw(self, context):
  108. layout = self.layout
  109. layout.use_property_split = True
  110. md = context.soft_body
  111. softbody = md.settings
  112. layout.active = softbody.use_goal and softbody_panel_enabled(md)
  113. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  114. col = flow.column()
  115. col.prop(softbody, "goal_default", text="Default")
  116. col.separator()
  117. col = flow.column(align=True)
  118. col.prop(softbody, "goal_min", text="Min")
  119. col.prop(softbody, "goal_max", text="Max")
  120. class PHYSICS_PT_softbody_goal_settings(PhysicButtonsPanel, Panel):
  121. bl_label = "Settings"
  122. bl_parent_id = 'PHYSICS_PT_softbody_goal'
  123. bl_options = {'DEFAULT_CLOSED'}
  124. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  125. def draw(self, context):
  126. layout = self.layout
  127. layout.use_property_split = True
  128. md = context.soft_body
  129. softbody = md.settings
  130. layout.active = softbody.use_goal and softbody_panel_enabled(md)
  131. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  132. col = flow.column()
  133. col.prop(softbody, "goal_spring", text="Stiffness")
  134. col = flow.column()
  135. col.prop(softbody, "goal_friction", text="Damping")
  136. class PHYSICS_PT_softbody_edge(PhysicButtonsPanel, Panel):
  137. bl_label = "Edges"
  138. bl_parent_id = 'PHYSICS_PT_softbody'
  139. bl_options = {'DEFAULT_CLOSED'}
  140. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  141. def draw_header(self, context):
  142. softbody = context.soft_body.settings
  143. self.layout.active = softbody_panel_enabled(context.soft_body)
  144. self.layout.prop(softbody, "use_edges", text="")
  145. def draw(self, context):
  146. layout = self.layout
  147. layout.use_property_split = True
  148. md = context.soft_body
  149. softbody = md.settings
  150. ob = context.object
  151. layout.active = softbody.use_edges and softbody_panel_enabled(md)
  152. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  153. col = flow.column()
  154. col.prop_search(softbody, "vertex_group_spring", ob, "vertex_groups", text="Springs")
  155. col.separator()
  156. col.prop(softbody, "pull")
  157. col.prop(softbody, "push")
  158. col.separator()
  159. col = flow.column()
  160. col.prop(softbody, "damping")
  161. col.prop(softbody, "plastic")
  162. col.prop(softbody, "bend")
  163. col.separator()
  164. col = flow.column()
  165. col.prop(softbody, "spring_length", text="Length")
  166. col.prop(softbody, "use_edge_collision", text="Collision Edge")
  167. col.prop(softbody, "use_face_collision", text="Face")
  168. class PHYSICS_PT_softbody_edge_aerodynamics(PhysicButtonsPanel, Panel):
  169. bl_label = "Aerodynamics"
  170. bl_parent_id = 'PHYSICS_PT_softbody_edge'
  171. bl_options = {'DEFAULT_CLOSED'}
  172. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  173. def draw(self, context):
  174. layout = self.layout
  175. layout.use_property_split = True
  176. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  177. md = context.soft_body
  178. softbody = md.settings
  179. flow.active = softbody.use_edges and softbody_panel_enabled(md)
  180. col = flow.column()
  181. col.prop(softbody, "aerodynamics_type", text="Type")
  182. col = flow.column()
  183. col.prop(softbody, "aero", text="Factor")
  184. class PHYSICS_PT_softbody_edge_stiffness(PhysicButtonsPanel, Panel):
  185. bl_label = "Stiffness"
  186. bl_parent_id = 'PHYSICS_PT_softbody_edge'
  187. bl_options = {'DEFAULT_CLOSED'}
  188. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  189. def draw_header(self, context):
  190. softbody = context.soft_body.settings
  191. self.layout.active = softbody_panel_enabled(context.soft_body)
  192. self.layout.prop(softbody, "use_stiff_quads", text="")
  193. def draw(self, context):
  194. layout = self.layout
  195. layout.use_property_split = True
  196. md = context.soft_body
  197. softbody = md.settings
  198. layout.active = softbody.use_edges and softbody.use_stiff_quads and softbody_panel_enabled(md)
  199. layout.prop(softbody, "shear")
  200. class PHYSICS_PT_softbody_collision(PhysicButtonsPanel, Panel):
  201. bl_label = "Self Collision"
  202. bl_parent_id = 'PHYSICS_PT_softbody'
  203. bl_options = {'DEFAULT_CLOSED'}
  204. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  205. def draw_header(self, context):
  206. softbody = context.soft_body.settings
  207. self.layout.active = softbody_panel_enabled(context.soft_body)
  208. self.layout.prop(softbody, "use_self_collision", text="")
  209. def draw(self, context):
  210. layout = self.layout
  211. layout.use_property_split = True
  212. md = context.soft_body
  213. softbody = md.settings
  214. layout.active = softbody.use_self_collision and softbody_panel_enabled(md)
  215. layout.prop(softbody, "collision_type", text="Calculation Type")
  216. layout.separator()
  217. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  218. col = flow.column()
  219. col.prop(softbody, "ball_size", text="Ball Size")
  220. col = flow.column()
  221. col.prop(softbody, "ball_stiff", text="Stiffness")
  222. col.prop(softbody, "ball_damp", text="Dampening")
  223. class PHYSICS_PT_softbody_solver(PhysicButtonsPanel, Panel):
  224. bl_label = "Solver"
  225. bl_parent_id = 'PHYSICS_PT_softbody'
  226. bl_options = {'DEFAULT_CLOSED'}
  227. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  228. def draw(self, context):
  229. layout = self.layout
  230. layout.use_property_split = True
  231. md = context.soft_body
  232. softbody = md.settings
  233. layout.active = softbody_panel_enabled(md)
  234. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  235. col = flow.column(align=True)
  236. col.prop(softbody, "step_min", text="Step Size Min")
  237. col.prop(softbody, "step_max", text="Max")
  238. col = flow.column()
  239. col.prop(softbody, "use_auto_step", text="Auto-Step")
  240. col.prop(softbody, "error_threshold")
  241. class PHYSICS_PT_softbody_solver_diagnostics(PhysicButtonsPanel, Panel):
  242. bl_label = "Diagnostics"
  243. bl_parent_id = 'PHYSICS_PT_softbody_solver'
  244. bl_options = {'DEFAULT_CLOSED'}
  245. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  246. def draw(self, context):
  247. layout = self.layout
  248. layout.use_property_split = True
  249. md = context.soft_body
  250. softbody = md.settings
  251. layout.active = softbody_panel_enabled(md)
  252. layout.prop(softbody, "use_diagnose")
  253. layout.prop(softbody, "use_estimate_matrix")
  254. class PHYSICS_PT_softbody_solver_helpers(PhysicButtonsPanel, Panel):
  255. bl_label = "Helpers"
  256. bl_parent_id = 'PHYSICS_PT_softbody_solver'
  257. bl_options = {'DEFAULT_CLOSED'}
  258. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  259. def draw(self, context):
  260. layout = self.layout
  261. layout.use_property_split = True
  262. md = context.soft_body
  263. softbody = md.settings
  264. layout.active = softbody_panel_enabled(md)
  265. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  266. col = flow.column()
  267. col.prop(softbody, "choke")
  268. col = flow.column()
  269. col.prop(softbody, "fuzzy")
  270. class PHYSICS_PT_softbody_field_weights(PhysicButtonsPanel, Panel):
  271. bl_label = "Field Weights"
  272. bl_parent_id = 'PHYSICS_PT_softbody'
  273. bl_options = {'DEFAULT_CLOSED'}
  274. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  275. def draw(self, context):
  276. md = context.soft_body
  277. softbody = md.settings
  278. effector_weights_ui(self, softbody.effector_weights, 'SOFTBODY')
  279. classes = (
  280. PHYSICS_PT_softbody,
  281. PHYSICS_PT_softbody_object,
  282. PHYSICS_PT_softbody_simulation,
  283. PHYSICS_PT_softbody_cache,
  284. PHYSICS_PT_softbody_goal,
  285. PHYSICS_PT_softbody_goal_settings,
  286. PHYSICS_PT_softbody_goal_strengths,
  287. PHYSICS_PT_softbody_edge,
  288. PHYSICS_PT_softbody_edge_aerodynamics,
  289. PHYSICS_PT_softbody_edge_stiffness,
  290. PHYSICS_PT_softbody_collision,
  291. PHYSICS_PT_softbody_solver,
  292. PHYSICS_PT_softbody_solver_diagnostics,
  293. PHYSICS_PT_softbody_solver_helpers,
  294. PHYSICS_PT_softbody_field_weights,
  295. )
  296. if __name__ == "__main__": # only for live edit.
  297. from bpy.utils import register_class
  298. for cls in classes:
  299. register_class(cls)