physics_server_3d.cpp 60 KB

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