bullet_physics_server.cpp 51 KB

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