physics_server_3d.cpp 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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/variant/typed_array.h"
  34. void PhysicsServer3DRenderingServerHandler::set_vertex(int p_vertex_id, const Vector3 &p_vertex) {
  35. GDVIRTUAL_CALL(_set_vertex, p_vertex_id, p_vertex);
  36. }
  37. void PhysicsServer3DRenderingServerHandler::set_normal(int p_vertex_id, const Vector3 &p_normal) {
  38. GDVIRTUAL_CALL(_set_normal, p_vertex_id, p_normal);
  39. }
  40. void PhysicsServer3DRenderingServerHandler::set_aabb(const AABB &p_aabb) {
  41. GDVIRTUAL_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::VECTOR3, "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_null(), 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_null(), 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_null(), 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_null(), 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_null(), 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_null(), 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_set_margin", "shape", "margin"), &PhysicsServer3D::shape_set_margin);
  568. ClassDB::bind_method(D_METHOD("shape_get_type", "shape"), &PhysicsServer3D::shape_get_type);
  569. ClassDB::bind_method(D_METHOD("shape_get_data", "shape"), &PhysicsServer3D::shape_get_data);
  570. ClassDB::bind_method(D_METHOD("shape_get_margin", "shape"), &PhysicsServer3D::shape_get_margin);
  571. ClassDB::bind_method(D_METHOD("space_create"), &PhysicsServer3D::space_create);
  572. ClassDB::bind_method(D_METHOD("space_set_active", "space", "active"), &PhysicsServer3D::space_set_active);
  573. ClassDB::bind_method(D_METHOD("space_is_active", "space"), &PhysicsServer3D::space_is_active);
  574. ClassDB::bind_method(D_METHOD("space_set_param", "space", "param", "value"), &PhysicsServer3D::space_set_param);
  575. ClassDB::bind_method(D_METHOD("space_get_param", "space", "param"), &PhysicsServer3D::space_get_param);
  576. ClassDB::bind_method(D_METHOD("space_get_direct_state", "space"), &PhysicsServer3D::space_get_direct_state);
  577. ClassDB::bind_method(D_METHOD("area_create"), &PhysicsServer3D::area_create);
  578. ClassDB::bind_method(D_METHOD("area_set_space", "area", "space"), &PhysicsServer3D::area_set_space);
  579. ClassDB::bind_method(D_METHOD("area_get_space", "area"), &PhysicsServer3D::area_get_space);
  580. ClassDB::bind_method(D_METHOD("area_add_shape", "area", "shape", "transform", "disabled"), &PhysicsServer3D::area_add_shape, DEFVAL(Transform3D()), DEFVAL(false));
  581. ClassDB::bind_method(D_METHOD("area_set_shape", "area", "shape_idx", "shape"), &PhysicsServer3D::area_set_shape);
  582. ClassDB::bind_method(D_METHOD("area_set_shape_transform", "area", "shape_idx", "transform"), &PhysicsServer3D::area_set_shape_transform);
  583. ClassDB::bind_method(D_METHOD("area_set_shape_disabled", "area", "shape_idx", "disabled"), &PhysicsServer3D::area_set_shape_disabled);
  584. ClassDB::bind_method(D_METHOD("area_get_shape_count", "area"), &PhysicsServer3D::area_get_shape_count);
  585. ClassDB::bind_method(D_METHOD("area_get_shape", "area", "shape_idx"), &PhysicsServer3D::area_get_shape);
  586. ClassDB::bind_method(D_METHOD("area_get_shape_transform", "area", "shape_idx"), &PhysicsServer3D::area_get_shape_transform);
  587. ClassDB::bind_method(D_METHOD("area_remove_shape", "area", "shape_idx"), &PhysicsServer3D::area_remove_shape);
  588. ClassDB::bind_method(D_METHOD("area_clear_shapes", "area"), &PhysicsServer3D::area_clear_shapes);
  589. ClassDB::bind_method(D_METHOD("area_set_collision_layer", "area", "layer"), &PhysicsServer3D::area_set_collision_layer);
  590. ClassDB::bind_method(D_METHOD("area_get_collision_layer", "area"), &PhysicsServer3D::area_get_collision_layer);
  591. ClassDB::bind_method(D_METHOD("area_set_collision_mask", "area", "mask"), &PhysicsServer3D::area_set_collision_mask);
  592. ClassDB::bind_method(D_METHOD("area_get_collision_mask", "area"), &PhysicsServer3D::area_get_collision_mask);
  593. ClassDB::bind_method(D_METHOD("area_set_param", "area", "param", "value"), &PhysicsServer3D::area_set_param);
  594. ClassDB::bind_method(D_METHOD("area_set_transform", "area", "transform"), &PhysicsServer3D::area_set_transform);
  595. ClassDB::bind_method(D_METHOD("area_get_param", "area", "param"), &PhysicsServer3D::area_get_param);
  596. ClassDB::bind_method(D_METHOD("area_get_transform", "area"), &PhysicsServer3D::area_get_transform);
  597. ClassDB::bind_method(D_METHOD("area_attach_object_instance_id", "area", "id"), &PhysicsServer3D::area_attach_object_instance_id);
  598. ClassDB::bind_method(D_METHOD("area_get_object_instance_id", "area"), &PhysicsServer3D::area_get_object_instance_id);
  599. ClassDB::bind_method(D_METHOD("area_set_monitor_callback", "area", "callback"), &PhysicsServer3D::area_set_monitor_callback);
  600. ClassDB::bind_method(D_METHOD("area_set_area_monitor_callback", "area", "callback"), &PhysicsServer3D::area_set_area_monitor_callback);
  601. ClassDB::bind_method(D_METHOD("area_set_monitorable", "area", "monitorable"), &PhysicsServer3D::area_set_monitorable);
  602. ClassDB::bind_method(D_METHOD("area_set_ray_pickable", "area", "enable"), &PhysicsServer3D::area_set_ray_pickable);
  603. ClassDB::bind_method(D_METHOD("body_create"), &PhysicsServer3D::body_create);
  604. ClassDB::bind_method(D_METHOD("body_set_space", "body", "space"), &PhysicsServer3D::body_set_space);
  605. ClassDB::bind_method(D_METHOD("body_get_space", "body"), &PhysicsServer3D::body_get_space);
  606. ClassDB::bind_method(D_METHOD("body_set_mode", "body", "mode"), &PhysicsServer3D::body_set_mode);
  607. ClassDB::bind_method(D_METHOD("body_get_mode", "body"), &PhysicsServer3D::body_get_mode);
  608. ClassDB::bind_method(D_METHOD("body_set_collision_layer", "body", "layer"), &PhysicsServer3D::body_set_collision_layer);
  609. ClassDB::bind_method(D_METHOD("body_get_collision_layer", "body"), &PhysicsServer3D::body_get_collision_layer);
  610. ClassDB::bind_method(D_METHOD("body_set_collision_mask", "body", "mask"), &PhysicsServer3D::body_set_collision_mask);
  611. ClassDB::bind_method(D_METHOD("body_get_collision_mask", "body"), &PhysicsServer3D::body_get_collision_mask);
  612. ClassDB::bind_method(D_METHOD("body_set_collision_priority", "body", "priority"), &PhysicsServer3D::body_set_collision_priority);
  613. ClassDB::bind_method(D_METHOD("body_get_collision_priority", "body"), &PhysicsServer3D::body_get_collision_priority);
  614. ClassDB::bind_method(D_METHOD("body_add_shape", "body", "shape", "transform", "disabled"), &PhysicsServer3D::body_add_shape, DEFVAL(Transform3D()), DEFVAL(false));
  615. ClassDB::bind_method(D_METHOD("body_set_shape", "body", "shape_idx", "shape"), &PhysicsServer3D::body_set_shape);
  616. ClassDB::bind_method(D_METHOD("body_set_shape_transform", "body", "shape_idx", "transform"), &PhysicsServer3D::body_set_shape_transform);
  617. ClassDB::bind_method(D_METHOD("body_set_shape_disabled", "body", "shape_idx", "disabled"), &PhysicsServer3D::body_set_shape_disabled);
  618. ClassDB::bind_method(D_METHOD("body_get_shape_count", "body"), &PhysicsServer3D::body_get_shape_count);
  619. ClassDB::bind_method(D_METHOD("body_get_shape", "body", "shape_idx"), &PhysicsServer3D::body_get_shape);
  620. ClassDB::bind_method(D_METHOD("body_get_shape_transform", "body", "shape_idx"), &PhysicsServer3D::body_get_shape_transform);
  621. ClassDB::bind_method(D_METHOD("body_remove_shape", "body", "shape_idx"), &PhysicsServer3D::body_remove_shape);
  622. ClassDB::bind_method(D_METHOD("body_clear_shapes", "body"), &PhysicsServer3D::body_clear_shapes);
  623. ClassDB::bind_method(D_METHOD("body_attach_object_instance_id", "body", "id"), &PhysicsServer3D::body_attach_object_instance_id);
  624. ClassDB::bind_method(D_METHOD("body_get_object_instance_id", "body"), &PhysicsServer3D::body_get_object_instance_id);
  625. ClassDB::bind_method(D_METHOD("body_set_enable_continuous_collision_detection", "body", "enable"), &PhysicsServer3D::body_set_enable_continuous_collision_detection);
  626. ClassDB::bind_method(D_METHOD("body_is_continuous_collision_detection_enabled", "body"), &PhysicsServer3D::body_is_continuous_collision_detection_enabled);
  627. ClassDB::bind_method(D_METHOD("body_set_param", "body", "param", "value"), &PhysicsServer3D::body_set_param);
  628. ClassDB::bind_method(D_METHOD("body_get_param", "body", "param"), &PhysicsServer3D::body_get_param);
  629. ClassDB::bind_method(D_METHOD("body_reset_mass_properties", "body"), &PhysicsServer3D::body_reset_mass_properties);
  630. ClassDB::bind_method(D_METHOD("body_set_state", "body", "state", "value"), &PhysicsServer3D::body_set_state);
  631. ClassDB::bind_method(D_METHOD("body_get_state", "body", "state"), &PhysicsServer3D::body_get_state);
  632. ClassDB::bind_method(D_METHOD("body_apply_central_impulse", "body", "impulse"), &PhysicsServer3D::body_apply_central_impulse);
  633. ClassDB::bind_method(D_METHOD("body_apply_impulse", "body", "impulse", "position"), &PhysicsServer3D::body_apply_impulse, Vector3());
  634. ClassDB::bind_method(D_METHOD("body_apply_torque_impulse", "body", "impulse"), &PhysicsServer3D::body_apply_torque_impulse);
  635. ClassDB::bind_method(D_METHOD("body_apply_central_force", "body", "force"), &PhysicsServer3D::body_apply_central_force);
  636. ClassDB::bind_method(D_METHOD("body_apply_force", "body", "force", "position"), &PhysicsServer3D::body_apply_force, Vector3());
  637. ClassDB::bind_method(D_METHOD("body_apply_torque", "body", "torque"), &PhysicsServer3D::body_apply_torque);
  638. ClassDB::bind_method(D_METHOD("body_add_constant_central_force", "body", "force"), &PhysicsServer3D::body_add_constant_central_force);
  639. ClassDB::bind_method(D_METHOD("body_add_constant_force", "body", "force", "position"), &PhysicsServer3D::body_add_constant_force, Vector3());
  640. ClassDB::bind_method(D_METHOD("body_add_constant_torque", "body", "torque"), &PhysicsServer3D::body_add_constant_torque);
  641. ClassDB::bind_method(D_METHOD("body_set_constant_force", "body", "force"), &PhysicsServer3D::body_set_constant_force);
  642. ClassDB::bind_method(D_METHOD("body_get_constant_force", "body"), &PhysicsServer3D::body_get_constant_force);
  643. ClassDB::bind_method(D_METHOD("body_set_constant_torque", "body", "torque"), &PhysicsServer3D::body_set_constant_torque);
  644. ClassDB::bind_method(D_METHOD("body_get_constant_torque", "body"), &PhysicsServer3D::body_get_constant_torque);
  645. ClassDB::bind_method(D_METHOD("body_set_axis_velocity", "body", "axis_velocity"), &PhysicsServer3D::body_set_axis_velocity);
  646. ClassDB::bind_method(D_METHOD("body_set_axis_lock", "body", "axis", "lock"), &PhysicsServer3D::body_set_axis_lock);
  647. ClassDB::bind_method(D_METHOD("body_is_axis_locked", "body", "axis"), &PhysicsServer3D::body_is_axis_locked);
  648. ClassDB::bind_method(D_METHOD("body_add_collision_exception", "body", "excepted_body"), &PhysicsServer3D::body_add_collision_exception);
  649. ClassDB::bind_method(D_METHOD("body_remove_collision_exception", "body", "excepted_body"), &PhysicsServer3D::body_remove_collision_exception);
  650. ClassDB::bind_method(D_METHOD("body_set_max_contacts_reported", "body", "amount"), &PhysicsServer3D::body_set_max_contacts_reported);
  651. ClassDB::bind_method(D_METHOD("body_get_max_contacts_reported", "body"), &PhysicsServer3D::body_get_max_contacts_reported);
  652. ClassDB::bind_method(D_METHOD("body_set_omit_force_integration", "body", "enable"), &PhysicsServer3D::body_set_omit_force_integration);
  653. ClassDB::bind_method(D_METHOD("body_is_omitting_force_integration", "body"), &PhysicsServer3D::body_is_omitting_force_integration);
  654. ClassDB::bind_method(D_METHOD("body_set_state_sync_callback", "body", "callable"), &PhysicsServer3D::body_set_state_sync_callback);
  655. ClassDB::bind_method(D_METHOD("body_set_force_integration_callback", "body", "callable", "userdata"), &PhysicsServer3D::body_set_force_integration_callback, DEFVAL(Variant()));
  656. ClassDB::bind_method(D_METHOD("body_set_ray_pickable", "body", "enable"), &PhysicsServer3D::body_set_ray_pickable);
  657. ClassDB::bind_method(D_METHOD("body_test_motion", "body", "parameters", "result"), &PhysicsServer3D::_body_test_motion, DEFVAL(Variant()));
  658. ClassDB::bind_method(D_METHOD("body_get_direct_state", "body"), &PhysicsServer3D::body_get_direct_state);
  659. /* SOFT BODY API */
  660. ClassDB::bind_method(D_METHOD("soft_body_create"), &PhysicsServer3D::soft_body_create);
  661. ClassDB::bind_method(D_METHOD("soft_body_update_rendering_server", "body", "rendering_server_handler"), &PhysicsServer3D::soft_body_update_rendering_server);
  662. ClassDB::bind_method(D_METHOD("soft_body_set_space", "body", "space"), &PhysicsServer3D::soft_body_set_space);
  663. ClassDB::bind_method(D_METHOD("soft_body_get_space", "body"), &PhysicsServer3D::soft_body_get_space);
  664. ClassDB::bind_method(D_METHOD("soft_body_set_mesh", "body", "mesh"), &PhysicsServer3D::soft_body_set_mesh);
  665. ClassDB::bind_method(D_METHOD("soft_body_get_bounds", "body"), &PhysicsServer3D::soft_body_get_bounds);
  666. ClassDB::bind_method(D_METHOD("soft_body_set_collision_layer", "body", "layer"), &PhysicsServer3D::soft_body_set_collision_layer);
  667. ClassDB::bind_method(D_METHOD("soft_body_get_collision_layer", "body"), &PhysicsServer3D::soft_body_get_collision_layer);
  668. ClassDB::bind_method(D_METHOD("soft_body_set_collision_mask", "body", "mask"), &PhysicsServer3D::soft_body_set_collision_mask);
  669. ClassDB::bind_method(D_METHOD("soft_body_get_collision_mask", "body"), &PhysicsServer3D::soft_body_get_collision_mask);
  670. ClassDB::bind_method(D_METHOD("soft_body_add_collision_exception", "body", "body_b"), &PhysicsServer3D::soft_body_add_collision_exception);
  671. ClassDB::bind_method(D_METHOD("soft_body_remove_collision_exception", "body", "body_b"), &PhysicsServer3D::soft_body_remove_collision_exception);
  672. ClassDB::bind_method(D_METHOD("soft_body_set_state", "body", "state", "variant"), &PhysicsServer3D::soft_body_set_state);
  673. ClassDB::bind_method(D_METHOD("soft_body_get_state", "body", "state"), &PhysicsServer3D::soft_body_get_state);
  674. ClassDB::bind_method(D_METHOD("soft_body_set_transform", "body", "transform"), &PhysicsServer3D::soft_body_set_transform);
  675. ClassDB::bind_method(D_METHOD("soft_body_set_ray_pickable", "body", "enable"), &PhysicsServer3D::soft_body_set_ray_pickable);
  676. ClassDB::bind_method(D_METHOD("soft_body_set_simulation_precision", "body", "simulation_precision"), &PhysicsServer3D::soft_body_set_simulation_precision);
  677. ClassDB::bind_method(D_METHOD("soft_body_get_simulation_precision", "body"), &PhysicsServer3D::soft_body_get_simulation_precision);
  678. ClassDB::bind_method(D_METHOD("soft_body_set_total_mass", "body", "total_mass"), &PhysicsServer3D::soft_body_set_total_mass);
  679. ClassDB::bind_method(D_METHOD("soft_body_get_total_mass", "body"), &PhysicsServer3D::soft_body_get_total_mass);
  680. ClassDB::bind_method(D_METHOD("soft_body_set_linear_stiffness", "body", "stiffness"), &PhysicsServer3D::soft_body_set_linear_stiffness);
  681. ClassDB::bind_method(D_METHOD("soft_body_get_linear_stiffness", "body"), &PhysicsServer3D::soft_body_get_linear_stiffness);
  682. ClassDB::bind_method(D_METHOD("soft_body_set_shrinking_factor", "body", "shrinking_factor"), &PhysicsServer3D::soft_body_set_shrinking_factor);
  683. ClassDB::bind_method(D_METHOD("soft_body_get_shrinking_factor", "body"), &PhysicsServer3D::soft_body_get_shrinking_factor);
  684. ClassDB::bind_method(D_METHOD("soft_body_set_pressure_coefficient", "body", "pressure_coefficient"), &PhysicsServer3D::soft_body_set_pressure_coefficient);
  685. ClassDB::bind_method(D_METHOD("soft_body_get_pressure_coefficient", "body"), &PhysicsServer3D::soft_body_get_pressure_coefficient);
  686. ClassDB::bind_method(D_METHOD("soft_body_set_damping_coefficient", "body", "damping_coefficient"), &PhysicsServer3D::soft_body_set_damping_coefficient);
  687. ClassDB::bind_method(D_METHOD("soft_body_get_damping_coefficient", "body"), &PhysicsServer3D::soft_body_get_damping_coefficient);
  688. ClassDB::bind_method(D_METHOD("soft_body_set_drag_coefficient", "body", "drag_coefficient"), &PhysicsServer3D::soft_body_set_drag_coefficient);
  689. ClassDB::bind_method(D_METHOD("soft_body_get_drag_coefficient", "body"), &PhysicsServer3D::soft_body_get_drag_coefficient);
  690. ClassDB::bind_method(D_METHOD("soft_body_move_point", "body", "point_index", "global_position"), &PhysicsServer3D::soft_body_move_point);
  691. ClassDB::bind_method(D_METHOD("soft_body_get_point_global_position", "body", "point_index"), &PhysicsServer3D::soft_body_get_point_global_position);
  692. ClassDB::bind_method(D_METHOD("soft_body_remove_all_pinned_points", "body"), &PhysicsServer3D::soft_body_remove_all_pinned_points);
  693. ClassDB::bind_method(D_METHOD("soft_body_pin_point", "body", "point_index", "pin"), &PhysicsServer3D::soft_body_pin_point);
  694. ClassDB::bind_method(D_METHOD("soft_body_is_point_pinned", "body", "point_index"), &PhysicsServer3D::soft_body_is_point_pinned);
  695. ClassDB::bind_method(D_METHOD("soft_body_apply_point_impulse", "body", "point_index", "impulse"), &PhysicsServer3D::soft_body_apply_point_impulse);
  696. ClassDB::bind_method(D_METHOD("soft_body_apply_point_force", "body", "point_index", "force"), &PhysicsServer3D::soft_body_apply_point_force);
  697. ClassDB::bind_method(D_METHOD("soft_body_apply_central_impulse", "body", "impulse"), &PhysicsServer3D::soft_body_apply_central_impulse);
  698. ClassDB::bind_method(D_METHOD("soft_body_apply_central_force", "body", "force"), &PhysicsServer3D::soft_body_apply_central_force);
  699. /* JOINT API */
  700. ClassDB::bind_method(D_METHOD("joint_create"), &PhysicsServer3D::joint_create);
  701. ClassDB::bind_method(D_METHOD("joint_clear", "joint"), &PhysicsServer3D::joint_clear);
  702. BIND_ENUM_CONSTANT(JOINT_TYPE_PIN);
  703. BIND_ENUM_CONSTANT(JOINT_TYPE_HINGE);
  704. BIND_ENUM_CONSTANT(JOINT_TYPE_SLIDER);
  705. BIND_ENUM_CONSTANT(JOINT_TYPE_CONE_TWIST);
  706. BIND_ENUM_CONSTANT(JOINT_TYPE_6DOF);
  707. BIND_ENUM_CONSTANT(JOINT_TYPE_MAX);
  708. ClassDB::bind_method(D_METHOD("joint_make_pin", "joint", "body_A", "local_A", "body_B", "local_B"), &PhysicsServer3D::joint_make_pin);
  709. ClassDB::bind_method(D_METHOD("pin_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::pin_joint_set_param);
  710. ClassDB::bind_method(D_METHOD("pin_joint_get_param", "joint", "param"), &PhysicsServer3D::pin_joint_get_param);
  711. ClassDB::bind_method(D_METHOD("pin_joint_set_local_a", "joint", "local_A"), &PhysicsServer3D::pin_joint_set_local_a);
  712. ClassDB::bind_method(D_METHOD("pin_joint_get_local_a", "joint"), &PhysicsServer3D::pin_joint_get_local_a);
  713. ClassDB::bind_method(D_METHOD("pin_joint_set_local_b", "joint", "local_B"), &PhysicsServer3D::pin_joint_set_local_b);
  714. ClassDB::bind_method(D_METHOD("pin_joint_get_local_b", "joint"), &PhysicsServer3D::pin_joint_get_local_b);
  715. BIND_ENUM_CONSTANT(PIN_JOINT_BIAS);
  716. BIND_ENUM_CONSTANT(PIN_JOINT_DAMPING);
  717. BIND_ENUM_CONSTANT(PIN_JOINT_IMPULSE_CLAMP);
  718. BIND_ENUM_CONSTANT(HINGE_JOINT_BIAS);
  719. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_UPPER);
  720. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_LOWER);
  721. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_BIAS);
  722. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_SOFTNESS);
  723. BIND_ENUM_CONSTANT(HINGE_JOINT_LIMIT_RELAXATION);
  724. BIND_ENUM_CONSTANT(HINGE_JOINT_MOTOR_TARGET_VELOCITY);
  725. BIND_ENUM_CONSTANT(HINGE_JOINT_MOTOR_MAX_IMPULSE);
  726. BIND_ENUM_CONSTANT(HINGE_JOINT_FLAG_USE_LIMIT);
  727. BIND_ENUM_CONSTANT(HINGE_JOINT_FLAG_ENABLE_MOTOR);
  728. ClassDB::bind_method(D_METHOD("joint_make_hinge", "joint", "body_A", "hinge_A", "body_B", "hinge_B"), &PhysicsServer3D::joint_make_hinge);
  729. ClassDB::bind_method(D_METHOD("hinge_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::hinge_joint_set_param);
  730. ClassDB::bind_method(D_METHOD("hinge_joint_get_param", "joint", "param"), &PhysicsServer3D::hinge_joint_get_param);
  731. ClassDB::bind_method(D_METHOD("hinge_joint_set_flag", "joint", "flag", "enabled"), &PhysicsServer3D::hinge_joint_set_flag);
  732. ClassDB::bind_method(D_METHOD("hinge_joint_get_flag", "joint", "flag"), &PhysicsServer3D::hinge_joint_get_flag);
  733. ClassDB::bind_method(D_METHOD("joint_make_slider", "joint", "body_A", "local_ref_A", "body_B", "local_ref_B"), &PhysicsServer3D::joint_make_slider);
  734. ClassDB::bind_method(D_METHOD("slider_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::slider_joint_set_param);
  735. ClassDB::bind_method(D_METHOD("slider_joint_get_param", "joint", "param"), &PhysicsServer3D::slider_joint_get_param);
  736. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_UPPER);
  737. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_LOWER);
  738. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS);
  739. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION);
  740. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_LIMIT_DAMPING);
  741. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_SOFTNESS);
  742. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_RESTITUTION);
  743. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_MOTION_DAMPING);
  744. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS);
  745. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION);
  746. BIND_ENUM_CONSTANT(SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING);
  747. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_UPPER);
  748. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_LOWER);
  749. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS);
  750. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION);
  751. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_LIMIT_DAMPING);
  752. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS);
  753. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION);
  754. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_MOTION_DAMPING);
  755. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS);
  756. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION);
  757. BIND_ENUM_CONSTANT(SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING);
  758. BIND_ENUM_CONSTANT(SLIDER_JOINT_MAX);
  759. 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);
  760. ClassDB::bind_method(D_METHOD("cone_twist_joint_set_param", "joint", "param", "value"), &PhysicsServer3D::cone_twist_joint_set_param);
  761. ClassDB::bind_method(D_METHOD("cone_twist_joint_get_param", "joint", "param"), &PhysicsServer3D::cone_twist_joint_get_param);
  762. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_SWING_SPAN);
  763. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_TWIST_SPAN);
  764. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_BIAS);
  765. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_SOFTNESS);
  766. BIND_ENUM_CONSTANT(CONE_TWIST_JOINT_RELAXATION);
  767. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_LOWER_LIMIT);
  768. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_UPPER_LIMIT);
  769. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS);
  770. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_RESTITUTION);
  771. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_DAMPING);
  772. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY);
  773. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT);
  774. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_SPRING_STIFFNESS);
  775. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_SPRING_DAMPING);
  776. BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT);
  777. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_LOWER_LIMIT);
  778. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_UPPER_LIMIT);
  779. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS);
  780. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_DAMPING);
  781. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_RESTITUTION);
  782. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_FORCE_LIMIT);
  783. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_ERP);
  784. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY);
  785. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT);
  786. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS);
  787. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_SPRING_DAMPING);
  788. BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT);
  789. BIND_ENUM_CONSTANT(G6DOF_JOINT_MAX);
  790. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT);
  791. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT);
  792. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING);
  793. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING);
  794. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_MOTOR);
  795. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR);
  796. BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_MAX);
  797. ClassDB::bind_method(D_METHOD("joint_get_type", "joint"), &PhysicsServer3D::joint_get_type);
  798. ClassDB::bind_method(D_METHOD("joint_set_solver_priority", "joint", "priority"), &PhysicsServer3D::joint_set_solver_priority);
  799. ClassDB::bind_method(D_METHOD("joint_get_solver_priority", "joint"), &PhysicsServer3D::joint_get_solver_priority);
  800. ClassDB::bind_method(D_METHOD("joint_disable_collisions_between_bodies", "joint", "disable"), &PhysicsServer3D::joint_disable_collisions_between_bodies);
  801. ClassDB::bind_method(D_METHOD("joint_is_disabled_collisions_between_bodies", "joint"), &PhysicsServer3D::joint_is_disabled_collisions_between_bodies);
  802. 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);
  803. ClassDB::bind_method(D_METHOD("generic_6dof_joint_set_param", "joint", "axis", "param", "value"), &PhysicsServer3D::generic_6dof_joint_set_param);
  804. ClassDB::bind_method(D_METHOD("generic_6dof_joint_get_param", "joint", "axis", "param"), &PhysicsServer3D::generic_6dof_joint_get_param);
  805. ClassDB::bind_method(D_METHOD("generic_6dof_joint_set_flag", "joint", "axis", "flag", "enable"), &PhysicsServer3D::generic_6dof_joint_set_flag);
  806. ClassDB::bind_method(D_METHOD("generic_6dof_joint_get_flag", "joint", "axis", "flag"), &PhysicsServer3D::generic_6dof_joint_get_flag);
  807. ClassDB::bind_method(D_METHOD("free_rid", "rid"), &PhysicsServer3D::free);
  808. ClassDB::bind_method(D_METHOD("set_active", "active"), &PhysicsServer3D::set_active);
  809. ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &PhysicsServer3D::get_process_info);
  810. BIND_ENUM_CONSTANT(SHAPE_WORLD_BOUNDARY);
  811. BIND_ENUM_CONSTANT(SHAPE_SEPARATION_RAY);
  812. BIND_ENUM_CONSTANT(SHAPE_SPHERE);
  813. BIND_ENUM_CONSTANT(SHAPE_BOX);
  814. BIND_ENUM_CONSTANT(SHAPE_CAPSULE);
  815. BIND_ENUM_CONSTANT(SHAPE_CYLINDER);
  816. BIND_ENUM_CONSTANT(SHAPE_CONVEX_POLYGON);
  817. BIND_ENUM_CONSTANT(SHAPE_CONCAVE_POLYGON);
  818. BIND_ENUM_CONSTANT(SHAPE_HEIGHTMAP);
  819. BIND_ENUM_CONSTANT(SHAPE_SOFT_BODY);
  820. BIND_ENUM_CONSTANT(SHAPE_CUSTOM);
  821. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_OVERRIDE_MODE);
  822. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY);
  823. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_VECTOR);
  824. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_IS_POINT);
  825. BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE);
  826. BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE);
  827. BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP);
  828. BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE);
  829. BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP);
  830. BIND_ENUM_CONSTANT(AREA_PARAM_PRIORITY);
  831. BIND_ENUM_CONSTANT(AREA_PARAM_WIND_FORCE_MAGNITUDE);
  832. BIND_ENUM_CONSTANT(AREA_PARAM_WIND_SOURCE);
  833. BIND_ENUM_CONSTANT(AREA_PARAM_WIND_DIRECTION);
  834. BIND_ENUM_CONSTANT(AREA_PARAM_WIND_ATTENUATION_FACTOR);
  835. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_DISABLED);
  836. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_COMBINE);
  837. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_COMBINE_REPLACE);
  838. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_REPLACE);
  839. BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_REPLACE_COMBINE);
  840. BIND_ENUM_CONSTANT(BODY_MODE_STATIC);
  841. BIND_ENUM_CONSTANT(BODY_MODE_KINEMATIC);
  842. BIND_ENUM_CONSTANT(BODY_MODE_RIGID);
  843. BIND_ENUM_CONSTANT(BODY_MODE_RIGID_LINEAR);
  844. BIND_ENUM_CONSTANT(BODY_PARAM_BOUNCE);
  845. BIND_ENUM_CONSTANT(BODY_PARAM_FRICTION);
  846. BIND_ENUM_CONSTANT(BODY_PARAM_MASS);
  847. BIND_ENUM_CONSTANT(BODY_PARAM_INERTIA);
  848. BIND_ENUM_CONSTANT(BODY_PARAM_CENTER_OF_MASS);
  849. BIND_ENUM_CONSTANT(BODY_PARAM_GRAVITY_SCALE);
  850. BIND_ENUM_CONSTANT(BODY_PARAM_LINEAR_DAMP_MODE);
  851. BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP_MODE);
  852. BIND_ENUM_CONSTANT(BODY_PARAM_LINEAR_DAMP);
  853. BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP);
  854. BIND_ENUM_CONSTANT(BODY_PARAM_MAX);
  855. BIND_ENUM_CONSTANT(BODY_DAMP_MODE_COMBINE);
  856. BIND_ENUM_CONSTANT(BODY_DAMP_MODE_REPLACE);
  857. BIND_ENUM_CONSTANT(BODY_STATE_TRANSFORM);
  858. BIND_ENUM_CONSTANT(BODY_STATE_LINEAR_VELOCITY);
  859. BIND_ENUM_CONSTANT(BODY_STATE_ANGULAR_VELOCITY);
  860. BIND_ENUM_CONSTANT(BODY_STATE_SLEEPING);
  861. BIND_ENUM_CONSTANT(BODY_STATE_CAN_SLEEP);
  862. BIND_ENUM_CONSTANT(AREA_BODY_ADDED);
  863. BIND_ENUM_CONSTANT(AREA_BODY_REMOVED);
  864. BIND_ENUM_CONSTANT(INFO_ACTIVE_OBJECTS);
  865. BIND_ENUM_CONSTANT(INFO_COLLISION_PAIRS);
  866. BIND_ENUM_CONSTANT(INFO_ISLAND_COUNT);
  867. BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_RECYCLE_RADIUS);
  868. BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_SEPARATION);
  869. BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION);
  870. BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_DEFAULT_BIAS);
  871. BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD);
  872. BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD);
  873. BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_TIME_TO_SLEEP);
  874. BIND_ENUM_CONSTANT(SPACE_PARAM_SOLVER_ITERATIONS);
  875. BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_X);
  876. BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_Y);
  877. BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_Z);
  878. BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_X);
  879. BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_Y);
  880. BIND_ENUM_CONSTANT(BODY_AXIS_ANGULAR_Z);
  881. #endif
  882. }
  883. PhysicsServer3D::PhysicsServer3D() {
  884. singleton = this;
  885. // World3D physics space
  886. GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "physics/3d/default_gravity", PROPERTY_HINT_RANGE, U"-32,32,0.001,or_less,or_greater,suffix:m/s\u00B2"), 9.8);
  887. GLOBAL_DEF_BASIC(PropertyInfo(Variant::VECTOR3, "physics/3d/default_gravity_vector", PROPERTY_HINT_RANGE, "-10,10,0.001,or_less,or_greater"), Vector3(0, -1, 0));
  888. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/default_linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), 0.1);
  889. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/default_angular_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), 0.1);
  890. // PhysicsServer3D
  891. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/sleep_threshold_linear", PROPERTY_HINT_RANGE, "0,1,0.001,or_greater"), 0.1);
  892. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/sleep_threshold_angular", PROPERTY_HINT_RANGE, "0,90,0.1,radians_as_degrees"), Math::deg_to_rad(8.0));
  893. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/time_before_sleep", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater"), 0.5);
  894. GLOBAL_DEF(PropertyInfo(Variant::INT, "physics/3d/solver/solver_iterations", PROPERTY_HINT_RANGE, "1,32,1,or_greater"), 16);
  895. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/contact_recycle_radius", PROPERTY_HINT_RANGE, "0,0.1,0.001,or_greater"), 0.01);
  896. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/contact_max_separation", PROPERTY_HINT_RANGE, "0,0.1,0.001,or_greater"), 0.05);
  897. 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);
  898. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/solver/default_contact_bias", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.8);
  899. }
  900. PhysicsServer3D::~PhysicsServer3D() {
  901. singleton = nullptr;
  902. }
  903. PhysicsServer3DManager *PhysicsServer3DManager::singleton = nullptr;
  904. const String PhysicsServer3DManager::setting_property_name(PNAME("physics/3d/physics_engine"));
  905. void PhysicsServer3DManager::on_servers_changed() {
  906. String physics_servers2("DEFAULT");
  907. for (int i = get_servers_count() - 1; 0 <= i; --i) {
  908. physics_servers2 += "," + get_server_name(i);
  909. }
  910. ProjectSettings::get_singleton()->set_custom_property_info(PropertyInfo(Variant::STRING, setting_property_name, PROPERTY_HINT_ENUM, physics_servers2));
  911. ProjectSettings::get_singleton()->set_restart_if_changed(setting_property_name, true);
  912. ProjectSettings::get_singleton()->set_as_basic(setting_property_name, true);
  913. }
  914. void PhysicsServer3DManager::_bind_methods() {
  915. ClassDB::bind_method(D_METHOD("register_server", "name", "create_callback"), &PhysicsServer3DManager::register_server);
  916. ClassDB::bind_method(D_METHOD("set_default_server", "name", "priority"), &PhysicsServer3DManager::set_default_server);
  917. }
  918. PhysicsServer3DManager *PhysicsServer3DManager::get_singleton() {
  919. return singleton;
  920. }
  921. void PhysicsServer3DManager::register_server(const String &p_name, const Callable &p_create_callback) {
  922. //ERR_FAIL_COND(!p_create_callback.is_valid());
  923. ERR_FAIL_COND(find_server_id(p_name) != -1);
  924. physics_servers.push_back(ClassInfo(p_name, p_create_callback));
  925. on_servers_changed();
  926. }
  927. void PhysicsServer3DManager::set_default_server(const String &p_name, int p_priority) {
  928. const int id = find_server_id(p_name);
  929. ERR_FAIL_COND(id == -1); // Not found
  930. if (default_server_priority < p_priority) {
  931. default_server_id = id;
  932. default_server_priority = p_priority;
  933. }
  934. }
  935. int PhysicsServer3DManager::find_server_id(const String &p_name) {
  936. for (int i = physics_servers.size() - 1; 0 <= i; --i) {
  937. if (p_name == physics_servers[i].name) {
  938. return i;
  939. }
  940. }
  941. return -1;
  942. }
  943. int PhysicsServer3DManager::get_servers_count() {
  944. return physics_servers.size();
  945. }
  946. String PhysicsServer3DManager::get_server_name(int p_id) {
  947. ERR_FAIL_INDEX_V(p_id, get_servers_count(), "");
  948. return physics_servers[p_id].name;
  949. }
  950. PhysicsServer3D *PhysicsServer3DManager::new_default_server() {
  951. if (default_server_id == -1) {
  952. return nullptr;
  953. }
  954. Variant ret;
  955. Callable::CallError ce;
  956. physics_servers[default_server_id].create_callback.callp(nullptr, 0, ret, ce);
  957. ERR_FAIL_COND_V(ce.error != Callable::CallError::CALL_OK, nullptr);
  958. return Object::cast_to<PhysicsServer3D>(ret.get_validated_object());
  959. }
  960. PhysicsServer3D *PhysicsServer3DManager::new_server(const String &p_name) {
  961. int id = find_server_id(p_name);
  962. if (id == -1) {
  963. return nullptr;
  964. } else {
  965. Variant ret;
  966. Callable::CallError ce;
  967. physics_servers[id].create_callback.callp(nullptr, 0, ret, ce);
  968. ERR_FAIL_COND_V(ce.error != Callable::CallError::CALL_OK, nullptr);
  969. return Object::cast_to<PhysicsServer3D>(ret.get_validated_object());
  970. }
  971. }
  972. PhysicsServer3DManager::PhysicsServer3DManager() {
  973. singleton = this;
  974. }
  975. PhysicsServer3DManager::~PhysicsServer3DManager() {
  976. singleton = nullptr;
  977. }
  978. #endif // _3D_DISABLED