physics_server_3d.cpp 65 KB

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