properties_physics_rigidbody_constraint.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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. class PHYSICS_PT_rigidbody_constraint_panel:
  23. bl_space_type = 'PROPERTIES'
  24. bl_region_type = 'WINDOW'
  25. bl_context = "physics"
  26. class PHYSICS_PT_rigid_body_constraint(PHYSICS_PT_rigidbody_constraint_panel, Panel):
  27. bl_label = "Rigid Body Constraint"
  28. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  29. @classmethod
  30. def poll(cls, context):
  31. ob = context.object
  32. return (ob and ob.rigid_body_constraint and context.engine in cls.COMPAT_ENGINES)
  33. def draw(self, context):
  34. layout = self.layout
  35. layout.use_property_split = True
  36. ob = context.object
  37. rbc = ob.rigid_body_constraint
  38. layout.prop(rbc, "type")
  39. class PHYSICS_PT_rigid_body_constraint_settings(PHYSICS_PT_rigidbody_constraint_panel, Panel):
  40. bl_label = "Settings"
  41. bl_parent_id = 'PHYSICS_PT_rigid_body_constraint'
  42. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  43. @classmethod
  44. def poll(cls, context):
  45. ob = context.object
  46. return (ob and ob.rigid_body_constraint and context.engine in cls.COMPAT_ENGINES)
  47. def draw(self, context):
  48. layout = self.layout
  49. layout.use_property_split = True
  50. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  51. ob = context.object
  52. rbc = ob.rigid_body_constraint
  53. col = flow.column()
  54. col.prop(rbc, "enabled")
  55. col.prop(rbc, "disable_collisions")
  56. if rbc.type != 'MOTOR':
  57. col = flow.column()
  58. col.prop(rbc, "use_breaking")
  59. sub = col.column()
  60. sub.active = rbc.use_breaking
  61. sub.prop(rbc, "breaking_threshold", text="Threshold")
  62. class PHYSICS_PT_rigid_body_constraint_objects(PHYSICS_PT_rigidbody_constraint_panel, Panel):
  63. bl_label = "Objects"
  64. bl_parent_id = 'PHYSICS_PT_rigid_body_constraint'
  65. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  66. @classmethod
  67. def poll(cls, context):
  68. ob = context.object
  69. return (ob and ob.rigid_body_constraint and context.engine in cls.COMPAT_ENGINES)
  70. def draw(self, context):
  71. layout = self.layout
  72. layout.use_property_split = True
  73. ob = context.object
  74. rbc = ob.rigid_body_constraint
  75. layout.prop(rbc, "object1", text="First")
  76. layout.prop(rbc, "object2", text="Second")
  77. class PHYSICS_PT_rigid_body_constraint_override_iterations(PHYSICS_PT_rigidbody_constraint_panel, Panel):
  78. bl_label = "Override Iterations"
  79. bl_parent_id = 'PHYSICS_PT_rigid_body_constraint'
  80. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  81. @classmethod
  82. def poll(cls, context):
  83. ob = context.object
  84. return (ob and ob.rigid_body_constraint and context.engine in cls.COMPAT_ENGINES)
  85. def draw_header(self, context):
  86. ob = context.object
  87. rbc = ob.rigid_body_constraint
  88. self.layout.row().prop(rbc, "use_override_solver_iterations", text="")
  89. def draw(self, context):
  90. layout = self.layout
  91. layout.use_property_split = True
  92. ob = context.object
  93. rbc = ob.rigid_body_constraint
  94. layout.active = rbc.use_override_solver_iterations
  95. layout.prop(rbc, "solver_iterations", text="Iterations")
  96. class PHYSICS_PT_rigid_body_constraint_limits(PHYSICS_PT_rigidbody_constraint_panel, Panel):
  97. bl_label = "Limits"
  98. bl_parent_id = 'PHYSICS_PT_rigid_body_constraint'
  99. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  100. @classmethod
  101. def poll(cls, context):
  102. ob = context.object
  103. rbc = ob.rigid_body_constraint
  104. return (ob and rbc and (rbc.type in {'GENERIC', 'GENERIC_SPRING', 'HINGE', 'SLIDER', 'PISTON'})
  105. and context.engine in cls.COMPAT_ENGINES)
  106. def draw(self, _context):
  107. return # do nothing.
  108. class PHYSICS_PT_rigid_body_constraint_limits_linear(PHYSICS_PT_rigidbody_constraint_panel, Panel):
  109. bl_label = "Linear"
  110. bl_parent_id = 'PHYSICS_PT_rigid_body_constraint_limits'
  111. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  112. @classmethod
  113. def poll(cls, context):
  114. ob = context.object
  115. rbc = ob.rigid_body_constraint
  116. return (ob and rbc
  117. and (rbc.type in {'GENERIC', 'GENERIC_SPRING', 'SLIDER', 'PISTON'})
  118. and context.engine in cls.COMPAT_ENGINES)
  119. def draw(self, context):
  120. layout = self.layout
  121. layout.use_property_split = True
  122. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  123. ob = context.object
  124. rbc = ob.rigid_body_constraint
  125. if rbc.type in {'PISTON', 'SLIDER'}:
  126. col = flow.column()
  127. col.prop(rbc, "use_limit_lin_x")
  128. sub = col.column(align=True)
  129. sub.active = rbc.use_limit_lin_x
  130. sub.prop(rbc, "limit_lin_x_lower", text="X Lower")
  131. sub.prop(rbc, "limit_lin_x_upper", text="Upper")
  132. elif rbc.type in {'GENERIC', 'GENERIC_SPRING'}:
  133. col = flow.column()
  134. col.prop(rbc, "use_limit_lin_x")
  135. sub = col.column(align=True)
  136. sub.active = rbc.use_limit_lin_x
  137. sub.prop(rbc, "limit_lin_x_lower", text="X Lower")
  138. sub.prop(rbc, "limit_lin_x_upper", text="Upper")
  139. col = flow.column()
  140. col.prop(rbc, "use_limit_lin_y")
  141. sub = col.column(align=True)
  142. sub.active = rbc.use_limit_lin_y
  143. sub.prop(rbc, "limit_lin_y_lower", text="Y Lower")
  144. sub.prop(rbc, "limit_lin_y_upper", text="Upper")
  145. col = flow.column()
  146. col.prop(rbc, "use_limit_lin_z")
  147. sub = col.column(align=True)
  148. sub.active = rbc.use_limit_lin_z
  149. sub.prop(rbc, "limit_lin_z_lower", text="Z Lower")
  150. sub.prop(rbc, "limit_lin_z_upper", text="Upper")
  151. class PHYSICS_PT_rigid_body_constraint_limits_angular(PHYSICS_PT_rigidbody_constraint_panel, Panel):
  152. bl_label = "Angular"
  153. bl_parent_id = 'PHYSICS_PT_rigid_body_constraint_limits'
  154. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  155. @classmethod
  156. def poll(cls, context):
  157. ob = context.object
  158. rbc = ob.rigid_body_constraint
  159. return (ob and rbc
  160. and (rbc.type in {'GENERIC', 'GENERIC_SPRING', 'HINGE', 'PISTON'})
  161. and context.engine in cls.COMPAT_ENGINES)
  162. def draw(self, context):
  163. layout = self.layout
  164. layout.use_property_split = True
  165. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  166. ob = context.object
  167. rbc = ob.rigid_body_constraint
  168. if rbc.type == 'HINGE':
  169. col = flow.column()
  170. col.prop(rbc, "use_limit_ang_z")
  171. sub = col.column(align=True)
  172. sub.active = rbc.use_limit_ang_z
  173. sub.prop(rbc, "limit_ang_z_lower", text="Z Lower")
  174. sub.prop(rbc, "limit_ang_z_upper", text="Upper")
  175. elif rbc.type == 'PISTON':
  176. col = flow.column()
  177. col.prop(rbc, "use_limit_ang_x")
  178. sub = col.column(align=True)
  179. sub.active = rbc.use_limit_ang_x
  180. sub.prop(rbc, "limit_ang_x_lower", text="X Lower")
  181. sub.prop(rbc, "limit_ang_x_upper", text="Upper")
  182. elif rbc.type in {'GENERIC', 'GENERIC_SPRING'}:
  183. col = flow.column()
  184. col.prop(rbc, "use_limit_ang_x")
  185. sub = col.column(align=True)
  186. sub.active = rbc.use_limit_ang_x
  187. sub.prop(rbc, "limit_ang_x_lower", text="X Lower")
  188. sub.prop(rbc, "limit_ang_x_upper", text="Upper")
  189. col = flow.column()
  190. col.prop(rbc, "use_limit_ang_y")
  191. sub = col.column(align=True)
  192. sub.active = rbc.use_limit_ang_y
  193. sub.prop(rbc, "limit_ang_y_lower", text="Y Lower")
  194. sub.prop(rbc, "limit_ang_y_upper", text="Upper")
  195. col = flow.column()
  196. col.prop(rbc, "use_limit_ang_z")
  197. sub = col.column(align=True)
  198. sub.active = rbc.use_limit_ang_z
  199. sub.prop(rbc, "limit_ang_z_lower", text="Z Lower")
  200. sub.prop(rbc, "limit_ang_z_upper", text="Upper")
  201. class PHYSICS_PT_rigid_body_constraint_motor(PHYSICS_PT_rigidbody_constraint_panel, Panel):
  202. bl_label = "Motor"
  203. bl_parent_id = 'PHYSICS_PT_rigid_body_constraint'
  204. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  205. @classmethod
  206. def poll(cls, context):
  207. ob = context.object
  208. rbc = ob.rigid_body_constraint
  209. return (ob and rbc and rbc.type == 'MOTOR'
  210. and context.engine in cls.COMPAT_ENGINES)
  211. def draw(self, _context):
  212. return # do nothing.
  213. class PHYSICS_PT_rigid_body_constraint_motor_angular(PHYSICS_PT_rigidbody_constraint_panel, Panel):
  214. bl_label = "Angular"
  215. bl_parent_id = 'PHYSICS_PT_rigid_body_constraint_motor'
  216. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  217. @classmethod
  218. def poll(cls, context):
  219. ob = context.object
  220. rbc = ob.rigid_body_constraint
  221. return (ob and rbc and rbc.type == 'MOTOR'
  222. and context.engine in cls.COMPAT_ENGINES)
  223. def draw_header(self, context):
  224. ob = context.object
  225. rbc = ob.rigid_body_constraint
  226. self.layout.row().prop(rbc, "use_motor_ang", text="")
  227. def draw(self, context):
  228. layout = self.layout
  229. layout.use_property_split = True
  230. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  231. ob = context.object
  232. rbc = ob.rigid_body_constraint
  233. flow.active = rbc.use_motor_ang
  234. col = flow.column(align=True)
  235. col.prop(rbc, "motor_ang_target_velocity", text="Target Velocity")
  236. col = flow.column(align=True)
  237. col.prop(rbc, "motor_ang_max_impulse", text="Max Impulse")
  238. class PHYSICS_PT_rigid_body_constraint_motor_linear(PHYSICS_PT_rigidbody_constraint_panel, Panel):
  239. bl_label = "Linear"
  240. bl_parent_id = 'PHYSICS_PT_rigid_body_constraint_motor'
  241. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  242. @classmethod
  243. def poll(cls, context):
  244. ob = context.object
  245. rbc = ob.rigid_body_constraint
  246. return (ob and rbc and rbc.type == 'MOTOR'
  247. and context.engine in cls.COMPAT_ENGINES)
  248. def draw_header(self, context):
  249. ob = context.object
  250. rbc = ob.rigid_body_constraint
  251. self.layout.row().prop(rbc, "use_motor_lin", text="")
  252. def draw(self, context):
  253. layout = self.layout
  254. layout.use_property_split = True
  255. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  256. ob = context.object
  257. rbc = ob.rigid_body_constraint
  258. flow.active = rbc.use_motor_lin
  259. col = flow.column(align=True)
  260. col.prop(rbc, "motor_lin_target_velocity", text="Target Velocity")
  261. col = flow.column(align=True)
  262. col.prop(rbc, "motor_lin_max_impulse", text="Max Impulse")
  263. class PHYSICS_PT_rigid_body_constraint_springs(PHYSICS_PT_rigidbody_constraint_panel, Panel):
  264. bl_label = "Springs"
  265. bl_parent_id = 'PHYSICS_PT_rigid_body_constraint'
  266. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  267. @classmethod
  268. def poll(cls, context):
  269. ob = context.object
  270. rbc = ob.rigid_body_constraint
  271. return (ob and ob.rigid_body_constraint
  272. and rbc.type == 'GENERIC_SPRING'
  273. and context.engine in cls.COMPAT_ENGINES)
  274. def draw(self, context):
  275. layout = self.layout
  276. layout.use_property_split = True
  277. ob = context.object
  278. rbc = ob.rigid_body_constraint
  279. layout.prop(rbc, "spring_type", text="Type")
  280. class PHYSICS_PT_rigid_body_constraint_springs_angular(PHYSICS_PT_rigidbody_constraint_panel, Panel):
  281. bl_label = "Angular"
  282. bl_parent_id = 'PHYSICS_PT_rigid_body_constraint_springs'
  283. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  284. @classmethod
  285. def poll(cls, context):
  286. ob = context.object
  287. rbc = ob.rigid_body_constraint
  288. return (ob and ob.rigid_body_constraint
  289. and rbc.type == 'GENERIC_SPRING'
  290. and context.engine in cls.COMPAT_ENGINES)
  291. def draw(self, context):
  292. layout = self.layout
  293. layout.use_property_split = True
  294. ob = context.object
  295. rbc = ob.rigid_body_constraint
  296. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  297. col = flow.column()
  298. col.prop(rbc, "use_spring_ang_x", text="X Angle")
  299. sub = col.column(align=True)
  300. sub.active = rbc.use_spring_ang_x
  301. sub.prop(rbc, "spring_stiffness_ang_x", text="X Stiffness")
  302. sub.prop(rbc, "spring_damping_ang_x", text="Damping")
  303. col = flow.column()
  304. col.prop(rbc, "use_spring_ang_y", text="Y Angle")
  305. sub = col.column(align=True)
  306. sub.active = rbc.use_spring_ang_y
  307. sub.prop(rbc, "spring_stiffness_ang_y", text="Y Stiffness")
  308. sub.prop(rbc, "spring_damping_ang_y", text="Damping")
  309. col = flow.column()
  310. col.prop(rbc, "use_spring_ang_z", text="Z Angle")
  311. sub = col.column(align=True)
  312. sub.active = rbc.use_spring_ang_z
  313. sub.prop(rbc, "spring_stiffness_ang_z", text="Z Stiffness")
  314. sub.prop(rbc, "spring_damping_ang_z", text="Damping")
  315. class PHYSICS_PT_rigid_body_constraint_springs_linear(PHYSICS_PT_rigidbody_constraint_panel, Panel):
  316. bl_label = "Linear"
  317. bl_parent_id = 'PHYSICS_PT_rigid_body_constraint_springs'
  318. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  319. @classmethod
  320. def poll(cls, context):
  321. ob = context.object
  322. rbc = ob.rigid_body_constraint
  323. return (ob and ob.rigid_body_constraint
  324. and rbc.type == 'GENERIC_SPRING'
  325. and context.engine in cls.COMPAT_ENGINES)
  326. def draw(self, context):
  327. layout = self.layout
  328. layout.use_property_split = True
  329. ob = context.object
  330. rbc = ob.rigid_body_constraint
  331. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  332. col = flow.column()
  333. col.prop(rbc, "use_spring_x", text="X Axis")
  334. sub = col.column(align=True)
  335. sub.active = rbc.use_spring_x
  336. sub.prop(rbc, "spring_stiffness_x", text="X Stiffness")
  337. sub.prop(rbc, "spring_damping_x", text="Damping")
  338. col = flow.column()
  339. col.prop(rbc, "use_spring_y", text="Y Axis")
  340. sub = col.column(align=True)
  341. sub.active = rbc.use_spring_y
  342. sub.prop(rbc, "spring_stiffness_y", text="Stiffness")
  343. sub.prop(rbc, "spring_damping_y", text="Damping")
  344. col = flow.column()
  345. col.prop(rbc, "use_spring_z", text="Z Axis")
  346. sub = col.column(align=True)
  347. sub.active = rbc.use_spring_z
  348. sub.prop(rbc, "spring_stiffness_z", text="Stiffness")
  349. sub.prop(rbc, "spring_damping_z", text="Damping")
  350. classes = (
  351. PHYSICS_PT_rigid_body_constraint,
  352. PHYSICS_PT_rigid_body_constraint_settings,
  353. PHYSICS_PT_rigid_body_constraint_limits,
  354. PHYSICS_PT_rigid_body_constraint_limits_angular,
  355. PHYSICS_PT_rigid_body_constraint_limits_linear,
  356. PHYSICS_PT_rigid_body_constraint_motor,
  357. PHYSICS_PT_rigid_body_constraint_motor_angular,
  358. PHYSICS_PT_rigid_body_constraint_motor_linear,
  359. PHYSICS_PT_rigid_body_constraint_objects,
  360. PHYSICS_PT_rigid_body_constraint_override_iterations,
  361. PHYSICS_PT_rigid_body_constraint_springs,
  362. PHYSICS_PT_rigid_body_constraint_springs_angular,
  363. PHYSICS_PT_rigid_body_constraint_springs_linear,
  364. )
  365. if __name__ == "__main__": # only for live edit.
  366. from bpy.utils import register_class
  367. for cls in classes:
  368. register_class(cls)