physics_server.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. /*************************************************************************/
  2. /* physics_server.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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.h"
  31. #include "core/method_bind_ext.gen.inc"
  32. #include "core/print_string.h"
  33. #include "core/project_settings.h"
  34. PhysicsServer *PhysicsServer::singleton = NULL;
  35. void PhysicsDirectBodyState::integrate_forces() {
  36. real_t step = get_step();
  37. Vector3 lv = get_linear_velocity();
  38. lv += get_total_gravity() * step;
  39. Vector3 av = get_angular_velocity();
  40. float linear_damp = 1.0 - step * get_total_linear_damp();
  41. if (linear_damp < 0) // reached zero in the given time
  42. linear_damp = 0;
  43. float angular_damp = 1.0 - step * get_total_angular_damp();
  44. if (angular_damp < 0) // reached zero in the given time
  45. angular_damp = 0;
  46. lv *= linear_damp;
  47. av *= angular_damp;
  48. set_linear_velocity(lv);
  49. set_angular_velocity(av);
  50. }
  51. Object *PhysicsDirectBodyState::get_contact_collider_object(int p_contact_idx) const {
  52. ObjectID objid = get_contact_collider_id(p_contact_idx);
  53. Object *obj = ObjectDB::get_instance(objid);
  54. return obj;
  55. }
  56. PhysicsServer *PhysicsServer::get_singleton() {
  57. return singleton;
  58. }
  59. void PhysicsDirectBodyState::_bind_methods() {
  60. ClassDB::bind_method(D_METHOD("get_total_gravity"), &PhysicsDirectBodyState::get_total_gravity);
  61. ClassDB::bind_method(D_METHOD("get_total_linear_damp"), &PhysicsDirectBodyState::get_total_linear_damp);
  62. ClassDB::bind_method(D_METHOD("get_total_angular_damp"), &PhysicsDirectBodyState::get_total_angular_damp);
  63. ClassDB::bind_method(D_METHOD("get_center_of_mass"), &PhysicsDirectBodyState::get_center_of_mass);
  64. ClassDB::bind_method(D_METHOD("get_principal_inertia_axes"), &PhysicsDirectBodyState::get_principal_inertia_axes);
  65. ClassDB::bind_method(D_METHOD("get_inverse_mass"), &PhysicsDirectBodyState::get_inverse_mass);
  66. ClassDB::bind_method(D_METHOD("get_inverse_inertia"), &PhysicsDirectBodyState::get_inverse_inertia);
  67. ClassDB::bind_method(D_METHOD("set_linear_velocity", "velocity"), &PhysicsDirectBodyState::set_linear_velocity);
  68. ClassDB::bind_method(D_METHOD("get_linear_velocity"), &PhysicsDirectBodyState::get_linear_velocity);
  69. ClassDB::bind_method(D_METHOD("set_angular_velocity", "velocity"), &PhysicsDirectBodyState::set_angular_velocity);
  70. ClassDB::bind_method(D_METHOD("get_angular_velocity"), &PhysicsDirectBodyState::get_angular_velocity);
  71. ClassDB::bind_method(D_METHOD("set_transform", "transform"), &PhysicsDirectBodyState::set_transform);
  72. ClassDB::bind_method(D_METHOD("get_transform"), &PhysicsDirectBodyState::get_transform);
  73. ClassDB::bind_method(D_METHOD("add_central_force", "force"), &PhysicsDirectBodyState::add_central_force);
  74. ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &PhysicsDirectBodyState::add_force);
  75. ClassDB::bind_method(D_METHOD("add_torque", "torque"), &PhysicsDirectBodyState::add_torque);
  76. ClassDB::bind_method(D_METHOD("apply_central_impulse", "j"), &PhysicsDirectBodyState::apply_central_impulse);
  77. ClassDB::bind_method(D_METHOD("apply_impulse", "position", "j"), &PhysicsDirectBodyState::apply_impulse);
  78. ClassDB::bind_method(D_METHOD("apply_torque_impulse", "j"), &PhysicsDirectBodyState::apply_torque_impulse);
  79. ClassDB::bind_method(D_METHOD("set_sleep_state", "enabled"), &PhysicsDirectBodyState::set_sleep_state);
  80. ClassDB::bind_method(D_METHOD("is_sleeping"), &PhysicsDirectBodyState::is_sleeping);
  81. ClassDB::bind_method(D_METHOD("get_contact_count"), &PhysicsDirectBodyState::get_contact_count);
  82. ClassDB::bind_method(D_METHOD("get_contact_local_position", "contact_idx"), &PhysicsDirectBodyState::get_contact_local_position);
  83. ClassDB::bind_method(D_METHOD("get_contact_local_normal", "contact_idx"), &PhysicsDirectBodyState::get_contact_local_normal);
  84. ClassDB::bind_method(D_METHOD("get_contact_impulse", "contact_idx"), &PhysicsDirectBodyState::get_contact_impulse);
  85. ClassDB::bind_method(D_METHOD("get_contact_local_shape", "contact_idx"), &PhysicsDirectBodyState::get_contact_local_shape);
  86. ClassDB::bind_method(D_METHOD("get_contact_collider", "contact_idx"), &PhysicsDirectBodyState::get_contact_collider);
  87. ClassDB::bind_method(D_METHOD("get_contact_collider_position", "contact_idx"), &PhysicsDirectBodyState::get_contact_collider_position);
  88. ClassDB::bind_method(D_METHOD("get_contact_collider_id", "contact_idx"), &PhysicsDirectBodyState::get_contact_collider_id);
  89. ClassDB::bind_method(D_METHOD("get_contact_collider_object", "contact_idx"), &PhysicsDirectBodyState::get_contact_collider_object);
  90. ClassDB::bind_method(D_METHOD("get_contact_collider_shape", "contact_idx"), &PhysicsDirectBodyState::get_contact_collider_shape);
  91. ClassDB::bind_method(D_METHOD("get_contact_collider_velocity_at_position", "contact_idx"), &PhysicsDirectBodyState::get_contact_collider_velocity_at_position);
  92. ClassDB::bind_method(D_METHOD("get_step"), &PhysicsDirectBodyState::get_step);
  93. ClassDB::bind_method(D_METHOD("integrate_forces"), &PhysicsDirectBodyState::integrate_forces);
  94. ClassDB::bind_method(D_METHOD("get_space_state"), &PhysicsDirectBodyState::get_space_state);
  95. ADD_PROPERTY(PropertyInfo(Variant::REAL, "step"), "", "get_step");
  96. ADD_PROPERTY(PropertyInfo(Variant::REAL, "inverse_mass"), "", "get_inverse_mass");
  97. ADD_PROPERTY(PropertyInfo(Variant::REAL, "total_angular_damp"), "", "get_total_angular_damp");
  98. ADD_PROPERTY(PropertyInfo(Variant::REAL, "total_linear_damp"), "", "get_total_linear_damp");
  99. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "inverse_inertia"), "", "get_inverse_inertia");
  100. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "total_gravity"), "", "get_total_gravity");
  101. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "center_of_mass"), "", "get_center_of_mass");
  102. ADD_PROPERTY(PropertyInfo(Variant::BASIS, "principal_inertia_axes"), "", "get_principal_inertia_axes");
  103. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "angular_velocity"), "set_angular_velocity", "get_angular_velocity");
  104. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "linear_velocity"), "set_linear_velocity", "get_linear_velocity");
  105. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sleeping"), "set_sleep_state", "is_sleeping");
  106. ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "transform"), "set_transform", "get_transform");
  107. }
  108. PhysicsDirectBodyState::PhysicsDirectBodyState() {}
  109. ///////////////////////////////////////////////////////
  110. void PhysicsShapeQueryParameters::set_shape(const RES &p_shape) {
  111. ERR_FAIL_COND(p_shape.is_null());
  112. shape = p_shape->get_rid();
  113. }
  114. void PhysicsShapeQueryParameters::set_shape_rid(const RID &p_shape) {
  115. shape = p_shape;
  116. }
  117. RID PhysicsShapeQueryParameters::get_shape_rid() const {
  118. return shape;
  119. }
  120. void PhysicsShapeQueryParameters::set_transform(const Transform &p_transform) {
  121. transform = p_transform;
  122. }
  123. Transform PhysicsShapeQueryParameters::get_transform() const {
  124. return transform;
  125. }
  126. void PhysicsShapeQueryParameters::set_margin(float p_margin) {
  127. margin = p_margin;
  128. }
  129. float PhysicsShapeQueryParameters::get_margin() const {
  130. return margin;
  131. }
  132. void PhysicsShapeQueryParameters::set_collision_mask(int p_collision_mask) {
  133. collision_mask = p_collision_mask;
  134. }
  135. int PhysicsShapeQueryParameters::get_collision_mask() const {
  136. return collision_mask;
  137. }
  138. void PhysicsShapeQueryParameters::set_exclude(const Vector<RID> &p_exclude) {
  139. exclude.clear();
  140. for (int i = 0; i < p_exclude.size(); i++)
  141. exclude.insert(p_exclude[i]);
  142. }
  143. Vector<RID> PhysicsShapeQueryParameters::get_exclude() const {
  144. Vector<RID> ret;
  145. ret.resize(exclude.size());
  146. int idx = 0;
  147. for (Set<RID>::Element *E = exclude.front(); E; E = E->next()) {
  148. ret.write[idx] = E->get();
  149. }
  150. return ret;
  151. }
  152. void PhysicsShapeQueryParameters::set_collide_with_bodies(bool p_enable) {
  153. collide_with_bodies = p_enable;
  154. }
  155. bool PhysicsShapeQueryParameters::is_collide_with_bodies_enabled() const {
  156. return collide_with_bodies;
  157. }
  158. void PhysicsShapeQueryParameters::set_collide_with_areas(bool p_enable) {
  159. collide_with_areas = p_enable;
  160. }
  161. bool PhysicsShapeQueryParameters::is_collide_with_areas_enabled() const {
  162. return collide_with_areas;
  163. }
  164. void PhysicsShapeQueryParameters::_bind_methods() {
  165. ClassDB::bind_method(D_METHOD("set_shape", "shape"), &PhysicsShapeQueryParameters::set_shape);
  166. ClassDB::bind_method(D_METHOD("set_shape_rid", "shape"), &PhysicsShapeQueryParameters::set_shape_rid);
  167. ClassDB::bind_method(D_METHOD("get_shape_rid"), &PhysicsShapeQueryParameters::get_shape_rid);
  168. ClassDB::bind_method(D_METHOD("set_transform", "transform"), &PhysicsShapeQueryParameters::set_transform);
  169. ClassDB::bind_method(D_METHOD("get_transform"), &PhysicsShapeQueryParameters::get_transform);
  170. ClassDB::bind_method(D_METHOD("set_margin", "margin"), &PhysicsShapeQueryParameters::set_margin);
  171. ClassDB::bind_method(D_METHOD("get_margin"), &PhysicsShapeQueryParameters::get_margin);
  172. ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &PhysicsShapeQueryParameters::set_collision_mask);
  173. ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsShapeQueryParameters::get_collision_mask);
  174. ClassDB::bind_method(D_METHOD("set_exclude", "exclude"), &PhysicsShapeQueryParameters::set_exclude);
  175. ClassDB::bind_method(D_METHOD("get_exclude"), &PhysicsShapeQueryParameters::get_exclude);
  176. ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &PhysicsShapeQueryParameters::set_collide_with_bodies);
  177. ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &PhysicsShapeQueryParameters::is_collide_with_bodies_enabled);
  178. ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &PhysicsShapeQueryParameters::set_collide_with_areas);
  179. ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &PhysicsShapeQueryParameters::is_collide_with_areas_enabled);
  180. ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
  181. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_NONE, itos(Variant::_RID) + ":"), "set_exclude", "get_exclude");
  182. ADD_PROPERTY(PropertyInfo(Variant::REAL, "margin", PROPERTY_HINT_RANGE, "0,100,0.01"), "set_margin", "get_margin");
  183. //ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), "set_shape", ""); // FIXME: Lacks a getter
  184. ADD_PROPERTY(PropertyInfo(Variant::_RID, "shape_rid"), "set_shape_rid", "get_shape_rid");
  185. ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "transform"), "set_transform", "get_transform");
  186. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled");
  187. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas"), "set_collide_with_areas", "is_collide_with_areas_enabled");
  188. }
  189. PhysicsShapeQueryParameters::PhysicsShapeQueryParameters() {
  190. margin = 0;
  191. collision_mask = 0x7FFFFFFF;
  192. collide_with_bodies = true;
  193. collide_with_areas = false;
  194. }
  195. /////////////////////////////////////
  196. Dictionary PhysicsDirectSpaceState::_intersect_ray(const Vector3 &p_from, const Vector3 &p_to, const Vector<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
  197. RayResult inters;
  198. Set<RID> exclude;
  199. for (int i = 0; i < p_exclude.size(); i++)
  200. exclude.insert(p_exclude[i]);
  201. bool res = intersect_ray(p_from, p_to, inters, exclude, p_collision_mask, p_collide_with_bodies, p_collide_with_areas);
  202. if (!res)
  203. return Dictionary();
  204. Dictionary d;
  205. d["position"] = inters.position;
  206. d["normal"] = inters.normal;
  207. d["collider_id"] = inters.collider_id;
  208. d["collider"] = inters.collider;
  209. d["shape"] = inters.shape;
  210. d["rid"] = inters.rid;
  211. return d;
  212. }
  213. Array PhysicsDirectSpaceState::_intersect_shape(const Ref<PhysicsShapeQueryParameters> &p_shape_query, int p_max_results) {
  214. ERR_FAIL_COND_V(!p_shape_query.is_valid(), Array());
  215. Vector<ShapeResult> sr;
  216. sr.resize(p_max_results);
  217. int rc = intersect_shape(p_shape_query->shape, p_shape_query->transform, p_shape_query->margin, sr.ptrw(), sr.size(), p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas);
  218. Array ret;
  219. ret.resize(rc);
  220. for (int i = 0; i < rc; i++) {
  221. Dictionary d;
  222. d["rid"] = sr[i].rid;
  223. d["collider_id"] = sr[i].collider_id;
  224. d["collider"] = sr[i].collider;
  225. d["shape"] = sr[i].shape;
  226. ret[i] = d;
  227. }
  228. return ret;
  229. }
  230. Array PhysicsDirectSpaceState::_cast_motion(const Ref<PhysicsShapeQueryParameters> &p_shape_query, const Vector3 &p_motion) {
  231. ERR_FAIL_COND_V(!p_shape_query.is_valid(), Array());
  232. float closest_safe, closest_unsafe;
  233. bool res = cast_motion(p_shape_query->shape, p_shape_query->transform, p_motion, p_shape_query->margin, closest_safe, closest_unsafe, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas);
  234. if (!res)
  235. return Array();
  236. Array ret;
  237. ret.resize(2);
  238. ret[0] = closest_safe;
  239. ret[1] = closest_unsafe;
  240. return ret;
  241. }
  242. Array PhysicsDirectSpaceState::_collide_shape(const Ref<PhysicsShapeQueryParameters> &p_shape_query, int p_max_results) {
  243. ERR_FAIL_COND_V(!p_shape_query.is_valid(), Array());
  244. Vector<Vector3> ret;
  245. ret.resize(p_max_results * 2);
  246. int rc = 0;
  247. bool res = collide_shape(p_shape_query->shape, p_shape_query->transform, p_shape_query->margin, ret.ptrw(), p_max_results, rc, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas);
  248. if (!res)
  249. return Array();
  250. Array r;
  251. r.resize(rc * 2);
  252. for (int i = 0; i < rc * 2; i++)
  253. r[i] = ret[i];
  254. return r;
  255. }
  256. Dictionary PhysicsDirectSpaceState::_get_rest_info(const Ref<PhysicsShapeQueryParameters> &p_shape_query) {
  257. ERR_FAIL_COND_V(!p_shape_query.is_valid(), Dictionary());
  258. ShapeRestInfo sri;
  259. bool res = rest_info(p_shape_query->shape, p_shape_query->transform, p_shape_query->margin, &sri, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas);
  260. Dictionary r;
  261. if (!res)
  262. return r;
  263. r["point"] = sri.point;
  264. r["normal"] = sri.normal;
  265. r["rid"] = sri.rid;
  266. r["collider_id"] = sri.collider_id;
  267. r["shape"] = sri.shape;
  268. r["linear_velocity"] = sri.linear_velocity;
  269. return r;
  270. }
  271. PhysicsDirectSpaceState::PhysicsDirectSpaceState() {
  272. }
  273. void PhysicsDirectSpaceState::_bind_methods() {
  274. ClassDB::bind_method(D_METHOD("intersect_ray", "from", "to", "exclude", "collision_mask", "collide_with_bodies", "collide_with_areas"), &PhysicsDirectSpaceState::_intersect_ray, DEFVAL(Array()), DEFVAL(0x7FFFFFFF), DEFVAL(true), DEFVAL(false));
  275. ClassDB::bind_method(D_METHOD("intersect_shape", "shape", "max_results"), &PhysicsDirectSpaceState::_intersect_shape, DEFVAL(32));
  276. ClassDB::bind_method(D_METHOD("cast_motion", "shape", "motion"), &PhysicsDirectSpaceState::_cast_motion);
  277. ClassDB::bind_method(D_METHOD("collide_shape", "shape", "max_results"), &PhysicsDirectSpaceState::_collide_shape, DEFVAL(32));
  278. ClassDB::bind_method(D_METHOD("get_rest_info", "shape"), &PhysicsDirectSpaceState::_get_rest_info);
  279. }
  280. int PhysicsShapeQueryResult::get_result_count() const {
  281. return result.size();
  282. }
  283. RID PhysicsShapeQueryResult::get_result_rid(int p_idx) const {
  284. return result[p_idx].rid;
  285. }
  286. ObjectID PhysicsShapeQueryResult::get_result_object_id(int p_idx) const {
  287. return result[p_idx].collider_id;
  288. }
  289. Object *PhysicsShapeQueryResult::get_result_object(int p_idx) const {
  290. return result[p_idx].collider;
  291. }
  292. int PhysicsShapeQueryResult::get_result_object_shape(int p_idx) const {
  293. return result[p_idx].shape;
  294. }
  295. PhysicsShapeQueryResult::PhysicsShapeQueryResult() {
  296. }
  297. void PhysicsShapeQueryResult::_bind_methods() {
  298. ClassDB::bind_method(D_METHOD("get_result_count"), &PhysicsShapeQueryResult::get_result_count);
  299. ClassDB::bind_method(D_METHOD("get_result_rid", "idx"), &PhysicsShapeQueryResult::get_result_rid);
  300. ClassDB::bind_method(D_METHOD("get_result_object_id", "idx"), &PhysicsShapeQueryResult::get_result_object_id);
  301. ClassDB::bind_method(D_METHOD("get_result_object", "idx"), &PhysicsShapeQueryResult::get_result_object);
  302. ClassDB::bind_method(D_METHOD("get_result_object_shape", "idx"), &PhysicsShapeQueryResult::get_result_object_shape);
  303. }
  304. ///////////////////////////////////////
  305. void PhysicsServer::_bind_methods() {
  306. #ifndef _3D_DISABLED
  307. ClassDB::bind_method(D_METHOD("shape_create", "type"), &PhysicsServer::shape_create);
  308. ClassDB::bind_method(D_METHOD("shape_set_data", "shape", "data"), &PhysicsServer::shape_set_data);
  309. ClassDB::bind_method(D_METHOD("shape_get_type", "shape"), &PhysicsServer::shape_get_type);
  310. ClassDB::bind_method(D_METHOD("shape_get_data", "shape"), &PhysicsServer::shape_get_data);
  311. ClassDB::bind_method(D_METHOD("space_create"), &PhysicsServer::space_create);
  312. ClassDB::bind_method(D_METHOD("space_set_active", "space", "active"), &PhysicsServer::space_set_active);
  313. ClassDB::bind_method(D_METHOD("space_is_active", "space"), &PhysicsServer::space_is_active);
  314. ClassDB::bind_method(D_METHOD("space_set_param", "space", "param", "value"), &PhysicsServer::space_set_param);
  315. ClassDB::bind_method(D_METHOD("space_get_param", "space", "param"), &PhysicsServer::space_get_param);
  316. ClassDB::bind_method(D_METHOD("space_get_direct_state", "space"), &PhysicsServer::space_get_direct_state);
  317. ClassDB::bind_method(D_METHOD("area_create"), &PhysicsServer::area_create);
  318. ClassDB::bind_method(D_METHOD("area_set_space", "area", "space"), &PhysicsServer::area_set_space);
  319. ClassDB::bind_method(D_METHOD("area_get_space", "area"), &PhysicsServer::area_get_space);
  320. ClassDB::bind_method(D_METHOD("area_set_space_override_mode", "area", "mode"), &PhysicsServer::area_set_space_override_mode);
  321. ClassDB::bind_method(D_METHOD("area_get_space_override_mode", "area"), &PhysicsServer::area_get_space_override_mode);
  322. ClassDB::bind_method(D_METHOD("area_add_shape", "area", "shape", "transform"), &PhysicsServer::area_add_shape, DEFVAL(Transform()));
  323. ClassDB::bind_method(D_METHOD("area_set_shape", "area", "shape_idx", "shape"), &PhysicsServer::area_set_shape);
  324. ClassDB::bind_method(D_METHOD("area_set_shape_transform", "area", "shape_idx", "transform"), &PhysicsServer::area_set_shape_transform);
  325. ClassDB::bind_method(D_METHOD("area_get_shape_count", "area"), &PhysicsServer::area_get_shape_count);
  326. ClassDB::bind_method(D_METHOD("area_get_shape", "area", "shape_idx"), &PhysicsServer::area_get_shape);
  327. ClassDB::bind_method(D_METHOD("area_get_shape_transform", "area", "shape_idx"), &PhysicsServer::area_get_shape_transform);
  328. ClassDB::bind_method(D_METHOD("area_remove_shape", "area", "shape_idx"), &PhysicsServer::area_remove_shape);
  329. ClassDB::bind_method(D_METHOD("area_clear_shapes", "area"), &PhysicsServer::area_clear_shapes);
  330. ClassDB::bind_method(D_METHOD("area_set_collision_layer", "area", "layer"), &PhysicsServer::area_set_collision_layer);
  331. ClassDB::bind_method(D_METHOD("area_set_collision_mask", "area", "mask"), &PhysicsServer::area_set_collision_mask);
  332. ClassDB::bind_method(D_METHOD("area_set_param", "area", "param", "value"), &PhysicsServer::area_set_param);
  333. ClassDB::bind_method(D_METHOD("area_set_transform", "area", "transform"), &PhysicsServer::area_set_transform);
  334. ClassDB::bind_method(D_METHOD("area_get_param", "area", "param"), &PhysicsServer::area_get_param);
  335. ClassDB::bind_method(D_METHOD("area_get_transform", "area"), &PhysicsServer::area_get_transform);
  336. ClassDB::bind_method(D_METHOD("area_attach_object_instance_id", "area", "id"), &PhysicsServer::area_attach_object_instance_id);
  337. ClassDB::bind_method(D_METHOD("area_get_object_instance_id", "area"), &PhysicsServer::area_get_object_instance_id);
  338. ClassDB::bind_method(D_METHOD("area_set_monitor_callback", "area", "receiver", "method"), &PhysicsServer::area_set_monitor_callback);
  339. ClassDB::bind_method(D_METHOD("area_set_area_monitor_callback", "area", "receiver", "method"), &PhysicsServer::area_set_area_monitor_callback);
  340. ClassDB::bind_method(D_METHOD("area_set_monitorable", "area", "monitorable"), &PhysicsServer::area_set_monitorable);
  341. ClassDB::bind_method(D_METHOD("area_set_ray_pickable", "area", "enable"), &PhysicsServer::area_set_ray_pickable);
  342. ClassDB::bind_method(D_METHOD("area_is_ray_pickable", "area"), &PhysicsServer::area_is_ray_pickable);
  343. ClassDB::bind_method(D_METHOD("body_create", "mode", "init_sleeping"), &PhysicsServer::body_create, DEFVAL(BODY_MODE_RIGID), DEFVAL(false));
  344. ClassDB::bind_method(D_METHOD("body_set_space", "body", "space"), &PhysicsServer::body_set_space);
  345. ClassDB::bind_method(D_METHOD("body_get_space", "body"), &PhysicsServer::body_get_space);
  346. ClassDB::bind_method(D_METHOD("body_set_mode", "body", "mode"), &PhysicsServer::body_set_mode);
  347. ClassDB::bind_method(D_METHOD("body_get_mode", "body"), &PhysicsServer::body_get_mode);
  348. ClassDB::bind_method(D_METHOD("body_set_collision_layer", "body", "layer"), &PhysicsServer::body_set_collision_layer);
  349. ClassDB::bind_method(D_METHOD("body_get_collision_layer", "body"), &PhysicsServer::body_get_collision_layer);
  350. ClassDB::bind_method(D_METHOD("body_set_collision_mask", "body", "mask"), &PhysicsServer::body_set_collision_mask);
  351. ClassDB::bind_method(D_METHOD("body_get_collision_mask", "body"), &PhysicsServer::body_get_collision_mask);
  352. ClassDB::bind_method(D_METHOD("body_add_shape", "body", "shape", "transform"), &PhysicsServer::body_add_shape, DEFVAL(Transform()));
  353. ClassDB::bind_method(D_METHOD("body_set_shape", "body", "shape_idx", "shape"), &PhysicsServer::body_set_shape);
  354. ClassDB::bind_method(D_METHOD("body_set_shape_transform", "body", "shape_idx", "transform"), &PhysicsServer::body_set_shape_transform);
  355. ClassDB::bind_method(D_METHOD("body_get_shape_count", "body"), &PhysicsServer::body_get_shape_count);
  356. ClassDB::bind_method(D_METHOD("body_get_shape", "body", "shape_idx"), &PhysicsServer::body_get_shape);
  357. ClassDB::bind_method(D_METHOD("body_get_shape_transform", "body", "shape_idx"), &PhysicsServer::body_get_shape_transform);
  358. ClassDB::bind_method(D_METHOD("body_remove_shape", "body", "shape_idx"), &PhysicsServer::body_remove_shape);
  359. ClassDB::bind_method(D_METHOD("body_clear_shapes", "body"), &PhysicsServer::body_clear_shapes);
  360. ClassDB::bind_method(D_METHOD("body_attach_object_instance_id", "body", "id"), &PhysicsServer::body_attach_object_instance_id);
  361. ClassDB::bind_method(D_METHOD("body_get_object_instance_id", "body"), &PhysicsServer::body_get_object_instance_id);
  362. ClassDB::bind_method(D_METHOD("body_set_enable_continuous_collision_detection", "body", "enable"), &PhysicsServer::body_set_enable_continuous_collision_detection);
  363. ClassDB::bind_method(D_METHOD("body_is_continuous_collision_detection_enabled", "body"), &PhysicsServer::body_is_continuous_collision_detection_enabled);
  364. ClassDB::bind_method(D_METHOD("body_set_param", "body", "param", "value"), &PhysicsServer::body_set_param);
  365. ClassDB::bind_method(D_METHOD("body_get_param", "body", "param"), &PhysicsServer::body_get_param);
  366. ClassDB::bind_method(D_METHOD("body_set_kinematic_safe_margin", "body", "margin"), &PhysicsServer::body_set_kinematic_safe_margin);
  367. ClassDB::bind_method(D_METHOD("body_get_kinematic_safe_margin", "body"), &PhysicsServer::body_get_kinematic_safe_margin);
  368. ClassDB::bind_method(D_METHOD("body_set_state", "body", "state", "value"), &PhysicsServer::body_set_state);
  369. ClassDB::bind_method(D_METHOD("body_get_state", "body", "state"), &PhysicsServer::body_get_state);
  370. ClassDB::bind_method(D_METHOD("body_add_central_force", "body", "force"), &PhysicsServer::body_add_central_force);
  371. ClassDB::bind_method(D_METHOD("body_add_force", "body", "force", "position"), &PhysicsServer::body_add_force);
  372. ClassDB::bind_method(D_METHOD("body_add_torque", "body", "torque"), &PhysicsServer::body_add_torque);
  373. ClassDB::bind_method(D_METHOD("body_apply_central_impulse", "body", "impulse"), &PhysicsServer::body_apply_central_impulse);
  374. ClassDB::bind_method(D_METHOD("body_apply_impulse", "body", "position", "impulse"), &PhysicsServer::body_apply_impulse);
  375. ClassDB::bind_method(D_METHOD("body_apply_torque_impulse", "body", "impulse"), &PhysicsServer::body_apply_torque_impulse);
  376. ClassDB::bind_method(D_METHOD("body_set_axis_velocity", "body", "axis_velocity"), &PhysicsServer::body_set_axis_velocity);
  377. ClassDB::bind_method(D_METHOD("body_set_axis_lock", "body", "axis", "lock"), &PhysicsServer::body_set_axis_lock);
  378. ClassDB::bind_method(D_METHOD("body_is_axis_locked", "body", "axis"), &PhysicsServer::body_is_axis_locked);
  379. ClassDB::bind_method(D_METHOD("body_add_collision_exception", "body", "excepted_body"), &PhysicsServer::body_add_collision_exception);
  380. ClassDB::bind_method(D_METHOD("body_remove_collision_exception", "body", "excepted_body"), &PhysicsServer::body_remove_collision_exception);
  381. ClassDB::bind_method(D_METHOD("body_set_max_contacts_reported", "body", "amount"), &PhysicsServer::body_set_max_contacts_reported);
  382. ClassDB::bind_method(D_METHOD("body_get_max_contacts_reported", "body"), &PhysicsServer::body_get_max_contacts_reported);
  383. ClassDB::bind_method(D_METHOD("body_set_omit_force_integration", "body", "enable"), &PhysicsServer::body_set_omit_force_integration);
  384. ClassDB::bind_method(D_METHOD("body_is_omitting_force_integration", "body"), &PhysicsServer::body_is_omitting_force_integration);
  385. ClassDB::bind_method(D_METHOD("body_set_force_integration_callback", "body", "receiver", "method", "userdata"), &PhysicsServer::body_set_force_integration_callback, DEFVAL(Variant()));
  386. ClassDB::bind_method(D_METHOD("body_set_ray_pickable", "body", "enable"), &PhysicsServer::body_set_ray_pickable);
  387. ClassDB::bind_method(D_METHOD("body_is_ray_pickable", "body"), &PhysicsServer::body_is_ray_pickable);
  388. ClassDB::bind_method(D_METHOD("body_get_direct_state", "body"), &PhysicsServer::body_get_direct_state);
  389. /* JOINT API */
  390. BIND_ENUM_CONSTANT(JOINT_PIN);
  391. BIND_ENUM_CONSTANT(JOINT_HINGE);
  392. BIND_ENUM_CONSTANT(JOINT_SLIDER);
  393. BIND_ENUM_CONSTANT(JOINT_CONE_TWIST);
  394. BIND_ENUM_CONSTANT(JOINT_6DOF);
  395. ClassDB::bind_method(D_METHOD("joint_create_pin", "body_A", "local_A", "body_B", "local_B"), &PhysicsServer::joint_create_pin);
  396. ClassDB::bind_method(D_METHOD("pin_joint_set_param", "joint", "param", "value"), &PhysicsServer::pin_joint_set_param);
  397. ClassDB::bind_method(D_METHOD("pin_joint_get_param", "joint", "param"), &PhysicsServer::pin_joint_get_param);
  398. ClassDB::bind_method(D_METHOD("pin_joint_set_local_a", "joint", "local_A"), &PhysicsServer::pin_joint_set_local_a);
  399. ClassDB::bind_method(D_METHOD("pin_joint_get_local_a", "joint"), &PhysicsServer::pin_joint_get_local_a);
  400. ClassDB::bind_method(D_METHOD("pin_joint_set_local_b", "joint", "local_B"), &PhysicsServer::pin_joint_set_local_b);
  401. ClassDB::bind_method(D_METHOD("pin_joint_get_local_b", "joint"), &PhysicsServer::pin_joint_get_local_b);
  402. BIND_ENUM_CONSTANT(PIN_JOINT_BIAS);
  403. BIND_ENUM_CONSTANT(PIN_JOINT_DAMPING);
  404. BIND_ENUM_CONSTANT(PIN_JOINT_IMPULSE_CLAMP);
  405. BIND_ENUM_CONSTANT(HINGE_JOINT_BIAS);
  406. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_UPPER);
  407. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_LOWER);
  408. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_BIAS);
  409. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_SOFTNESS);
  410. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_RELAXATION);
  411. BIND_ENUM_CONSTANT(HINGE_JOINT_MOTOR_TARGET_VELOCITY);
  412. BIND_ENUM_CONSTANT(HINGE_JOINT_MOTOR_MAX_IMPULSE);
  413. BIND_ENUM_CONSTANT(HINGE_JOINT_FLAG_USE_LIMIT);
  414. BIND_ENUM_CONSTANT(HINGE_JOINT_FLAG_ENABLE_MOTOR);
  415. ClassDB::bind_method(D_METHOD("joint_create_hinge", "body_A", "hinge_A", "body_B", "hinge_B"), &PhysicsServer::joint_create_hinge);
  416. ClassDB::bind_method(D_METHOD("hinge_joint_set_param", "joint", "param", "value"), &PhysicsServer::hinge_joint_set_param);
  417. ClassDB::bind_method(D_METHOD("hinge_joint_get_param", "joint", "param"), &PhysicsServer::hinge_joint_get_param);
  418. ClassDB::bind_method(D_METHOD("hinge_joint_set_flag", "joint", "flag", "enabled"), &PhysicsServer::hinge_joint_set_flag);
  419. ClassDB::bind_method(D_METHOD("hinge_joint_get_flag", "joint", "flag"), &PhysicsServer::hinge_joint_get_flag);
  420. ClassDB::bind_method(D_METHOD("joint_create_slider", "body_A", "local_ref_A", "body_B", "local_ref_B"), &PhysicsServer::joint_create_slider);
  421. ClassDB::bind_method(D_METHOD("slider_joint_set_param", "joint", "param", "value"), &PhysicsServer::slider_joint_set_param);
  422. ClassDB::bind_method(D_METHOD("slider_joint_get_param", "joint", "param"), &PhysicsServer::slider_joint_get_param);
  423. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_UPPER);
  424. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_LOWER);
  425. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS);
  426. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION);
  427. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_DAMPING);
  428. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_SOFTNESS);
  429. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_RESTITUTION);
  430. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_DAMPING);
  431. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS);
  432. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION);
  433. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING);
  434. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_UPPER);
  435. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_LOWER);
  436. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS);
  437. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION);
  438. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_DAMPING);
  439. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS);
  440. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION);
  441. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_DAMPING);
  442. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS);
  443. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION);
  444. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING);
  445. BIND_ENUM_CONSTANT(SLIDER_JOINT_MAX);
  446. ClassDB::bind_method(D_METHOD("joint_create_cone_twist", "body_A", "local_ref_A", "body_B", "local_ref_B"), &PhysicsServer::joint_create_cone_twist);
  447. ClassDB::bind_method(D_METHOD("cone_twist_joint_set_param", "joint", "param", "value"), &PhysicsServer::cone_twist_joint_set_param);
  448. ClassDB::bind_method(D_METHOD("cone_twist_joint_get_param", "joint", "param"), &PhysicsServer::cone_twist_joint_get_param);
  449. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_SWING_SPAN);
  450. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_TWIST_SPAN);
  451. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_BIAS);
  452. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_SOFTNESS);
  453. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_RELAXATION);
  454. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_LOWER_LIMIT);
  455. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_UPPER_LIMIT);
  456. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS);
  457. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_RESTITUTION);
  458. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_DAMPING);
  459. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY);
  460. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT);
  461. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_LOWER_LIMIT);
  462. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_UPPER_LIMIT);
  463. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS);
  464. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_DAMPING);
  465. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_RESTITUTION);
  466. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_FORCE_LIMIT);
  467. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_ERP);
  468. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY);
  469. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT);
  470. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT);
  471. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT);
  472. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_MOTOR);
  473. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR);
  474. ClassDB::bind_method(D_METHOD("joint_get_type", "joint"), &PhysicsServer::joint_get_type);
  475. ClassDB::bind_method(D_METHOD("joint_set_solver_priority", "joint", "priority"), &PhysicsServer::joint_set_solver_priority);
  476. ClassDB::bind_method(D_METHOD("joint_get_solver_priority", "joint"), &PhysicsServer::joint_get_solver_priority);
  477. ClassDB::bind_method(D_METHOD("joint_create_generic_6dof", "body_A", "local_ref_A", "body_B", "local_ref_B"), &PhysicsServer::joint_create_generic_6dof);
  478. ClassDB::bind_method(D_METHOD("generic_6dof_joint_set_param", "joint", "axis", "param", "value"), &PhysicsServer::generic_6dof_joint_set_param);
  479. ClassDB::bind_method(D_METHOD("generic_6dof_joint_get_param", "joint", "axis", "param"), &PhysicsServer::generic_6dof_joint_get_param);
  480. ClassDB::bind_method(D_METHOD("generic_6dof_joint_set_flag", "joint", "axis", "flag", "enable"), &PhysicsServer::generic_6dof_joint_set_flag);
  481. ClassDB::bind_method(D_METHOD("generic_6dof_joint_get_flag", "joint", "axis", "flag"), &PhysicsServer::generic_6dof_joint_get_flag);
  482. ClassDB::bind_method(D_METHOD("free_rid", "rid"), &PhysicsServer::free);
  483. ClassDB::bind_method(D_METHOD("set_active", "active"), &PhysicsServer::set_active);
  484. ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &PhysicsServer::get_process_info);
  485. BIND_ENUM_CONSTANT(SHAPE_PLANE);
  486. BIND_ENUM_CONSTANT(SHAPE_RAY);
  487. BIND_ENUM_CONSTANT(SHAPE_SPHERE);
  488. BIND_ENUM_CONSTANT(SHAPE_BOX);
  489. BIND_ENUM_CONSTANT(SHAPE_CAPSULE);
  490. BIND_ENUM_CONSTANT(SHAPE_CYLINDER);
  491. BIND_ENUM_CONSTANT(SHAPE_CONVEX_POLYGON);
  492. BIND_ENUM_CONSTANT(SHAPE_CONCAVE_POLYGON);
  493. BIND_ENUM_CONSTANT(SHAPE_HEIGHTMAP);
  494. BIND_ENUM_CONSTANT(SHAPE_CUSTOM);
  495. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY);
  496. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_VECTOR);
  497. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_IS_POINT);
  498. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_DISTANCE_SCALE);
  499. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_POINT_ATTENUATION);
  500. BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP);
  501. BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP);
  502. BIND_ENUM_CONSTANT(AREA_PARAM_PRIORITY);
  503. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_DISABLED);
  504. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_COMBINE);
  505. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_COMBINE_REPLACE);
  506. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_REPLACE);
  507. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_REPLACE_COMBINE);
  508. BIND_ENUM_CONSTANT(BODY_MODE_STATIC);
  509. BIND_ENUM_CONSTANT(BODY_MODE_KINEMATIC);
  510. BIND_ENUM_CONSTANT(BODY_MODE_RIGID);
  511. BIND_ENUM_CONSTANT(BODY_MODE_CHARACTER);
  512. BIND_ENUM_CONSTANT(BODY_PARAM_BOUNCE);
  513. BIND_ENUM_CONSTANT(BODY_PARAM_FRICTION);
  514. BIND_ENUM_CONSTANT(BODY_PARAM_MASS);
  515. BIND_ENUM_CONSTANT(BODY_PARAM_GRAVITY_SCALE);
  516. BIND_ENUM_CONSTANT(BODY_PARAM_LINEAR_DAMP);
  517. BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP);
  518. BIND_ENUM_CONSTANT(BODY_PARAM_MAX);
  519. BIND_ENUM_CONSTANT(BODY_STATE_TRANSFORM);
  520. BIND_ENUM_CONSTANT(BODY_STATE_LINEAR_VELOCITY);
  521. BIND_ENUM_CONSTANT(BODY_STATE_ANGULAR_VELOCITY);
  522. BIND_ENUM_CONSTANT(BODY_STATE_SLEEPING);
  523. BIND_ENUM_CONSTANT(BODY_STATE_CAN_SLEEP);
  524. BIND_ENUM_CONSTANT(AREA_BODY_ADDED);
  525. BIND_ENUM_CONSTANT(AREA_BODY_REMOVED);
  526. BIND_ENUM_CONSTANT(INFO_ACTIVE_OBJECTS);
  527. BIND_ENUM_CONSTANT(INFO_COLLISION_PAIRS);
  528. BIND_ENUM_CONSTANT(INFO_ISLAND_COUNT);
  529. BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_RECYCLE_RADIUS);
  530. BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_SEPARATION);
  531. BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION);
  532. BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD);
  533. BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD);
  534. BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_TIME_TO_SLEEP);
  535. BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO);
  536. BIND_ENUM_CONSTANT(SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS);
  537. BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_X);
  538. BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_Y);
  539. BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_Z);
  540. BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_X);
  541. BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_Y);
  542. BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_Z);
  543. #endif
  544. }
  545. PhysicsServer::PhysicsServer() {
  546. ERR_FAIL_COND(singleton != NULL);
  547. singleton = this;
  548. }
  549. PhysicsServer::~PhysicsServer() {
  550. singleton = NULL;
  551. }
  552. Vector<PhysicsServerManager::ClassInfo> PhysicsServerManager::physics_servers;
  553. int PhysicsServerManager::default_server_id = -1;
  554. int PhysicsServerManager::default_server_priority = -1;
  555. const String PhysicsServerManager::setting_property_name("physics/3d/physics_engine");
  556. void PhysicsServerManager::on_servers_changed() {
  557. String physics_servers("DEFAULT");
  558. for (int i = get_servers_count() - 1; 0 <= i; --i) {
  559. physics_servers += "," + get_server_name(i);
  560. }
  561. ProjectSettings::get_singleton()->set_custom_property_info(setting_property_name, PropertyInfo(Variant::STRING, setting_property_name, PROPERTY_HINT_ENUM, physics_servers));
  562. }
  563. void PhysicsServerManager::register_server(const String &p_name, CreatePhysicsServerCallback p_creat_callback) {
  564. ERR_FAIL_COND(!p_creat_callback);
  565. ERR_FAIL_COND(find_server_id(p_name) != -1);
  566. physics_servers.push_back(ClassInfo(p_name, p_creat_callback));
  567. on_servers_changed();
  568. }
  569. void PhysicsServerManager::set_default_server(const String &p_name, int p_priority) {
  570. const int id = find_server_id(p_name);
  571. ERR_FAIL_COND(id == -1); // Not found
  572. if (default_server_priority < p_priority) {
  573. default_server_id = id;
  574. default_server_priority = p_priority;
  575. }
  576. }
  577. int PhysicsServerManager::find_server_id(const String &p_name) {
  578. for (int i = physics_servers.size() - 1; 0 <= i; --i) {
  579. if (p_name == physics_servers[i].name) {
  580. return i;
  581. }
  582. }
  583. return -1;
  584. }
  585. int PhysicsServerManager::get_servers_count() {
  586. return physics_servers.size();
  587. }
  588. String PhysicsServerManager::get_server_name(int p_id) {
  589. ERR_FAIL_INDEX_V(p_id, get_servers_count(), "");
  590. return physics_servers[p_id].name;
  591. }
  592. PhysicsServer *PhysicsServerManager::new_default_server() {
  593. ERR_FAIL_COND_V(default_server_id == -1, NULL);
  594. return physics_servers[default_server_id].create_callback();
  595. }
  596. PhysicsServer *PhysicsServerManager::new_server(const String &p_name) {
  597. int id = find_server_id(p_name);
  598. if (id == -1) {
  599. return NULL;
  600. } else {
  601. return physics_servers[id].create_callback();
  602. }
  603. }