physics_server_3d.cpp 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  1. /**************************************************************************/
  2. /* physics_server_3d.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/string/print_string.h"
  33. #include "core/variant/typed_array.h"
  34. void PhysicsServer3DRenderingServerHandler::set_vertex(int p_vertex_id, const void *p_vector3) {
  35. GDVIRTUAL_REQUIRED_CALL(_set_vertex, p_vertex_id, p_vector3);
  36. }
  37. void PhysicsServer3DRenderingServerHandler::set_normal(int p_vertex_id, const void *p_vector3) {
  38. GDVIRTUAL_REQUIRED_CALL(_set_normal, p_vertex_id, p_vector3);
  39. }
  40. void PhysicsServer3DRenderingServerHandler::set_aabb(const AABB &p_aabb) {
  41. GDVIRTUAL_REQUIRED_CALL(_set_aabb, p_aabb);
  42. }
  43. void PhysicsServer3DRenderingServerHandler::_bind_methods() {
  44. GDVIRTUAL_BIND(_set_vertex, "vertex_id", "vertices");
  45. GDVIRTUAL_BIND(_set_normal, "vertex_id", "normals");
  46. GDVIRTUAL_BIND(_set_aabb, "aabb");
  47. }
  48. PhysicsServer3D *PhysicsServer3D::singleton = nullptr;
  49. void PhysicsDirectBodyState3D::integrate_forces() {
  50. real_t step = get_step();
  51. Vector3 lv = get_linear_velocity();
  52. lv += get_total_gravity() * step;
  53. Vector3 av = get_angular_velocity();
  54. real_t linear_damp = 1.0 - step * get_total_linear_damp();
  55. if (linear_damp < 0) { // reached zero in the given time
  56. linear_damp = 0;
  57. }
  58. real_t angular_damp = 1.0 - step * get_total_angular_damp();
  59. if (angular_damp < 0) { // reached zero in the given time
  60. angular_damp = 0;
  61. }
  62. lv *= linear_damp;
  63. av *= angular_damp;
  64. set_linear_velocity(lv);
  65. set_angular_velocity(av);
  66. }
  67. Object *PhysicsDirectBodyState3D::get_contact_collider_object(int p_contact_idx) const {
  68. ObjectID objid = get_contact_collider_id(p_contact_idx);
  69. Object *obj = ObjectDB::get_instance(objid);
  70. return obj;
  71. }
  72. PhysicsServer3D *PhysicsServer3D::get_singleton() {
  73. return singleton;
  74. }
  75. void PhysicsDirectBodyState3D::_bind_methods() {
  76. ClassDB::bind_method(D_METHOD("get_total_gravity"), &PhysicsDirectBodyState3D::get_total_gravity);
  77. ClassDB::bind_method(D_METHOD("get_total_linear_damp"), &PhysicsDirectBodyState3D::get_total_linear_damp);
  78. ClassDB::bind_method(D_METHOD("get_total_angular_damp"), &PhysicsDirectBodyState3D::get_total_angular_damp);
  79. ClassDB::bind_method(D_METHOD("get_center_of_mass"), &PhysicsDirectBodyState3D::get_center_of_mass);
  80. ClassDB::bind_method(D_METHOD("get_center_of_mass_local"), &PhysicsDirectBodyState3D::get_center_of_mass_local);
  81. ClassDB::bind_method(D_METHOD("get_principal_inertia_axes"), &PhysicsDirectBodyState3D::get_principal_inertia_axes);
  82. ClassDB::bind_method(D_METHOD("get_inverse_mass"), &PhysicsDirectBodyState3D::get_inverse_mass);
  83. ClassDB::bind_method(D_METHOD("get_inverse_inertia"), &PhysicsDirectBodyState3D::get_inverse_inertia);
  84. ClassDB::bind_method(D_METHOD("get_inverse_inertia_tensor"), &PhysicsDirectBodyState3D::get_inverse_inertia_tensor);
  85. ClassDB::bind_method(D_METHOD("set_linear_velocity", "velocity"), &PhysicsDirectBodyState3D::set_linear_velocity);
  86. ClassDB::bind_method(D_METHOD("get_linear_velocity"), &PhysicsDirectBodyState3D::get_linear_velocity);
  87. ClassDB::bind_method(D_METHOD("set_angular_velocity", "velocity"), &PhysicsDirectBodyState3D::set_angular_velocity);
  88. ClassDB::bind_method(D_METHOD("get_angular_velocity"), &PhysicsDirectBodyState3D::get_angular_velocity);
  89. ClassDB::bind_method(D_METHOD("set_transform", "transform"), &PhysicsDirectBodyState3D::set_transform);
  90. ClassDB::bind_method(D_METHOD("get_transform"), &PhysicsDirectBodyState3D::get_transform);
  91. ClassDB::bind_method(D_METHOD("get_velocity_at_local_position", "local_position"), &PhysicsDirectBodyState3D::get_velocity_at_local_position);
  92. ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &PhysicsDirectBodyState3D::apply_central_impulse, Vector3());
  93. ClassDB::bind_method(D_METHOD("apply_impulse", "impulse", "position"), &PhysicsDirectBodyState3D::apply_impulse, Vector3());
  94. ClassDB::bind_method(D_METHOD("apply_torque_impulse", "impulse"), &PhysicsDirectBodyState3D::apply_torque_impulse);
  95. ClassDB::bind_method(D_METHOD("apply_central_force", "force"), &PhysicsDirectBodyState3D::apply_central_force, Vector3());
  96. ClassDB::bind_method(D_METHOD("apply_force", "force", "position"), &PhysicsDirectBodyState3D::apply_force, Vector3());
  97. ClassDB::bind_method(D_METHOD("apply_torque", "torque"), &PhysicsDirectBodyState3D::apply_torque);
  98. ClassDB::bind_method(D_METHOD("add_constant_central_force", "force"), &PhysicsDirectBodyState3D::add_constant_central_force, Vector3());
  99. ClassDB::bind_method(D_METHOD("add_constant_force", "force", "position"), &PhysicsDirectBodyState3D::add_constant_force, Vector3());
  100. ClassDB::bind_method(D_METHOD("add_constant_torque", "torque"), &PhysicsDirectBodyState3D::add_constant_torque);
  101. ClassDB::bind_method(D_METHOD("set_constant_force", "force"), &PhysicsDirectBodyState3D::set_constant_force);
  102. ClassDB::bind_method(D_METHOD("get_constant_force"), &PhysicsDirectBodyState3D::get_constant_force);
  103. ClassDB::bind_method(D_METHOD("set_constant_torque", "torque"), &PhysicsDirectBodyState3D::set_constant_torque);
  104. ClassDB::bind_method(D_METHOD("get_constant_torque"), &PhysicsDirectBodyState3D::get_constant_torque);
  105. ClassDB::bind_method(D_METHOD("set_sleep_state", "enabled"), &PhysicsDirectBodyState3D::set_sleep_state);
  106. ClassDB::bind_method(D_METHOD("is_sleeping"), &PhysicsDirectBodyState3D::is_sleeping);
  107. ClassDB::bind_method(D_METHOD("get_contact_count"), &PhysicsDirectBodyState3D::get_contact_count);
  108. ClassDB::bind_method(D_METHOD("get_contact_local_position", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_local_position);
  109. ClassDB::bind_method(D_METHOD("get_contact_local_normal", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_local_normal);
  110. ClassDB::bind_method(D_METHOD("get_contact_impulse", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_impulse);
  111. ClassDB::bind_method(D_METHOD("get_contact_local_shape", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_local_shape);
  112. ClassDB::bind_method(D_METHOD("get_contact_local_velocity_at_position", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_local_velocity_at_position);
  113. ClassDB::bind_method(D_METHOD("get_contact_collider", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider);
  114. ClassDB::bind_method(D_METHOD("get_contact_collider_position", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_position);
  115. ClassDB::bind_method(D_METHOD("get_contact_collider_id", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_id);
  116. ClassDB::bind_method(D_METHOD("get_contact_collider_object", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_object);
  117. ClassDB::bind_method(D_METHOD("get_contact_collider_shape", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_shape);
  118. ClassDB::bind_method(D_METHOD("get_contact_collider_velocity_at_position", "contact_idx"), &PhysicsDirectBodyState3D::get_contact_collider_velocity_at_position);
  119. ClassDB::bind_method(D_METHOD("get_step"), &PhysicsDirectBodyState3D::get_step);
  120. ClassDB::bind_method(D_METHOD("integrate_forces"), &PhysicsDirectBodyState3D::integrate_forces);
  121. ClassDB::bind_method(D_METHOD("get_space_state"), &PhysicsDirectBodyState3D::get_space_state);
  122. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "step"), "", "get_step");
  123. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inverse_mass"), "", "get_inverse_mass");
  124. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "total_angular_damp"), "", "get_total_angular_damp");
  125. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "total_linear_damp"), "", "get_total_linear_damp");
  126. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "inverse_inertia"), "", "get_inverse_inertia");
  127. ADD_PROPERTY(PropertyInfo(Variant::BASIS, "inverse_inertia_tensor"), "", "get_inverse_inertia_tensor");
  128. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "total_gravity"), "", "get_total_gravity");
  129. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "center_of_mass"), "", "get_center_of_mass");
  130. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "center_of_mass_local"), "", "get_center_of_mass_local");
  131. ADD_PROPERTY(PropertyInfo(Variant::BASIS, "principal_inertia_axes"), "", "get_principal_inertia_axes");
  132. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "angular_velocity"), "set_angular_velocity", "get_angular_velocity");
  133. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "linear_velocity"), "set_linear_velocity", "get_linear_velocity");
  134. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sleeping"), "set_sleep_state", "is_sleeping");
  135. ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "transform"), "set_transform", "get_transform");
  136. }
  137. PhysicsDirectBodyState3D::PhysicsDirectBodyState3D() {}
  138. ///////////////////////////////////////////////////////
  139. void PhysicsRayQueryParameters3D::set_exclude(const TypedArray<RID> &p_exclude) {
  140. parameters.exclude.clear();
  141. for (int i = 0; i < p_exclude.size(); i++) {
  142. parameters.exclude.insert(p_exclude[i]);
  143. }
  144. }
  145. TypedArray<RID> PhysicsRayQueryParameters3D::get_exclude() const {
  146. TypedArray<RID> ret;
  147. ret.resize(parameters.exclude.size());
  148. int idx = 0;
  149. for (const RID &E : parameters.exclude) {
  150. ret[idx++] = E;
  151. }
  152. return ret;
  153. }
  154. void PhysicsRayQueryParameters3D::_bind_methods() {
  155. ClassDB::bind_static_method("PhysicsRayQueryParameters3D", D_METHOD("create", "from", "to", "collision_mask", "exclude"), &PhysicsRayQueryParameters3D::create, DEFVAL(UINT32_MAX), DEFVAL(TypedArray<RID>()));
  156. ClassDB::bind_method(D_METHOD("set_from", "from"), &PhysicsRayQueryParameters3D::set_from);
  157. ClassDB::bind_method(D_METHOD("get_from"), &PhysicsRayQueryParameters3D::get_from);
  158. ClassDB::bind_method(D_METHOD("set_to", "to"), &PhysicsRayQueryParameters3D::set_to);
  159. ClassDB::bind_method(D_METHOD("get_to"), &PhysicsRayQueryParameters3D::get_to);
  160. ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &PhysicsRayQueryParameters3D::set_collision_mask);
  161. ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsRayQueryParameters3D::get_collision_mask);
  162. ClassDB::bind_method(D_METHOD("set_exclude", "exclude"), &PhysicsRayQueryParameters3D::set_exclude);
  163. ClassDB::bind_method(D_METHOD("get_exclude"), &PhysicsRayQueryParameters3D::get_exclude);
  164. ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &PhysicsRayQueryParameters3D::set_collide_with_bodies);
  165. ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &PhysicsRayQueryParameters3D::is_collide_with_bodies_enabled);
  166. ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &PhysicsRayQueryParameters3D::set_collide_with_areas);
  167. ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &PhysicsRayQueryParameters3D::is_collide_with_areas_enabled);
  168. ClassDB::bind_method(D_METHOD("set_hit_from_inside", "enable"), &PhysicsRayQueryParameters3D::set_hit_from_inside);
  169. ClassDB::bind_method(D_METHOD("is_hit_from_inside_enabled"), &PhysicsRayQueryParameters3D::is_hit_from_inside_enabled);
  170. ClassDB::bind_method(D_METHOD("set_hit_back_faces", "enable"), &PhysicsRayQueryParameters3D::set_hit_back_faces);
  171. ClassDB::bind_method(D_METHOD("is_hit_back_faces_enabled"), &PhysicsRayQueryParameters3D::is_hit_back_faces_enabled);
  172. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "from"), "set_from", "get_from");
  173. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "to"), "set_to", "get_to");
  174. ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
  175. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude", "get_exclude");
  176. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled");
  177. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas"), "set_collide_with_areas", "is_collide_with_areas_enabled");
  178. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hit_from_inside"), "set_hit_from_inside", "is_hit_from_inside_enabled");
  179. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hit_back_faces"), "set_hit_back_faces", "is_hit_back_faces_enabled");
  180. }
  181. ///////////////////////////////////////////////////////
  182. Ref<PhysicsRayQueryParameters3D> PhysicsRayQueryParameters3D::create(Vector3 p_from, Vector3 p_to, uint32_t p_mask, const TypedArray<RID> &p_exclude) {
  183. Ref<PhysicsRayQueryParameters3D> params;
  184. params.instantiate();
  185. params->set_from(p_from);
  186. params->set_to(p_to);
  187. params->set_collision_mask(p_mask);
  188. params->set_exclude(p_exclude);
  189. return params;
  190. }
  191. void PhysicsPointQueryParameters3D::set_exclude(const TypedArray<RID> &p_exclude) {
  192. parameters.exclude.clear();
  193. for (int i = 0; i < p_exclude.size(); i++) {
  194. parameters.exclude.insert(p_exclude[i]);
  195. }
  196. }
  197. TypedArray<RID> PhysicsPointQueryParameters3D::get_exclude() const {
  198. TypedArray<RID> ret;
  199. ret.resize(parameters.exclude.size());
  200. int idx = 0;
  201. for (const RID &E : parameters.exclude) {
  202. ret[idx++] = E;
  203. }
  204. return ret;
  205. }
  206. void PhysicsPointQueryParameters3D::_bind_methods() {
  207. ClassDB::bind_method(D_METHOD("set_position", "position"), &PhysicsPointQueryParameters3D::set_position);
  208. ClassDB::bind_method(D_METHOD("get_position"), &PhysicsPointQueryParameters3D::get_position);
  209. ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &PhysicsPointQueryParameters3D::set_collision_mask);
  210. ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsPointQueryParameters3D::get_collision_mask);
  211. ClassDB::bind_method(D_METHOD("set_exclude", "exclude"), &PhysicsPointQueryParameters3D::set_exclude);
  212. ClassDB::bind_method(D_METHOD("get_exclude"), &PhysicsPointQueryParameters3D::get_exclude);
  213. ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &PhysicsPointQueryParameters3D::set_collide_with_bodies);
  214. ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &PhysicsPointQueryParameters3D::is_collide_with_bodies_enabled);
  215. ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &PhysicsPointQueryParameters3D::set_collide_with_areas);
  216. ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &PhysicsPointQueryParameters3D::is_collide_with_areas_enabled);
  217. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position"), "set_position", "get_position");
  218. ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
  219. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude", "get_exclude");
  220. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled");
  221. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas"), "set_collide_with_areas", "is_collide_with_areas_enabled");
  222. }
  223. ///////////////////////////////////////////////////////
  224. void PhysicsShapeQueryParameters3D::set_shape(const Ref<Resource> &p_shape_ref) {
  225. ERR_FAIL_COND(p_shape_ref.is_null());
  226. shape_ref = p_shape_ref;
  227. parameters.shape_rid = p_shape_ref->get_rid();
  228. }
  229. void PhysicsShapeQueryParameters3D::set_shape_rid(const RID &p_shape) {
  230. if (parameters.shape_rid != p_shape) {
  231. shape_ref = Ref<Resource>();
  232. parameters.shape_rid = p_shape;
  233. }
  234. }
  235. void PhysicsShapeQueryParameters3D::set_exclude(const TypedArray<RID> &p_exclude) {
  236. parameters.exclude.clear();
  237. for (int i = 0; i < p_exclude.size(); i++) {
  238. parameters.exclude.insert(p_exclude[i]);
  239. }
  240. }
  241. TypedArray<RID> PhysicsShapeQueryParameters3D::get_exclude() const {
  242. TypedArray<RID> ret;
  243. ret.resize(parameters.exclude.size());
  244. int idx = 0;
  245. for (const RID &E : parameters.exclude) {
  246. ret[idx++] = E;
  247. }
  248. return ret;
  249. }
  250. void PhysicsShapeQueryParameters3D::_bind_methods() {
  251. ClassDB::bind_method(D_METHOD("set_shape", "shape"), &PhysicsShapeQueryParameters3D::set_shape);
  252. ClassDB::bind_method(D_METHOD("get_shape"), &PhysicsShapeQueryParameters3D::get_shape);
  253. ClassDB::bind_method(D_METHOD("set_shape_rid", "shape"), &PhysicsShapeQueryParameters3D::set_shape_rid);
  254. ClassDB::bind_method(D_METHOD("get_shape_rid"), &PhysicsShapeQueryParameters3D::get_shape_rid);
  255. ClassDB::bind_method(D_METHOD("set_transform", "transform"), &PhysicsShapeQueryParameters3D::set_transform);
  256. ClassDB::bind_method(D_METHOD("get_transform"), &PhysicsShapeQueryParameters3D::get_transform);
  257. ClassDB::bind_method(D_METHOD("set_motion", "motion"), &PhysicsShapeQueryParameters3D::set_motion);
  258. ClassDB::bind_method(D_METHOD("get_motion"), &PhysicsShapeQueryParameters3D::get_motion);
  259. ClassDB::bind_method(D_METHOD("set_margin", "margin"), &PhysicsShapeQueryParameters3D::set_margin);
  260. ClassDB::bind_method(D_METHOD("get_margin"), &PhysicsShapeQueryParameters3D::get_margin);
  261. ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &PhysicsShapeQueryParameters3D::set_collision_mask);
  262. ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsShapeQueryParameters3D::get_collision_mask);
  263. ClassDB::bind_method(D_METHOD("set_exclude", "exclude"), &PhysicsShapeQueryParameters3D::set_exclude);
  264. ClassDB::bind_method(D_METHOD("get_exclude"), &PhysicsShapeQueryParameters3D::get_exclude);
  265. ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &PhysicsShapeQueryParameters3D::set_collide_with_bodies);
  266. ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &PhysicsShapeQueryParameters3D::is_collide_with_bodies_enabled);
  267. ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &PhysicsShapeQueryParameters3D::set_collide_with_areas);
  268. ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &PhysicsShapeQueryParameters3D::is_collide_with_areas_enabled);
  269. ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
  270. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude", "get_exclude");
  271. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin", PROPERTY_HINT_RANGE, "0,100,0.01"), "set_margin", "get_margin");
  272. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "motion"), "set_motion", "get_motion");
  273. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape3D"), "set_shape", "get_shape");
  274. ADD_PROPERTY(PropertyInfo(Variant::RID, "shape_rid"), "set_shape_rid", "get_shape_rid");
  275. ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "transform"), "set_transform", "get_transform");
  276. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled");
  277. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas"), "set_collide_with_areas", "is_collide_with_areas_enabled");
  278. }
  279. /////////////////////////////////////
  280. Dictionary PhysicsDirectSpaceState3D::_intersect_ray(const Ref<PhysicsRayQueryParameters3D> &p_ray_query) {
  281. ERR_FAIL_COND_V(!p_ray_query.is_valid(), Dictionary());
  282. RayResult result;
  283. bool res = intersect_ray(p_ray_query->get_parameters(), result);
  284. if (!res) {
  285. return Dictionary();
  286. }
  287. Dictionary d;
  288. d["position"] = result.position;
  289. d["normal"] = result.normal;
  290. d["collider_id"] = result.collider_id;
  291. d["collider"] = result.collider;
  292. d["shape"] = result.shape;
  293. d["rid"] = result.rid;
  294. return d;
  295. }
  296. TypedArray<Dictionary> PhysicsDirectSpaceState3D::_intersect_point(const Ref<PhysicsPointQueryParameters3D> &p_point_query, int p_max_results) {
  297. ERR_FAIL_COND_V(p_point_query.is_null(), TypedArray<Dictionary>());
  298. Vector<ShapeResult> ret;
  299. ret.resize(p_max_results);
  300. int rc = intersect_point(p_point_query->get_parameters(), ret.ptrw(), ret.size());
  301. if (rc == 0) {
  302. return TypedArray<Dictionary>();
  303. }
  304. TypedArray<Dictionary> r;
  305. r.resize(rc);
  306. for (int i = 0; i < rc; i++) {
  307. Dictionary d;
  308. d["rid"] = ret[i].rid;
  309. d["collider_id"] = ret[i].collider_id;
  310. d["collider"] = ret[i].collider;
  311. d["shape"] = ret[i].shape;
  312. r[i] = d;
  313. }
  314. return r;
  315. }
  316. TypedArray<Dictionary> PhysicsDirectSpaceState3D::_intersect_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results) {
  317. ERR_FAIL_COND_V(!p_shape_query.is_valid(), TypedArray<Dictionary>());
  318. Vector<ShapeResult> sr;
  319. sr.resize(p_max_results);
  320. int rc = intersect_shape(p_shape_query->get_parameters(), sr.ptrw(), sr.size());
  321. TypedArray<Dictionary> ret;
  322. ret.resize(rc);
  323. for (int i = 0; i < rc; i++) {
  324. Dictionary d;
  325. d["rid"] = sr[i].rid;
  326. d["collider_id"] = sr[i].collider_id;
  327. d["collider"] = sr[i].collider;
  328. d["shape"] = sr[i].shape;
  329. ret[i] = d;
  330. }
  331. return ret;
  332. }
  333. Vector<real_t> PhysicsDirectSpaceState3D::_cast_motion(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query) {
  334. ERR_FAIL_COND_V(!p_shape_query.is_valid(), Vector<real_t>());
  335. real_t closest_safe = 1.0f, closest_unsafe = 1.0f;
  336. bool res = cast_motion(p_shape_query->get_parameters(), closest_safe, closest_unsafe);
  337. if (!res) {
  338. return Vector<real_t>();
  339. }
  340. Vector<real_t> ret;
  341. ret.resize(2);
  342. ret.write[0] = closest_safe;
  343. ret.write[1] = closest_unsafe;
  344. return ret;
  345. }
  346. TypedArray<Vector3> PhysicsDirectSpaceState3D::_collide_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results) {
  347. ERR_FAIL_COND_V(!p_shape_query.is_valid(), TypedArray<Vector3>());
  348. Vector<Vector3> ret;
  349. ret.resize(p_max_results * 2);
  350. int rc = 0;
  351. bool res = collide_shape(p_shape_query->get_parameters(), ret.ptrw(), p_max_results, rc);
  352. if (!res) {
  353. return TypedArray<Vector3>();
  354. }
  355. TypedArray<Vector3> r;
  356. r.resize(rc * 2);
  357. for (int i = 0; i < rc * 2; i++) {
  358. r[i] = ret[i];
  359. }
  360. return r;
  361. }
  362. Dictionary PhysicsDirectSpaceState3D::_get_rest_info(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query) {
  363. ERR_FAIL_COND_V(!p_shape_query.is_valid(), Dictionary());
  364. ShapeRestInfo sri;
  365. bool res = rest_info(p_shape_query->get_parameters(), &sri);
  366. Dictionary r;
  367. if (!res) {
  368. return r;
  369. }
  370. r["point"] = sri.point;
  371. r["normal"] = sri.normal;
  372. r["rid"] = sri.rid;
  373. r["collider_id"] = sri.collider_id;
  374. r["shape"] = sri.shape;
  375. r["linear_velocity"] = sri.linear_velocity;
  376. return r;
  377. }
  378. PhysicsDirectSpaceState3D::PhysicsDirectSpaceState3D() {
  379. }
  380. void PhysicsDirectSpaceState3D::_bind_methods() {
  381. ClassDB::bind_method(D_METHOD("intersect_point", "parameters", "max_results"), &PhysicsDirectSpaceState3D::_intersect_point, DEFVAL(32));
  382. ClassDB::bind_method(D_METHOD("intersect_ray", "parameters"), &PhysicsDirectSpaceState3D::_intersect_ray);
  383. ClassDB::bind_method(D_METHOD("intersect_shape", "parameters", "max_results"), &PhysicsDirectSpaceState3D::_intersect_shape, DEFVAL(32));
  384. ClassDB::bind_method(D_METHOD("cast_motion", "parameters"), &PhysicsDirectSpaceState3D::_cast_motion);
  385. ClassDB::bind_method(D_METHOD("collide_shape", "parameters", "max_results"), &PhysicsDirectSpaceState3D::_collide_shape, DEFVAL(32));
  386. ClassDB::bind_method(D_METHOD("get_rest_info", "parameters"), &PhysicsDirectSpaceState3D::_get_rest_info);
  387. }
  388. ///////////////////////////////
  389. TypedArray<RID> PhysicsTestMotionParameters3D::get_exclude_bodies() const {
  390. TypedArray<RID> exclude;
  391. exclude.resize(parameters.exclude_bodies.size());
  392. int body_index = 0;
  393. for (const RID &body : parameters.exclude_bodies) {
  394. exclude[body_index++] = body;
  395. }
  396. return exclude;
  397. }
  398. void PhysicsTestMotionParameters3D::set_exclude_bodies(const TypedArray<RID> &p_exclude) {
  399. parameters.exclude_bodies.clear();
  400. for (int i = 0; i < p_exclude.size(); i++) {
  401. parameters.exclude_bodies.insert(p_exclude[i]);
  402. }
  403. }
  404. TypedArray<uint64_t> PhysicsTestMotionParameters3D::get_exclude_objects() const {
  405. TypedArray<uint64_t> exclude;
  406. exclude.resize(parameters.exclude_objects.size());
  407. int object_index = 0;
  408. for (const ObjectID &object_id : parameters.exclude_objects) {
  409. exclude[object_index++] = object_id;
  410. }
  411. return exclude;
  412. }
  413. void PhysicsTestMotionParameters3D::set_exclude_objects(const TypedArray<uint64_t> &p_exclude) {
  414. parameters.exclude_objects.clear();
  415. for (int i = 0; i < p_exclude.size(); ++i) {
  416. ObjectID object_id = p_exclude[i];
  417. ERR_CONTINUE(object_id.is_null());
  418. parameters.exclude_objects.insert(object_id);
  419. }
  420. }
  421. void PhysicsTestMotionParameters3D::_bind_methods() {
  422. ClassDB::bind_method(D_METHOD("get_from"), &PhysicsTestMotionParameters3D::get_from);
  423. ClassDB::bind_method(D_METHOD("set_from", "from"), &PhysicsTestMotionParameters3D::set_from);
  424. ClassDB::bind_method(D_METHOD("get_motion"), &PhysicsTestMotionParameters3D::get_motion);
  425. ClassDB::bind_method(D_METHOD("set_motion", "motion"), &PhysicsTestMotionParameters3D::set_motion);
  426. ClassDB::bind_method(D_METHOD("get_margin"), &PhysicsTestMotionParameters3D::get_margin);
  427. ClassDB::bind_method(D_METHOD("set_margin", "margin"), &PhysicsTestMotionParameters3D::set_margin);
  428. ClassDB::bind_method(D_METHOD("get_max_collisions"), &PhysicsTestMotionParameters3D::get_max_collisions);
  429. ClassDB::bind_method(D_METHOD("set_max_collisions", "max_collisions"), &PhysicsTestMotionParameters3D::set_max_collisions);
  430. ClassDB::bind_method(D_METHOD("is_collide_separation_ray_enabled"), &PhysicsTestMotionParameters3D::is_collide_separation_ray_enabled);
  431. ClassDB::bind_method(D_METHOD("set_collide_separation_ray_enabled", "enabled"), &PhysicsTestMotionParameters3D::set_collide_separation_ray_enabled);
  432. ClassDB::bind_method(D_METHOD("get_exclude_bodies"), &PhysicsTestMotionParameters3D::get_exclude_bodies);
  433. ClassDB::bind_method(D_METHOD("set_exclude_bodies", "exclude_list"), &PhysicsTestMotionParameters3D::set_exclude_bodies);
  434. ClassDB::bind_method(D_METHOD("get_exclude_objects"), &PhysicsTestMotionParameters3D::get_exclude_objects);
  435. ClassDB::bind_method(D_METHOD("set_exclude_objects", "exclude_list"), &PhysicsTestMotionParameters3D::set_exclude_objects);
  436. ClassDB::bind_method(D_METHOD("is_recovery_as_collision_enabled"), &PhysicsTestMotionParameters3D::is_recovery_as_collision_enabled);
  437. ClassDB::bind_method(D_METHOD("set_recovery_as_collision_enabled", "enabled"), &PhysicsTestMotionParameters3D::set_recovery_as_collision_enabled);
  438. ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "from"), "set_from", "get_from");
  439. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "motion"), "set_motion", "get_motion");
  440. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin"), "set_margin", "get_margin");
  441. ADD_PROPERTY(PropertyInfo(Variant::INT, "max_collisions"), "set_max_collisions", "get_max_collisions");
  442. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_separation_ray"), "set_collide_separation_ray_enabled", "is_collide_separation_ray_enabled");
  443. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude_bodies", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude_bodies", "get_exclude_bodies");
  444. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude_objects"), "set_exclude_objects", "get_exclude_objects");
  445. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "recovery_as_collision"), "set_recovery_as_collision_enabled", "is_recovery_as_collision_enabled");
  446. }
  447. ///////////////////////////////
  448. Vector3 PhysicsTestMotionResult3D::get_travel() const {
  449. return result.travel;
  450. }
  451. Vector3 PhysicsTestMotionResult3D::get_remainder() const {
  452. return result.remainder;
  453. }
  454. real_t PhysicsTestMotionResult3D::get_collision_safe_fraction() const {
  455. return result.collision_safe_fraction;
  456. }
  457. real_t PhysicsTestMotionResult3D::get_collision_unsafe_fraction() const {
  458. return result.collision_unsafe_fraction;
  459. }
  460. int PhysicsTestMotionResult3D::get_collision_count() const {
  461. return result.collision_count;
  462. }
  463. Vector3 PhysicsTestMotionResult3D::get_collision_point(int p_collision_index) const {
  464. ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, Vector3());
  465. return result.collisions[p_collision_index].position;
  466. }
  467. Vector3 PhysicsTestMotionResult3D::get_collision_normal(int p_collision_index) const {
  468. ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, Vector3());
  469. return result.collisions[p_collision_index].normal;
  470. }
  471. Vector3 PhysicsTestMotionResult3D::get_collider_velocity(int p_collision_index) const {
  472. ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, Vector3());
  473. return result.collisions[p_collision_index].collider_velocity;
  474. }
  475. ObjectID PhysicsTestMotionResult3D::get_collider_id(int p_collision_index) const {
  476. ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, ObjectID());
  477. return result.collisions[p_collision_index].collider_id;
  478. }
  479. RID PhysicsTestMotionResult3D::get_collider_rid(int p_collision_index) const {
  480. ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, RID());
  481. return result.collisions[p_collision_index].collider;
  482. }
  483. Object *PhysicsTestMotionResult3D::get_collider(int p_collision_index) const {
  484. ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, nullptr);
  485. return ObjectDB::get_instance(result.collisions[p_collision_index].collider_id);
  486. }
  487. int PhysicsTestMotionResult3D::get_collider_shape(int p_collision_index) const {
  488. ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, 0);
  489. return result.collisions[p_collision_index].collider_shape;
  490. }
  491. int PhysicsTestMotionResult3D::get_collision_local_shape(int p_collision_index) const {
  492. ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, 0);
  493. return result.collisions[p_collision_index].local_shape;
  494. }
  495. real_t PhysicsTestMotionResult3D::get_collision_depth(int p_collision_index) const {
  496. ERR_FAIL_INDEX_V(p_collision_index, result.collision_count, 0.0);
  497. return result.collisions[p_collision_index].depth;
  498. }
  499. void PhysicsTestMotionResult3D::_bind_methods() {
  500. ClassDB::bind_method(D_METHOD("get_travel"), &PhysicsTestMotionResult3D::get_travel);
  501. ClassDB::bind_method(D_METHOD("get_remainder"), &PhysicsTestMotionResult3D::get_remainder);
  502. ClassDB::bind_method(D_METHOD("get_collision_safe_fraction"), &PhysicsTestMotionResult3D::get_collision_safe_fraction);
  503. ClassDB::bind_method(D_METHOD("get_collision_unsafe_fraction"), &PhysicsTestMotionResult3D::get_collision_unsafe_fraction);
  504. ClassDB::bind_method(D_METHOD("get_collision_count"), &PhysicsTestMotionResult3D::get_collision_count);
  505. ClassDB::bind_method(D_METHOD("get_collision_point", "collision_index"), &PhysicsTestMotionResult3D::get_collision_point, DEFVAL(0));
  506. ClassDB::bind_method(D_METHOD("get_collision_normal", "collision_index"), &PhysicsTestMotionResult3D::get_collision_normal, DEFVAL(0));
  507. ClassDB::bind_method(D_METHOD("get_collider_velocity", "collision_index"), &PhysicsTestMotionResult3D::get_collider_velocity, DEFVAL(0));
  508. ClassDB::bind_method(D_METHOD("get_collider_id", "collision_index"), &PhysicsTestMotionResult3D::get_collider_id, DEFVAL(0));
  509. ClassDB::bind_method(D_METHOD("get_collider_rid", "collision_index"), &PhysicsTestMotionResult3D::get_collider_rid, DEFVAL(0));
  510. ClassDB::bind_method(D_METHOD("get_collider", "collision_index"), &PhysicsTestMotionResult3D::get_collider, DEFVAL(0));
  511. ClassDB::bind_method(D_METHOD("get_collider_shape", "collision_index"), &PhysicsTestMotionResult3D::get_collider_shape, DEFVAL(0));
  512. ClassDB::bind_method(D_METHOD("get_collision_local_shape", "collision_index"), &PhysicsTestMotionResult3D::get_collision_local_shape, DEFVAL(0));
  513. ClassDB::bind_method(D_METHOD("get_collision_depth", "collision_index"), &PhysicsTestMotionResult3D::get_collision_depth, DEFVAL(0));
  514. }
  515. ///////////////////////////////////////
  516. bool PhysicsServer3D::_body_test_motion(RID p_body, const Ref<PhysicsTestMotionParameters3D> &p_parameters, const Ref<PhysicsTestMotionResult3D> &p_result) {
  517. ERR_FAIL_COND_V(!p_parameters.is_valid(), false);
  518. MotionResult *result_ptr = nullptr;
  519. if (p_result.is_valid()) {
  520. result_ptr = p_result->get_result_ptr();
  521. }
  522. return body_test_motion(p_body, p_parameters->get_parameters(), result_ptr);
  523. }
  524. RID PhysicsServer3D::shape_create(ShapeType p_shape) {
  525. switch (p_shape) {
  526. case SHAPE_WORLD_BOUNDARY:
  527. return world_boundary_shape_create();
  528. case SHAPE_SEPARATION_RAY:
  529. return separation_ray_shape_create();
  530. case SHAPE_SPHERE:
  531. return sphere_shape_create();
  532. case SHAPE_BOX:
  533. return box_shape_create();
  534. case SHAPE_CAPSULE:
  535. return capsule_shape_create();
  536. case SHAPE_CYLINDER:
  537. return cylinder_shape_create();
  538. case SHAPE_CONVEX_POLYGON:
  539. return convex_polygon_shape_create();
  540. case SHAPE_CONCAVE_POLYGON:
  541. return concave_polygon_shape_create();
  542. case SHAPE_HEIGHTMAP:
  543. return heightmap_shape_create();
  544. case SHAPE_CUSTOM:
  545. return custom_shape_create();
  546. default:
  547. return RID();
  548. }
  549. }
  550. void PhysicsServer3D::_bind_methods() {
  551. #ifndef _3D_DISABLED
  552. ClassDB::bind_method(D_METHOD("world_boundary_shape_create"), &PhysicsServer3D::world_boundary_shape_create);
  553. ClassDB::bind_method(D_METHOD("separation_ray_shape_create"), &PhysicsServer3D::separation_ray_shape_create);
  554. ClassDB::bind_method(D_METHOD("sphere_shape_create"), &PhysicsServer3D::sphere_shape_create);
  555. ClassDB::bind_method(D_METHOD("box_shape_create"), &PhysicsServer3D::box_shape_create);
  556. ClassDB::bind_method(D_METHOD("capsule_shape_create"), &PhysicsServer3D::capsule_shape_create);
  557. ClassDB::bind_method(D_METHOD("cylinder_shape_create"), &PhysicsServer3D::cylinder_shape_create);
  558. ClassDB::bind_method(D_METHOD("convex_polygon_shape_create"), &PhysicsServer3D::convex_polygon_shape_create);
  559. ClassDB::bind_method(D_METHOD("concave_polygon_shape_create"), &PhysicsServer3D::concave_polygon_shape_create);
  560. ClassDB::bind_method(D_METHOD("heightmap_shape_create"), &PhysicsServer3D::heightmap_shape_create);
  561. ClassDB::bind_method(D_METHOD("custom_shape_create"), &PhysicsServer3D::custom_shape_create);
  562. ClassDB::bind_method(D_METHOD("shape_set_data", "shape", "data"), &PhysicsServer3D::shape_set_data);
  563. ClassDB::bind_method(D_METHOD("shape_get_type", "shape"), &PhysicsServer3D::shape_get_type);
  564. ClassDB::bind_method(D_METHOD("shape_get_data", "shape"), &PhysicsServer3D::shape_get_data);
  565. ClassDB::bind_method(D_METHOD("space_create"), &PhysicsServer3D::space_create);
  566. ClassDB::bind_method(D_METHOD("space_set_active", "space", "active"), &PhysicsServer3D::space_set_active);
  567. ClassDB::bind_method(D_METHOD("space_is_active", "space"), &PhysicsServer3D::space_is_active);
  568. ClassDB::bind_method(D_METHOD("space_set_param", "space", "param", "value"), &PhysicsServer3D::space_set_param);
  569. ClassDB::bind_method(D_METHOD("space_get_param", "space", "param"), &PhysicsServer3D::space_get_param);
  570. ClassDB::bind_method(D_METHOD("space_get_direct_state", "space"), &PhysicsServer3D::space_get_direct_state);
  571. ClassDB::bind_method(D_METHOD("area_create"), &PhysicsServer3D::area_create);
  572. ClassDB::bind_method(D_METHOD("area_set_space", "area", "space"), &PhysicsServer3D::area_set_space);
  573. ClassDB::bind_method(D_METHOD("area_get_space", "area"), &PhysicsServer3D::area_get_space);
  574. ClassDB::bind_method(D_METHOD("area_add_shape", "area", "shape", "transform", "disabled"), &PhysicsServer3D::area_add_shape, DEFVAL(Transform3D()), DEFVAL(false));
  575. ClassDB::bind_method(D_METHOD("area_set_shape", "area", "shape_idx", "shape"), &PhysicsServer3D::area_set_shape);
  576. ClassDB::bind_method(D_METHOD("area_set_shape_transform", "area", "shape_idx", "transform"), &PhysicsServer3D::area_set_shape_transform);
  577. ClassDB::bind_method(D_METHOD("area_set_shape_disabled", "area", "shape_idx", "disabled"), &PhysicsServer3D::area_set_shape_disabled);
  578. ClassDB::bind_method(D_METHOD("area_get_shape_count", "area"), &PhysicsServer3D::area_get_shape_count);
  579. ClassDB::bind_method(D_METHOD("area_get_shape", "area", "shape_idx"), &PhysicsServer3D::area_get_shape);
  580. ClassDB::bind_method(D_METHOD("area_get_shape_transform", "area", "shape_idx"), &PhysicsServer3D::area_get_shape_transform);
  581. ClassDB::bind_method(D_METHOD("area_remove_shape", "area", "shape_idx"), &PhysicsServer3D::area_remove_shape);
  582. ClassDB::bind_method(D_METHOD("area_clear_shapes", "area"), &PhysicsServer3D::area_clear_shapes);
  583. ClassDB::bind_method(D_METHOD("area_set_collision_layer", "area", "layer"), &PhysicsServer3D::area_set_collision_layer);
  584. ClassDB::bind_method(D_METHOD("area_get_collision_layer", "area"), &PhysicsServer3D::area_get_collision_layer);
  585. ClassDB::bind_method(D_METHOD("area_set_collision_mask", "area", "mask"), &PhysicsServer3D::area_set_collision_mask);
  586. ClassDB::bind_method(D_METHOD("area_get_collision_mask", "area"), &PhysicsServer3D::area_get_collision_mask);
  587. ClassDB::bind_method(D_METHOD("area_set_param", "area", "param", "value"), &PhysicsServer3D::area_set_param);
  588. ClassDB::bind_method(D_METHOD("area_set_transform", "area", "transform"), &PhysicsServer3D::area_set_transform);
  589. ClassDB::bind_method(D_METHOD("area_get_param", "area", "param"), &PhysicsServer3D::area_get_param);
  590. ClassDB::bind_method(D_METHOD("area_get_transform", "area"), &PhysicsServer3D::area_get_transform);
  591. ClassDB::bind_method(D_METHOD("area_attach_object_instance_id", "area", "id"), &PhysicsServer3D::area_attach_object_instance_id);
  592. ClassDB::bind_method(D_METHOD("area_get_object_instance_id", "area"), &PhysicsServer3D::area_get_object_instance_id);
  593. ClassDB::bind_method(D_METHOD("area_set_monitor_callback", "area", "callback"), &PhysicsServer3D::area_set_monitor_callback);
  594. ClassDB::bind_method(D_METHOD("area_set_area_monitor_callback", "area", "callback"), &PhysicsServer3D::area_set_area_monitor_callback);
  595. ClassDB::bind_method(D_METHOD("area_set_monitorable", "area", "monitorable"), &PhysicsServer3D::area_set_monitorable);
  596. ClassDB::bind_method(D_METHOD("area_set_ray_pickable", "area", "enable"), &PhysicsServer3D::area_set_ray_pickable);
  597. ClassDB::bind_method(D_METHOD("body_create"), &PhysicsServer3D::body_create);
  598. ClassDB::bind_method(D_METHOD("body_set_space", "body", "space"), &PhysicsServer3D::body_set_space);
  599. ClassDB::bind_method(D_METHOD("body_get_space", "body"), &PhysicsServer3D::body_get_space);
  600. ClassDB::bind_method(D_METHOD("body_set_mode", "body", "mode"), &PhysicsServer3D::body_set_mode);
  601. ClassDB::bind_method(D_METHOD("body_get_mode", "body"), &PhysicsServer3D::body_get_mode);
  602. ClassDB::bind_method(D_METHOD("body_set_collision_layer", "body", "layer"), &PhysicsServer3D::body_set_collision_layer);
  603. ClassDB::bind_method(D_METHOD("body_get_collision_layer", "body"), &PhysicsServer3D::body_get_collision_layer);
  604. ClassDB::bind_method(D_METHOD("body_set_collision_mask", "body", "mask"), &PhysicsServer3D::body_set_collision_mask);
  605. ClassDB::bind_method(D_METHOD("body_get_collision_mask", "body"), &PhysicsServer3D::body_get_collision_mask);
  606. ClassDB::bind_method(D_METHOD("body_set_collision_priority", "body", "priority"), &PhysicsServer3D::body_set_collision_priority);
  607. ClassDB::bind_method(D_METHOD("body_get_collision_priority", "body"), &PhysicsServer3D::body_get_collision_priority);
  608. ClassDB::bind_method(D_METHOD("body_add_shape", "body", "shape", "transform", "disabled"), &PhysicsServer3D::body_add_shape, DEFVAL(Transform3D()), DEFVAL(false));
  609. ClassDB::bind_method(D_METHOD("body_set_shape", "body", "shape_idx", "shape"), &PhysicsServer3D::body_set_shape);
  610. ClassDB::bind_method(D_METHOD("body_set_shape_transform", "body", "shape_idx", "transform"), &PhysicsServer3D::body_set_shape_transform);
  611. ClassDB::bind_method(D_METHOD("body_set_shape_disabled", "body", "shape_idx", "disabled"), &PhysicsServer3D::body_set_shape_disabled);
  612. ClassDB::bind_method(D_METHOD("body_get_shape_count", "body"), &PhysicsServer3D::body_get_shape_count);
  613. ClassDB::bind_method(D_METHOD("body_get_shape", "body", "shape_idx"), &PhysicsServer3D::body_get_shape);
  614. ClassDB::bind_method(D_METHOD("body_get_shape_transform", "body", "shape_idx"), &PhysicsServer3D::body_get_shape_transform);
  615. ClassDB::bind_method(D_METHOD("body_remove_shape", "body", "shape_idx"), &PhysicsServer3D::body_remove_shape);
  616. ClassDB::bind_method(D_METHOD("body_clear_shapes", "body"), &PhysicsServer3D::body_clear_shapes);
  617. ClassDB::bind_method(D_METHOD("body_attach_object_instance_id", "body", "id"), &PhysicsServer3D::body_attach_object_instance_id);
  618. ClassDB::bind_method(D_METHOD("body_get_object_instance_id", "body"), &PhysicsServer3D::body_get_object_instance_id);
  619. ClassDB::bind_method(D_METHOD("body_set_enable_continuous_collision_detection", "body", "enable"), &PhysicsServer3D::body_set_enable_continuous_collision_detection);
  620. ClassDB::bind_method(D_METHOD("body_is_continuous_collision_detection_enabled", "body"), &PhysicsServer3D::body_is_continuous_collision_detection_enabled);
  621. ClassDB::bind_method(D_METHOD("body_set_param", "body", "param", "value"), &PhysicsServer3D::body_set_param);
  622. ClassDB::bind_method(D_METHOD("body_get_param", "body", "param"), &PhysicsServer3D::body_get_param);
  623. ClassDB::bind_method(D_METHOD("body_reset_mass_properties", "body"), &PhysicsServer3D::body_reset_mass_properties);
  624. ClassDB::bind_method(D_METHOD("body_set_state", "body", "state", "value"), &PhysicsServer3D::body_set_state);
  625. ClassDB::bind_method(D_METHOD("body_get_state", "body", "state"), &PhysicsServer3D::body_get_state);
  626. ClassDB::bind_method(D_METHOD("body_apply_central_impulse", "body", "impulse"), &PhysicsServer3D::body_apply_central_impulse);
  627. ClassDB::bind_method(D_METHOD("body_apply_impulse", "body", "impulse", "position"), &PhysicsServer3D::body_apply_impulse, Vector3());
  628. ClassDB::bind_method(D_METHOD("body_apply_torque_impulse", "body", "impulse"), &PhysicsServer3D::body_apply_torque_impulse);
  629. ClassDB::bind_method(D_METHOD("body_apply_central_force", "body", "force"), &PhysicsServer3D::body_apply_central_force);
  630. ClassDB::bind_method(D_METHOD("body_apply_force", "body", "force", "position"), &PhysicsServer3D::body_apply_force, Vector3());
  631. ClassDB::bind_method(D_METHOD("body_apply_torque", "body", "torque"), &PhysicsServer3D::body_apply_torque);
  632. ClassDB::bind_method(D_METHOD("body_add_constant_central_force", "body", "force"), &PhysicsServer3D::body_add_constant_central_force);
  633. ClassDB::bind_method(D_METHOD("body_add_constant_force", "body", "force", "position"), &PhysicsServer3D::body_add_constant_force, Vector3());
  634. ClassDB::bind_method(D_METHOD("body_add_constant_torque", "body", "torque"), &PhysicsServer3D::body_add_constant_torque);
  635. ClassDB::bind_method(D_METHOD("body_set_constant_force", "body", "force"), &PhysicsServer3D::body_set_constant_force);
  636. ClassDB::bind_method(D_METHOD("body_get_constant_force", "body"), &PhysicsServer3D::body_get_constant_force);
  637. ClassDB::bind_method(D_METHOD("body_set_constant_torque", "body", "torque"), &PhysicsServer3D::body_set_constant_torque);
  638. ClassDB::bind_method(D_METHOD("body_get_constant_torque", "body"), &PhysicsServer3D::body_get_constant_torque);
  639. ClassDB::bind_method(D_METHOD("body_set_axis_velocity", "body", "axis_velocity"), &PhysicsServer3D::body_set_axis_velocity);
  640. ClassDB::bind_method(D_METHOD("body_set_axis_lock", "body", "axis", "lock"), &PhysicsServer3D::body_set_axis_lock);
  641. ClassDB::bind_method(D_METHOD("body_is_axis_locked", "body", "axis"), &PhysicsServer3D::body_is_axis_locked);
  642. ClassDB::bind_method(D_METHOD("body_add_collision_exception", "body", "excepted_body"), &PhysicsServer3D::body_add_collision_exception);
  643. ClassDB::bind_method(D_METHOD("body_remove_collision_exception", "body", "excepted_body"), &PhysicsServer3D::body_remove_collision_exception);
  644. ClassDB::bind_method(D_METHOD("body_set_max_contacts_reported", "body", "amount"), &PhysicsServer3D::body_set_max_contacts_reported);
  645. ClassDB::bind_method(D_METHOD("body_get_max_contacts_reported", "body"), &PhysicsServer3D::body_get_max_contacts_reported);
  646. ClassDB::bind_method(D_METHOD("body_set_omit_force_integration", "body", "enable"), &PhysicsServer3D::body_set_omit_force_integration);
  647. ClassDB::bind_method(D_METHOD("body_is_omitting_force_integration", "body"), &PhysicsServer3D::body_is_omitting_force_integration);
  648. ClassDB::bind_method(D_METHOD("body_set_force_integration_callback", "body", "callable", "userdata"), &PhysicsServer3D::body_set_force_integration_callback, DEFVAL(Variant()));
  649. ClassDB::bind_method(D_METHOD("body_set_ray_pickable", "body", "enable"), &PhysicsServer3D::body_set_ray_pickable);
  650. ClassDB::bind_method(D_METHOD("body_test_motion", "body", "parameters", "result"), &PhysicsServer3D::_body_test_motion, DEFVAL(Variant()));
  651. ClassDB::bind_method(D_METHOD("body_get_direct_state", "body"), &PhysicsServer3D::body_get_direct_state);
  652. /* SOFT BODY API */
  653. ClassDB::bind_method(D_METHOD("soft_body_get_bounds", "body"), &PhysicsServer3D::soft_body_get_bounds);
  654. /* JOINT API */
  655. ClassDB::bind_method(D_METHOD("joint_create"), &PhysicsServer3D::joint_create);
  656. ClassDB::bind_method(D_METHOD("joint_clear", "joint"), &PhysicsServer3D::joint_clear);
  657. BIND_ENUM_CONSTANT(JOINT_TYPE_PIN);
  658. BIND_ENUM_CONSTANT(JOINT_TYPE_HINGE);
  659. BIND_ENUM_CONSTANT(JOINT_TYPE_SLIDER);
  660. BIND_ENUM_CONSTANT(JOINT_TYPE_CONE_TWIST);
  661. BIND_ENUM_CONSTANT(JOINT_TYPE_6DOF);
  662. BIND_ENUM_CONSTANT(JOINT_TYPE_MAX);
  663. ClassDB::bind_method(D_METHOD("joint_make_pin", "joint", "body_A", "local_A", "body_B", "local_B"), &PhysicsServer3D::joint_make_pin);
  664. ClassDB::bind_method(D_METHOD("pin_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::pin_joint_set_param);
  665. ClassDB::bind_method(D_METHOD("pin_joint_get_param", "joint", "param"), &PhysicsServer3D::pin_joint_get_param);
  666. ClassDB::bind_method(D_METHOD("pin_joint_set_local_a", "joint", "local_A"), &PhysicsServer3D::pin_joint_set_local_a);
  667. ClassDB::bind_method(D_METHOD("pin_joint_get_local_a", "joint"), &PhysicsServer3D::pin_joint_get_local_a);
  668. ClassDB::bind_method(D_METHOD("pin_joint_set_local_b", "joint", "local_B"), &PhysicsServer3D::pin_joint_set_local_b);
  669. ClassDB::bind_method(D_METHOD("pin_joint_get_local_b", "joint"), &PhysicsServer3D::pin_joint_get_local_b);
  670. BIND_ENUM_CONSTANT(PIN_JOINT_BIAS);
  671. BIND_ENUM_CONSTANT(PIN_JOINT_DAMPING);
  672. BIND_ENUM_CONSTANT(PIN_JOINT_IMPULSE_CLAMP);
  673. BIND_ENUM_CONSTANT(HINGE_JOINT_BIAS);
  674. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_UPPER);
  675. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_LOWER);
  676. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_BIAS);
  677. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_SOFTNESS);
  678. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_RELAXATION);
  679. BIND_ENUM_CONSTANT(HINGE_JOINT_MOTOR_TARGET_VELOCITY);
  680. BIND_ENUM_CONSTANT(HINGE_JOINT_MOTOR_MAX_IMPULSE);
  681. BIND_ENUM_CONSTANT(HINGE_JOINT_FLAG_USE_LIMIT);
  682. BIND_ENUM_CONSTANT(HINGE_JOINT_FLAG_ENABLE_MOTOR);
  683. ClassDB::bind_method(D_METHOD("joint_make_hinge", "joint", "body_A", "hinge_A", "body_B", "hinge_B"), &PhysicsServer3D::joint_make_hinge);
  684. ClassDB::bind_method(D_METHOD("hinge_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::hinge_joint_set_param);
  685. ClassDB::bind_method(D_METHOD("hinge_joint_get_param", "joint", "param"), &PhysicsServer3D::hinge_joint_get_param);
  686. ClassDB::bind_method(D_METHOD("hinge_joint_set_flag", "joint", "flag", "enabled"), &PhysicsServer3D::hinge_joint_set_flag);
  687. ClassDB::bind_method(D_METHOD("hinge_joint_get_flag", "joint", "flag"), &PhysicsServer3D::hinge_joint_get_flag);
  688. ClassDB::bind_method(D_METHOD("joint_make_slider", "joint", "body_A", "local_ref_A", "body_B", "local_ref_B"), &PhysicsServer3D::joint_make_slider);
  689. ClassDB::bind_method(D_METHOD("slider_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::slider_joint_set_param);
  690. ClassDB::bind_method(D_METHOD("slider_joint_get_param", "joint", "param"), &PhysicsServer3D::slider_joint_get_param);
  691. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_UPPER);
  692. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_LOWER);
  693. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS);
  694. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION);
  695. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_DAMPING);
  696. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_SOFTNESS);
  697. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_RESTITUTION);
  698. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_DAMPING);
  699. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS);
  700. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION);
  701. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING);
  702. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_UPPER);
  703. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_LOWER);
  704. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS);
  705. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION);
  706. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_DAMPING);
  707. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS);
  708. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION);
  709. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_DAMPING);
  710. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS);
  711. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION);
  712. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING);
  713. BIND_ENUM_CONSTANT(SLIDER_JOINT_MAX);
  714. ClassDB::bind_method(D_METHOD("joint_make_cone_twist", "joint", "body_A", "local_ref_A", "body_B", "local_ref_B"), &PhysicsServer3D::joint_make_cone_twist);
  715. ClassDB::bind_method(D_METHOD("cone_twist_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::cone_twist_joint_set_param);
  716. ClassDB::bind_method(D_METHOD("cone_twist_joint_get_param", "joint", "param"), &PhysicsServer3D::cone_twist_joint_get_param);
  717. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_SWING_SPAN);
  718. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_TWIST_SPAN);
  719. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_BIAS);
  720. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_SOFTNESS);
  721. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_RELAXATION);
  722. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_LOWER_LIMIT);
  723. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_UPPER_LIMIT);
  724. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS);
  725. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_RESTITUTION);
  726. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_DAMPING);
  727. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY);
  728. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT);
  729. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_LOWER_LIMIT);
  730. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_UPPER_LIMIT);
  731. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS);
  732. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_DAMPING);
  733. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_RESTITUTION);
  734. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_FORCE_LIMIT);
  735. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_ERP);
  736. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY);
  737. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT);
  738. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT);
  739. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT);
  740. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_MOTOR);
  741. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR);
  742. ClassDB::bind_method(D_METHOD("joint_get_type", "joint"), &PhysicsServer3D::joint_get_type);
  743. ClassDB::bind_method(D_METHOD("joint_set_solver_priority", "joint", "priority"), &PhysicsServer3D::joint_set_solver_priority);
  744. ClassDB::bind_method(D_METHOD("joint_get_solver_priority", "joint"), &PhysicsServer3D::joint_get_solver_priority);
  745. ClassDB::bind_method(D_METHOD("joint_disable_collisions_between_bodies", "joint", "disable"), &PhysicsServer3D::joint_disable_collisions_between_bodies);
  746. ClassDB::bind_method(D_METHOD("joint_is_disabled_collisions_between_bodies", "joint"), &PhysicsServer3D::joint_is_disabled_collisions_between_bodies);
  747. ClassDB::bind_method(D_METHOD("joint_make_generic_6dof", "joint", "body_A", "local_ref_A", "body_B", "local_ref_B"), &PhysicsServer3D::joint_make_generic_6dof);
  748. ClassDB::bind_method(D_METHOD("generic_6dof_joint_set_param", "joint", "axis", "param", "value"), &PhysicsServer3D::generic_6dof_joint_set_param);
  749. ClassDB::bind_method(D_METHOD("generic_6dof_joint_get_param", "joint", "axis", "param"), &PhysicsServer3D::generic_6dof_joint_get_param);
  750. ClassDB::bind_method(D_METHOD("generic_6dof_joint_set_flag", "joint", "axis", "flag", "enable"), &PhysicsServer3D::generic_6dof_joint_set_flag);
  751. ClassDB::bind_method(D_METHOD("generic_6dof_joint_get_flag", "joint", "axis", "flag"), &PhysicsServer3D::generic_6dof_joint_get_flag);
  752. ClassDB::bind_method(D_METHOD("free_rid", "rid"), &PhysicsServer3D::free);
  753. ClassDB::bind_method(D_METHOD("set_active", "active"), &PhysicsServer3D::set_active);
  754. ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &PhysicsServer3D::get_process_info);
  755. BIND_ENUM_CONSTANT(SHAPE_WORLD_BOUNDARY);
  756. BIND_ENUM_CONSTANT(SHAPE_SEPARATION_RAY);
  757. BIND_ENUM_CONSTANT(SHAPE_SPHERE);
  758. BIND_ENUM_CONSTANT(SHAPE_BOX);
  759. BIND_ENUM_CONSTANT(SHAPE_CAPSULE);
  760. BIND_ENUM_CONSTANT(SHAPE_CYLINDER);
  761. BIND_ENUM_CONSTANT(SHAPE_CONVEX_POLYGON);
  762. BIND_ENUM_CONSTANT(SHAPE_CONCAVE_POLYGON);
  763. BIND_ENUM_CONSTANT(SHAPE_HEIGHTMAP);
  764. BIND_ENUM_CONSTANT(SHAPE_SOFT_BODY);
  765. BIND_ENUM_CONSTANT(SHAPE_CUSTOM);
  766. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_OVERRIDE_MODE);
  767. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY);
  768. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_VECTOR);
  769. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_IS_POINT);
  770. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE);
  771. BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE);
  772. BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP);
  773. BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE);
  774. BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP);
  775. BIND_ENUM_CONSTANT(AREA_PARAM_PRIORITY);
  776. BIND_ENUM_CONSTANT(AREA_PARAM_WIND_FORCE_MAGNITUDE);
  777. BIND_ENUM_CONSTANT(AREA_PARAM_WIND_SOURCE);
  778. BIND_ENUM_CONSTANT(AREA_PARAM_WIND_DIRECTION);
  779. BIND_ENUM_CONSTANT(AREA_PARAM_WIND_ATTENUATION_FACTOR);
  780. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_DISABLED);
  781. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_COMBINE);
  782. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_COMBINE_REPLACE);
  783. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_REPLACE);
  784. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_REPLACE_COMBINE);
  785. BIND_ENUM_CONSTANT(BODY_MODE_STATIC);
  786. BIND_ENUM_CONSTANT(BODY_MODE_KINEMATIC);
  787. BIND_ENUM_CONSTANT(BODY_MODE_RIGID);
  788. BIND_ENUM_CONSTANT(BODY_MODE_RIGID_LINEAR);
  789. BIND_ENUM_CONSTANT(BODY_PARAM_BOUNCE);
  790. BIND_ENUM_CONSTANT(BODY_PARAM_FRICTION);
  791. BIND_ENUM_CONSTANT(BODY_PARAM_MASS);
  792. BIND_ENUM_CONSTANT(BODY_PARAM_INERTIA);
  793. BIND_ENUM_CONSTANT(BODY_PARAM_CENTER_OF_MASS);
  794. BIND_ENUM_CONSTANT(BODY_PARAM_GRAVITY_SCALE);
  795. BIND_ENUM_CONSTANT(BODY_PARAM_LINEAR_DAMP_MODE);
  796. BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP_MODE);
  797. BIND_ENUM_CONSTANT(BODY_PARAM_LINEAR_DAMP);
  798. BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP);
  799. BIND_ENUM_CONSTANT(BODY_PARAM_MAX);
  800. BIND_ENUM_CONSTANT(BODY_DAMP_MODE_COMBINE);
  801. BIND_ENUM_CONSTANT(BODY_DAMP_MODE_REPLACE);
  802. BIND_ENUM_CONSTANT(BODY_STATE_TRANSFORM);
  803. BIND_ENUM_CONSTANT(BODY_STATE_LINEAR_VELOCITY);
  804. BIND_ENUM_CONSTANT(BODY_STATE_ANGULAR_VELOCITY);
  805. BIND_ENUM_CONSTANT(BODY_STATE_SLEEPING);
  806. BIND_ENUM_CONSTANT(BODY_STATE_CAN_SLEEP);
  807. BIND_ENUM_CONSTANT(AREA_BODY_ADDED);
  808. BIND_ENUM_CONSTANT(AREA_BODY_REMOVED);
  809. BIND_ENUM_CONSTANT(INFO_ACTIVE_OBJECTS);
  810. BIND_ENUM_CONSTANT(INFO_COLLISION_PAIRS);
  811. BIND_ENUM_CONSTANT(INFO_ISLAND_COUNT);
  812. BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_RECYCLE_RADIUS);
  813. BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_SEPARATION);
  814. BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION);
  815. BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_DEFAULT_BIAS);
  816. BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD);
  817. BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD);
  818. BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_TIME_TO_SLEEP);
  819. BIND_ENUM_CONSTANT(SPACE_PARAM_SOLVER_ITERATIONS);
  820. BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_X);
  821. BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_Y);
  822. BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_Z);
  823. BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_X);
  824. BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_Y);
  825. BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_Z);
  826. #endif
  827. }
  828. PhysicsServer3D::PhysicsServer3D() {
  829. singleton = this;
  830. // World3D physics space
  831. GLOBAL_DEF_BASIC("physics/3d/default_gravity", 9.8);
  832. GLOBAL_DEF_BASIC("physics/3d/default_gravity_vector", Vector3(0, -1, 0));
  833. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/default_linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), 0.1);
  834. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/default_angular_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), 0.1);
  835. // PhysicsServer3D
  836. GLOBAL_DEF("physics/3d/sleep_threshold_linear", 0.1);
  837. GLOBAL_DEF("physics/3d/sleep_threshold_angular", Math::deg_to_rad(8.0));
  838. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/time_before_sleep", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater"), 0.5);
  839. GLOBAL_DEF(PropertyInfo(Variant::INT, "physics/3d/solver/solver_iterations", PROPERTY_HINT_RANGE, "1,32,1,or_greater"), 16);
  840. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/contact_recycle_radius", PROPERTY_HINT_RANGE, "0,0.1,0.001,or_greater"), 0.01);
  841. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/contact_max_separation", PROPERTY_HINT_RANGE, "0,0.1,0.001,or_greater"), 0.05);
  842. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/contact_max_allowed_penetration", PROPERTY_HINT_RANGE, "0.001,0.1,0.001,or_greater"), 0.01);
  843. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/default_contact_bias", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.8);
  844. }
  845. PhysicsServer3D::~PhysicsServer3D() {
  846. singleton = nullptr;
  847. }
  848. PhysicsServer3DManager *PhysicsServer3DManager::singleton = nullptr;
  849. const String PhysicsServer3DManager::setting_property_name(PNAME("physics/3d/physics_engine"));
  850. void PhysicsServer3DManager::on_servers_changed() {
  851. String physics_servers2("DEFAULT");
  852. for (int i = get_servers_count() - 1; 0 <= i; --i) {
  853. physics_servers2 += "," + get_server_name(i);
  854. }
  855. ProjectSettings::get_singleton()->set_custom_property_info(PropertyInfo(Variant::STRING, setting_property_name, PROPERTY_HINT_ENUM, physics_servers2));
  856. ProjectSettings::get_singleton()->set_restart_if_changed(setting_property_name, true);
  857. }
  858. void PhysicsServer3DManager::_bind_methods() {
  859. ClassDB::bind_method(D_METHOD("register_server", "name", "create_callback"), &PhysicsServer3DManager::register_server);
  860. ClassDB::bind_method(D_METHOD("set_default_server", "name", "priority"), &PhysicsServer3DManager::set_default_server);
  861. }
  862. PhysicsServer3DManager *PhysicsServer3DManager::get_singleton() {
  863. return singleton;
  864. }
  865. void PhysicsServer3DManager::register_server(const String &p_name, const Callable &p_create_callback) {
  866. //ERR_FAIL_COND(!p_create_callback.is_valid());
  867. ERR_FAIL_COND(find_server_id(p_name) != -1);
  868. physics_servers.push_back(ClassInfo(p_name, p_create_callback));
  869. on_servers_changed();
  870. }
  871. void PhysicsServer3DManager::set_default_server(const String &p_name, int p_priority) {
  872. const int id = find_server_id(p_name);
  873. ERR_FAIL_COND(id == -1); // Not found
  874. if (default_server_priority < p_priority) {
  875. default_server_id = id;
  876. default_server_priority = p_priority;
  877. }
  878. }
  879. int PhysicsServer3DManager::find_server_id(const String &p_name) {
  880. for (int i = physics_servers.size() - 1; 0 <= i; --i) {
  881. if (p_name == physics_servers[i].name) {
  882. return i;
  883. }
  884. }
  885. return -1;
  886. }
  887. int PhysicsServer3DManager::get_servers_count() {
  888. return physics_servers.size();
  889. }
  890. String PhysicsServer3DManager::get_server_name(int p_id) {
  891. ERR_FAIL_INDEX_V(p_id, get_servers_count(), "");
  892. return physics_servers[p_id].name;
  893. }
  894. PhysicsServer3D *PhysicsServer3DManager::new_default_server() {
  895. ERR_FAIL_COND_V(default_server_id == -1, nullptr);
  896. Variant ret;
  897. Callable::CallError ce;
  898. physics_servers[default_server_id].create_callback.callp(nullptr, 0, ret, ce);
  899. ERR_FAIL_COND_V(ce.error != Callable::CallError::CALL_OK, nullptr);
  900. return Object::cast_to<PhysicsServer3D>(ret.get_validated_object());
  901. }
  902. PhysicsServer3D *PhysicsServer3DManager::new_server(const String &p_name) {
  903. int id = find_server_id(p_name);
  904. if (id == -1) {
  905. return nullptr;
  906. } else {
  907. Variant ret;
  908. Callable::CallError ce;
  909. physics_servers[id].create_callback.callp(nullptr, 0, ret, ce);
  910. ERR_FAIL_COND_V(ce.error != Callable::CallError::CALL_OK, nullptr);
  911. return Object::cast_to<PhysicsServer3D>(ret.get_validated_object());
  912. }
  913. }
  914. PhysicsServer3DManager::PhysicsServer3DManager() {
  915. singleton = this;
  916. }
  917. PhysicsServer3DManager::~PhysicsServer3DManager() {
  918. singleton = nullptr;
  919. }