bullet_physics_server.cpp 51 KB

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