bullet_physics_server.cpp 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591
  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. real_t BulletPhysicsServer::shape_get_custom_solver_bias(RID p_shape) const {
  137. //WARN_PRINT("Bias not supported by Bullet physics engine");
  138. return 0.;
  139. }
  140. RID BulletPhysicsServer::space_create() {
  141. SpaceBullet *space = bulletnew(SpaceBullet);
  142. CreateThenReturnRID(space_owner, space);
  143. }
  144. void BulletPhysicsServer::space_set_active(RID p_space, bool p_active) {
  145. SpaceBullet *space = space_owner.get(p_space);
  146. ERR_FAIL_COND(!space);
  147. if (space_is_active(p_space) == p_active) {
  148. return;
  149. }
  150. if (p_active) {
  151. ++active_spaces_count;
  152. active_spaces.push_back(space);
  153. } else {
  154. --active_spaces_count;
  155. active_spaces.erase(space);
  156. }
  157. }
  158. bool BulletPhysicsServer::space_is_active(RID p_space) const {
  159. SpaceBullet *space = space_owner.get(p_space);
  160. ERR_FAIL_COND_V(!space, false);
  161. return -1 != active_spaces.find(space);
  162. }
  163. void BulletPhysicsServer::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) {
  164. SpaceBullet *space = space_owner.get(p_space);
  165. ERR_FAIL_COND(!space);
  166. space->set_param(p_param, p_value);
  167. }
  168. real_t BulletPhysicsServer::space_get_param(RID p_space, SpaceParameter p_param) const {
  169. SpaceBullet *space = space_owner.get(p_space);
  170. ERR_FAIL_COND_V(!space, 0);
  171. return space->get_param(p_param);
  172. }
  173. PhysicsDirectSpaceState *BulletPhysicsServer::space_get_direct_state(RID p_space) {
  174. SpaceBullet *space = space_owner.get(p_space);
  175. ERR_FAIL_COND_V(!space, NULL);
  176. return space->get_direct_state();
  177. }
  178. void BulletPhysicsServer::space_set_debug_contacts(RID p_space, int p_max_contacts) {
  179. SpaceBullet *space = space_owner.get(p_space);
  180. ERR_FAIL_COND(!space);
  181. space->set_debug_contacts(p_max_contacts);
  182. }
  183. Vector<Vector3> BulletPhysicsServer::space_get_contacts(RID p_space) const {
  184. SpaceBullet *space = space_owner.get(p_space);
  185. ERR_FAIL_COND_V(!space, Vector<Vector3>());
  186. return space->get_debug_contacts();
  187. }
  188. int BulletPhysicsServer::space_get_contact_count(RID p_space) const {
  189. SpaceBullet *space = space_owner.get(p_space);
  190. ERR_FAIL_COND_V(!space, 0);
  191. return space->get_debug_contact_count();
  192. }
  193. RID BulletPhysicsServer::area_create() {
  194. AreaBullet *area = bulletnew(AreaBullet);
  195. area->set_collision_layer(1);
  196. area->set_collision_mask(1);
  197. CreateThenReturnRID(area_owner, area)
  198. }
  199. void BulletPhysicsServer::area_set_space(RID p_area, RID p_space) {
  200. AreaBullet *area = area_owner.get(p_area);
  201. ERR_FAIL_COND(!area);
  202. SpaceBullet *space = NULL;
  203. if (p_space.is_valid()) {
  204. space = space_owner.get(p_space);
  205. ERR_FAIL_COND(!space);
  206. }
  207. area->set_space(space);
  208. }
  209. RID BulletPhysicsServer::area_get_space(RID p_area) const {
  210. AreaBullet *area = area_owner.get(p_area);
  211. return area->get_space()->get_self();
  212. }
  213. void BulletPhysicsServer::area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) {
  214. AreaBullet *area = area_owner.get(p_area);
  215. ERR_FAIL_COND(!area)
  216. area->set_spOv_mode(p_mode);
  217. }
  218. PhysicsServer::AreaSpaceOverrideMode BulletPhysicsServer::area_get_space_override_mode(RID p_area) const {
  219. AreaBullet *area = area_owner.get(p_area);
  220. ERR_FAIL_COND_V(!area, PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED);
  221. return area->get_spOv_mode();
  222. }
  223. void BulletPhysicsServer::area_add_shape(RID p_area, RID p_shape, const Transform &p_transform) {
  224. AreaBullet *area = area_owner.get(p_area);
  225. ERR_FAIL_COND(!area);
  226. ShapeBullet *shape = shape_owner.get(p_shape);
  227. ERR_FAIL_COND(!shape);
  228. area->add_shape(shape, p_transform);
  229. }
  230. void BulletPhysicsServer::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) {
  231. AreaBullet *area = area_owner.get(p_area);
  232. ERR_FAIL_COND(!area);
  233. ShapeBullet *shape = shape_owner.get(p_shape);
  234. ERR_FAIL_COND(!shape);
  235. area->set_shape(p_shape_idx, shape);
  236. }
  237. void BulletPhysicsServer::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform) {
  238. AreaBullet *area = area_owner.get(p_area);
  239. ERR_FAIL_COND(!area);
  240. area->set_shape_transform(p_shape_idx, p_transform);
  241. }
  242. int BulletPhysicsServer::area_get_shape_count(RID p_area) const {
  243. AreaBullet *area = area_owner.get(p_area);
  244. ERR_FAIL_COND_V(!area, 0);
  245. return area->get_shape_count();
  246. }
  247. RID BulletPhysicsServer::area_get_shape(RID p_area, int p_shape_idx) const {
  248. AreaBullet *area = area_owner.get(p_area);
  249. ERR_FAIL_COND_V(!area, RID());
  250. return area->get_shape(p_shape_idx)->get_self();
  251. }
  252. Transform BulletPhysicsServer::area_get_shape_transform(RID p_area, int p_shape_idx) const {
  253. AreaBullet *area = area_owner.get(p_area);
  254. ERR_FAIL_COND_V(!area, Transform());
  255. return area->get_shape_transform(p_shape_idx);
  256. }
  257. void BulletPhysicsServer::area_remove_shape(RID p_area, int p_shape_idx) {
  258. AreaBullet *area = area_owner.get(p_area);
  259. ERR_FAIL_COND(!area);
  260. return area->remove_shape(p_shape_idx);
  261. }
  262. void BulletPhysicsServer::area_clear_shapes(RID p_area) {
  263. AreaBullet *area = area_owner.get(p_area);
  264. ERR_FAIL_COND(!area);
  265. for (int i = area->get_shape_count(); 0 < i; --i)
  266. area->remove_shape(0);
  267. }
  268. void BulletPhysicsServer::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) {
  269. AreaBullet *area = area_owner.get(p_area);
  270. ERR_FAIL_COND(!area);
  271. area->set_shape_disabled(p_shape_idx, p_disabled);
  272. }
  273. void BulletPhysicsServer::area_attach_object_instance_id(RID p_area, ObjectID p_ID) {
  274. if (space_owner.owns(p_area)) {
  275. return;
  276. }
  277. AreaBullet *area = area_owner.get(p_area);
  278. ERR_FAIL_COND(!area);
  279. area->set_instance_id(p_ID);
  280. }
  281. ObjectID BulletPhysicsServer::area_get_object_instance_id(RID p_area) const {
  282. if (space_owner.owns(p_area)) {
  283. return 0;
  284. }
  285. AreaBullet *area = area_owner.get(p_area);
  286. ERR_FAIL_COND_V(!area, ObjectID());
  287. return area->get_instance_id();
  288. }
  289. void BulletPhysicsServer::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) {
  290. if (space_owner.owns(p_area)) {
  291. SpaceBullet *space = space_owner.get(p_area);
  292. if (space) {
  293. space->set_param(p_param, p_value);
  294. }
  295. } else {
  296. AreaBullet *area = area_owner.get(p_area);
  297. ERR_FAIL_COND(!area);
  298. area->set_param(p_param, p_value);
  299. }
  300. }
  301. Variant BulletPhysicsServer::area_get_param(RID p_area, AreaParameter p_param) const {
  302. if (space_owner.owns(p_area)) {
  303. SpaceBullet *space = space_owner.get(p_area);
  304. return space->get_param(p_param);
  305. } else {
  306. AreaBullet *area = area_owner.get(p_area);
  307. ERR_FAIL_COND_V(!area, Variant());
  308. return area->get_param(p_param);
  309. }
  310. }
  311. void BulletPhysicsServer::area_set_transform(RID p_area, const Transform &p_transform) {
  312. AreaBullet *area = area_owner.get(p_area);
  313. ERR_FAIL_COND(!area);
  314. area->set_transform(p_transform);
  315. }
  316. Transform BulletPhysicsServer::area_get_transform(RID p_area) const {
  317. AreaBullet *area = area_owner.get(p_area);
  318. ERR_FAIL_COND_V(!area, Transform());
  319. return area->get_transform();
  320. }
  321. void BulletPhysicsServer::area_set_collision_mask(RID p_area, uint32_t p_mask) {
  322. AreaBullet *area = area_owner.get(p_area);
  323. ERR_FAIL_COND(!area);
  324. area->set_collision_mask(p_mask);
  325. }
  326. void BulletPhysicsServer::area_set_collision_layer(RID p_area, uint32_t p_layer) {
  327. AreaBullet *area = area_owner.get(p_area);
  328. ERR_FAIL_COND(!area);
  329. area->set_collision_layer(p_layer);
  330. }
  331. void BulletPhysicsServer::area_set_monitorable(RID p_area, bool p_monitorable) {
  332. AreaBullet *area = area_owner.get(p_area);
  333. ERR_FAIL_COND(!area);
  334. area->set_monitorable(p_monitorable);
  335. }
  336. void BulletPhysicsServer::area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) {
  337. AreaBullet *area = area_owner.get(p_area);
  338. ERR_FAIL_COND(!area);
  339. area->set_event_callback(CollisionObjectBullet::TYPE_RIGID_BODY, p_receiver ? p_receiver->get_instance_id() : 0, p_method);
  340. }
  341. void BulletPhysicsServer::area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) {
  342. AreaBullet *area = area_owner.get(p_area);
  343. ERR_FAIL_COND(!area);
  344. area->set_event_callback(CollisionObjectBullet::TYPE_AREA, p_receiver ? p_receiver->get_instance_id() : 0, p_method);
  345. }
  346. void BulletPhysicsServer::area_set_ray_pickable(RID p_area, bool p_enable) {
  347. AreaBullet *area = area_owner.get(p_area);
  348. ERR_FAIL_COND(!area);
  349. area->set_ray_pickable(p_enable);
  350. }
  351. bool BulletPhysicsServer::area_is_ray_pickable(RID p_area) const {
  352. AreaBullet *area = area_owner.get(p_area);
  353. ERR_FAIL_COND_V(!area, false);
  354. return area->is_ray_pickable();
  355. }
  356. RID BulletPhysicsServer::body_create(BodyMode p_mode, bool p_init_sleeping) {
  357. RigidBodyBullet *body = bulletnew(RigidBodyBullet);
  358. body->set_mode(p_mode);
  359. body->set_collision_layer(1);
  360. body->set_collision_mask(1);
  361. if (p_init_sleeping)
  362. body->set_state(BODY_STATE_SLEEPING, p_init_sleeping);
  363. CreateThenReturnRID(rigid_body_owner, body);
  364. }
  365. void BulletPhysicsServer::body_set_space(RID p_body, RID p_space) {
  366. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  367. ERR_FAIL_COND(!body);
  368. SpaceBullet *space = NULL;
  369. if (p_space.is_valid()) {
  370. space = space_owner.get(p_space);
  371. ERR_FAIL_COND(!space);
  372. }
  373. if (body->get_space() == space)
  374. return; //pointles
  375. body->set_space(space);
  376. }
  377. RID BulletPhysicsServer::body_get_space(RID p_body) const {
  378. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  379. ERR_FAIL_COND_V(!body, RID());
  380. SpaceBullet *space = body->get_space();
  381. if (!space)
  382. return RID();
  383. return space->get_self();
  384. }
  385. void BulletPhysicsServer::body_set_mode(RID p_body, PhysicsServer::BodyMode p_mode) {
  386. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  387. ERR_FAIL_COND(!body);
  388. body->set_mode(p_mode);
  389. }
  390. PhysicsServer::BodyMode BulletPhysicsServer::body_get_mode(RID p_body) const {
  391. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  392. ERR_FAIL_COND_V(!body, BODY_MODE_STATIC);
  393. return body->get_mode();
  394. }
  395. void BulletPhysicsServer::body_add_shape(RID p_body, RID p_shape, const Transform &p_transform) {
  396. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  397. ERR_FAIL_COND(!body);
  398. ShapeBullet *shape = shape_owner.get(p_shape);
  399. ERR_FAIL_COND(!shape);
  400. body->add_shape(shape, p_transform);
  401. }
  402. void BulletPhysicsServer::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) {
  403. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  404. ERR_FAIL_COND(!body);
  405. ShapeBullet *shape = shape_owner.get(p_shape);
  406. ERR_FAIL_COND(!shape);
  407. body->set_shape(p_shape_idx, shape);
  408. }
  409. void BulletPhysicsServer::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform) {
  410. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  411. ERR_FAIL_COND(!body);
  412. body->set_shape_transform(p_shape_idx, p_transform);
  413. }
  414. int BulletPhysicsServer::body_get_shape_count(RID p_body) const {
  415. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  416. ERR_FAIL_COND_V(!body, 0);
  417. return body->get_shape_count();
  418. }
  419. RID BulletPhysicsServer::body_get_shape(RID p_body, int p_shape_idx) const {
  420. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  421. ERR_FAIL_COND_V(!body, RID());
  422. ShapeBullet *shape = body->get_shape(p_shape_idx);
  423. ERR_FAIL_COND_V(!shape, RID());
  424. return shape->get_self();
  425. }
  426. Transform BulletPhysicsServer::body_get_shape_transform(RID p_body, int p_shape_idx) const {
  427. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  428. ERR_FAIL_COND_V(!body, Transform());
  429. return body->get_shape_transform(p_shape_idx);
  430. }
  431. void BulletPhysicsServer::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) {
  432. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  433. ERR_FAIL_COND(!body);
  434. body->set_shape_disabled(p_shape_idx, p_disabled);
  435. }
  436. void BulletPhysicsServer::body_remove_shape(RID p_body, int p_shape_idx) {
  437. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  438. ERR_FAIL_COND(!body);
  439. body->remove_shape(p_shape_idx);
  440. }
  441. void BulletPhysicsServer::body_clear_shapes(RID p_body) {
  442. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  443. ERR_FAIL_COND(!body);
  444. body->remove_all_shapes();
  445. }
  446. void BulletPhysicsServer::body_attach_object_instance_id(RID p_body, uint32_t p_ID) {
  447. CollisionObjectBullet *body = get_collisin_object(p_body);
  448. ERR_FAIL_COND(!body);
  449. body->set_instance_id(p_ID);
  450. }
  451. uint32_t BulletPhysicsServer::body_get_object_instance_id(RID p_body) const {
  452. CollisionObjectBullet *body = get_collisin_object(p_body);
  453. ERR_FAIL_COND_V(!body, 0);
  454. return body->get_instance_id();
  455. }
  456. void BulletPhysicsServer::body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) {
  457. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  458. ERR_FAIL_COND(!body);
  459. body->set_continuous_collision_detection(p_enable);
  460. }
  461. bool BulletPhysicsServer::body_is_continuous_collision_detection_enabled(RID p_body) const {
  462. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  463. ERR_FAIL_COND_V(!body, false);
  464. return body->is_continuous_collision_detection_enabled();
  465. }
  466. void BulletPhysicsServer::body_set_collision_layer(RID p_body, uint32_t p_layer) {
  467. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  468. ERR_FAIL_COND(!body);
  469. body->set_collision_layer(p_layer);
  470. }
  471. uint32_t BulletPhysicsServer::body_get_collision_layer(RID p_body) const {
  472. const RigidBodyBullet *body = rigid_body_owner.get(p_body);
  473. ERR_FAIL_COND_V(!body, 0);
  474. return body->get_collision_layer();
  475. }
  476. void BulletPhysicsServer::body_set_collision_mask(RID p_body, uint32_t p_mask) {
  477. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  478. ERR_FAIL_COND(!body);
  479. body->set_collision_mask(p_mask);
  480. }
  481. uint32_t BulletPhysicsServer::body_get_collision_mask(RID p_body) const {
  482. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  483. ERR_FAIL_COND_V(!body, 0);
  484. return body->get_collision_mask();
  485. }
  486. void BulletPhysicsServer::body_set_user_flags(RID p_body, uint32_t p_flags) {
  487. // This function si not currently supported
  488. }
  489. uint32_t BulletPhysicsServer::body_get_user_flags(RID p_body) const {
  490. // This function si not currently supported
  491. return 0;
  492. }
  493. void BulletPhysicsServer::body_set_param(RID p_body, BodyParameter p_param, float p_value) {
  494. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  495. ERR_FAIL_COND(!body);
  496. body->set_param(p_param, p_value);
  497. }
  498. float BulletPhysicsServer::body_get_param(RID p_body, BodyParameter p_param) const {
  499. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  500. ERR_FAIL_COND_V(!body, 0);
  501. return body->get_param(p_param);
  502. }
  503. void BulletPhysicsServer::body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode) {
  504. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  505. ERR_FAIL_COND(!body);
  506. body->set_combine_mode(p_param, p_mode);
  507. }
  508. PhysicsServer::CombineMode BulletPhysicsServer::body_get_combine_mode(RID p_body, BodyParameter p_param) const {
  509. RigidBodyBullet *body = rigid_body_owner.get(p_body);
  510. ERR_FAIL_COND_V(!body, COMBINE_MODE_INHERIT);
  511. return body->get_combine_mode(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) {
  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);
  680. }
  681. RID BulletPhysicsServer::soft_body_create(bool p_init_sleeping) {
  682. SoftBodyBullet *body = bulletnew(SoftBodyBullet);
  683. body->set_collision_layer(1);
  684. body->set_collision_mask(1);
  685. if (p_init_sleeping)
  686. body->set_activation_state(false);
  687. CreateThenReturnRID(soft_body_owner, body);
  688. }
  689. void BulletPhysicsServer::soft_body_update_visual_server(RID p_body, class SoftBodyVisualServerHandler *p_visual_server_handler) {
  690. SoftBodyBullet *body = soft_body_owner.get(p_body);
  691. ERR_FAIL_COND(!body);
  692. body->update_visual_server(p_visual_server_handler);
  693. }
  694. void BulletPhysicsServer::soft_body_set_space(RID p_body, RID p_space) {
  695. SoftBodyBullet *body = soft_body_owner.get(p_body);
  696. ERR_FAIL_COND(!body);
  697. SpaceBullet *space = NULL;
  698. if (p_space.is_valid()) {
  699. space = space_owner.get(p_space);
  700. ERR_FAIL_COND(!space);
  701. }
  702. if (body->get_space() == space)
  703. return; //pointles
  704. body->set_space(space);
  705. }
  706. RID BulletPhysicsServer::soft_body_get_space(RID p_body) const {
  707. SoftBodyBullet *body = soft_body_owner.get(p_body);
  708. ERR_FAIL_COND_V(!body, RID());
  709. SpaceBullet *space = body->get_space();
  710. if (!space)
  711. return RID();
  712. return space->get_self();
  713. }
  714. void BulletPhysicsServer::soft_body_set_mesh(RID p_body, const REF &p_mesh) {
  715. SoftBodyBullet *body = soft_body_owner.get(p_body);
  716. ERR_FAIL_COND(!body);
  717. body->set_soft_mesh(p_mesh);
  718. }
  719. void BulletPhysicsServer::soft_body_set_collision_layer(RID p_body, uint32_t p_layer) {
  720. SoftBodyBullet *body = soft_body_owner.get(p_body);
  721. ERR_FAIL_COND(!body);
  722. body->set_collision_layer(p_layer);
  723. }
  724. uint32_t BulletPhysicsServer::soft_body_get_collision_layer(RID p_body) const {
  725. const SoftBodyBullet *body = soft_body_owner.get(p_body);
  726. ERR_FAIL_COND_V(!body, 0);
  727. return body->get_collision_layer();
  728. }
  729. void BulletPhysicsServer::soft_body_set_collision_mask(RID p_body, uint32_t p_mask) {
  730. SoftBodyBullet *body = soft_body_owner.get(p_body);
  731. ERR_FAIL_COND(!body);
  732. body->set_collision_mask(p_mask);
  733. }
  734. uint32_t BulletPhysicsServer::soft_body_get_collision_mask(RID p_body) const {
  735. const SoftBodyBullet *body = soft_body_owner.get(p_body);
  736. ERR_FAIL_COND_V(!body, 0);
  737. return body->get_collision_mask();
  738. }
  739. void BulletPhysicsServer::soft_body_add_collision_exception(RID p_body, RID p_body_b) {
  740. SoftBodyBullet *body = soft_body_owner.get(p_body);
  741. ERR_FAIL_COND(!body);
  742. CollisionObjectBullet *other_body = rigid_body_owner.get(p_body_b);
  743. if (!other_body) {
  744. other_body = soft_body_owner.get(p_body_b);
  745. }
  746. ERR_FAIL_COND(!other_body);
  747. body->add_collision_exception(other_body);
  748. }
  749. void BulletPhysicsServer::soft_body_remove_collision_exception(RID p_body, RID p_body_b) {
  750. SoftBodyBullet *body = soft_body_owner.get(p_body);
  751. ERR_FAIL_COND(!body);
  752. CollisionObjectBullet *other_body = rigid_body_owner.get(p_body_b);
  753. if (!other_body) {
  754. other_body = soft_body_owner.get(p_body_b);
  755. }
  756. ERR_FAIL_COND(!other_body);
  757. body->remove_collision_exception(other_body);
  758. }
  759. void BulletPhysicsServer::soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {
  760. SoftBodyBullet *body = soft_body_owner.get(p_body);
  761. ERR_FAIL_COND(!body);
  762. for (int i = 0; i < body->get_exceptions().size(); i++) {
  763. p_exceptions->push_back(body->get_exceptions()[i]);
  764. }
  765. }
  766. void BulletPhysicsServer::soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) {
  767. print_line("TODO MUST BE IMPLEMENTED");
  768. }
  769. Variant BulletPhysicsServer::soft_body_get_state(RID p_body, BodyState p_state) const {
  770. print_line("TODO MUST BE IMPLEMENTED");
  771. return Variant();
  772. }
  773. void BulletPhysicsServer::soft_body_set_transform(RID p_body, const Transform &p_transform) {
  774. SoftBodyBullet *body = soft_body_owner.get(p_body);
  775. ERR_FAIL_COND(!body);
  776. body->set_soft_transform(p_transform);
  777. }
  778. Vector3 BulletPhysicsServer::soft_body_get_vertex_position(RID p_body, int vertex_index) const {
  779. const SoftBodyBullet *body = soft_body_owner.get(p_body);
  780. Vector3 pos;
  781. ERR_FAIL_COND_V(!body, pos);
  782. body->get_node_position(vertex_index, pos);
  783. return pos;
  784. }
  785. void BulletPhysicsServer::soft_body_set_ray_pickable(RID p_body, bool p_enable) {
  786. SoftBodyBullet *body = soft_body_owner.get(p_body);
  787. ERR_FAIL_COND(!body);
  788. body->set_ray_pickable(p_enable);
  789. }
  790. bool BulletPhysicsServer::soft_body_is_ray_pickable(RID p_body) const {
  791. SoftBodyBullet *body = soft_body_owner.get(p_body);
  792. ERR_FAIL_COND_V(!body, false);
  793. return body->is_ray_pickable();
  794. }
  795. void BulletPhysicsServer::soft_body_set_simulation_precision(RID p_body, int p_simulation_precision) {
  796. SoftBodyBullet *body = soft_body_owner.get(p_body);
  797. ERR_FAIL_COND(!body);
  798. body->set_simulation_precision(p_simulation_precision);
  799. }
  800. int BulletPhysicsServer::soft_body_get_simulation_precision(RID p_body) {
  801. SoftBodyBullet *body = soft_body_owner.get(p_body);
  802. ERR_FAIL_COND_V(!body, 0.f);
  803. return body->get_simulation_precision();
  804. }
  805. void BulletPhysicsServer::soft_body_set_total_mass(RID p_body, real_t p_total_mass) {
  806. SoftBodyBullet *body = soft_body_owner.get(p_body);
  807. ERR_FAIL_COND(!body);
  808. body->set_total_mass(p_total_mass);
  809. }
  810. real_t BulletPhysicsServer::soft_body_get_total_mass(RID p_body) {
  811. SoftBodyBullet *body = soft_body_owner.get(p_body);
  812. ERR_FAIL_COND_V(!body, 0.f);
  813. return body->get_total_mass();
  814. }
  815. void BulletPhysicsServer::soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness) {
  816. SoftBodyBullet *body = soft_body_owner.get(p_body);
  817. ERR_FAIL_COND(!body);
  818. body->set_linear_stiffness(p_stiffness);
  819. }
  820. real_t BulletPhysicsServer::soft_body_get_linear_stiffness(RID p_body) {
  821. SoftBodyBullet *body = soft_body_owner.get(p_body);
  822. ERR_FAIL_COND_V(!body, 0.f);
  823. return body->get_linear_stiffness();
  824. }
  825. void BulletPhysicsServer::soft_body_set_areaAngular_stiffness(RID p_body, real_t p_stiffness) {
  826. SoftBodyBullet *body = soft_body_owner.get(p_body);
  827. ERR_FAIL_COND(!body);
  828. body->set_areaAngular_stiffness(p_stiffness);
  829. }
  830. real_t BulletPhysicsServer::soft_body_get_areaAngular_stiffness(RID p_body) {
  831. SoftBodyBullet *body = soft_body_owner.get(p_body);
  832. ERR_FAIL_COND_V(!body, 0.f);
  833. return body->get_areaAngular_stiffness();
  834. }
  835. void BulletPhysicsServer::soft_body_set_volume_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_volume_stiffness(p_stiffness);
  839. }
  840. real_t BulletPhysicsServer::soft_body_get_volume_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_volume_stiffness();
  844. }
  845. void BulletPhysicsServer::soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) {
  846. SoftBodyBullet *body = soft_body_owner.get(p_body);
  847. ERR_FAIL_COND(!body);
  848. body->set_pressure_coefficient(p_pressure_coefficient);
  849. }
  850. real_t BulletPhysicsServer::soft_body_get_pressure_coefficient(RID p_body) {
  851. SoftBodyBullet *body = soft_body_owner.get(p_body);
  852. ERR_FAIL_COND_V(!body, 0.f);
  853. return body->get_pressure_coefficient();
  854. }
  855. void BulletPhysicsServer::soft_body_set_pose_matching_coefficient(RID p_body, real_t p_pose_matching_coefficient) {
  856. SoftBodyBullet *body = soft_body_owner.get(p_body);
  857. ERR_FAIL_COND(!body);
  858. return body->set_pose_matching_coefficient(p_pose_matching_coefficient);
  859. }
  860. real_t BulletPhysicsServer::soft_body_get_pose_matching_coefficient(RID p_body) {
  861. SoftBodyBullet *body = soft_body_owner.get(p_body);
  862. ERR_FAIL_COND_V(!body, 0.f);
  863. return body->get_pose_matching_coefficient();
  864. }
  865. void BulletPhysicsServer::soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient) {
  866. SoftBodyBullet *body = soft_body_owner.get(p_body);
  867. ERR_FAIL_COND(!body);
  868. body->set_damping_coefficient(p_damping_coefficient);
  869. }
  870. real_t BulletPhysicsServer::soft_body_get_damping_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_damping_coefficient();
  874. }
  875. void BulletPhysicsServer::soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient) {
  876. SoftBodyBullet *body = soft_body_owner.get(p_body);
  877. ERR_FAIL_COND(!body);
  878. body->set_drag_coefficient(p_drag_coefficient);
  879. }
  880. real_t BulletPhysicsServer::soft_body_get_drag_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_drag_coefficient();
  884. }
  885. void BulletPhysicsServer::soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) {
  886. SoftBodyBullet *body = soft_body_owner.get(p_body);
  887. ERR_FAIL_COND(!body);
  888. body->set_node_position(p_point_index, p_global_position);
  889. }
  890. Vector3 BulletPhysicsServer::soft_body_get_point_global_position(RID p_body, int p_point_index) {
  891. SoftBodyBullet *body = soft_body_owner.get(p_body);
  892. ERR_FAIL_COND_V(!body, Vector3(0., 0., 0.));
  893. Vector3 pos;
  894. body->get_node_position(p_point_index, pos);
  895. return pos;
  896. }
  897. Vector3 BulletPhysicsServer::soft_body_get_point_offset(RID p_body, int p_point_index) const {
  898. SoftBodyBullet *body = soft_body_owner.get(p_body);
  899. ERR_FAIL_COND_V(!body, Vector3());
  900. Vector3 res;
  901. body->get_node_offset(p_point_index, res);
  902. return res;
  903. }
  904. void BulletPhysicsServer::soft_body_remove_all_pinned_points(RID p_body) {
  905. SoftBodyBullet *body = soft_body_owner.get(p_body);
  906. ERR_FAIL_COND(!body);
  907. body->reset_all_node_mass();
  908. }
  909. void BulletPhysicsServer::soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) {
  910. SoftBodyBullet *body = soft_body_owner.get(p_body);
  911. ERR_FAIL_COND(!body);
  912. body->set_node_mass(p_point_index, p_pin ? 0 : 1);
  913. }
  914. bool BulletPhysicsServer::soft_body_is_point_pinned(RID p_body, int p_point_index) {
  915. SoftBodyBullet *body = soft_body_owner.get(p_body);
  916. ERR_FAIL_COND_V(!body, 0.f);
  917. return body->get_node_mass(p_point_index);
  918. }
  919. PhysicsServer::JointType BulletPhysicsServer::joint_get_type(RID p_joint) const {
  920. JointBullet *joint = joint_owner.get(p_joint);
  921. ERR_FAIL_COND_V(!joint, JOINT_PIN);
  922. return joint->get_type();
  923. }
  924. void BulletPhysicsServer::joint_set_solver_priority(RID p_joint, int p_priority) {
  925. // Joint priority not supported by bullet
  926. }
  927. int BulletPhysicsServer::joint_get_solver_priority(RID p_joint) const {
  928. // Joint priority not supported by bullet
  929. return 0;
  930. }
  931. void BulletPhysicsServer::joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) {
  932. JointBullet *joint = joint_owner.get(p_joint);
  933. ERR_FAIL_COND(!joint);
  934. joint->disable_collisions_between_bodies(p_disable);
  935. }
  936. bool BulletPhysicsServer::joint_is_disabled_collisions_between_bodies(RID p_joint) const {
  937. JointBullet *joint(joint_owner.get(p_joint));
  938. ERR_FAIL_COND_V(!joint, false);
  939. return joint->is_disabled_collisions_between_bodies();
  940. }
  941. RID BulletPhysicsServer::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) {
  942. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  943. ERR_FAIL_COND_V(!body_A, RID());
  944. JointAssertSpace(body_A, "A", RID());
  945. RigidBodyBullet *body_B = NULL;
  946. if (p_body_B.is_valid()) {
  947. body_B = rigid_body_owner.get(p_body_B);
  948. JointAssertSpace(body_B, "B", RID());
  949. JointAssertSameSpace(body_A, body_B, RID());
  950. }
  951. ERR_FAIL_COND_V(body_A == body_B, RID());
  952. JointBullet *joint = bulletnew(PinJointBullet(body_A, p_local_A, body_B, p_local_B));
  953. AddJointToSpace(body_A, joint);
  954. CreateThenReturnRID(joint_owner, joint);
  955. }
  956. void BulletPhysicsServer::pin_joint_set_param(RID p_joint, PinJointParam p_param, float p_value) {
  957. JointBullet *joint = joint_owner.get(p_joint);
  958. ERR_FAIL_COND(!joint);
  959. ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
  960. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  961. pin_joint->set_param(p_param, p_value);
  962. }
  963. float BulletPhysicsServer::pin_joint_get_param(RID p_joint, PinJointParam p_param) const {
  964. JointBullet *joint = joint_owner.get(p_joint);
  965. ERR_FAIL_COND_V(!joint, 0);
  966. ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, 0);
  967. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  968. return pin_joint->get_param(p_param);
  969. }
  970. void BulletPhysicsServer::pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) {
  971. JointBullet *joint = joint_owner.get(p_joint);
  972. ERR_FAIL_COND(!joint);
  973. ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
  974. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  975. pin_joint->setPivotInA(p_A);
  976. }
  977. Vector3 BulletPhysicsServer::pin_joint_get_local_a(RID p_joint) const {
  978. JointBullet *joint = joint_owner.get(p_joint);
  979. ERR_FAIL_COND_V(!joint, Vector3());
  980. ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3());
  981. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  982. return pin_joint->getPivotInA();
  983. }
  984. void BulletPhysicsServer::pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) {
  985. JointBullet *joint = joint_owner.get(p_joint);
  986. ERR_FAIL_COND(!joint);
  987. ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
  988. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  989. pin_joint->setPivotInB(p_B);
  990. }
  991. Vector3 BulletPhysicsServer::pin_joint_get_local_b(RID p_joint) const {
  992. JointBullet *joint = joint_owner.get(p_joint);
  993. ERR_FAIL_COND_V(!joint, Vector3());
  994. ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3());
  995. PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint);
  996. return pin_joint->getPivotInB();
  997. }
  998. RID BulletPhysicsServer::joint_create_hinge(RID p_body_A, const Transform &p_hinge_A, RID p_body_B, const Transform &p_hinge_B) {
  999. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1000. ERR_FAIL_COND_V(!body_A, RID());
  1001. JointAssertSpace(body_A, "A", RID());
  1002. RigidBodyBullet *body_B = NULL;
  1003. if (p_body_B.is_valid()) {
  1004. body_B = rigid_body_owner.get(p_body_B);
  1005. JointAssertSpace(body_B, "B", RID());
  1006. JointAssertSameSpace(body_A, body_B, RID());
  1007. }
  1008. ERR_FAIL_COND_V(body_A == body_B, RID());
  1009. JointBullet *joint = bulletnew(HingeJointBullet(body_A, body_B, p_hinge_A, p_hinge_B));
  1010. AddJointToSpace(body_A, joint);
  1011. CreateThenReturnRID(joint_owner, joint);
  1012. }
  1013. 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) {
  1014. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1015. ERR_FAIL_COND_V(!body_A, RID());
  1016. JointAssertSpace(body_A, "A", RID());
  1017. RigidBodyBullet *body_B = NULL;
  1018. if (p_body_B.is_valid()) {
  1019. body_B = rigid_body_owner.get(p_body_B);
  1020. JointAssertSpace(body_B, "B", RID());
  1021. JointAssertSameSpace(body_A, body_B, RID());
  1022. }
  1023. ERR_FAIL_COND_V(body_A == body_B, RID());
  1024. JointBullet *joint = bulletnew(HingeJointBullet(body_A, body_B, p_pivot_A, p_pivot_B, p_axis_A, p_axis_B));
  1025. AddJointToSpace(body_A, joint);
  1026. CreateThenReturnRID(joint_owner, joint);
  1027. }
  1028. void BulletPhysicsServer::hinge_joint_set_param(RID p_joint, HingeJointParam p_param, float p_value) {
  1029. JointBullet *joint = joint_owner.get(p_joint);
  1030. ERR_FAIL_COND(!joint);
  1031. ERR_FAIL_COND(joint->get_type() != JOINT_HINGE);
  1032. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  1033. hinge_joint->set_param(p_param, p_value);
  1034. }
  1035. float BulletPhysicsServer::hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const {
  1036. JointBullet *joint = joint_owner.get(p_joint);
  1037. ERR_FAIL_COND_V(!joint, 0);
  1038. ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, 0);
  1039. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  1040. return hinge_joint->get_param(p_param);
  1041. }
  1042. void BulletPhysicsServer::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value) {
  1043. JointBullet *joint = joint_owner.get(p_joint);
  1044. ERR_FAIL_COND(!joint);
  1045. ERR_FAIL_COND(joint->get_type() != JOINT_HINGE);
  1046. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  1047. hinge_joint->set_flag(p_flag, p_value);
  1048. }
  1049. bool BulletPhysicsServer::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const {
  1050. JointBullet *joint = joint_owner.get(p_joint);
  1051. ERR_FAIL_COND_V(!joint, false);
  1052. ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, false);
  1053. HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint);
  1054. return hinge_joint->get_flag(p_flag);
  1055. }
  1056. 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) {
  1057. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1058. ERR_FAIL_COND_V(!body_A, RID());
  1059. JointAssertSpace(body_A, "A", RID());
  1060. RigidBodyBullet *body_B = NULL;
  1061. if (p_body_B.is_valid()) {
  1062. body_B = rigid_body_owner.get(p_body_B);
  1063. JointAssertSpace(body_B, "B", RID());
  1064. JointAssertSameSpace(body_A, body_B, RID());
  1065. }
  1066. ERR_FAIL_COND_V(body_A == body_B, RID());
  1067. JointBullet *joint = bulletnew(SliderJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B));
  1068. AddJointToSpace(body_A, joint);
  1069. CreateThenReturnRID(joint_owner, joint);
  1070. }
  1071. void BulletPhysicsServer::slider_joint_set_param(RID p_joint, SliderJointParam p_param, float p_value) {
  1072. JointBullet *joint = joint_owner.get(p_joint);
  1073. ERR_FAIL_COND(!joint);
  1074. ERR_FAIL_COND(joint->get_type() != JOINT_SLIDER);
  1075. SliderJointBullet *slider_joint = static_cast<SliderJointBullet *>(joint);
  1076. slider_joint->set_param(p_param, p_value);
  1077. }
  1078. float BulletPhysicsServer::slider_joint_get_param(RID p_joint, SliderJointParam p_param) const {
  1079. JointBullet *joint = joint_owner.get(p_joint);
  1080. ERR_FAIL_COND_V(!joint, 0);
  1081. ERR_FAIL_COND_V(joint->get_type() != JOINT_SLIDER, 0);
  1082. SliderJointBullet *slider_joint = static_cast<SliderJointBullet *>(joint);
  1083. return slider_joint->get_param(p_param);
  1084. }
  1085. 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) {
  1086. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1087. ERR_FAIL_COND_V(!body_A, RID());
  1088. JointAssertSpace(body_A, "A", RID());
  1089. RigidBodyBullet *body_B = NULL;
  1090. if (p_body_B.is_valid()) {
  1091. body_B = rigid_body_owner.get(p_body_B);
  1092. JointAssertSpace(body_B, "B", RID());
  1093. JointAssertSameSpace(body_A, body_B, RID());
  1094. }
  1095. JointBullet *joint = bulletnew(ConeTwistJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B));
  1096. AddJointToSpace(body_A, joint);
  1097. CreateThenReturnRID(joint_owner, joint);
  1098. }
  1099. void BulletPhysicsServer::cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, float p_value) {
  1100. JointBullet *joint = joint_owner.get(p_joint);
  1101. ERR_FAIL_COND(!joint);
  1102. ERR_FAIL_COND(joint->get_type() != JOINT_CONE_TWIST);
  1103. ConeTwistJointBullet *coneTwist_joint = static_cast<ConeTwistJointBullet *>(joint);
  1104. coneTwist_joint->set_param(p_param, p_value);
  1105. }
  1106. float BulletPhysicsServer::cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const {
  1107. JointBullet *joint = joint_owner.get(p_joint);
  1108. ERR_FAIL_COND_V(!joint, 0.);
  1109. ERR_FAIL_COND_V(joint->get_type() != JOINT_CONE_TWIST, 0.);
  1110. ConeTwistJointBullet *coneTwist_joint = static_cast<ConeTwistJointBullet *>(joint);
  1111. return coneTwist_joint->get_param(p_param);
  1112. }
  1113. 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) {
  1114. RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
  1115. ERR_FAIL_COND_V(!body_A, RID());
  1116. JointAssertSpace(body_A, "A", RID());
  1117. RigidBodyBullet *body_B = NULL;
  1118. if (p_body_B.is_valid()) {
  1119. body_B = rigid_body_owner.get(p_body_B);
  1120. JointAssertSpace(body_B, "B", RID());
  1121. JointAssertSameSpace(body_A, body_B, RID());
  1122. }
  1123. ERR_FAIL_COND_V(body_A == body_B, RID());
  1124. JointBullet *joint = bulletnew(Generic6DOFJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B, true));
  1125. AddJointToSpace(body_A, joint);
  1126. CreateThenReturnRID(joint_owner, joint);
  1127. }
  1128. void BulletPhysicsServer::generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param, float p_value) {
  1129. JointBullet *joint = joint_owner.get(p_joint);
  1130. ERR_FAIL_COND(!joint);
  1131. ERR_FAIL_COND(joint->get_type() != JOINT_6DOF);
  1132. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1133. generic_6dof_joint->set_param(p_axis, p_param, p_value);
  1134. }
  1135. float BulletPhysicsServer::generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param) {
  1136. JointBullet *joint = joint_owner.get(p_joint);
  1137. ERR_FAIL_COND_V(!joint, 0);
  1138. ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, 0);
  1139. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1140. return generic_6dof_joint->get_param(p_axis, p_param);
  1141. }
  1142. void BulletPhysicsServer::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag, bool p_enable) {
  1143. JointBullet *joint = joint_owner.get(p_joint);
  1144. ERR_FAIL_COND(!joint);
  1145. ERR_FAIL_COND(joint->get_type() != JOINT_6DOF);
  1146. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1147. generic_6dof_joint->set_flag(p_axis, p_flag, p_enable);
  1148. }
  1149. bool BulletPhysicsServer::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag) {
  1150. JointBullet *joint = joint_owner.get(p_joint);
  1151. ERR_FAIL_COND_V(!joint, false);
  1152. ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, false);
  1153. Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint);
  1154. return generic_6dof_joint->get_flag(p_axis, p_flag);
  1155. }
  1156. void BulletPhysicsServer::free(RID p_rid) {
  1157. if (shape_owner.owns(p_rid)) {
  1158. ShapeBullet *shape = shape_owner.get(p_rid);
  1159. // Notify the shape is configured
  1160. for (Map<ShapeOwnerBullet *, int>::Element *element = shape->get_owners().front(); element; element = element->next()) {
  1161. static_cast<ShapeOwnerBullet *>(element->key())->remove_shape(shape);
  1162. }
  1163. shape_owner.free(p_rid);
  1164. bulletdelete(shape);
  1165. } else if (rigid_body_owner.owns(p_rid)) {
  1166. RigidBodyBullet *body = rigid_body_owner.get(p_rid);
  1167. body->set_space(NULL);
  1168. body->remove_all_shapes(true);
  1169. rigid_body_owner.free(p_rid);
  1170. bulletdelete(body);
  1171. } else if (soft_body_owner.owns(p_rid)) {
  1172. SoftBodyBullet *body = soft_body_owner.get(p_rid);
  1173. body->set_space(NULL);
  1174. soft_body_owner.free(p_rid);
  1175. bulletdelete(body);
  1176. } else if (area_owner.owns(p_rid)) {
  1177. AreaBullet *area = area_owner.get(p_rid);
  1178. area->set_space(NULL);
  1179. area->remove_all_shapes(true);
  1180. area_owner.free(p_rid);
  1181. bulletdelete(area);
  1182. } else if (joint_owner.owns(p_rid)) {
  1183. JointBullet *joint = joint_owner.get(p_rid);
  1184. joint->destroy_internal_constraint();
  1185. joint_owner.free(p_rid);
  1186. bulletdelete(joint);
  1187. } else if (space_owner.owns(p_rid)) {
  1188. SpaceBullet *space = space_owner.get(p_rid);
  1189. space->remove_all_collision_objects();
  1190. space_set_active(p_rid, false);
  1191. space_owner.free(p_rid);
  1192. bulletdelete(space);
  1193. } else {
  1194. ERR_EXPLAIN("Invalid ID");
  1195. ERR_FAIL();
  1196. }
  1197. }
  1198. void BulletPhysicsServer::init() {
  1199. BulletPhysicsDirectBodyState::initSingleton();
  1200. }
  1201. void BulletPhysicsServer::step(float p_deltaTime) {
  1202. if (!active)
  1203. return;
  1204. BulletPhysicsDirectBodyState::singleton_setDeltaTime(p_deltaTime);
  1205. for (int i = 0; i < active_spaces_count; ++i) {
  1206. active_spaces[i]->step(p_deltaTime);
  1207. }
  1208. }
  1209. void BulletPhysicsServer::sync() {
  1210. }
  1211. void BulletPhysicsServer::flush_queries() {
  1212. }
  1213. void BulletPhysicsServer::finish() {
  1214. BulletPhysicsDirectBodyState::destroySingleton();
  1215. }
  1216. int BulletPhysicsServer::get_process_info(ProcessInfo p_info) {
  1217. return 0;
  1218. }
  1219. CollisionObjectBullet *BulletPhysicsServer::get_collisin_object(RID p_object) const {
  1220. if (rigid_body_owner.owns(p_object)) {
  1221. return rigid_body_owner.getornull(p_object);
  1222. }
  1223. if (area_owner.owns(p_object)) {
  1224. return area_owner.getornull(p_object);
  1225. }
  1226. if (soft_body_owner.owns(p_object)) {
  1227. return soft_body_owner.getornull(p_object);
  1228. }
  1229. return NULL;
  1230. }
  1231. RigidCollisionObjectBullet *BulletPhysicsServer::get_rigid_collisin_object(RID p_object) const {
  1232. if (rigid_body_owner.owns(p_object)) {
  1233. return rigid_body_owner.getornull(p_object);
  1234. }
  1235. if (area_owner.owns(p_object)) {
  1236. return area_owner.getornull(p_object);
  1237. }
  1238. return NULL;
  1239. }