bullet_physics_server.cpp 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596
  1. /**************************************************************************/
  2. /* bullet_physics_server.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "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. ERR_FAIL_COND_V(!area, RID());
  216. SpaceBullet *space = area->get_space();
  217. if (!space) {
  218. return RID();
  219. }
  220. return space->get_self();
  221. }
  222. void BulletPhysicsServer::area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) {
  223. AreaBullet *area = area_owner.get(p_area);
  224. ERR_FAIL_COND(!area);
  225. area->set_spOv_mode(p_mode);
  226. }
  227. PhysicsServer::AreaSpaceOverrideMode BulletPhysicsServer::area_get_space_override_mode(RID p_area) const {
  228. AreaBullet *area = area_owner.get(p_area);
  229. ERR_FAIL_COND_V(!area, PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED);
  230. return area->get_spOv_mode();
  231. }
  232. void BulletPhysicsServer::area_add_shape(RID p_area, RID p_shape, const Transform &p_transform, bool p_disabled) {
  233. AreaBullet *area = area_owner.get(p_area);
  234. ERR_FAIL_COND(!area);
  235. ShapeBullet *shape = shape_owner.get(p_shape);
  236. ERR_FAIL_COND(!shape);
  237. area->add_shape(shape, p_transform, p_disabled);
  238. }
  239. void BulletPhysicsServer::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) {
  240. AreaBullet *area = area_owner.get(p_area);
  241. ERR_FAIL_COND(!area);
  242. ShapeBullet *shape = shape_owner.get(p_shape);
  243. ERR_FAIL_COND(!shape);
  244. area->set_shape(p_shape_idx, shape);
  245. }
  246. void BulletPhysicsServer::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform) {
  247. AreaBullet *area = area_owner.get(p_area);
  248. ERR_FAIL_COND(!area);
  249. area->set_shape_transform(p_shape_idx, p_transform);
  250. }
  251. int BulletPhysicsServer::area_get_shape_count(RID p_area) const {
  252. AreaBullet *area = area_owner.get(p_area);
  253. ERR_FAIL_COND_V(!area, 0);
  254. return area->get_shape_count();
  255. }
  256. RID BulletPhysicsServer::area_get_shape(RID p_area, int p_shape_idx) const {
  257. AreaBullet *area = area_owner.get(p_area);
  258. ERR_FAIL_COND_V(!area, RID());
  259. return area->get_shape(p_shape_idx)->get_self();
  260. }
  261. Transform BulletPhysicsServer::area_get_shape_transform(RID p_area, int p_shape_idx) const {
  262. AreaBullet *area = area_owner.get(p_area);
  263. ERR_FAIL_COND_V(!area, Transform());
  264. return area->get_shape_transform(p_shape_idx);
  265. }
  266. void BulletPhysicsServer::area_remove_shape(RID p_area, int p_shape_idx) {
  267. AreaBullet *area = area_owner.get(p_area);
  268. ERR_FAIL_COND(!area);
  269. return area->remove_shape_full(p_shape_idx);
  270. }
  271. void BulletPhysicsServer::area_clear_shapes(RID p_area) {
  272. AreaBullet *area = area_owner.get(p_area);
  273. ERR_FAIL_COND(!area);
  274. for (int i = area->get_shape_count(); 0 < i; --i) {
  275. area->remove_shape_full(0);
  276. }
  277. }
  278. void BulletPhysicsServer::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) {
  279. AreaBullet *area = area_owner.get(p_area);
  280. ERR_FAIL_COND(!area);
  281. area->set_shape_disabled(p_shape_idx, p_disabled);
  282. }
  283. void BulletPhysicsServer::area_attach_object_instance_id(RID p_area, ObjectID p_id) {
  284. if (space_owner.owns(p_area)) {
  285. return;
  286. }
  287. AreaBullet *area = area_owner.get(p_area);
  288. ERR_FAIL_COND(!area);
  289. area->set_instance_id(p_id);
  290. }
  291. ObjectID BulletPhysicsServer::area_get_object_instance_id(RID p_area) const {
  292. if (space_owner.owns(p_area)) {
  293. return 0;
  294. }
  295. AreaBullet *area = area_owner.get(p_area);
  296. ERR_FAIL_COND_V(!area, ObjectID());
  297. return area->get_instance_id();
  298. }
  299. void BulletPhysicsServer::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) {
  300. if (space_owner.owns(p_area)) {
  301. SpaceBullet *space = space_owner.get(p_area);
  302. if (space) {
  303. space->set_param(p_param, p_value);
  304. }
  305. } else {
  306. AreaBullet *area = area_owner.get(p_area);
  307. ERR_FAIL_COND(!area);
  308. area->set_param(p_param, p_value);
  309. }
  310. }
  311. Variant BulletPhysicsServer::area_get_param(RID p_area, AreaParameter p_param) const {
  312. if (space_owner.owns(p_area)) {
  313. SpaceBullet *space = space_owner.get(p_area);
  314. return space->get_param(p_param);
  315. } else {
  316. AreaBullet *area = area_owner.get(p_area);
  317. ERR_FAIL_COND_V(!area, Variant());
  318. return area->get_param(p_param);
  319. }
  320. }
  321. void BulletPhysicsServer::area_set_transform(RID p_area, const Transform &p_transform) {
  322. AreaBullet *area = area_owner.get(p_area);
  323. ERR_FAIL_COND(!area);
  324. area->set_transform(p_transform);
  325. }
  326. Transform BulletPhysicsServer::area_get_transform(RID p_area) const {
  327. AreaBullet *area = area_owner.get(p_area);
  328. ERR_FAIL_COND_V(!area, Transform());
  329. return area->get_transform();
  330. }
  331. void BulletPhysicsServer::area_set_collision_mask(RID p_area, uint32_t p_mask) {
  332. AreaBullet *area = area_owner.get(p_area);
  333. ERR_FAIL_COND(!area);
  334. area->set_collision_mask(p_mask);
  335. }
  336. void BulletPhysicsServer::area_set_collision_layer(RID p_area, uint32_t p_layer) {
  337. AreaBullet *area = area_owner.get(p_area);
  338. ERR_FAIL_COND(!area);
  339. area->set_collision_layer(p_layer);
  340. }
  341. void BulletPhysicsServer::area_set_monitorable(RID p_area, bool p_monitorable) {
  342. AreaBullet *area = area_owner.get(p_area);
  343. ERR_FAIL_COND(!area);
  344. area->set_monitorable(p_monitorable);
  345. }
  346. void BulletPhysicsServer::area_set_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_RIGID_BODY, p_receiver ? p_receiver->get_instance_id() : 0, p_method);
  350. }
  351. void BulletPhysicsServer::area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) {
  352. AreaBullet *area = area_owner.get(p_area);
  353. ERR_FAIL_COND(!area);
  354. area->set_event_callback(CollisionObjectBullet::TYPE_AREA, p_receiver ? p_receiver->get_instance_id() : 0, p_method);
  355. }
  356. void BulletPhysicsServer::area_set_ray_pickable(RID p_area, bool p_enable) {
  357. AreaBullet *area = area_owner.get(p_area);
  358. ERR_FAIL_COND(!area);
  359. area->set_ray_pickable(p_enable);
  360. }
  361. bool BulletPhysicsServer::area_is_ray_pickable(RID p_area) const {
  362. AreaBullet *area = area_owner.get(p_area);
  363. ERR_FAIL_COND_V(!area, false);
  364. return area->is_ray_pickable();
  365. }
  366. RID BulletPhysicsServer::body_create(BodyMode p_mode, bool p_init_sleeping) {
  367. RigidBodyBullet *body = bulletnew(RigidBodyBullet);
  368. body->set_mode(p_mode);
  369. body->set_collision_layer(1);
  370. body->set_collision_mask(1);
  371. if (p_init_sleeping) {
  372. body->set_state(BODY_STATE_SLEEPING, p_init_sleeping);
  373. }
  374. CreateThenReturnRID(rigid_body_owner, body);
  375. }
  376. void BulletPhysicsServer::body_set_space(RID p_body, RID p_space) {
  377. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  378. ERR_FAIL_COND(!body);
  379. SpaceBullet *space = nullptr;
  380. if (p_space.is_valid()) {
  381. space = space_owner.get(p_space);
  382. ERR_FAIL_COND(!space);
  383. }
  384. if (body->get_space() == space) {
  385. return; //pointles
  386. }
  387. body->set_space(space);
  388. }
  389. RID BulletPhysicsServer::body_get_space(RID p_body) const {
  390. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  391. ERR_FAIL_COND_V(!body, RID());
  392. SpaceBullet *space = body->get_space();
  393. if (!space) {
  394. return RID();
  395. }
  396. return space->get_self();
  397. }
  398. void BulletPhysicsServer::body_set_mode(RID p_body, PhysicsServer::BodyMode p_mode) {
  399. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  400. ERR_FAIL_COND(!body);
  401. body->set_mode(p_mode);
  402. }
  403. PhysicsServer::BodyMode BulletPhysicsServer::body_get_mode(RID p_body) const {
  404. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  405. ERR_FAIL_COND_V(!body, BODY_MODE_STATIC);
  406. return body->get_mode();
  407. }
  408. void BulletPhysicsServer::body_add_shape(RID p_body, RID p_shape, const Transform &p_transform, bool p_disabled) {
  409. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  410. ERR_FAIL_COND(!body);
  411. ShapeBullet *shape = shape_owner.get(p_shape);
  412. ERR_FAIL_COND(!shape);
  413. body->add_shape(shape, p_transform, p_disabled);
  414. }
  415. void BulletPhysicsServer::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) {
  416. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  417. ERR_FAIL_COND(!body);
  418. ShapeBullet *shape = shape_owner.get(p_shape);
  419. ERR_FAIL_COND(!shape);
  420. body->set_shape(p_shape_idx, shape);
  421. }
  422. void BulletPhysicsServer::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform) {
  423. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  424. ERR_FAIL_COND(!body);
  425. body->set_shape_transform(p_shape_idx, p_transform);
  426. }
  427. int BulletPhysicsServer::body_get_shape_count(RID p_body) const {
  428. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  429. ERR_FAIL_COND_V(!body, 0);
  430. return body->get_shape_count();
  431. }
  432. RID BulletPhysicsServer::body_get_shape(RID p_body, int p_shape_idx) const {
  433. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  434. ERR_FAIL_COND_V(!body, RID());
  435. ShapeBullet *shape = body->get_shape(p_shape_idx);
  436. ERR_FAIL_COND_V(!shape, RID());
  437. return shape->get_self();
  438. }
  439. Transform BulletPhysicsServer::body_get_shape_transform(RID p_body, int p_shape_idx) const {
  440. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  441. ERR_FAIL_COND_V(!body, Transform());
  442. return body->get_shape_transform(p_shape_idx);
  443. }
  444. void BulletPhysicsServer::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) {
  445. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  446. ERR_FAIL_COND(!body);
  447. body->set_shape_disabled(p_shape_idx, p_disabled);
  448. }
  449. void BulletPhysicsServer::body_remove_shape(RID p_body, int p_shape_idx) {
  450. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  451. ERR_FAIL_COND(!body);
  452. body->remove_shape_full(p_shape_idx);
  453. }
  454. void BulletPhysicsServer::body_clear_shapes(RID p_body) {
  455. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  456. ERR_FAIL_COND(!body);
  457. body->remove_all_shapes();
  458. }
  459. void BulletPhysicsServer::body_attach_object_instance_id(RID p_body, uint32_t p_id) {
  460. CollisionObjectBullet *body = get_collision_object(p_body);
  461. ERR_FAIL_COND(!body);
  462. body->set_instance_id(p_id);
  463. }
  464. uint32_t BulletPhysicsServer::body_get_object_instance_id(RID p_body) const {
  465. CollisionObjectBullet *body = get_collision_object(p_body);
  466. ERR_FAIL_COND_V(!body, 0);
  467. return body->get_instance_id();
  468. }
  469. void BulletPhysicsServer::body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) {
  470. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  471. ERR_FAIL_COND(!body);
  472. body->set_continuous_collision_detection(p_enable);
  473. }
  474. bool BulletPhysicsServer::body_is_continuous_collision_detection_enabled(RID p_body) const {
  475. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  476. ERR_FAIL_COND_V(!body, false);
  477. return body->is_continuous_collision_detection_enabled();
  478. }
  479. void BulletPhysicsServer::body_set_collision_layer(RID p_body, uint32_t p_layer) {
  480. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  481. ERR_FAIL_COND(!body);
  482. body->set_collision_layer(p_layer);
  483. }
  484. uint32_t BulletPhysicsServer::body_get_collision_layer(RID p_body) const {
  485. const RigidBodyBullet *body = rigid_body_owner.get(p_body);
  486. ERR_FAIL_COND_V(!body, 0);
  487. return body->get_collision_layer();
  488. }
  489. void BulletPhysicsServer::body_set_collision_mask(RID p_body, uint32_t p_mask) {
  490. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  491. ERR_FAIL_COND(!body);
  492. body->set_collision_mask(p_mask);
  493. }
  494. uint32_t BulletPhysicsServer::body_get_collision_mask(RID p_body) const {
  495. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  496. ERR_FAIL_COND_V(!body, 0);
  497. return body->get_collision_mask();
  498. }
  499. void BulletPhysicsServer::body_set_user_flags(RID p_body, uint32_t p_flags) {
  500. // This function si not currently supported
  501. }
  502. uint32_t BulletPhysicsServer::body_get_user_flags(RID p_body) const {
  503. // This function si not currently supported
  504. return 0;
  505. }
  506. void BulletPhysicsServer::body_set_param(RID p_body, BodyParameter p_param, float p_value) {
  507. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  508. ERR_FAIL_COND(!body);
  509. body->set_param(p_param, p_value);
  510. }
  511. float BulletPhysicsServer::body_get_param(RID p_body, BodyParameter p_param) const {
  512. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  513. ERR_FAIL_COND_V(!body, 0);
  514. return body->get_param(p_param);
  515. }
  516. void BulletPhysicsServer::body_set_kinematic_safe_margin(RID p_body, real_t p_margin) {
  517. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  518. ERR_FAIL_COND(!body);
  519. if (body->get_kinematic_utilities()) {
  520. body->get_kinematic_utilities()->setSafeMargin(p_margin);
  521. }
  522. }
  523. real_t BulletPhysicsServer::body_get_kinematic_safe_margin(RID p_body) const {
  524. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  525. ERR_FAIL_COND_V(!body, 0);
  526. if (body->get_kinematic_utilities()) {
  527. return body->get_kinematic_utilities()->safe_margin;
  528. }
  529. return 0;
  530. }
  531. void BulletPhysicsServer::body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) {
  532. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  533. ERR_FAIL_COND(!body);
  534. body->set_state(p_state, p_variant);
  535. }
  536. Variant BulletPhysicsServer::body_get_state(RID p_body, BodyState p_state) const {
  537. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  538. ERR_FAIL_COND_V(!body, Variant());
  539. return body->get_state(p_state);
  540. }
  541. void BulletPhysicsServer::body_set_applied_force(RID p_body, const Vector3 &p_force) {
  542. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  543. ERR_FAIL_COND(!body);
  544. body->set_applied_force(p_force);
  545. }
  546. Vector3 BulletPhysicsServer::body_get_applied_force(RID p_body) const {
  547. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  548. ERR_FAIL_COND_V(!body, Vector3());
  549. return body->get_applied_force();
  550. }
  551. void BulletPhysicsServer::body_set_applied_torque(RID p_body, const Vector3 &p_torque) {
  552. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  553. ERR_FAIL_COND(!body);
  554. body->set_applied_torque(p_torque);
  555. }
  556. Vector3 BulletPhysicsServer::body_get_applied_torque(RID p_body) const {
  557. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  558. ERR_FAIL_COND_V(!body, Vector3());
  559. return body->get_applied_torque();
  560. }
  561. void BulletPhysicsServer::body_add_central_force(RID p_body, const Vector3 &p_force) {
  562. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  563. ERR_FAIL_COND(!body);
  564. body->apply_central_force(p_force);
  565. }
  566. void BulletPhysicsServer::body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_pos) {
  567. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  568. ERR_FAIL_COND(!body);
  569. body->apply_force(p_force, p_pos);
  570. }
  571. void BulletPhysicsServer::body_add_torque(RID p_body, const Vector3 &p_torque) {
  572. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  573. ERR_FAIL_COND(!body);
  574. body->apply_torque(p_torque);
  575. }
  576. void BulletPhysicsServer::body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) {
  577. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  578. ERR_FAIL_COND(!body);
  579. body->apply_central_impulse(p_impulse);
  580. }
  581. void BulletPhysicsServer::body_apply_impulse(RID p_body, const Vector3 &p_pos, const Vector3 &p_impulse) {
  582. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  583. ERR_FAIL_COND(!body);
  584. body->apply_impulse(p_pos, p_impulse);
  585. }
  586. void BulletPhysicsServer::body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) {
  587. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  588. ERR_FAIL_COND(!body);
  589. body->apply_torque_impulse(p_impulse);
  590. }
  591. void BulletPhysicsServer::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) {
  592. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  593. ERR_FAIL_COND(!body);
  594. Vector3 v = body->get_linear_velocity();
  595. Vector3 axis = p_axis_velocity.normalized();
  596. v -= axis * axis.dot(v);
  597. v += p_axis_velocity;
  598. body->set_linear_velocity(v);
  599. }
  600. void BulletPhysicsServer::body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) {
  601. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  602. ERR_FAIL_COND(!body);
  603. body->set_axis_lock(p_axis, p_lock);
  604. }
  605. bool BulletPhysicsServer::body_is_axis_locked(RID p_body, BodyAxis p_axis) const {
  606. const RigidBodyBullet *body = rigid_body_owner.get(p_body);
  607. ERR_FAIL_COND_V(!body, 0);
  608. return body->is_axis_locked(p_axis);
  609. }
  610. void BulletPhysicsServer::body_add_collision_exception(RID p_body, RID p_body_b) {
  611. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  612. ERR_FAIL_COND(!body);
  613. RigidBodyBullet *other_body = rigid_body_owner.get(p_body_b);
  614. ERR_FAIL_COND(!other_body);
  615. body->add_collision_exception(other_body);
  616. }
  617. void BulletPhysicsServer::body_remove_collision_exception(RID p_body, RID p_body_b) {
  618. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  619. ERR_FAIL_COND(!body);
  620. RigidBodyBullet *other_body = rigid_body_owner.get(p_body_b);
  621. ERR_FAIL_COND(!other_body);
  622. body->remove_collision_exception(other_body);
  623. }
  624. void BulletPhysicsServer::body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {
  625. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  626. ERR_FAIL_COND(!body);
  627. for (int i = 0; i < body->get_exceptions().size(); i++) {
  628. p_exceptions->push_back(body->get_exceptions()[i]);
  629. }
  630. }
  631. void BulletPhysicsServer::body_set_max_contacts_reported(RID p_body, int p_contacts) {
  632. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  633. ERR_FAIL_COND(!body);
  634. body->set_max_collisions_detection(p_contacts);
  635. }
  636. int BulletPhysicsServer::body_get_max_contacts_reported(RID p_body) const {
  637. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  638. ERR_FAIL_COND_V(!body, 0);
  639. return body->get_max_collisions_detection();
  640. }
  641. void BulletPhysicsServer::body_set_contacts_reported_depth_threshold(RID p_body, float p_threshold) {
  642. // Not supported by bullet and even Godot
  643. }
  644. float BulletPhysicsServer::body_get_contacts_reported_depth_threshold(RID p_body) const {
  645. // Not supported by bullet and even Godot
  646. return 0.;
  647. }
  648. void BulletPhysicsServer::body_set_omit_force_integration(RID p_body, bool p_omit) {
  649. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  650. ERR_FAIL_COND(!body);
  651. body->set_omit_forces_integration(p_omit);
  652. }
  653. bool BulletPhysicsServer::body_is_omitting_force_integration(RID p_body) const {
  654. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  655. ERR_FAIL_COND_V(!body, false);
  656. return body->get_omit_forces_integration();
  657. }
  658. void BulletPhysicsServer::body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata) {
  659. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  660. ERR_FAIL_COND(!body);
  661. body->set_force_integration_callback(p_receiver ? p_receiver->get_instance_id() : ObjectID(0), p_method, p_udata);
  662. }
  663. void BulletPhysicsServer::body_set_ray_pickable(RID p_body, bool p_enable) {
  664. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  665. ERR_FAIL_COND(!body);
  666. body->set_ray_pickable(p_enable);
  667. }
  668. bool BulletPhysicsServer::body_is_ray_pickable(RID p_body) const {
  669. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  670. ERR_FAIL_COND_V(!body, false);
  671. return body->is_ray_pickable();
  672. }
  673. PhysicsDirectBodyState *BulletPhysicsServer::body_get_direct_state(RID p_body) {
  674. if (!rigid_body_owner.owns(p_body)) {
  675. return nullptr;
  676. }
  677. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  678. ERR_FAIL_COND_V_MSG(!body, nullptr, "Body with RID " + itos(p_body.get_id()) + " not owned by this server.");
  679. if (!body->get_space()) {
  680. return nullptr;
  681. }
  682. return body->get_direct_state();
  683. }
  684. 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) {
  685. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  686. ERR_FAIL_COND_V(!body, false);
  687. ERR_FAIL_COND_V(!body->get_space(), false);
  688. return body->get_space()->test_body_motion(body, p_from, p_motion, p_infinite_inertia, r_result, p_exclude_raycast_shapes, p_exclude);
  689. }
  690. 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) {
  691. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  692. ERR_FAIL_COND_V(!body, 0);
  693. ERR_FAIL_COND_V(!body->get_space(), 0);
  694. return body->get_space()->test_ray_separation(body, p_transform, p_infinite_inertia, r_recover_motion, r_results, p_result_max, p_margin);
  695. }
  696. RID BulletPhysicsServer::soft_body_create(bool p_init_sleeping) {
  697. SoftBodyBullet *body = bulletnew(SoftBodyBullet);
  698. body->set_collision_layer(1);
  699. body->set_collision_mask(1);
  700. if (p_init_sleeping) {
  701. body->set_activation_state(false);
  702. }
  703. CreateThenReturnRID(soft_body_owner, body);
  704. }
  705. void BulletPhysicsServer::soft_body_update_visual_server(RID p_body, class SoftBodyVisualServerHandler *p_visual_server_handler) {
  706. SoftBodyBullet *body = soft_body_owner.get(p_body);
  707. ERR_FAIL_COND(!body);
  708. body->update_visual_server(p_visual_server_handler);
  709. }
  710. void BulletPhysicsServer::soft_body_set_space(RID p_body, RID p_space) {
  711. SoftBodyBullet *body = soft_body_owner.get(p_body);
  712. ERR_FAIL_COND(!body);
  713. SpaceBullet *space = nullptr;
  714. if (p_space.is_valid()) {
  715. space = space_owner.get(p_space);
  716. ERR_FAIL_COND(!space);
  717. }
  718. if (body->get_space() == space) {
  719. return; //pointles
  720. }
  721. body->set_space(space);
  722. }
  723. RID BulletPhysicsServer::soft_body_get_space(RID p_body) const {
  724. SoftBodyBullet *body = soft_body_owner.get(p_body);
  725. ERR_FAIL_COND_V(!body, RID());
  726. SpaceBullet *space = body->get_space();
  727. if (!space) {
  728. return RID();
  729. }
  730. return space->get_self();
  731. }
  732. void BulletPhysicsServer::soft_body_set_mesh(RID p_body, const REF &p_mesh) {
  733. SoftBodyBullet *body = soft_body_owner.get(p_body);
  734. ERR_FAIL_COND(!body);
  735. body->set_soft_mesh(p_mesh);
  736. }
  737. void BulletPhysicsServer::soft_body_set_collision_layer(RID p_body, uint32_t p_layer) {
  738. SoftBodyBullet *body = soft_body_owner.get(p_body);
  739. ERR_FAIL_COND(!body);
  740. body->set_collision_layer(p_layer);
  741. }
  742. uint32_t BulletPhysicsServer::soft_body_get_collision_layer(RID p_body) const {
  743. const SoftBodyBullet *body = soft_body_owner.get(p_body);
  744. ERR_FAIL_COND_V(!body, 0);
  745. return body->get_collision_layer();
  746. }
  747. void BulletPhysicsServer::soft_body_set_collision_mask(RID p_body, uint32_t p_mask) {
  748. SoftBodyBullet *body = soft_body_owner.get(p_body);
  749. ERR_FAIL_COND(!body);
  750. body->set_collision_mask(p_mask);
  751. }
  752. uint32_t BulletPhysicsServer::soft_body_get_collision_mask(RID p_body) const {
  753. const SoftBodyBullet *body = soft_body_owner.get(p_body);
  754. ERR_FAIL_COND_V(!body, 0);
  755. return body->get_collision_mask();
  756. }
  757. void BulletPhysicsServer::soft_body_add_collision_exception(RID p_body, RID p_body_b) {
  758. SoftBodyBullet *body = soft_body_owner.get(p_body);
  759. ERR_FAIL_COND(!body);
  760. CollisionObjectBullet *other_body = rigid_body_owner.get(p_body_b);
  761. if (!other_body) {
  762. other_body = soft_body_owner.get(p_body_b);
  763. }
  764. ERR_FAIL_COND(!other_body);
  765. body->add_collision_exception(other_body);
  766. }
  767. void BulletPhysicsServer::soft_body_remove_collision_exception(RID p_body, RID p_body_b) {
  768. SoftBodyBullet *body = soft_body_owner.get(p_body);
  769. ERR_FAIL_COND(!body);
  770. CollisionObjectBullet *other_body = rigid_body_owner.get(p_body_b);
  771. if (!other_body) {
  772. other_body = soft_body_owner.get(p_body_b);
  773. }
  774. ERR_FAIL_COND(!other_body);
  775. body->remove_collision_exception(other_body);
  776. }
  777. void BulletPhysicsServer::soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {
  778. SoftBodyBullet *body = soft_body_owner.get(p_body);
  779. ERR_FAIL_COND(!body);
  780. for (int i = 0; i < body->get_exceptions().size(); i++) {
  781. p_exceptions->push_back(body->get_exceptions()[i]);
  782. }
  783. }
  784. void BulletPhysicsServer::soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) {
  785. // FIXME: Must be implemented.
  786. WARN_PRINT("soft_body_state is not implemented yet in Bullet backend.");
  787. }
  788. Variant BulletPhysicsServer::soft_body_get_state(RID p_body, BodyState p_state) const {
  789. // FIXME: Must be implemented.
  790. WARN_PRINT("soft_body_state is not implemented yet in Bullet backend.");
  791. return Variant();
  792. }
  793. void BulletPhysicsServer::soft_body_set_transform(RID p_body, const Transform &p_transform) {
  794. SoftBodyBullet *body = soft_body_owner.get(p_body);
  795. ERR_FAIL_COND(!body);
  796. body->set_soft_transform(p_transform);
  797. }
  798. Vector3 BulletPhysicsServer::soft_body_get_vertex_position(RID p_body, int vertex_index) const {
  799. const SoftBodyBullet *body = soft_body_owner.get(p_body);
  800. Vector3 pos;
  801. ERR_FAIL_COND_V(!body, pos);
  802. body->get_node_position(vertex_index, pos);
  803. return pos;
  804. }
  805. void BulletPhysicsServer::soft_body_set_ray_pickable(RID p_body, bool p_enable) {
  806. SoftBodyBullet *body = soft_body_owner.get(p_body);
  807. ERR_FAIL_COND(!body);
  808. body->set_ray_pickable(p_enable);
  809. }
  810. bool BulletPhysicsServer::soft_body_is_ray_pickable(RID p_body) const {
  811. SoftBodyBullet *body = soft_body_owner.get(p_body);
  812. ERR_FAIL_COND_V(!body, false);
  813. return body->is_ray_pickable();
  814. }
  815. void BulletPhysicsServer::soft_body_set_simulation_precision(RID p_body, int p_simulation_precision) {
  816. SoftBodyBullet *body = soft_body_owner.get(p_body);
  817. ERR_FAIL_COND(!body);
  818. body->set_simulation_precision(p_simulation_precision);
  819. }
  820. int BulletPhysicsServer::soft_body_get_simulation_precision(RID p_body) {
  821. SoftBodyBullet *body = soft_body_owner.get(p_body);
  822. ERR_FAIL_COND_V(!body, 0.f);
  823. return body->get_simulation_precision();
  824. }
  825. void BulletPhysicsServer::soft_body_set_total_mass(RID p_body, real_t p_total_mass) {
  826. SoftBodyBullet *body = soft_body_owner.get(p_body);
  827. ERR_FAIL_COND(!body);
  828. body->set_total_mass(p_total_mass);
  829. }
  830. real_t BulletPhysicsServer::soft_body_get_total_mass(RID p_body) {
  831. SoftBodyBullet *body = soft_body_owner.get(p_body);
  832. ERR_FAIL_COND_V(!body, 0.f);
  833. return body->get_total_mass();
  834. }
  835. void BulletPhysicsServer::soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness) {
  836. SoftBodyBullet *body = soft_body_owner.get(p_body);
  837. ERR_FAIL_COND(!body);
  838. body->set_linear_stiffness(p_stiffness);
  839. }
  840. real_t BulletPhysicsServer::soft_body_get_linear_stiffness(RID p_body) {
  841. SoftBodyBullet *body = soft_body_owner.get(p_body);
  842. ERR_FAIL_COND_V(!body, 0.f);
  843. return body->get_linear_stiffness();
  844. }
  845. void BulletPhysicsServer::soft_body_set_areaAngular_stiffness(RID p_body, real_t p_stiffness) {
  846. SoftBodyBullet *body = soft_body_owner.get(p_body);
  847. ERR_FAIL_COND(!body);
  848. body->set_areaAngular_stiffness(p_stiffness);
  849. }
  850. real_t BulletPhysicsServer::soft_body_get_areaAngular_stiffness(RID p_body) {
  851. SoftBodyBullet *body = soft_body_owner.get(p_body);
  852. ERR_FAIL_COND_V(!body, 0.f);
  853. return body->get_areaAngular_stiffness();
  854. }
  855. void BulletPhysicsServer::soft_body_set_volume_stiffness(RID p_body, real_t p_stiffness) {
  856. SoftBodyBullet *body = soft_body_owner.get(p_body);
  857. ERR_FAIL_COND(!body);
  858. body->set_volume_stiffness(p_stiffness);
  859. }
  860. real_t BulletPhysicsServer::soft_body_get_volume_stiffness(RID p_body) {
  861. SoftBodyBullet *body = soft_body_owner.get(p_body);
  862. ERR_FAIL_COND_V(!body, 0.f);
  863. return body->get_volume_stiffness();
  864. }
  865. void BulletPhysicsServer::soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) {
  866. SoftBodyBullet *body = soft_body_owner.get(p_body);
  867. ERR_FAIL_COND(!body);
  868. body->set_pressure_coefficient(p_pressure_coefficient);
  869. }
  870. real_t BulletPhysicsServer::soft_body_get_pressure_coefficient(RID p_body) {
  871. SoftBodyBullet *body = soft_body_owner.get(p_body);
  872. ERR_FAIL_COND_V(!body, 0.f);
  873. return body->get_pressure_coefficient();
  874. }
  875. void BulletPhysicsServer::soft_body_set_pose_matching_coefficient(RID p_body, real_t p_pose_matching_coefficient) {
  876. SoftBodyBullet *body = soft_body_owner.get(p_body);
  877. ERR_FAIL_COND(!body);
  878. return body->set_pose_matching_coefficient(p_pose_matching_coefficient);
  879. }
  880. real_t BulletPhysicsServer::soft_body_get_pose_matching_coefficient(RID p_body) {
  881. SoftBodyBullet *body = soft_body_owner.get(p_body);
  882. ERR_FAIL_COND_V(!body, 0.f);
  883. return body->get_pose_matching_coefficient();
  884. }
  885. void BulletPhysicsServer::soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient) {
  886. SoftBodyBullet *body = soft_body_owner.get(p_body);
  887. ERR_FAIL_COND(!body);
  888. body->set_damping_coefficient(p_damping_coefficient);
  889. }
  890. real_t BulletPhysicsServer::soft_body_get_damping_coefficient(RID p_body) {
  891. SoftBodyBullet *body = soft_body_owner.get(p_body);
  892. ERR_FAIL_COND_V(!body, 0.f);
  893. return body->get_damping_coefficient();
  894. }
  895. void BulletPhysicsServer::soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient) {
  896. SoftBodyBullet *body = soft_body_owner.get(p_body);
  897. ERR_FAIL_COND(!body);
  898. body->set_drag_coefficient(p_drag_coefficient);
  899. }
  900. real_t BulletPhysicsServer::soft_body_get_drag_coefficient(RID p_body) {
  901. SoftBodyBullet *body = soft_body_owner.get(p_body);
  902. ERR_FAIL_COND_V(!body, 0.f);
  903. return body->get_drag_coefficient();
  904. }
  905. void BulletPhysicsServer::soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) {
  906. SoftBodyBullet *body = soft_body_owner.get(p_body);
  907. ERR_FAIL_COND(!body);
  908. body->set_node_position(p_point_index, p_global_position);
  909. }
  910. Vector3 BulletPhysicsServer::soft_body_get_point_global_position(RID p_body, int p_point_index) {
  911. SoftBodyBullet *body = soft_body_owner.get(p_body);
  912. ERR_FAIL_COND_V(!body, Vector3(0., 0., 0.));
  913. Vector3 pos;
  914. body->get_node_position(p_point_index, pos);
  915. return pos;
  916. }
  917. Vector3 BulletPhysicsServer::soft_body_get_point_offset(RID p_body, int p_point_index) const {
  918. SoftBodyBullet *body = soft_body_owner.get(p_body);
  919. ERR_FAIL_COND_V(!body, Vector3());
  920. Vector3 res;
  921. body->get_node_offset(p_point_index, res);
  922. return res;
  923. }
  924. void BulletPhysicsServer::soft_body_remove_all_pinned_points(RID p_body) {
  925. SoftBodyBullet *body = soft_body_owner.get(p_body);
  926. ERR_FAIL_COND(!body);
  927. body->reset_all_node_mass();
  928. }
  929. void BulletPhysicsServer::soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) {
  930. SoftBodyBullet *body = soft_body_owner.get(p_body);
  931. ERR_FAIL_COND(!body);
  932. body->set_node_mass(p_point_index, p_pin ? 0 : 1);
  933. }
  934. bool BulletPhysicsServer::soft_body_is_point_pinned(RID p_body, int p_point_index) {
  935. SoftBodyBullet *body = soft_body_owner.get(p_body);
  936. ERR_FAIL_COND_V(!body, 0.f);
  937. return body->get_node_mass(p_point_index);
  938. }
  939. PhysicsServer::JointType BulletPhysicsServer::joint_get_type(RID p_joint) const {
  940. JointBullet *joint = joint_owner.get(p_joint);
  941. ERR_FAIL_COND_V(!joint, JOINT_PIN);
  942. return joint->get_type();
  943. }
  944. void BulletPhysicsServer::joint_set_solver_priority(RID p_joint, int p_priority) {
  945. // Joint priority not supported by bullet
  946. }
  947. int BulletPhysicsServer::joint_get_solver_priority(RID p_joint) const {
  948. // Joint priority not supported by bullet
  949. return 0;
  950. }
  951. void BulletPhysicsServer::joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) {
  952. JointBullet *joint = joint_owner.get(p_joint);
  953. ERR_FAIL_COND(!joint);
  954. joint->disable_collisions_between_bodies(p_disable);
  955. }
  956. bool BulletPhysicsServer::joint_is_disabled_collisions_between_bodies(RID p_joint) const {
  957. JointBullet *joint(joint_owner.get(p_joint));
  958. ERR_FAIL_COND_V(!joint, false);
  959. return joint->is_disabled_collisions_between_bodies();
  960. }
  961. RID BulletPhysicsServer::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) {
  962. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  963. ERR_FAIL_COND_V(!body_A, RID());
  964. JointAssertSpace(body_A, "A", RID());
  965. RigidBodyBullet *body_B = nullptr;
  966. if (p_body_B.is_valid()) {
  967. body_B = rigid_body_owner.get(p_body_B);
  968. JointAssertSpace(body_B, "B", RID());
  969. JointAssertSameSpace(body_A, body_B, RID());
  970. }
  971. ERR_FAIL_COND_V(body_A == body_B, RID());
  972. JointBullet *joint = bulletnew(PinJointBullet(body_A, p_local_A, body_B, p_local_B));
  973. AddJointToSpace(body_A, joint);
  974. CreateThenReturnRID(joint_owner, joint);
  975. }
  976. void BulletPhysicsServer::pin_joint_set_param(RID p_joint, PinJointParam p_param, float p_value) {
  977. JointBullet *joint = joint_owner.get(p_joint);
  978. ERR_FAIL_COND(!joint);
  979. ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
  980. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  981. pin_joint->set_param(p_param, p_value);
  982. }
  983. float BulletPhysicsServer::pin_joint_get_param(RID p_joint, PinJointParam p_param) const {
  984. JointBullet *joint = joint_owner.get(p_joint);
  985. ERR_FAIL_COND_V(!joint, 0);
  986. ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, 0);
  987. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  988. return pin_joint->get_param(p_param);
  989. }
  990. void BulletPhysicsServer::pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) {
  991. JointBullet *joint = joint_owner.get(p_joint);
  992. ERR_FAIL_COND(!joint);
  993. ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
  994. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  995. pin_joint->setPivotInA(p_A);
  996. }
  997. Vector3 BulletPhysicsServer::pin_joint_get_local_a(RID p_joint) const {
  998. JointBullet *joint = joint_owner.get(p_joint);
  999. ERR_FAIL_COND_V(!joint, Vector3());
  1000. ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3());
  1001. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  1002. return pin_joint->getPivotInA();
  1003. }
  1004. void BulletPhysicsServer::pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) {
  1005. JointBullet *joint = joint_owner.get(p_joint);
  1006. ERR_FAIL_COND(!joint);
  1007. ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
  1008. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  1009. pin_joint->setPivotInB(p_B);
  1010. }
  1011. Vector3 BulletPhysicsServer::pin_joint_get_local_b(RID p_joint) const {
  1012. JointBullet *joint = joint_owner.get(p_joint);
  1013. ERR_FAIL_COND_V(!joint, Vector3());
  1014. ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3());
  1015. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  1016. return pin_joint->getPivotInB();
  1017. }
  1018. RID BulletPhysicsServer::joint_create_hinge(RID p_body_A, const Transform &p_hinge_A, RID p_body_B, const Transform &p_hinge_B) {
  1019. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1020. ERR_FAIL_COND_V(!body_A, RID());
  1021. JointAssertSpace(body_A, "A", RID());
  1022. RigidBodyBullet *body_B = nullptr;
  1023. if (p_body_B.is_valid()) {
  1024. body_B = rigid_body_owner.get(p_body_B);
  1025. JointAssertSpace(body_B, "B", RID());
  1026. JointAssertSameSpace(body_A, body_B, RID());
  1027. }
  1028. ERR_FAIL_COND_V(body_A == body_B, RID());
  1029. JointBullet *joint = bulletnew(HingeJointBullet(body_A, body_B, p_hinge_A, p_hinge_B));
  1030. AddJointToSpace(body_A, joint);
  1031. CreateThenReturnRID(joint_owner, joint);
  1032. }
  1033. 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) {
  1034. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1035. ERR_FAIL_COND_V(!body_A, RID());
  1036. JointAssertSpace(body_A, "A", RID());
  1037. RigidBodyBullet *body_B = nullptr;
  1038. if (p_body_B.is_valid()) {
  1039. body_B = rigid_body_owner.get(p_body_B);
  1040. JointAssertSpace(body_B, "B", RID());
  1041. JointAssertSameSpace(body_A, body_B, RID());
  1042. }
  1043. ERR_FAIL_COND_V(body_A == body_B, RID());
  1044. JointBullet *joint = bulletnew(HingeJointBullet(body_A, body_B, p_pivot_A, p_pivot_B, p_axis_A, p_axis_B));
  1045. AddJointToSpace(body_A, joint);
  1046. CreateThenReturnRID(joint_owner, joint);
  1047. }
  1048. void BulletPhysicsServer::hinge_joint_set_param(RID p_joint, HingeJointParam p_param, float p_value) {
  1049. JointBullet *joint = joint_owner.get(p_joint);
  1050. ERR_FAIL_COND(!joint);
  1051. ERR_FAIL_COND(joint->get_type() != JOINT_HINGE);
  1052. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  1053. hinge_joint->set_param(p_param, p_value);
  1054. }
  1055. float BulletPhysicsServer::hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const {
  1056. JointBullet *joint = joint_owner.get(p_joint);
  1057. ERR_FAIL_COND_V(!joint, 0);
  1058. ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, 0);
  1059. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  1060. return hinge_joint->get_param(p_param);
  1061. }
  1062. void BulletPhysicsServer::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value) {
  1063. JointBullet *joint = joint_owner.get(p_joint);
  1064. ERR_FAIL_COND(!joint);
  1065. ERR_FAIL_COND(joint->get_type() != JOINT_HINGE);
  1066. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  1067. hinge_joint->set_flag(p_flag, p_value);
  1068. }
  1069. bool BulletPhysicsServer::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const {
  1070. JointBullet *joint = joint_owner.get(p_joint);
  1071. ERR_FAIL_COND_V(!joint, false);
  1072. ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, false);
  1073. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  1074. return hinge_joint->get_flag(p_flag);
  1075. }
  1076. 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) {
  1077. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1078. ERR_FAIL_COND_V(!body_A, RID());
  1079. JointAssertSpace(body_A, "A", RID());
  1080. RigidBodyBullet *body_B = nullptr;
  1081. if (p_body_B.is_valid()) {
  1082. body_B = rigid_body_owner.get(p_body_B);
  1083. JointAssertSpace(body_B, "B", RID());
  1084. JointAssertSameSpace(body_A, body_B, RID());
  1085. }
  1086. ERR_FAIL_COND_V(body_A == body_B, RID());
  1087. JointBullet *joint = bulletnew(SliderJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B));
  1088. AddJointToSpace(body_A, joint);
  1089. CreateThenReturnRID(joint_owner, joint);
  1090. }
  1091. void BulletPhysicsServer::slider_joint_set_param(RID p_joint, SliderJointParam p_param, float p_value) {
  1092. JointBullet *joint = joint_owner.get(p_joint);
  1093. ERR_FAIL_COND(!joint);
  1094. ERR_FAIL_COND(joint->get_type() != JOINT_SLIDER);
  1095. SliderJointBullet *slider_joint = static_cast<SliderJointBullet *>(joint);
  1096. slider_joint->set_param(p_param, p_value);
  1097. }
  1098. float BulletPhysicsServer::slider_joint_get_param(RID p_joint, SliderJointParam p_param) const {
  1099. JointBullet *joint = joint_owner.get(p_joint);
  1100. ERR_FAIL_COND_V(!joint, 0);
  1101. ERR_FAIL_COND_V(joint->get_type() != JOINT_SLIDER, 0);
  1102. SliderJointBullet *slider_joint = static_cast<SliderJointBullet *>(joint);
  1103. return slider_joint->get_param(p_param);
  1104. }
  1105. 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) {
  1106. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1107. ERR_FAIL_COND_V(!body_A, RID());
  1108. JointAssertSpace(body_A, "A", RID());
  1109. RigidBodyBullet *body_B = nullptr;
  1110. if (p_body_B.is_valid()) {
  1111. body_B = rigid_body_owner.get(p_body_B);
  1112. JointAssertSpace(body_B, "B", RID());
  1113. JointAssertSameSpace(body_A, body_B, RID());
  1114. }
  1115. JointBullet *joint = bulletnew(ConeTwistJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B));
  1116. AddJointToSpace(body_A, joint);
  1117. CreateThenReturnRID(joint_owner, joint);
  1118. }
  1119. void BulletPhysicsServer::cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, float p_value) {
  1120. JointBullet *joint = joint_owner.get(p_joint);
  1121. ERR_FAIL_COND(!joint);
  1122. ERR_FAIL_COND(joint->get_type() != JOINT_CONE_TWIST);
  1123. ConeTwistJointBullet *coneTwist_joint = static_cast<ConeTwistJointBullet *>(joint);
  1124. coneTwist_joint->set_param(p_param, p_value);
  1125. }
  1126. float BulletPhysicsServer::cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const {
  1127. JointBullet *joint = joint_owner.get(p_joint);
  1128. ERR_FAIL_COND_V(!joint, 0.);
  1129. ERR_FAIL_COND_V(joint->get_type() != JOINT_CONE_TWIST, 0.);
  1130. ConeTwistJointBullet *coneTwist_joint = static_cast<ConeTwistJointBullet *>(joint);
  1131. return coneTwist_joint->get_param(p_param);
  1132. }
  1133. 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) {
  1134. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1135. ERR_FAIL_COND_V(!body_A, RID());
  1136. JointAssertSpace(body_A, "A", RID());
  1137. RigidBodyBullet *body_B = nullptr;
  1138. if (p_body_B.is_valid()) {
  1139. body_B = rigid_body_owner.get(p_body_B);
  1140. JointAssertSpace(body_B, "B", RID());
  1141. JointAssertSameSpace(body_A, body_B, RID());
  1142. }
  1143. ERR_FAIL_COND_V(body_A == body_B, RID());
  1144. JointBullet *joint = bulletnew(Generic6DOFJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B));
  1145. AddJointToSpace(body_A, joint);
  1146. CreateThenReturnRID(joint_owner, joint);
  1147. }
  1148. void BulletPhysicsServer::generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param, float p_value) {
  1149. JointBullet *joint = joint_owner.get(p_joint);
  1150. ERR_FAIL_COND(!joint);
  1151. ERR_FAIL_COND(joint->get_type() != JOINT_6DOF);
  1152. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1153. generic_6dof_joint->set_param(p_axis, p_param, p_value);
  1154. }
  1155. float BulletPhysicsServer::generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param) {
  1156. JointBullet *joint = joint_owner.get(p_joint);
  1157. ERR_FAIL_COND_V(!joint, 0);
  1158. ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, 0);
  1159. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1160. return generic_6dof_joint->get_param(p_axis, p_param);
  1161. }
  1162. void BulletPhysicsServer::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag, bool p_enable) {
  1163. JointBullet *joint = joint_owner.get(p_joint);
  1164. ERR_FAIL_COND(!joint);
  1165. ERR_FAIL_COND(joint->get_type() != JOINT_6DOF);
  1166. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1167. generic_6dof_joint->set_flag(p_axis, p_flag, p_enable);
  1168. }
  1169. bool BulletPhysicsServer::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag) {
  1170. JointBullet *joint = joint_owner.get(p_joint);
  1171. ERR_FAIL_COND_V(!joint, false);
  1172. ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, false);
  1173. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1174. return generic_6dof_joint->get_flag(p_axis, p_flag);
  1175. }
  1176. void BulletPhysicsServer::free(RID p_rid) {
  1177. if (!p_rid.is_valid()) {
  1178. ERR_FAIL_MSG("PhysicsServer attempted to free a NULL RID.");
  1179. return;
  1180. }
  1181. if (shape_owner.owns(p_rid)) {
  1182. ShapeBullet *shape = shape_owner.get(p_rid);
  1183. // Notify the shape is configured
  1184. for (Map<ShapeOwnerBullet *, int>::Element *element = shape->get_owners().front(); element; element = element->next()) {
  1185. static_cast<ShapeOwnerBullet *>(element->key())->remove_shape_full(shape);
  1186. }
  1187. shape_owner.free(p_rid);
  1188. bulletdelete(shape);
  1189. } else if (rigid_body_owner.owns(p_rid)) {
  1190. RigidBodyBullet *body = rigid_body_owner.get(p_rid);
  1191. body->set_space(nullptr);
  1192. body->remove_all_shapes(true, true);
  1193. rigid_body_owner.free(p_rid);
  1194. bulletdelete(body);
  1195. } else if (soft_body_owner.owns(p_rid)) {
  1196. SoftBodyBullet *body = soft_body_owner.get(p_rid);
  1197. body->set_space(nullptr);
  1198. soft_body_owner.free(p_rid);
  1199. bulletdelete(body);
  1200. } else if (area_owner.owns(p_rid)) {
  1201. AreaBullet *area = area_owner.get(p_rid);
  1202. area->set_space(nullptr);
  1203. area->remove_all_shapes(true, true);
  1204. area_owner.free(p_rid);
  1205. bulletdelete(area);
  1206. } else if (joint_owner.owns(p_rid)) {
  1207. JointBullet *joint = joint_owner.get(p_rid);
  1208. joint->destroy_internal_constraint();
  1209. joint_owner.free(p_rid);
  1210. bulletdelete(joint);
  1211. } else if (space_owner.owns(p_rid)) {
  1212. SpaceBullet *space = space_owner.get(p_rid);
  1213. space->remove_all_collision_objects();
  1214. space_set_active(p_rid, false);
  1215. space_owner.free(p_rid);
  1216. bulletdelete(space);
  1217. } else {
  1218. ERR_FAIL_MSG("RID not found by PhysicsServer.");
  1219. }
  1220. }
  1221. void BulletPhysicsServer::init() {
  1222. }
  1223. void BulletPhysicsServer::step(float p_deltaTime) {
  1224. if (!active) {
  1225. return;
  1226. }
  1227. for (int i = 0; i < active_spaces_count; ++i) {
  1228. active_spaces[i]->step(p_deltaTime);
  1229. }
  1230. }
  1231. void BulletPhysicsServer::flush_queries() {
  1232. }
  1233. void BulletPhysicsServer::finish() {
  1234. }
  1235. void BulletPhysicsServer::set_collision_iterations(int p_iterations) {
  1236. WARN_PRINT("Changing the number of 3D physics collision iterations is only supported when using GodotPhysics, not Bullet.");
  1237. }
  1238. int BulletPhysicsServer::get_process_info(ProcessInfo p_info) {
  1239. return 0;
  1240. }
  1241. CollisionObjectBullet *BulletPhysicsServer::get_collision_object(RID p_object) const {
  1242. if (rigid_body_owner.owns(p_object)) {
  1243. return rigid_body_owner.getornull(p_object);
  1244. }
  1245. if (area_owner.owns(p_object)) {
  1246. return area_owner.getornull(p_object);
  1247. }
  1248. if (soft_body_owner.owns(p_object)) {
  1249. return soft_body_owner.getornull(p_object);
  1250. }
  1251. return nullptr;
  1252. }
  1253. RigidCollisionObjectBullet *BulletPhysicsServer::get_rigid_collision_object(RID p_object) const {
  1254. if (rigid_body_owner.owns(p_object)) {
  1255. return rigid_body_owner.getornull(p_object);
  1256. }
  1257. if (area_owner.owns(p_object)) {
  1258. return area_owner.getornull(p_object);
  1259. }
  1260. return nullptr;
  1261. }