bullet_physics_server.cpp 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530
  1. /*************************************************************************/
  2. /* bullet_physics_server.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "bullet_physics_server.h"
  31. #include "bullet_utilities.h"
  32. #include "cone_twist_joint_bullet.h"
  33. #include "core/error/error_macros.h"
  34. #include "core/object/class_db.h"
  35. #include "core/string/ustring.h"
  36. #include "generic_6dof_joint_bullet.h"
  37. #include "hinge_joint_bullet.h"
  38. #include "pin_joint_bullet.h"
  39. #include "shape_bullet.h"
  40. #include "slider_joint_bullet.h"
  41. #include <LinearMath/btVector3.h>
  42. #include <assert.h>
  43. /**
  44. @author AndreaCatania
  45. */
  46. #define CreateThenReturnRID(owner, ridData) \
  47. RID rid = owner.make_rid(ridData); \
  48. ridData->set_self(rid); \
  49. ridData->_set_physics_server(this); \
  50. return rid;
  51. // <--------------- Joint creation asserts
  52. /// Assert the body is assigned to a space
  53. #define JointAssertSpace(body, bIndex, ret) \
  54. if (!body->get_space()) { \
  55. ERR_PRINT("Before create a joint the Body" + String(bIndex) + " must be added to a space!"); \
  56. return ret; \
  57. }
  58. /// Assert the two bodies of joint are in the same space
  59. #define JointAssertSameSpace(bodyA, bodyB, ret) \
  60. if (bodyA->get_space() != bodyB->get_space()) { \
  61. ERR_PRINT("In order to create a joint the Body_A and Body_B must be in the same space!"); \
  62. return RID(); \
  63. }
  64. #define AddJointToSpace(body, joint) \
  65. body->get_space()->add_constraint(joint, joint->is_disabled_collisions_between_bodies());
  66. // <--------------- Joint creation asserts
  67. void BulletPhysicsServer3D::_bind_methods() {
  68. //ClassDB::bind_method(D_METHOD("DoTest"), &BulletPhysicsServer3D::DoTest);
  69. }
  70. BulletPhysicsServer3D::BulletPhysicsServer3D() :
  71. PhysicsServer3D() {}
  72. BulletPhysicsServer3D::~BulletPhysicsServer3D() {}
  73. RID BulletPhysicsServer3D::shape_create(ShapeType p_shape) {
  74. ShapeBullet *shape = nullptr;
  75. switch (p_shape) {
  76. case SHAPE_WORLD_BOUNDARY: {
  77. shape = bulletnew(WorldBoundaryShapeBullet);
  78. } break;
  79. case SHAPE_SPHERE: {
  80. shape = bulletnew(SphereShapeBullet);
  81. } break;
  82. case SHAPE_BOX: {
  83. shape = bulletnew(BoxShapeBullet);
  84. } break;
  85. case SHAPE_CAPSULE: {
  86. shape = bulletnew(CapsuleShapeBullet);
  87. } break;
  88. case SHAPE_CYLINDER: {
  89. shape = bulletnew(CylinderShapeBullet);
  90. } break;
  91. case SHAPE_CONVEX_POLYGON: {
  92. shape = bulletnew(ConvexPolygonShapeBullet);
  93. } break;
  94. case SHAPE_CONCAVE_POLYGON: {
  95. shape = bulletnew(ConcavePolygonShapeBullet);
  96. } break;
  97. case SHAPE_HEIGHTMAP: {
  98. shape = bulletnew(HeightMapShapeBullet);
  99. } break;
  100. case SHAPE_RAY: {
  101. shape = bulletnew(RayShapeBullet);
  102. } break;
  103. case SHAPE_CUSTOM:
  104. default:
  105. ERR_FAIL_V(RID());
  106. break;
  107. }
  108. CreateThenReturnRID(shape_owner, shape)
  109. }
  110. void BulletPhysicsServer3D::shape_set_data(RID p_shape, const Variant &p_data) {
  111. ShapeBullet *shape = shape_owner.getornull(p_shape);
  112. ERR_FAIL_COND(!shape);
  113. shape->set_data(p_data);
  114. }
  115. void BulletPhysicsServer3D::shape_set_custom_solver_bias(RID p_shape, real_t p_bias) {
  116. //WARN_PRINT("Bias not supported by Bullet physics engine");
  117. }
  118. PhysicsServer3D::ShapeType BulletPhysicsServer3D::shape_get_type(RID p_shape) const {
  119. ShapeBullet *shape = shape_owner.getornull(p_shape);
  120. ERR_FAIL_COND_V(!shape, PhysicsServer3D::SHAPE_CUSTOM);
  121. return shape->get_type();
  122. }
  123. Variant BulletPhysicsServer3D::shape_get_data(RID p_shape) const {
  124. ShapeBullet *shape = shape_owner.getornull(p_shape);
  125. ERR_FAIL_COND_V(!shape, Variant());
  126. return shape->get_data();
  127. }
  128. void BulletPhysicsServer3D::shape_set_margin(RID p_shape, real_t p_margin) {
  129. ShapeBullet *shape = shape_owner.getornull(p_shape);
  130. ERR_FAIL_COND(!shape);
  131. shape->set_margin(p_margin);
  132. }
  133. real_t BulletPhysicsServer3D::shape_get_margin(RID p_shape) const {
  134. ShapeBullet *shape = shape_owner.getornull(p_shape);
  135. ERR_FAIL_COND_V(!shape, 0.0);
  136. return shape->get_margin();
  137. }
  138. real_t BulletPhysicsServer3D::shape_get_custom_solver_bias(RID p_shape) const {
  139. //WARN_PRINT("Bias not supported by Bullet physics engine");
  140. return 0.;
  141. }
  142. RID BulletPhysicsServer3D::space_create() {
  143. SpaceBullet *space = bulletnew(SpaceBullet);
  144. CreateThenReturnRID(space_owner, space);
  145. }
  146. void BulletPhysicsServer3D::space_set_active(RID p_space, bool p_active) {
  147. SpaceBullet *space = space_owner.getornull(p_space);
  148. ERR_FAIL_COND(!space);
  149. if (space_is_active(p_space) == p_active) {
  150. return;
  151. }
  152. if (p_active) {
  153. ++active_spaces_count;
  154. active_spaces.push_back(space);
  155. } else {
  156. --active_spaces_count;
  157. active_spaces.erase(space);
  158. }
  159. }
  160. bool BulletPhysicsServer3D::space_is_active(RID p_space) const {
  161. SpaceBullet *space = space_owner.getornull(p_space);
  162. ERR_FAIL_COND_V(!space, false);
  163. return -1 != active_spaces.find(space);
  164. }
  165. void BulletPhysicsServer3D::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) {
  166. SpaceBullet *space = space_owner.getornull(p_space);
  167. ERR_FAIL_COND(!space);
  168. space->set_param(p_param, p_value);
  169. }
  170. real_t BulletPhysicsServer3D::space_get_param(RID p_space, SpaceParameter p_param) const {
  171. SpaceBullet *space = space_owner.getornull(p_space);
  172. ERR_FAIL_COND_V(!space, 0);
  173. return space->get_param(p_param);
  174. }
  175. PhysicsDirectSpaceState3D *BulletPhysicsServer3D::space_get_direct_state(RID p_space) {
  176. SpaceBullet *space = space_owner.getornull(p_space);
  177. ERR_FAIL_COND_V(!space, nullptr);
  178. return space->get_direct_state();
  179. }
  180. void BulletPhysicsServer3D::space_set_debug_contacts(RID p_space, int p_max_contacts) {
  181. SpaceBullet *space = space_owner.getornull(p_space);
  182. ERR_FAIL_COND(!space);
  183. space->set_debug_contacts(p_max_contacts);
  184. }
  185. Vector<Vector3> BulletPhysicsServer3D::space_get_contacts(RID p_space) const {
  186. SpaceBullet *space = space_owner.getornull(p_space);
  187. ERR_FAIL_COND_V(!space, Vector<Vector3>());
  188. return space->get_debug_contacts();
  189. }
  190. int BulletPhysicsServer3D::space_get_contact_count(RID p_space) const {
  191. SpaceBullet *space = space_owner.getornull(p_space);
  192. ERR_FAIL_COND_V(!space, 0);
  193. return space->get_debug_contact_count();
  194. }
  195. RID BulletPhysicsServer3D::area_create() {
  196. AreaBullet *area = bulletnew(AreaBullet);
  197. area->set_collision_layer(1);
  198. area->set_collision_mask(1);
  199. CreateThenReturnRID(area_owner, area)
  200. }
  201. void BulletPhysicsServer3D::area_set_space(RID p_area, RID p_space) {
  202. AreaBullet *area = area_owner.getornull(p_area);
  203. ERR_FAIL_COND(!area);
  204. SpaceBullet *space = nullptr;
  205. if (p_space.is_valid()) {
  206. space = space_owner.getornull(p_space);
  207. ERR_FAIL_COND(!space);
  208. }
  209. area->set_space(space);
  210. }
  211. RID BulletPhysicsServer3D::area_get_space(RID p_area) const {
  212. AreaBullet *area = area_owner.getornull(p_area);
  213. return area->get_space()->get_self();
  214. }
  215. void BulletPhysicsServer3D::area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) {
  216. AreaBullet *area = area_owner.getornull(p_area);
  217. ERR_FAIL_COND(!area);
  218. area->set_spOv_mode(p_mode);
  219. }
  220. PhysicsServer3D::AreaSpaceOverrideMode BulletPhysicsServer3D::area_get_space_override_mode(RID p_area) const {
  221. AreaBullet *area = area_owner.getornull(p_area);
  222. ERR_FAIL_COND_V(!area, PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED);
  223. return area->get_spOv_mode();
  224. }
  225. void BulletPhysicsServer3D::area_add_shape(RID p_area, RID p_shape, const Transform3D &p_transform, bool p_disabled) {
  226. AreaBullet *area = area_owner.getornull(p_area);
  227. ERR_FAIL_COND(!area);
  228. ShapeBullet *shape = shape_owner.getornull(p_shape);
  229. ERR_FAIL_COND(!shape);
  230. area->add_shape(shape, p_transform, p_disabled);
  231. }
  232. void BulletPhysicsServer3D::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) {
  233. AreaBullet *area = area_owner.getornull(p_area);
  234. ERR_FAIL_COND(!area);
  235. ShapeBullet *shape = shape_owner.getornull(p_shape);
  236. ERR_FAIL_COND(!shape);
  237. area->set_shape(p_shape_idx, shape);
  238. }
  239. void BulletPhysicsServer3D::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform3D &p_transform) {
  240. AreaBullet *area = area_owner.getornull(p_area);
  241. ERR_FAIL_COND(!area);
  242. area->set_shape_transform(p_shape_idx, p_transform);
  243. }
  244. int BulletPhysicsServer3D::area_get_shape_count(RID p_area) const {
  245. AreaBullet *area = area_owner.getornull(p_area);
  246. ERR_FAIL_COND_V(!area, 0);
  247. return area->get_shape_count();
  248. }
  249. RID BulletPhysicsServer3D::area_get_shape(RID p_area, int p_shape_idx) const {
  250. AreaBullet *area = area_owner.getornull(p_area);
  251. ERR_FAIL_COND_V(!area, RID());
  252. return area->get_shape(p_shape_idx)->get_self();
  253. }
  254. Transform3D BulletPhysicsServer3D::area_get_shape_transform(RID p_area, int p_shape_idx) const {
  255. AreaBullet *area = area_owner.getornull(p_area);
  256. ERR_FAIL_COND_V(!area, Transform3D());
  257. return area->get_shape_transform(p_shape_idx);
  258. }
  259. void BulletPhysicsServer3D::area_remove_shape(RID p_area, int p_shape_idx) {
  260. AreaBullet *area = area_owner.getornull(p_area);
  261. ERR_FAIL_COND(!area);
  262. return area->remove_shape_full(p_shape_idx);
  263. }
  264. void BulletPhysicsServer3D::area_clear_shapes(RID p_area) {
  265. AreaBullet *area = area_owner.getornull(p_area);
  266. ERR_FAIL_COND(!area);
  267. for (int i = area->get_shape_count(); 0 < i; --i) {
  268. area->remove_shape_full(0);
  269. }
  270. }
  271. void BulletPhysicsServer3D::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) {
  272. AreaBullet *area = area_owner.getornull(p_area);
  273. ERR_FAIL_COND(!area);
  274. area->set_shape_disabled(p_shape_idx, p_disabled);
  275. }
  276. void BulletPhysicsServer3D::area_attach_object_instance_id(RID p_area, ObjectID p_id) {
  277. if (space_owner.owns(p_area)) {
  278. return;
  279. }
  280. AreaBullet *area = area_owner.getornull(p_area);
  281. ERR_FAIL_COND(!area);
  282. area->set_instance_id(p_id);
  283. }
  284. ObjectID BulletPhysicsServer3D::area_get_object_instance_id(RID p_area) const {
  285. if (space_owner.owns(p_area)) {
  286. return ObjectID();
  287. }
  288. AreaBullet *area = area_owner.getornull(p_area);
  289. ERR_FAIL_COND_V(!area, ObjectID());
  290. return area->get_instance_id();
  291. }
  292. void BulletPhysicsServer3D::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) {
  293. if (space_owner.owns(p_area)) {
  294. SpaceBullet *space = space_owner.getornull(p_area);
  295. if (space) {
  296. space->set_param(p_param, p_value);
  297. }
  298. } else {
  299. AreaBullet *area = area_owner.getornull(p_area);
  300. ERR_FAIL_COND(!area);
  301. area->set_param(p_param, p_value);
  302. }
  303. }
  304. Variant BulletPhysicsServer3D::area_get_param(RID p_area, AreaParameter p_param) const {
  305. if (space_owner.owns(p_area)) {
  306. SpaceBullet *space = space_owner.getornull(p_area);
  307. return space->get_param(p_param);
  308. } else {
  309. AreaBullet *area = area_owner.getornull(p_area);
  310. ERR_FAIL_COND_V(!area, Variant());
  311. return area->get_param(p_param);
  312. }
  313. }
  314. void BulletPhysicsServer3D::area_set_transform(RID p_area, const Transform3D &p_transform) {
  315. AreaBullet *area = area_owner.getornull(p_area);
  316. ERR_FAIL_COND(!area);
  317. area->set_transform(p_transform);
  318. }
  319. Transform3D BulletPhysicsServer3D::area_get_transform(RID p_area) const {
  320. AreaBullet *area = area_owner.getornull(p_area);
  321. ERR_FAIL_COND_V(!area, Transform3D());
  322. return area->get_transform();
  323. }
  324. void BulletPhysicsServer3D::area_set_collision_mask(RID p_area, uint32_t p_mask) {
  325. AreaBullet *area = area_owner.getornull(p_area);
  326. ERR_FAIL_COND(!area);
  327. area->set_collision_mask(p_mask);
  328. }
  329. void BulletPhysicsServer3D::area_set_collision_layer(RID p_area, uint32_t p_layer) {
  330. AreaBullet *area = area_owner.getornull(p_area);
  331. ERR_FAIL_COND(!area);
  332. area->set_collision_layer(p_layer);
  333. }
  334. void BulletPhysicsServer3D::area_set_monitorable(RID p_area, bool p_monitorable) {
  335. AreaBullet *area = area_owner.getornull(p_area);
  336. ERR_FAIL_COND(!area);
  337. area->set_monitorable(p_monitorable);
  338. }
  339. void BulletPhysicsServer3D::area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) {
  340. AreaBullet *area = area_owner.getornull(p_area);
  341. ERR_FAIL_COND(!area);
  342. area->set_event_callback(CollisionObjectBullet::TYPE_RIGID_BODY, p_receiver ? p_receiver->get_instance_id() : ObjectID(), p_method);
  343. }
  344. void BulletPhysicsServer3D::area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) {
  345. AreaBullet *area = area_owner.getornull(p_area);
  346. ERR_FAIL_COND(!area);
  347. area->set_event_callback(CollisionObjectBullet::TYPE_AREA, p_receiver ? p_receiver->get_instance_id() : ObjectID(), p_method);
  348. }
  349. void BulletPhysicsServer3D::area_set_ray_pickable(RID p_area, bool p_enable) {
  350. AreaBullet *area = area_owner.getornull(p_area);
  351. ERR_FAIL_COND(!area);
  352. area->set_ray_pickable(p_enable);
  353. }
  354. RID BulletPhysicsServer3D::body_create(BodyMode p_mode, bool p_init_sleeping) {
  355. RigidBodyBullet *body = bulletnew(RigidBodyBullet);
  356. body->set_mode(p_mode);
  357. body->set_collision_layer(1);
  358. body->set_collision_mask(1);
  359. if (p_init_sleeping) {
  360. body->set_state(BODY_STATE_SLEEPING, p_init_sleeping);
  361. }
  362. CreateThenReturnRID(rigid_body_owner, body);
  363. }
  364. void BulletPhysicsServer3D::body_set_space(RID p_body, RID p_space) {
  365. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  366. ERR_FAIL_COND(!body);
  367. SpaceBullet *space = nullptr;
  368. if (p_space.is_valid()) {
  369. space = space_owner.getornull(p_space);
  370. ERR_FAIL_COND(!space);
  371. }
  372. if (body->get_space() == space) {
  373. return; //pointless
  374. }
  375. body->set_space(space);
  376. }
  377. RID BulletPhysicsServer3D::body_get_space(RID p_body) const {
  378. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  379. ERR_FAIL_COND_V(!body, RID());
  380. SpaceBullet *space = body->get_space();
  381. if (!space) {
  382. return RID();
  383. }
  384. return space->get_self();
  385. }
  386. void BulletPhysicsServer3D::body_set_mode(RID p_body, PhysicsServer3D::BodyMode p_mode) {
  387. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  388. ERR_FAIL_COND(!body);
  389. body->set_mode(p_mode);
  390. }
  391. PhysicsServer3D::BodyMode BulletPhysicsServer3D::body_get_mode(RID p_body) const {
  392. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  393. ERR_FAIL_COND_V(!body, BODY_MODE_STATIC);
  394. return body->get_mode();
  395. }
  396. void BulletPhysicsServer3D::body_add_shape(RID p_body, RID p_shape, const Transform3D &p_transform, bool p_disabled) {
  397. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  398. ERR_FAIL_COND(!body);
  399. ShapeBullet *shape = shape_owner.getornull(p_shape);
  400. ERR_FAIL_COND(!shape);
  401. body->add_shape(shape, p_transform, p_disabled);
  402. }
  403. void BulletPhysicsServer3D::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) {
  404. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  405. ERR_FAIL_COND(!body);
  406. ShapeBullet *shape = shape_owner.getornull(p_shape);
  407. ERR_FAIL_COND(!shape);
  408. body->set_shape(p_shape_idx, shape);
  409. }
  410. void BulletPhysicsServer3D::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform3D &p_transform) {
  411. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  412. ERR_FAIL_COND(!body);
  413. body->set_shape_transform(p_shape_idx, p_transform);
  414. }
  415. int BulletPhysicsServer3D::body_get_shape_count(RID p_body) const {
  416. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  417. ERR_FAIL_COND_V(!body, 0);
  418. return body->get_shape_count();
  419. }
  420. RID BulletPhysicsServer3D::body_get_shape(RID p_body, int p_shape_idx) const {
  421. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  422. ERR_FAIL_COND_V(!body, RID());
  423. ShapeBullet *shape = body->get_shape(p_shape_idx);
  424. ERR_FAIL_COND_V(!shape, RID());
  425. return shape->get_self();
  426. }
  427. Transform3D BulletPhysicsServer3D::body_get_shape_transform(RID p_body, int p_shape_idx) const {
  428. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  429. ERR_FAIL_COND_V(!body, Transform3D());
  430. return body->get_shape_transform(p_shape_idx);
  431. }
  432. void BulletPhysicsServer3D::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) {
  433. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  434. ERR_FAIL_COND(!body);
  435. body->set_shape_disabled(p_shape_idx, p_disabled);
  436. }
  437. void BulletPhysicsServer3D::body_remove_shape(RID p_body, int p_shape_idx) {
  438. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  439. ERR_FAIL_COND(!body);
  440. body->remove_shape_full(p_shape_idx);
  441. }
  442. void BulletPhysicsServer3D::body_clear_shapes(RID p_body) {
  443. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  444. ERR_FAIL_COND(!body);
  445. body->remove_all_shapes();
  446. }
  447. void BulletPhysicsServer3D::body_attach_object_instance_id(RID p_body, ObjectID p_id) {
  448. CollisionObjectBullet *body = get_collision_object(p_body);
  449. ERR_FAIL_COND(!body);
  450. body->set_instance_id(p_id);
  451. }
  452. ObjectID BulletPhysicsServer3D::body_get_object_instance_id(RID p_body) const {
  453. CollisionObjectBullet *body = get_collision_object(p_body);
  454. ERR_FAIL_COND_V(!body, ObjectID());
  455. return body->get_instance_id();
  456. }
  457. void BulletPhysicsServer3D::body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) {
  458. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  459. ERR_FAIL_COND(!body);
  460. body->set_continuous_collision_detection(p_enable);
  461. }
  462. bool BulletPhysicsServer3D::body_is_continuous_collision_detection_enabled(RID p_body) const {
  463. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  464. ERR_FAIL_COND_V(!body, false);
  465. return body->is_continuous_collision_detection_enabled();
  466. }
  467. void BulletPhysicsServer3D::body_set_collision_layer(RID p_body, uint32_t p_layer) {
  468. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  469. ERR_FAIL_COND(!body);
  470. body->set_collision_layer(p_layer);
  471. }
  472. uint32_t BulletPhysicsServer3D::body_get_collision_layer(RID p_body) const {
  473. const RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  474. ERR_FAIL_COND_V(!body, 0);
  475. return body->get_collision_layer();
  476. }
  477. void BulletPhysicsServer3D::body_set_collision_mask(RID p_body, uint32_t p_mask) {
  478. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  479. ERR_FAIL_COND(!body);
  480. body->set_collision_mask(p_mask);
  481. }
  482. uint32_t BulletPhysicsServer3D::body_get_collision_mask(RID p_body) const {
  483. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  484. ERR_FAIL_COND_V(!body, 0);
  485. return body->get_collision_mask();
  486. }
  487. void BulletPhysicsServer3D::body_set_user_flags(RID p_body, uint32_t p_flags) {
  488. // This function is not currently supported
  489. }
  490. uint32_t BulletPhysicsServer3D::body_get_user_flags(RID p_body) const {
  491. // This function is not currently supported
  492. return 0;
  493. }
  494. void BulletPhysicsServer3D::body_set_param(RID p_body, BodyParameter p_param, real_t p_value) {
  495. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  496. ERR_FAIL_COND(!body);
  497. body->set_param(p_param, p_value);
  498. }
  499. real_t BulletPhysicsServer3D::body_get_param(RID p_body, BodyParameter p_param) const {
  500. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  501. ERR_FAIL_COND_V(!body, 0);
  502. return body->get_param(p_param);
  503. }
  504. void BulletPhysicsServer3D::body_set_kinematic_safe_margin(RID p_body, real_t p_margin) {
  505. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  506. ERR_FAIL_COND(!body);
  507. if (body->get_kinematic_utilities()) {
  508. body->get_kinematic_utilities()->setSafeMargin(p_margin);
  509. }
  510. }
  511. real_t BulletPhysicsServer3D::body_get_kinematic_safe_margin(RID p_body) const {
  512. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  513. ERR_FAIL_COND_V(!body, 0);
  514. if (body->get_kinematic_utilities()) {
  515. return body->get_kinematic_utilities()->safe_margin;
  516. }
  517. return 0;
  518. }
  519. void BulletPhysicsServer3D::body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) {
  520. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  521. ERR_FAIL_COND(!body);
  522. body->set_state(p_state, p_variant);
  523. }
  524. Variant BulletPhysicsServer3D::body_get_state(RID p_body, BodyState p_state) const {
  525. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  526. ERR_FAIL_COND_V(!body, Variant());
  527. return body->get_state(p_state);
  528. }
  529. void BulletPhysicsServer3D::body_set_applied_force(RID p_body, const Vector3 &p_force) {
  530. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  531. ERR_FAIL_COND(!body);
  532. body->set_applied_force(p_force);
  533. }
  534. Vector3 BulletPhysicsServer3D::body_get_applied_force(RID p_body) const {
  535. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  536. ERR_FAIL_COND_V(!body, Vector3());
  537. return body->get_applied_force();
  538. }
  539. void BulletPhysicsServer3D::body_set_applied_torque(RID p_body, const Vector3 &p_torque) {
  540. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  541. ERR_FAIL_COND(!body);
  542. body->set_applied_torque(p_torque);
  543. }
  544. Vector3 BulletPhysicsServer3D::body_get_applied_torque(RID p_body) const {
  545. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  546. ERR_FAIL_COND_V(!body, Vector3());
  547. return body->get_applied_torque();
  548. }
  549. void BulletPhysicsServer3D::body_add_central_force(RID p_body, const Vector3 &p_force) {
  550. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  551. ERR_FAIL_COND(!body);
  552. body->apply_central_force(p_force);
  553. }
  554. void BulletPhysicsServer3D::body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position) {
  555. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  556. ERR_FAIL_COND(!body);
  557. body->apply_force(p_force, p_position);
  558. }
  559. void BulletPhysicsServer3D::body_add_torque(RID p_body, const Vector3 &p_torque) {
  560. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  561. ERR_FAIL_COND(!body);
  562. body->apply_torque(p_torque);
  563. }
  564. void BulletPhysicsServer3D::body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) {
  565. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  566. ERR_FAIL_COND(!body);
  567. body->apply_central_impulse(p_impulse);
  568. }
  569. void BulletPhysicsServer3D::body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position) {
  570. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  571. ERR_FAIL_COND(!body);
  572. body->apply_impulse(p_impulse, p_position);
  573. }
  574. void BulletPhysicsServer3D::body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) {
  575. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  576. ERR_FAIL_COND(!body);
  577. body->apply_torque_impulse(p_impulse);
  578. }
  579. void BulletPhysicsServer3D::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) {
  580. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  581. ERR_FAIL_COND(!body);
  582. Vector3 v = body->get_linear_velocity();
  583. Vector3 axis = p_axis_velocity.normalized();
  584. v -= axis * axis.dot(v);
  585. v += p_axis_velocity;
  586. body->set_linear_velocity(v);
  587. }
  588. void BulletPhysicsServer3D::body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) {
  589. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  590. ERR_FAIL_COND(!body);
  591. body->set_axis_lock(p_axis, p_lock);
  592. }
  593. bool BulletPhysicsServer3D::body_is_axis_locked(RID p_body, BodyAxis p_axis) const {
  594. const RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  595. ERR_FAIL_COND_V(!body, 0);
  596. return body->is_axis_locked(p_axis);
  597. }
  598. void BulletPhysicsServer3D::body_add_collision_exception(RID p_body, RID p_body_b) {
  599. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  600. ERR_FAIL_COND(!body);
  601. RigidBodyBullet *other_body = rigid_body_owner.getornull(p_body_b);
  602. ERR_FAIL_COND(!other_body);
  603. body->add_collision_exception(other_body);
  604. }
  605. void BulletPhysicsServer3D::body_remove_collision_exception(RID p_body, RID p_body_b) {
  606. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  607. ERR_FAIL_COND(!body);
  608. RigidBodyBullet *other_body = rigid_body_owner.getornull(p_body_b);
  609. ERR_FAIL_COND(!other_body);
  610. body->remove_collision_exception(other_body);
  611. }
  612. void BulletPhysicsServer3D::body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {
  613. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  614. ERR_FAIL_COND(!body);
  615. for (int i = 0; i < body->get_exceptions().size(); i++) {
  616. p_exceptions->push_back(body->get_exceptions()[i]);
  617. }
  618. }
  619. void BulletPhysicsServer3D::body_set_max_contacts_reported(RID p_body, int p_contacts) {
  620. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  621. ERR_FAIL_COND(!body);
  622. body->set_max_collisions_detection(p_contacts);
  623. }
  624. int BulletPhysicsServer3D::body_get_max_contacts_reported(RID p_body) const {
  625. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  626. ERR_FAIL_COND_V(!body, 0);
  627. return body->get_max_collisions_detection();
  628. }
  629. void BulletPhysicsServer3D::body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) {
  630. // Not supported by bullet and even Godot
  631. }
  632. real_t BulletPhysicsServer3D::body_get_contacts_reported_depth_threshold(RID p_body) const {
  633. // Not supported by bullet and even Godot
  634. return 0.;
  635. }
  636. void BulletPhysicsServer3D::body_set_omit_force_integration(RID p_body, bool p_omit) {
  637. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  638. ERR_FAIL_COND(!body);
  639. body->set_omit_forces_integration(p_omit);
  640. }
  641. bool BulletPhysicsServer3D::body_is_omitting_force_integration(RID p_body) const {
  642. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  643. ERR_FAIL_COND_V(!body, false);
  644. return body->get_omit_forces_integration();
  645. }
  646. void BulletPhysicsServer3D::body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_udata) {
  647. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  648. ERR_FAIL_COND(!body);
  649. body->set_force_integration_callback(p_callable, p_udata);
  650. }
  651. void BulletPhysicsServer3D::body_set_ray_pickable(RID p_body, bool p_enable) {
  652. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  653. ERR_FAIL_COND(!body);
  654. body->set_ray_pickable(p_enable);
  655. }
  656. PhysicsDirectBodyState3D *BulletPhysicsServer3D::body_get_direct_state(RID p_body) {
  657. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  658. ERR_FAIL_COND_V(!body, nullptr);
  659. return BulletPhysicsDirectBodyState3D::get_singleton(body);
  660. }
  661. bool BulletPhysicsServer3D::body_test_motion(RID p_body, const Transform3D &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result, bool p_exclude_raycast_shapes, const Set<RID> &p_exclude) {
  662. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  663. ERR_FAIL_COND_V(!body, false);
  664. ERR_FAIL_COND_V(!body->get_space(), false);
  665. return body->get_space()->test_body_motion(body, p_from, p_motion, p_infinite_inertia, r_result, p_exclude_raycast_shapes, p_exclude);
  666. }
  667. int BulletPhysicsServer3D::body_test_ray_separation(RID p_body, const Transform3D &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, real_t p_margin) {
  668. RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
  669. ERR_FAIL_COND_V(!body, 0);
  670. ERR_FAIL_COND_V(!body->get_space(), 0);
  671. return body->get_space()->test_ray_separation(body, p_transform, p_infinite_inertia, r_recover_motion, r_results, p_result_max, p_margin);
  672. }
  673. RID BulletPhysicsServer3D::soft_body_create(bool p_init_sleeping) {
  674. SoftBodyBullet *body = bulletnew(SoftBodyBullet);
  675. body->set_collision_layer(1);
  676. body->set_collision_mask(1);
  677. if (p_init_sleeping) {
  678. body->set_activation_state(false);
  679. }
  680. CreateThenReturnRID(soft_body_owner, body);
  681. }
  682. void BulletPhysicsServer3D::soft_body_update_rendering_server(RID p_body, RenderingServerHandler *p_rendering_server_handler) {
  683. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  684. ERR_FAIL_COND(!body);
  685. body->update_rendering_server(p_rendering_server_handler);
  686. }
  687. void BulletPhysicsServer3D::soft_body_set_space(RID p_body, RID p_space) {
  688. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  689. ERR_FAIL_COND(!body);
  690. SpaceBullet *space = nullptr;
  691. if (p_space.is_valid()) {
  692. space = space_owner.getornull(p_space);
  693. ERR_FAIL_COND(!space);
  694. }
  695. if (body->get_space() == space) {
  696. return; //pointless
  697. }
  698. body->set_space(space);
  699. }
  700. RID BulletPhysicsServer3D::soft_body_get_space(RID p_body) const {
  701. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  702. ERR_FAIL_COND_V(!body, RID());
  703. SpaceBullet *space = body->get_space();
  704. if (!space) {
  705. return RID();
  706. }
  707. return space->get_self();
  708. }
  709. void BulletPhysicsServer3D::soft_body_set_mesh(RID p_body, const REF &p_mesh) {
  710. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  711. ERR_FAIL_COND(!body);
  712. body->set_soft_mesh(p_mesh);
  713. }
  714. AABB BulletPhysicsServer::soft_body_get_bounds(RID p_body) const {
  715. SoftBodyBullet *body = soft_body_owner.get(p_body);
  716. ERR_FAIL_COND_V(!body, AABB());
  717. return body->get_bounds();
  718. }
  719. void BulletPhysicsServer3D::soft_body_set_collision_layer(RID p_body, uint32_t p_layer) {
  720. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  721. ERR_FAIL_COND(!body);
  722. body->set_collision_layer(p_layer);
  723. }
  724. uint32_t BulletPhysicsServer3D::soft_body_get_collision_layer(RID p_body) const {
  725. const SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  726. ERR_FAIL_COND_V(!body, 0);
  727. return body->get_collision_layer();
  728. }
  729. void BulletPhysicsServer3D::soft_body_set_collision_mask(RID p_body, uint32_t p_mask) {
  730. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  731. ERR_FAIL_COND(!body);
  732. body->set_collision_mask(p_mask);
  733. }
  734. uint32_t BulletPhysicsServer3D::soft_body_get_collision_mask(RID p_body) const {
  735. const SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  736. ERR_FAIL_COND_V(!body, 0);
  737. return body->get_collision_mask();
  738. }
  739. void BulletPhysicsServer3D::soft_body_add_collision_exception(RID p_body, RID p_body_b) {
  740. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  741. ERR_FAIL_COND(!body);
  742. CollisionObjectBullet *other_body = rigid_body_owner.getornull(p_body_b);
  743. if (!other_body) {
  744. other_body = soft_body_owner.getornull(p_body_b);
  745. }
  746. ERR_FAIL_COND(!other_body);
  747. body->add_collision_exception(other_body);
  748. }
  749. void BulletPhysicsServer3D::soft_body_remove_collision_exception(RID p_body, RID p_body_b) {
  750. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  751. ERR_FAIL_COND(!body);
  752. CollisionObjectBullet *other_body = rigid_body_owner.getornull(p_body_b);
  753. if (!other_body) {
  754. other_body = soft_body_owner.getornull(p_body_b);
  755. }
  756. ERR_FAIL_COND(!other_body);
  757. body->remove_collision_exception(other_body);
  758. }
  759. void BulletPhysicsServer3D::soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {
  760. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  761. ERR_FAIL_COND(!body);
  762. for (int i = 0; i < body->get_exceptions().size(); i++) {
  763. p_exceptions->push_back(body->get_exceptions()[i]);
  764. }
  765. }
  766. void BulletPhysicsServer3D::soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) {
  767. // FIXME: Must be implemented.
  768. WARN_PRINT("soft_body_state is not implemented yet in Bullet backend.");
  769. }
  770. Variant BulletPhysicsServer3D::soft_body_get_state(RID p_body, BodyState p_state) const {
  771. // FIXME: Must be implemented.
  772. WARN_PRINT("soft_body_state is not implemented yet in Bullet backend.");
  773. return Variant();
  774. }
  775. void BulletPhysicsServer3D::soft_body_set_transform(RID p_body, const Transform3D &p_transform) {
  776. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  777. ERR_FAIL_COND(!body);
  778. body->set_soft_transform(p_transform);
  779. }
  780. void BulletPhysicsServer3D::soft_body_set_ray_pickable(RID p_body, bool p_enable) {
  781. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  782. ERR_FAIL_COND(!body);
  783. body->set_ray_pickable(p_enable);
  784. }
  785. void BulletPhysicsServer3D::soft_body_set_simulation_precision(RID p_body, int p_simulation_precision) {
  786. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  787. ERR_FAIL_COND(!body);
  788. body->set_simulation_precision(p_simulation_precision);
  789. }
  790. int BulletPhysicsServer3D::soft_body_get_simulation_precision(RID p_body) const {
  791. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  792. ERR_FAIL_COND_V(!body, 0.f);
  793. return body->get_simulation_precision();
  794. }
  795. void BulletPhysicsServer3D::soft_body_set_total_mass(RID p_body, real_t p_total_mass) {
  796. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  797. ERR_FAIL_COND(!body);
  798. body->set_total_mass(p_total_mass);
  799. }
  800. real_t BulletPhysicsServer3D::soft_body_get_total_mass(RID p_body) const {
  801. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  802. ERR_FAIL_COND_V(!body, 0.f);
  803. return body->get_total_mass();
  804. }
  805. void BulletPhysicsServer3D::soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness) const {
  806. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  807. ERR_FAIL_COND(!body);
  808. body->set_linear_stiffness(p_stiffness);
  809. }
  810. real_t BulletPhysicsServer3D::soft_body_get_linear_stiffness(RID p_body) {
  811. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  812. ERR_FAIL_COND_V(!body, 0.f);
  813. return body->get_linear_stiffness();
  814. }
  815. void BulletPhysicsServer3D::soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) {
  816. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  817. ERR_FAIL_COND(!body);
  818. body->set_pressure_coefficient(p_pressure_coefficient);
  819. }
  820. real_t BulletPhysicsServer3D::soft_body_get_pressure_coefficient(RID p_body) const {
  821. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  822. ERR_FAIL_COND_V(!body, 0.f);
  823. return body->get_pressure_coefficient();
  824. }
  825. void BulletPhysicsServer3D::soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient) {
  826. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  827. ERR_FAIL_COND(!body);
  828. body->set_damping_coefficient(p_damping_coefficient);
  829. }
  830. real_t BulletPhysicsServer3D::soft_body_get_damping_coefficient(RID p_body) const {
  831. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  832. ERR_FAIL_COND_V(!body, 0.f);
  833. return body->get_damping_coefficient();
  834. }
  835. void BulletPhysicsServer3D::soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient) {
  836. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  837. ERR_FAIL_COND(!body);
  838. body->set_drag_coefficient(p_drag_coefficient);
  839. }
  840. real_t BulletPhysicsServer3D::soft_body_get_drag_coefficient(RID p_body) const {
  841. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  842. ERR_FAIL_COND_V(!body, 0.f);
  843. return body->get_drag_coefficient();
  844. }
  845. void BulletPhysicsServer3D::soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) {
  846. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  847. ERR_FAIL_COND(!body);
  848. body->set_node_position(p_point_index, p_global_position);
  849. }
  850. Vector3 BulletPhysicsServer3D::soft_body_get_point_global_position(RID p_body, int p_point_index) const {
  851. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  852. ERR_FAIL_COND_V(!body, Vector3(0., 0., 0.));
  853. Vector3 pos;
  854. body->get_node_position(p_point_index, pos);
  855. return pos;
  856. }
  857. void BulletPhysicsServer3D::soft_body_remove_all_pinned_points(RID p_body) {
  858. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  859. ERR_FAIL_COND(!body);
  860. body->reset_all_node_mass();
  861. }
  862. void BulletPhysicsServer3D::soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) {
  863. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  864. ERR_FAIL_COND(!body);
  865. body->set_node_mass(p_point_index, p_pin ? 0 : 1);
  866. }
  867. bool BulletPhysicsServer3D::soft_body_is_point_pinned(RID p_body, int p_point_index) const {
  868. SoftBodyBullet *body = soft_body_owner.getornull(p_body);
  869. ERR_FAIL_COND_V(!body, 0.f);
  870. return body->get_node_mass(p_point_index);
  871. }
  872. PhysicsServer3D::JointType BulletPhysicsServer3D::joint_get_type(RID p_joint) const {
  873. JointBullet *joint = joint_owner.getornull(p_joint);
  874. ERR_FAIL_COND_V(!joint, JOINT_PIN);
  875. return joint->get_type();
  876. }
  877. void BulletPhysicsServer3D::joint_set_solver_priority(RID p_joint, int p_priority) {
  878. // Joint priority not supported by bullet
  879. }
  880. int BulletPhysicsServer3D::joint_get_solver_priority(RID p_joint) const {
  881. // Joint priority not supported by bullet
  882. return 0;
  883. }
  884. void BulletPhysicsServer3D::joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) {
  885. JointBullet *joint = joint_owner.getornull(p_joint);
  886. ERR_FAIL_COND(!joint);
  887. joint->disable_collisions_between_bodies(p_disable);
  888. }
  889. bool BulletPhysicsServer3D::joint_is_disabled_collisions_between_bodies(RID p_joint) const {
  890. JointBullet *joint(joint_owner.getornull(p_joint));
  891. ERR_FAIL_COND_V(!joint, false);
  892. return joint->is_disabled_collisions_between_bodies();
  893. }
  894. RID BulletPhysicsServer3D::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) {
  895. RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A);
  896. ERR_FAIL_COND_V(!body_A, RID());
  897. JointAssertSpace(body_A, "A", RID());
  898. RigidBodyBullet *body_B = nullptr;
  899. if (p_body_B.is_valid()) {
  900. body_B = rigid_body_owner.getornull(p_body_B);
  901. JointAssertSpace(body_B, "B", RID());
  902. JointAssertSameSpace(body_A, body_B, RID());
  903. }
  904. ERR_FAIL_COND_V(body_A == body_B, RID());
  905. JointBullet *joint = bulletnew(PinJointBullet(body_A, p_local_A, body_B, p_local_B));
  906. AddJointToSpace(body_A, joint);
  907. CreateThenReturnRID(joint_owner, joint);
  908. }
  909. void BulletPhysicsServer3D::pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) {
  910. JointBullet *joint = joint_owner.getornull(p_joint);
  911. ERR_FAIL_COND(!joint);
  912. ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
  913. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  914. pin_joint->set_param(p_param, p_value);
  915. }
  916. real_t BulletPhysicsServer3D::pin_joint_get_param(RID p_joint, PinJointParam p_param) const {
  917. JointBullet *joint = joint_owner.getornull(p_joint);
  918. ERR_FAIL_COND_V(!joint, 0);
  919. ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, 0);
  920. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  921. return pin_joint->get_param(p_param);
  922. }
  923. void BulletPhysicsServer3D::pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) {
  924. JointBullet *joint = joint_owner.getornull(p_joint);
  925. ERR_FAIL_COND(!joint);
  926. ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
  927. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  928. pin_joint->setPivotInA(p_A);
  929. }
  930. Vector3 BulletPhysicsServer3D::pin_joint_get_local_a(RID p_joint) const {
  931. JointBullet *joint = joint_owner.getornull(p_joint);
  932. ERR_FAIL_COND_V(!joint, Vector3());
  933. ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3());
  934. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  935. return pin_joint->getPivotInA();
  936. }
  937. void BulletPhysicsServer3D::pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) {
  938. JointBullet *joint = joint_owner.getornull(p_joint);
  939. ERR_FAIL_COND(!joint);
  940. ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
  941. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  942. pin_joint->setPivotInB(p_B);
  943. }
  944. Vector3 BulletPhysicsServer3D::pin_joint_get_local_b(RID p_joint) const {
  945. JointBullet *joint = joint_owner.getornull(p_joint);
  946. ERR_FAIL_COND_V(!joint, Vector3());
  947. ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3());
  948. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  949. return pin_joint->getPivotInB();
  950. }
  951. RID BulletPhysicsServer3D::joint_create_hinge(RID p_body_A, const Transform3D &p_hinge_A, RID p_body_B, const Transform3D &p_hinge_B) {
  952. RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A);
  953. ERR_FAIL_COND_V(!body_A, RID());
  954. JointAssertSpace(body_A, "A", RID());
  955. RigidBodyBullet *body_B = nullptr;
  956. if (p_body_B.is_valid()) {
  957. body_B = rigid_body_owner.getornull(p_body_B);
  958. JointAssertSpace(body_B, "B", RID());
  959. JointAssertSameSpace(body_A, body_B, RID());
  960. }
  961. ERR_FAIL_COND_V(body_A == body_B, RID());
  962. JointBullet *joint = bulletnew(HingeJointBullet(body_A, body_B, p_hinge_A, p_hinge_B));
  963. AddJointToSpace(body_A, joint);
  964. CreateThenReturnRID(joint_owner, joint);
  965. }
  966. RID BulletPhysicsServer3D::joint_create_hinge_simple(RID p_body_A, const Vector3 &p_pivot_A, const Vector3 &p_axis_A, RID p_body_B, const Vector3 &p_pivot_B, const Vector3 &p_axis_B) {
  967. RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A);
  968. ERR_FAIL_COND_V(!body_A, RID());
  969. JointAssertSpace(body_A, "A", RID());
  970. RigidBodyBullet *body_B = nullptr;
  971. if (p_body_B.is_valid()) {
  972. body_B = rigid_body_owner.getornull(p_body_B);
  973. JointAssertSpace(body_B, "B", RID());
  974. JointAssertSameSpace(body_A, body_B, RID());
  975. }
  976. ERR_FAIL_COND_V(body_A == body_B, RID());
  977. JointBullet *joint = bulletnew(HingeJointBullet(body_A, body_B, p_pivot_A, p_pivot_B, p_axis_A, p_axis_B));
  978. AddJointToSpace(body_A, joint);
  979. CreateThenReturnRID(joint_owner, joint);
  980. }
  981. void BulletPhysicsServer3D::hinge_joint_set_param(RID p_joint, HingeJointParam p_param, real_t p_value) {
  982. JointBullet *joint = joint_owner.getornull(p_joint);
  983. ERR_FAIL_COND(!joint);
  984. ERR_FAIL_COND(joint->get_type() != JOINT_HINGE);
  985. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  986. hinge_joint->set_param(p_param, p_value);
  987. }
  988. real_t BulletPhysicsServer3D::hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const {
  989. JointBullet *joint = joint_owner.getornull(p_joint);
  990. ERR_FAIL_COND_V(!joint, 0);
  991. ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, 0);
  992. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  993. return hinge_joint->get_param(p_param);
  994. }
  995. void BulletPhysicsServer3D::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value) {
  996. JointBullet *joint = joint_owner.getornull(p_joint);
  997. ERR_FAIL_COND(!joint);
  998. ERR_FAIL_COND(joint->get_type() != JOINT_HINGE);
  999. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  1000. hinge_joint->set_flag(p_flag, p_value);
  1001. }
  1002. bool BulletPhysicsServer3D::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const {
  1003. JointBullet *joint = joint_owner.getornull(p_joint);
  1004. ERR_FAIL_COND_V(!joint, false);
  1005. ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, false);
  1006. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  1007. return hinge_joint->get_flag(p_flag);
  1008. }
  1009. RID BulletPhysicsServer3D::joint_create_slider(RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) {
  1010. RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A);
  1011. ERR_FAIL_COND_V(!body_A, RID());
  1012. JointAssertSpace(body_A, "A", RID());
  1013. RigidBodyBullet *body_B = nullptr;
  1014. if (p_body_B.is_valid()) {
  1015. body_B = rigid_body_owner.getornull(p_body_B);
  1016. JointAssertSpace(body_B, "B", RID());
  1017. JointAssertSameSpace(body_A, body_B, RID());
  1018. }
  1019. ERR_FAIL_COND_V(body_A == body_B, RID());
  1020. JointBullet *joint = bulletnew(SliderJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B));
  1021. AddJointToSpace(body_A, joint);
  1022. CreateThenReturnRID(joint_owner, joint);
  1023. }
  1024. void BulletPhysicsServer3D::slider_joint_set_param(RID p_joint, SliderJointParam p_param, real_t p_value) {
  1025. JointBullet *joint = joint_owner.getornull(p_joint);
  1026. ERR_FAIL_COND(!joint);
  1027. ERR_FAIL_COND(joint->get_type() != JOINT_SLIDER);
  1028. SliderJointBullet *slider_joint = static_cast<SliderJointBullet *>(joint);
  1029. slider_joint->set_param(p_param, p_value);
  1030. }
  1031. real_t BulletPhysicsServer3D::slider_joint_get_param(RID p_joint, SliderJointParam p_param) const {
  1032. JointBullet *joint = joint_owner.getornull(p_joint);
  1033. ERR_FAIL_COND_V(!joint, 0);
  1034. ERR_FAIL_COND_V(joint->get_type() != JOINT_SLIDER, 0);
  1035. SliderJointBullet *slider_joint = static_cast<SliderJointBullet *>(joint);
  1036. return slider_joint->get_param(p_param);
  1037. }
  1038. RID BulletPhysicsServer3D::joint_create_cone_twist(RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) {
  1039. RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A);
  1040. ERR_FAIL_COND_V(!body_A, RID());
  1041. JointAssertSpace(body_A, "A", RID());
  1042. RigidBodyBullet *body_B = nullptr;
  1043. if (p_body_B.is_valid()) {
  1044. body_B = rigid_body_owner.getornull(p_body_B);
  1045. JointAssertSpace(body_B, "B", RID());
  1046. JointAssertSameSpace(body_A, body_B, RID());
  1047. }
  1048. JointBullet *joint = bulletnew(ConeTwistJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B));
  1049. AddJointToSpace(body_A, joint);
  1050. CreateThenReturnRID(joint_owner, joint);
  1051. }
  1052. void BulletPhysicsServer3D::cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, real_t p_value) {
  1053. JointBullet *joint = joint_owner.getornull(p_joint);
  1054. ERR_FAIL_COND(!joint);
  1055. ERR_FAIL_COND(joint->get_type() != JOINT_CONE_TWIST);
  1056. ConeTwistJointBullet *coneTwist_joint = static_cast<ConeTwistJointBullet *>(joint);
  1057. coneTwist_joint->set_param(p_param, p_value);
  1058. }
  1059. real_t BulletPhysicsServer3D::cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const {
  1060. JointBullet *joint = joint_owner.getornull(p_joint);
  1061. ERR_FAIL_COND_V(!joint, 0.);
  1062. ERR_FAIL_COND_V(joint->get_type() != JOINT_CONE_TWIST, 0.);
  1063. ConeTwistJointBullet *coneTwist_joint = static_cast<ConeTwistJointBullet *>(joint);
  1064. return coneTwist_joint->get_param(p_param);
  1065. }
  1066. RID BulletPhysicsServer3D::joint_create_generic_6dof(RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) {
  1067. RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A);
  1068. ERR_FAIL_COND_V(!body_A, RID());
  1069. JointAssertSpace(body_A, "A", RID());
  1070. RigidBodyBullet *body_B = nullptr;
  1071. if (p_body_B.is_valid()) {
  1072. body_B = rigid_body_owner.getornull(p_body_B);
  1073. JointAssertSpace(body_B, "B", RID());
  1074. JointAssertSameSpace(body_A, body_B, RID());
  1075. }
  1076. ERR_FAIL_COND_V(body_A == body_B, RID());
  1077. JointBullet *joint = bulletnew(Generic6DOFJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B));
  1078. AddJointToSpace(body_A, joint);
  1079. CreateThenReturnRID(joint_owner, joint);
  1080. }
  1081. void BulletPhysicsServer3D::generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param, real_t p_value) {
  1082. JointBullet *joint = joint_owner.getornull(p_joint);
  1083. ERR_FAIL_COND(!joint);
  1084. ERR_FAIL_COND(joint->get_type() != JOINT_6DOF);
  1085. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1086. generic_6dof_joint->set_param(p_axis, p_param, p_value);
  1087. }
  1088. real_t BulletPhysicsServer3D::generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param) {
  1089. JointBullet *joint = joint_owner.getornull(p_joint);
  1090. ERR_FAIL_COND_V(!joint, 0);
  1091. ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, 0);
  1092. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1093. return generic_6dof_joint->get_param(p_axis, p_param);
  1094. }
  1095. void BulletPhysicsServer3D::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag, bool p_enable) {
  1096. JointBullet *joint = joint_owner.getornull(p_joint);
  1097. ERR_FAIL_COND(!joint);
  1098. ERR_FAIL_COND(joint->get_type() != JOINT_6DOF);
  1099. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1100. generic_6dof_joint->set_flag(p_axis, p_flag, p_enable);
  1101. }
  1102. bool BulletPhysicsServer3D::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag) {
  1103. JointBullet *joint = joint_owner.getornull(p_joint);
  1104. ERR_FAIL_COND_V(!joint, false);
  1105. ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, false);
  1106. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1107. return generic_6dof_joint->get_flag(p_axis, p_flag);
  1108. }
  1109. void BulletPhysicsServer3D::free(RID p_rid) {
  1110. if (shape_owner.owns(p_rid)) {
  1111. ShapeBullet *shape = shape_owner.getornull(p_rid);
  1112. // Notify the shape is configured
  1113. for (Map<ShapeOwnerBullet *, int>::Element *element = shape->get_owners().front(); element; element = element->next()) {
  1114. static_cast<ShapeOwnerBullet *>(element->key())->remove_shape_full(shape);
  1115. }
  1116. shape_owner.free(p_rid);
  1117. bulletdelete(shape);
  1118. } else if (rigid_body_owner.owns(p_rid)) {
  1119. RigidBodyBullet *body = rigid_body_owner.getornull(p_rid);
  1120. body->set_space(nullptr);
  1121. body->remove_all_shapes(true, true);
  1122. rigid_body_owner.free(p_rid);
  1123. bulletdelete(body);
  1124. } else if (soft_body_owner.owns(p_rid)) {
  1125. SoftBodyBullet *body = soft_body_owner.getornull(p_rid);
  1126. body->set_space(nullptr);
  1127. soft_body_owner.free(p_rid);
  1128. bulletdelete(body);
  1129. } else if (area_owner.owns(p_rid)) {
  1130. AreaBullet *area = area_owner.getornull(p_rid);
  1131. area->set_space(nullptr);
  1132. area->remove_all_shapes(true, true);
  1133. area_owner.free(p_rid);
  1134. bulletdelete(area);
  1135. } else if (joint_owner.owns(p_rid)) {
  1136. JointBullet *joint = joint_owner.getornull(p_rid);
  1137. joint->destroy_internal_constraint();
  1138. joint_owner.free(p_rid);
  1139. bulletdelete(joint);
  1140. } else if (space_owner.owns(p_rid)) {
  1141. SpaceBullet *space = space_owner.getornull(p_rid);
  1142. space->remove_all_collision_objects();
  1143. space_set_active(p_rid, false);
  1144. space_owner.free(p_rid);
  1145. bulletdelete(space);
  1146. } else {
  1147. ERR_FAIL_MSG("Invalid ID.");
  1148. }
  1149. }
  1150. void BulletPhysicsServer3D::init() {
  1151. BulletPhysicsDirectBodyState3D::initSingleton();
  1152. }
  1153. void BulletPhysicsServer3D::step(real_t p_deltaTime) {
  1154. if (!active) {
  1155. return;
  1156. }
  1157. BulletPhysicsDirectBodyState3D::singleton_setDeltaTime(p_deltaTime);
  1158. for (int i = 0; i < active_spaces_count; ++i) {
  1159. active_spaces[i]->step(p_deltaTime);
  1160. }
  1161. }
  1162. void BulletPhysicsServer3D::flush_queries() {
  1163. if (!active) {
  1164. return;
  1165. }
  1166. for (int i = 0; i < active_spaces_count; ++i) {
  1167. active_spaces[i]->flush_queries();
  1168. }
  1169. }
  1170. void BulletPhysicsServer3D::finish() {
  1171. BulletPhysicsDirectBodyState3D::destroySingleton();
  1172. }
  1173. int BulletPhysicsServer3D::get_process_info(ProcessInfo p_info) {
  1174. return 0;
  1175. }
  1176. SpaceBullet *BulletPhysicsServer3D::get_space(RID p_rid) const {
  1177. ERR_FAIL_COND_V_MSG(space_owner.owns(p_rid) == false, nullptr, "The RID is not valid.");
  1178. return space_owner.getornull(p_rid);
  1179. }
  1180. ShapeBullet *BulletPhysicsServer3D::get_shape(RID p_rid) const {
  1181. ERR_FAIL_COND_V_MSG(shape_owner.owns(p_rid) == false, nullptr, "The RID is not valid.");
  1182. return shape_owner.getornull(p_rid);
  1183. }
  1184. CollisionObjectBullet *BulletPhysicsServer3D::get_collision_object(RID p_object) const {
  1185. if (rigid_body_owner.owns(p_object)) {
  1186. return rigid_body_owner.getornull(p_object);
  1187. }
  1188. if (area_owner.owns(p_object)) {
  1189. return area_owner.getornull(p_object);
  1190. }
  1191. if (soft_body_owner.owns(p_object)) {
  1192. return soft_body_owner.getornull(p_object);
  1193. }
  1194. ERR_FAIL_V_MSG(nullptr, "The RID is no valid.");
  1195. }
  1196. RigidCollisionObjectBullet *BulletPhysicsServer3D::get_rigid_collision_object(RID p_object) const {
  1197. if (rigid_body_owner.owns(p_object)) {
  1198. return rigid_body_owner.getornull(p_object);
  1199. }
  1200. if (area_owner.owns(p_object)) {
  1201. return area_owner.getornull(p_object);
  1202. }
  1203. ERR_FAIL_V_MSG(nullptr, "The RID is no valid.");
  1204. }
  1205. JointBullet *BulletPhysicsServer3D::get_joint(RID p_rid) const {
  1206. ERR_FAIL_COND_V_MSG(joint_owner.owns(p_rid) == false, nullptr, "The RID is not valid.");
  1207. return joint_owner.getornull(p_rid);
  1208. }