physics_server_3d.cpp 60 KB

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