properties_physics_common.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. import bpy
  20. from bpy.types import (
  21. Panel,
  22. )
  23. from bpy.app.translations import contexts as i18n_contexts
  24. class PhysicButtonsPanel:
  25. bl_space_type = 'PROPERTIES'
  26. bl_region_type = 'WINDOW'
  27. bl_context = "physics"
  28. @classmethod
  29. def poll(cls, context):
  30. return (context.object) and context.engine in cls.COMPAT_ENGINES
  31. def physics_add(layout, md, name, type, typeicon, toggles):
  32. row = layout.row(align=True)
  33. if md:
  34. row.context_pointer_set("modifier", md)
  35. row.operator(
  36. "object.modifier_remove",
  37. text=name,
  38. text_ctxt=i18n_contexts.default,
  39. icon='X',
  40. )
  41. if toggles:
  42. row.prop(md, "show_render", text="")
  43. row.prop(md, "show_viewport", text="")
  44. else:
  45. row.operator(
  46. "object.modifier_add",
  47. text=name,
  48. text_ctxt=i18n_contexts.default,
  49. icon=typeicon,
  50. ).type = type
  51. def physics_add_special(layout, data, name, addop, removeop, typeicon):
  52. row = layout.row(align=True)
  53. if data:
  54. row.operator(removeop, text=name, text_ctxt=i18n_contexts.default, icon='X')
  55. else:
  56. row.operator(addop, text=name, text_ctxt=i18n_contexts.default, icon=typeicon)
  57. class PHYSICS_PT_add(PhysicButtonsPanel, Panel):
  58. bl_label = ""
  59. bl_options = {'HIDE_HEADER'}
  60. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  61. def draw(self, context):
  62. layout = self.layout
  63. row = layout.row(align=True)
  64. row.alignment = 'LEFT'
  65. row.label(text="Enable physics for:")
  66. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  67. obj = context.object
  68. col = flow.column()
  69. if obj.field.type == 'NONE':
  70. col.operator("object.forcefield_toggle", text="Force Field", icon='FORCE_FORCE')
  71. else:
  72. col.operator("object.forcefield_toggle", text="Force Field", icon='X')
  73. if obj.type == 'MESH':
  74. physics_add(col, context.collision, "Collision", 'COLLISION', 'MOD_PHYSICS', False)
  75. physics_add(col, context.cloth, "Cloth", 'CLOTH', 'MOD_CLOTH', True)
  76. physics_add(col, context.dynamic_paint, "Dynamic Paint", 'DYNAMIC_PAINT', 'MOD_DYNAMICPAINT', True)
  77. col = flow.column()
  78. if obj.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE', 'FONT'}:
  79. physics_add(col, context.soft_body, "Soft Body", 'SOFT_BODY', 'MOD_SOFT', True)
  80. if obj.type == 'MESH':
  81. physics_add(col, context.fluid, "Fluid", 'FLUID_SIMULATION', 'MOD_FLUIDSIM', True)
  82. physics_add(col, context.smoke, "Smoke", 'SMOKE', 'MOD_SMOKE', True)
  83. physics_add_special(
  84. col, obj.rigid_body, "Rigid Body",
  85. "rigidbody.object_add",
  86. "rigidbody.object_remove",
  87. 'RIGID_BODY'
  88. )
  89. # all types of objects can have rigid body constraint.
  90. physics_add_special(
  91. col, obj.rigid_body_constraint, "Rigid Body Constraint",
  92. "rigidbody.constraint_add",
  93. "rigidbody.constraint_remove",
  94. 'RIGID_BODY_CONSTRAINT'
  95. )
  96. # cache-type can be 'PSYS' 'HAIR' 'SMOKE' etc.
  97. def point_cache_ui(self, cache, enabled, cachetype):
  98. layout = self.layout
  99. layout.use_property_split = True
  100. layout.context_pointer_set("point_cache", cache)
  101. is_saved = bpy.data.is_saved
  102. # NOTE: TODO temporarly used until the animate properties are properly skipped.
  103. layout.use_property_decorate = False # No animation (remove this later on).
  104. if not cachetype == 'RIGID_BODY':
  105. row = layout.row()
  106. row.template_list(
  107. "UI_UL_list", "point_caches", cache, "point_caches",
  108. cache.point_caches, "active_index", rows=1,
  109. )
  110. col = row.column(align=True)
  111. col.operator("ptcache.add", icon='ADD', text="")
  112. col.operator("ptcache.remove", icon='REMOVE', text="")
  113. if cachetype in {'PSYS', 'HAIR', 'SMOKE'}:
  114. col = layout.column()
  115. if cachetype == 'SMOKE':
  116. col.prop(cache, "use_library_path", text="Use Library Path")
  117. col.prop(cache, "use_external")
  118. if cache.use_external:
  119. col = layout.column()
  120. col.prop(cache, "index", text="Index")
  121. col.prop(cache, "filepath", text="Path")
  122. cache_info = cache.info
  123. if cache_info:
  124. col = layout.column()
  125. col.alignment = 'RIGHT'
  126. col.label(text=cache_info)
  127. else:
  128. if cachetype in {'SMOKE', 'DYNAMIC_PAINT'}:
  129. if not is_saved:
  130. col = layout.column(align=True)
  131. col.alignment = 'RIGHT'
  132. col.label(text="Cache is disabled until the file is saved")
  133. layout.enabled = False
  134. if not cache.use_external or cachetype == 'SMOKE':
  135. col = layout.column(align=True)
  136. if cachetype not in {'PSYS', 'DYNAMIC_PAINT'}:
  137. col.enabled = enabled
  138. col.prop(cache, "frame_start", text="Simulation Start")
  139. col.prop(cache, "frame_end")
  140. if cachetype not in {'SMOKE', 'CLOTH', 'DYNAMIC_PAINT', 'RIGID_BODY'}:
  141. col.prop(cache, "frame_step")
  142. cache_info = cache.info
  143. if cachetype != 'SMOKE' and cache_info: # avoid empty space.
  144. col = layout.column(align=True)
  145. col.alignment = 'RIGHT'
  146. col.label(text=cache_info)
  147. can_bake = True
  148. if cachetype not in {'SMOKE', 'DYNAMIC_PAINT', 'RIGID_BODY'}:
  149. if not is_saved:
  150. col = layout.column(align=True)
  151. col.alignment = 'RIGHT'
  152. col.label(text="Options are disabled until the file is saved")
  153. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  154. flow.enabled = enabled and is_saved
  155. col = flow.column(align=True)
  156. col.prop(cache, "use_disk_cache")
  157. subcol = col.column()
  158. subcol.active = cache.use_disk_cache
  159. subcol.prop(cache, "use_library_path", text="Use Library Path")
  160. col = flow.column()
  161. col.active = cache.use_disk_cache
  162. col.prop(cache, "compression", text="Compression")
  163. if cache.id_data.library and not cache.use_disk_cache:
  164. can_bake = False
  165. col = layout.column(align=True)
  166. col.alignment = 'RIGHT'
  167. col.separator()
  168. col.label(text="Linked object baking requires Disk Cache to be enabled")
  169. else:
  170. layout.separator()
  171. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=False)
  172. col = flow.column()
  173. col.active = can_bake
  174. if cache.is_baked is True:
  175. col.operator("ptcache.free_bake", text="Delete Bake")
  176. else:
  177. col.operator("ptcache.bake", text="Bake").bake = True
  178. sub = col.row()
  179. sub.enabled = (cache.is_frame_skip or cache.is_outdated) and enabled
  180. sub.operator("ptcache.bake", text="Calculate To Frame").bake = False
  181. sub = col.column()
  182. sub.enabled = enabled
  183. sub.operator("ptcache.bake_from_cache", text="Current Cache to Bake")
  184. col = flow.column()
  185. col.operator("ptcache.bake_all", text="Bake All Dynamics").bake = True
  186. col.operator("ptcache.free_bake_all", text="Delete All Bakes")
  187. col.operator("ptcache.bake_all", text="Update All To Frame").bake = False
  188. def effector_weights_ui(self, weights, weight_type):
  189. layout = self.layout
  190. layout.use_property_split = True
  191. # NOTE: TODO temporarly used until the animate properties are properly skipped.
  192. layout.use_property_decorate = False # No animation (remove this later on).
  193. layout.prop(weights, "collection")
  194. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  195. col = flow.column()
  196. col.prop(weights, "gravity", slider=True)
  197. col.prop(weights, "all", slider=True)
  198. col.prop(weights, "force", slider=True)
  199. col.prop(weights, "vortex", slider=True)
  200. col = flow.column()
  201. col.prop(weights, "magnetic", slider=True)
  202. col.prop(weights, "harmonic", slider=True)
  203. col.prop(weights, "charge", slider=True)
  204. col.prop(weights, "lennardjones", slider=True)
  205. col = flow.column()
  206. col.prop(weights, "wind", slider=True)
  207. col.prop(weights, "curve_guide", slider=True)
  208. col.prop(weights, "texture", slider=True)
  209. if weight_type != 'SMOKE':
  210. col.prop(weights, "smokeflow", slider=True)
  211. col = flow.column()
  212. col.prop(weights, "turbulence", slider=True)
  213. col.prop(weights, "drag", slider=True)
  214. col.prop(weights, "boid", slider=True)
  215. def basic_force_field_settings_ui(self, field):
  216. layout = self.layout
  217. layout.use_property_split = True
  218. if not field or field.type == 'NONE':
  219. return
  220. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  221. col = flow.column()
  222. if field.type == 'DRAG':
  223. col.prop(field, "linear_drag", text="Linear")
  224. else:
  225. col.prop(field, "strength")
  226. if field.type == 'TURBULENCE':
  227. col.prop(field, "size")
  228. col.prop(field, "flow")
  229. elif field.type == 'HARMONIC':
  230. col.prop(field, "harmonic_damping", text="Damping")
  231. col.prop(field, "rest_length")
  232. elif field.type == 'VORTEX' and field.shape != 'POINT':
  233. col.prop(field, "inflow")
  234. elif field.type == 'DRAG':
  235. col.prop(field, "quadratic_drag", text="Quadratic")
  236. else:
  237. col.prop(field, "flow")
  238. col.prop(field, "apply_to_location", text="Affect Location")
  239. col.prop(field, "apply_to_rotation", text="Affect Rotation")
  240. col = flow.column()
  241. sub = col.column(align=True)
  242. sub.prop(field, "noise", text="Noise Amount")
  243. sub.prop(field, "seed", text="Seed")
  244. if field.type == 'TURBULENCE':
  245. col.prop(field, "use_global_coords", text="Global")
  246. elif field.type == 'HARMONIC':
  247. col.prop(field, "use_multiple_springs")
  248. if field.type == 'FORCE':
  249. col.prop(field, "use_gravity_falloff", text="Gravitation")
  250. col.prop(field, "use_absorption")
  251. def basic_force_field_falloff_ui(self, field):
  252. layout = self.layout
  253. if not field or field.type == 'NONE':
  254. return
  255. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  256. col = flow.column()
  257. col.prop(field, "z_direction")
  258. col.prop(field, "falloff_power", text="Power")
  259. col = flow.column()
  260. col.prop(field, "use_min_distance", text="Use Minimum")
  261. sub = col.column(align=True)
  262. sub.active = field.use_min_distance
  263. sub.prop(field, "distance_min", text="Min Distance")
  264. col = flow.column()
  265. col.prop(field, "use_max_distance", text="Use Maximum")
  266. sub = col.column(align=True)
  267. sub.active = field.use_max_distance
  268. sub.prop(field, "distance_max", text="Max Distance")
  269. classes = (
  270. PHYSICS_PT_add,
  271. )
  272. if __name__ == "__main__": # only for live edit.
  273. from bpy.utils import register_class
  274. for cls in classes:
  275. register_class(cls)