physics_server_3d_extension.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*************************************************************************/
  2. /* physics_server_3d_extension.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "physics_server_3d_extension.h"
  31. bool PhysicsDirectSpaceState3DExtension::is_body_excluded_from_query(const RID &p_body) const {
  32. return exclude && exclude->has(p_body);
  33. }
  34. thread_local const HashSet<RID> *PhysicsDirectSpaceState3DExtension::exclude = nullptr;
  35. void PhysicsDirectSpaceState3DExtension::_bind_methods() {
  36. GDVIRTUAL_BIND(_intersect_ray, "from", "to", "collision_mask", "collide_with_bodies", "collide_with_areas", "hit_from_inside", "hit_back_faces", "result");
  37. GDVIRTUAL_BIND(_intersect_point, "position", "collision_mask", "collide_with_bodies", "collide_with_areas", "results", "max_results");
  38. GDVIRTUAL_BIND(_intersect_shape, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "result_count", "max_results");
  39. GDVIRTUAL_BIND(_cast_motion, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "closest_safe", "closest_unsafe", "info");
  40. GDVIRTUAL_BIND(_collide_shape, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "results", "max_results", "result_count");
  41. GDVIRTUAL_BIND(_rest_info, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "rest_info");
  42. GDVIRTUAL_BIND(_get_closest_point_to_object_volume, "object", "point");
  43. }
  44. PhysicsDirectSpaceState3DExtension::PhysicsDirectSpaceState3DExtension() {
  45. }
  46. void PhysicsDirectBodyState3DExtension::_bind_methods() {
  47. GDVIRTUAL_BIND(_get_total_gravity);
  48. GDVIRTUAL_BIND(_get_total_linear_damp);
  49. GDVIRTUAL_BIND(_get_total_angular_damp);
  50. GDVIRTUAL_BIND(_get_center_of_mass);
  51. GDVIRTUAL_BIND(_get_center_of_mass_local);
  52. GDVIRTUAL_BIND(_get_principal_inertia_axes);
  53. GDVIRTUAL_BIND(_get_inverse_mass);
  54. GDVIRTUAL_BIND(_get_inverse_inertia);
  55. GDVIRTUAL_BIND(_set_linear_velocity, "velocity");
  56. GDVIRTUAL_BIND(_get_linear_velocity);
  57. GDVIRTUAL_BIND(_set_angular_velocity, "velocity");
  58. GDVIRTUAL_BIND(_get_angular_velocity);
  59. GDVIRTUAL_BIND(_set_transform, "transform");
  60. GDVIRTUAL_BIND(_get_transform);
  61. GDVIRTUAL_BIND(_get_velocity_at_local_position, "local_position");
  62. GDVIRTUAL_BIND(_apply_central_impulse, "impulse");
  63. GDVIRTUAL_BIND(_apply_impulse, "impulse", "position");
  64. GDVIRTUAL_BIND(_apply_torque_impulse, "impulse");
  65. GDVIRTUAL_BIND(_apply_central_force, "force");
  66. GDVIRTUAL_BIND(_apply_force, "force", "position");
  67. GDVIRTUAL_BIND(_apply_torque, "torque");
  68. GDVIRTUAL_BIND(_add_constant_central_force, "force");
  69. GDVIRTUAL_BIND(_add_constant_force, "force", "position");
  70. GDVIRTUAL_BIND(_add_constant_torque, "torque");
  71. GDVIRTUAL_BIND(_set_constant_force, "force");
  72. GDVIRTUAL_BIND(_get_constant_force);
  73. GDVIRTUAL_BIND(_set_constant_torque, "torque");
  74. GDVIRTUAL_BIND(_get_constant_torque);
  75. GDVIRTUAL_BIND(_set_sleep_state, "enabled");
  76. GDVIRTUAL_BIND(_is_sleeping);
  77. GDVIRTUAL_BIND(_get_contact_count);
  78. GDVIRTUAL_BIND(_get_contact_local_position, "contact_idx");
  79. GDVIRTUAL_BIND(_get_contact_local_normal, "contact_idx");
  80. GDVIRTUAL_BIND(_get_contact_impulse, "contact_idx");
  81. GDVIRTUAL_BIND(_get_contact_local_shape, "contact_idx");
  82. GDVIRTUAL_BIND(_get_contact_collider, "contact_idx");
  83. GDVIRTUAL_BIND(_get_contact_collider_position, "contact_idx");
  84. GDVIRTUAL_BIND(_get_contact_collider_id, "contact_idx");
  85. GDVIRTUAL_BIND(_get_contact_collider_object, "contact_idx");
  86. GDVIRTUAL_BIND(_get_contact_collider_shape, "contact_idx");
  87. GDVIRTUAL_BIND(_get_contact_collider_velocity_at_position, "contact_idx");
  88. GDVIRTUAL_BIND(_get_step);
  89. GDVIRTUAL_BIND(_integrate_forces);
  90. GDVIRTUAL_BIND(_get_space_state);
  91. }
  92. PhysicsDirectBodyState3DExtension::PhysicsDirectBodyState3DExtension() {
  93. }
  94. thread_local const HashSet<RID> *PhysicsServer3DExtension::exclude_bodies = nullptr;
  95. thread_local const HashSet<ObjectID> *PhysicsServer3DExtension::exclude_objects = nullptr;
  96. bool PhysicsServer3DExtension::body_test_motion_is_excluding_body(RID p_body) const {
  97. return exclude_bodies && exclude_bodies->has(p_body);
  98. }
  99. bool PhysicsServer3DExtension::body_test_motion_is_excluding_object(ObjectID p_object) const {
  100. return exclude_objects && exclude_objects->has(p_object);
  101. }
  102. void PhysicsServer3DExtension::_bind_methods() {
  103. GDVIRTUAL_BIND(_world_boundary_shape_create);
  104. GDVIRTUAL_BIND(_separation_ray_shape_create);
  105. GDVIRTUAL_BIND(_sphere_shape_create);
  106. GDVIRTUAL_BIND(_box_shape_create);
  107. GDVIRTUAL_BIND(_capsule_shape_create);
  108. GDVIRTUAL_BIND(_cylinder_shape_create);
  109. GDVIRTUAL_BIND(_convex_polygon_shape_create);
  110. GDVIRTUAL_BIND(_concave_polygon_shape_create);
  111. GDVIRTUAL_BIND(_heightmap_shape_create);
  112. GDVIRTUAL_BIND(_custom_shape_create);
  113. GDVIRTUAL_BIND(_shape_set_data, "shape", "data");
  114. GDVIRTUAL_BIND(_shape_get_type, "shape");
  115. GDVIRTUAL_BIND(_shape_get_data, "shape");
  116. GDVIRTUAL_BIND(_space_create);
  117. GDVIRTUAL_BIND(_space_set_active, "space", "active");
  118. GDVIRTUAL_BIND(_space_is_active, "space");
  119. GDVIRTUAL_BIND(_space_set_param, "space", "param", "value");
  120. GDVIRTUAL_BIND(_space_get_param, "space", "param");
  121. GDVIRTUAL_BIND(_space_get_direct_state, "space");
  122. GDVIRTUAL_BIND(_area_create);
  123. GDVIRTUAL_BIND(_area_set_space, "area", "space");
  124. GDVIRTUAL_BIND(_area_get_space, "area");
  125. GDVIRTUAL_BIND(_area_add_shape, "area", "shape", "transform", "disabled");
  126. GDVIRTUAL_BIND(_area_set_shape, "area", "shape_idx", "shape");
  127. GDVIRTUAL_BIND(_area_set_shape_transform, "area", "shape_idx", "transform");
  128. GDVIRTUAL_BIND(_area_set_shape_disabled, "area", "shape_idx", "disabled");
  129. GDVIRTUAL_BIND(_area_get_shape_count, "area");
  130. GDVIRTUAL_BIND(_area_get_shape, "area", "shape_idx");
  131. GDVIRTUAL_BIND(_area_get_shape_transform, "area", "shape_idx");
  132. GDVIRTUAL_BIND(_area_remove_shape, "area", "shape_idx");
  133. GDVIRTUAL_BIND(_area_clear_shapes, "area");
  134. GDVIRTUAL_BIND(_area_set_collision_layer, "area", "layer");
  135. GDVIRTUAL_BIND(_area_set_collision_mask, "area", "mask");
  136. GDVIRTUAL_BIND(_area_set_param, "area", "param", "value");
  137. GDVIRTUAL_BIND(_area_set_transform, "area", "transform");
  138. GDVIRTUAL_BIND(_area_get_param, "area", "param");
  139. GDVIRTUAL_BIND(_area_get_transform, "area");
  140. GDVIRTUAL_BIND(_area_attach_object_instance_id, "area", "id");
  141. GDVIRTUAL_BIND(_area_get_object_instance_id, "area");
  142. GDVIRTUAL_BIND(_area_set_monitor_callback, "area", "callback");
  143. GDVIRTUAL_BIND(_area_set_area_monitor_callback, "area", "callback");
  144. GDVIRTUAL_BIND(_area_set_monitorable, "area", "monitorable");
  145. GDVIRTUAL_BIND(_area_set_ray_pickable, "area", "enable");
  146. GDVIRTUAL_BIND(_body_create);
  147. GDVIRTUAL_BIND(_body_set_space, "body", "space");
  148. GDVIRTUAL_BIND(_body_get_space, "body");
  149. GDVIRTUAL_BIND(_body_set_mode, "body", "mode");
  150. GDVIRTUAL_BIND(_body_get_mode, "body");
  151. GDVIRTUAL_BIND(_body_set_collision_layer, "body", "layer");
  152. GDVIRTUAL_BIND(_body_get_collision_layer, "body");
  153. GDVIRTUAL_BIND(_body_set_collision_mask, "body", "mask");
  154. GDVIRTUAL_BIND(_body_get_collision_mask, "body");
  155. GDVIRTUAL_BIND(_body_set_collision_priority, "body", "priority");
  156. GDVIRTUAL_BIND(_body_get_collision_priority, "body");
  157. GDVIRTUAL_BIND(_body_add_shape, "body", "shape", "transform", "disabled");
  158. GDVIRTUAL_BIND(_body_set_shape, "body", "shape_idx", "shape");
  159. GDVIRTUAL_BIND(_body_set_shape_transform, "body", "shape_idx", "transform");
  160. GDVIRTUAL_BIND(_body_set_shape_disabled, "body", "shape_idx", "disabled");
  161. GDVIRTUAL_BIND(_body_get_shape_count, "body");
  162. GDVIRTUAL_BIND(_body_get_shape, "body", "shape_idx");
  163. GDVIRTUAL_BIND(_body_get_shape_transform, "body", "shape_idx");
  164. GDVIRTUAL_BIND(_body_remove_shape, "body", "shape_idx");
  165. GDVIRTUAL_BIND(_body_clear_shapes, "body");
  166. GDVIRTUAL_BIND(_body_attach_object_instance_id, "body", "id");
  167. GDVIRTUAL_BIND(_body_get_object_instance_id, "body");
  168. GDVIRTUAL_BIND(_body_set_enable_continuous_collision_detection, "body", "enable");
  169. GDVIRTUAL_BIND(_body_is_continuous_collision_detection_enabled, "body");
  170. GDVIRTUAL_BIND(_body_set_param, "body", "param", "value");
  171. GDVIRTUAL_BIND(_body_get_param, "body", "param");
  172. GDVIRTUAL_BIND(_body_reset_mass_properties, "body");
  173. GDVIRTUAL_BIND(_body_set_state, "body", "state", "value");
  174. GDVIRTUAL_BIND(_body_get_state, "body", "state");
  175. GDVIRTUAL_BIND(_body_apply_central_impulse, "body", "impulse");
  176. GDVIRTUAL_BIND(_body_apply_impulse, "body", "impulse", "position");
  177. GDVIRTUAL_BIND(_body_apply_torque_impulse, "body", "impulse");
  178. GDVIRTUAL_BIND(_body_apply_central_force, "body", "force");
  179. GDVIRTUAL_BIND(_body_apply_force, "body", "force", "position");
  180. GDVIRTUAL_BIND(_body_apply_torque, "body", "torque");
  181. GDVIRTUAL_BIND(_body_add_constant_central_force, "body", "force");
  182. GDVIRTUAL_BIND(_body_add_constant_force, "body", "force", "position");
  183. GDVIRTUAL_BIND(_body_add_constant_torque, "body", "torque");
  184. GDVIRTUAL_BIND(_body_set_constant_force, "body", "force");
  185. GDVIRTUAL_BIND(_body_get_constant_force, "body");
  186. GDVIRTUAL_BIND(_body_set_constant_torque, "body", "torque");
  187. GDVIRTUAL_BIND(_body_get_constant_torque, "body");
  188. GDVIRTUAL_BIND(_body_set_axis_velocity, "body", "axis_velocity");
  189. GDVIRTUAL_BIND(_body_set_axis_lock, "body", "axis", "lock");
  190. GDVIRTUAL_BIND(_body_is_axis_locked, "body", "axis");
  191. GDVIRTUAL_BIND(_body_add_collision_exception, "body", "excepted_body");
  192. GDVIRTUAL_BIND(_body_remove_collision_exception, "body", "excepted_body");
  193. GDVIRTUAL_BIND(_body_set_max_contacts_reported, "body", "amount");
  194. GDVIRTUAL_BIND(_body_get_max_contacts_reported, "body");
  195. GDVIRTUAL_BIND(_body_set_omit_force_integration, "body", "enable");
  196. GDVIRTUAL_BIND(_body_is_omitting_force_integration, "body");
  197. GDVIRTUAL_BIND(_body_set_force_integration_callback, "body", "callable", "userdata");
  198. GDVIRTUAL_BIND(_body_set_ray_pickable, "body", "enable");
  199. GDVIRTUAL_BIND(_body_test_motion, "body", "from", "motion", "margin", "max_collisions", "collide_separation_ray", "result");
  200. GDVIRTUAL_BIND(_body_get_direct_state, "body");
  201. GDVIRTUAL_BIND(_soft_body_get_bounds, "body");
  202. GDVIRTUAL_BIND(_joint_create);
  203. GDVIRTUAL_BIND(_joint_clear, "joint");
  204. GDVIRTUAL_BIND(_joint_make_pin, "joint", "body_A", "local_A", "body_B", "local_B");
  205. GDVIRTUAL_BIND(_pin_joint_set_param, "joint", "param", "value");
  206. GDVIRTUAL_BIND(_pin_joint_get_param, "joint", "param");
  207. GDVIRTUAL_BIND(_pin_joint_set_local_a, "joint", "local_A");
  208. GDVIRTUAL_BIND(_pin_joint_get_local_a, "joint");
  209. GDVIRTUAL_BIND(_pin_joint_set_local_b, "joint", "local_B");
  210. GDVIRTUAL_BIND(_pin_joint_get_local_b, "joint");
  211. GDVIRTUAL_BIND(_joint_make_hinge, "joint", "body_A", "hinge_A", "body_B", "hinge_B");
  212. GDVIRTUAL_BIND(_hinge_joint_set_param, "joint", "param", "value");
  213. GDVIRTUAL_BIND(_hinge_joint_get_param, "joint", "param");
  214. GDVIRTUAL_BIND(_hinge_joint_set_flag, "joint", "flag", "enabled");
  215. GDVIRTUAL_BIND(_hinge_joint_get_flag, "joint", "flag");
  216. GDVIRTUAL_BIND(_joint_make_slider, "joint", "body_A", "local_ref_A", "body_B", "local_ref_B");
  217. GDVIRTUAL_BIND(_slider_joint_set_param, "joint", "param", "value");
  218. GDVIRTUAL_BIND(_slider_joint_get_param, "joint", "param");
  219. GDVIRTUAL_BIND(_joint_make_cone_twist, "joint", "body_A", "local_ref_A", "body_B", "local_ref_B");
  220. GDVIRTUAL_BIND(_cone_twist_joint_set_param, "joint", "param", "value");
  221. GDVIRTUAL_BIND(_cone_twist_joint_get_param, "joint", "param");
  222. GDVIRTUAL_BIND(_joint_get_type, "joint");
  223. GDVIRTUAL_BIND(_joint_set_solver_priority, "joint", "priority");
  224. GDVIRTUAL_BIND(_joint_get_solver_priority, "joint");
  225. GDVIRTUAL_BIND(_joint_make_generic_6dof, "joint", "body_A", "local_ref_A", "body_B", "local_ref_B");
  226. GDVIRTUAL_BIND(_generic_6dof_joint_set_param, "joint", "axis", "param", "value");
  227. GDVIRTUAL_BIND(_generic_6dof_joint_get_param, "joint", "axis", "param");
  228. GDVIRTUAL_BIND(_generic_6dof_joint_set_flag, "joint", "axis", "flag", "enable");
  229. GDVIRTUAL_BIND(_generic_6dof_joint_get_flag, "joint", "axis", "flag");
  230. GDVIRTUAL_BIND(_free_rid, "rid");
  231. GDVIRTUAL_BIND(_set_active, "active");
  232. GDVIRTUAL_BIND(_get_process_info, "process_info");
  233. }
  234. PhysicsServer3DExtension::PhysicsServer3DExtension() {
  235. }
  236. PhysicsServer3DExtension::~PhysicsServer3DExtension() {
  237. }