shape_bullet.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /*************************************************************************/
  2. /* shape_bullet.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 "shape_bullet.h"
  31. #include "btRayShape.h"
  32. #include "bullet_physics_server.h"
  33. #include "bullet_types_converter.h"
  34. #include "bullet_utilities.h"
  35. #include "core/project_settings.h"
  36. #include "shape_owner_bullet.h"
  37. #include <BulletCollision/CollisionDispatch/btInternalEdgeUtility.h>
  38. #include <BulletCollision/CollisionShapes/btConvexPointCloudShape.h>
  39. #include <BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h>
  40. #include <btBulletCollisionCommon.h>
  41. /**
  42. @author AndreaCatania
  43. */
  44. ShapeBullet::ShapeBullet() :
  45. margin(0.04) {}
  46. ShapeBullet::~ShapeBullet() {}
  47. btCollisionShape *ShapeBullet::create_bt_shape(const Vector3 &p_implicit_scale, real_t p_extra_edge) {
  48. btVector3 s;
  49. G_TO_B(p_implicit_scale, s);
  50. return create_bt_shape(s, p_extra_edge);
  51. }
  52. btCollisionShape *ShapeBullet::prepare(btCollisionShape *p_btShape) const {
  53. p_btShape->setUserPointer(const_cast<ShapeBullet *>(this));
  54. p_btShape->setMargin(margin);
  55. return p_btShape;
  56. }
  57. void ShapeBullet::notifyShapeChanged() {
  58. for (Map<ShapeOwnerBullet *, int>::Element *E = owners.front(); E; E = E->next()) {
  59. ShapeOwnerBullet *owner = static_cast<ShapeOwnerBullet *>(E->key());
  60. owner->shape_changed(owner->find_shape(this));
  61. }
  62. }
  63. void ShapeBullet::add_owner(ShapeOwnerBullet *p_owner) {
  64. Map<ShapeOwnerBullet *, int>::Element *E = owners.find(p_owner);
  65. if (E) {
  66. E->get()++;
  67. } else {
  68. owners[p_owner] = 1; // add new owner
  69. }
  70. }
  71. void ShapeBullet::remove_owner(ShapeOwnerBullet *p_owner, bool p_permanentlyFromThisBody) {
  72. Map<ShapeOwnerBullet *, int>::Element *E = owners.find(p_owner);
  73. if (!E) return;
  74. E->get()--;
  75. if (p_permanentlyFromThisBody || 0 >= E->get()) {
  76. owners.erase(E);
  77. }
  78. }
  79. bool ShapeBullet::is_owner(ShapeOwnerBullet *p_owner) const {
  80. return owners.has(p_owner);
  81. }
  82. const Map<ShapeOwnerBullet *, int> &ShapeBullet::get_owners() const {
  83. return owners;
  84. }
  85. void ShapeBullet::set_margin(real_t p_margin) {
  86. margin = p_margin;
  87. notifyShapeChanged();
  88. }
  89. real_t ShapeBullet::get_margin() const {
  90. return margin;
  91. }
  92. btEmptyShape *ShapeBullet::create_shape_empty() {
  93. return bulletnew(btEmptyShape);
  94. }
  95. btStaticPlaneShape *ShapeBullet::create_shape_plane(const btVector3 &planeNormal, btScalar planeConstant) {
  96. return bulletnew(btStaticPlaneShape(planeNormal, planeConstant));
  97. }
  98. btSphereShape *ShapeBullet::create_shape_sphere(btScalar radius) {
  99. return bulletnew(btSphereShape(radius));
  100. }
  101. btBoxShape *ShapeBullet::create_shape_box(const btVector3 &boxHalfExtents) {
  102. return bulletnew(btBoxShape(boxHalfExtents));
  103. }
  104. btCapsuleShapeZ *ShapeBullet::create_shape_capsule(btScalar radius, btScalar height) {
  105. return bulletnew(btCapsuleShapeZ(radius, height));
  106. }
  107. btCylinderShape *ShapeBullet::create_shape_cylinder(btScalar radius, btScalar height) {
  108. return bulletnew(btCylinderShape(btVector3(radius, height / 2.0, radius)));
  109. }
  110. btConvexPointCloudShape *ShapeBullet::create_shape_convex(btAlignedObjectArray<btVector3> &p_vertices, const btVector3 &p_local_scaling) {
  111. return bulletnew(btConvexPointCloudShape(&p_vertices[0], p_vertices.size(), p_local_scaling));
  112. }
  113. btScaledBvhTriangleMeshShape *ShapeBullet::create_shape_concave(btBvhTriangleMeshShape *p_mesh_shape, const btVector3 &p_local_scaling) {
  114. if (p_mesh_shape) {
  115. return bulletnew(btScaledBvhTriangleMeshShape(p_mesh_shape, p_local_scaling));
  116. } else {
  117. return NULL;
  118. }
  119. }
  120. btHeightfieldTerrainShape *ShapeBullet::create_shape_height_field(PoolVector<real_t> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height) {
  121. const btScalar ignoredHeightScale(1);
  122. const int YAxis = 1; // 0=X, 1=Y, 2=Z
  123. const bool flipQuadEdges = false;
  124. const void *heightsPtr = p_heights.read().ptr();
  125. return bulletnew(btHeightfieldTerrainShape(p_width, p_depth, heightsPtr, ignoredHeightScale, p_min_height, p_max_height, YAxis, PHY_FLOAT, flipQuadEdges));
  126. }
  127. btRayShape *ShapeBullet::create_shape_ray(real_t p_length, bool p_slips_on_slope) {
  128. btRayShape *r(bulletnew(btRayShape(p_length)));
  129. r->setSlipsOnSlope(p_slips_on_slope);
  130. return r;
  131. }
  132. /* PLANE */
  133. PlaneShapeBullet::PlaneShapeBullet() :
  134. ShapeBullet() {}
  135. void PlaneShapeBullet::set_data(const Variant &p_data) {
  136. setup(p_data);
  137. }
  138. Variant PlaneShapeBullet::get_data() const {
  139. return plane;
  140. }
  141. PhysicsServer::ShapeType PlaneShapeBullet::get_type() const {
  142. return PhysicsServer::SHAPE_PLANE;
  143. }
  144. void PlaneShapeBullet::setup(const Plane &p_plane) {
  145. plane = p_plane;
  146. notifyShapeChanged();
  147. }
  148. btCollisionShape *PlaneShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) {
  149. btVector3 btPlaneNormal;
  150. G_TO_B(plane.normal, btPlaneNormal);
  151. return prepare(PlaneShapeBullet::create_shape_plane(btPlaneNormal, plane.d));
  152. }
  153. /* Sphere */
  154. SphereShapeBullet::SphereShapeBullet() :
  155. ShapeBullet() {}
  156. void SphereShapeBullet::set_data(const Variant &p_data) {
  157. setup(p_data);
  158. }
  159. Variant SphereShapeBullet::get_data() const {
  160. return radius;
  161. }
  162. PhysicsServer::ShapeType SphereShapeBullet::get_type() const {
  163. return PhysicsServer::SHAPE_SPHERE;
  164. }
  165. void SphereShapeBullet::setup(real_t p_radius) {
  166. radius = p_radius;
  167. notifyShapeChanged();
  168. }
  169. btCollisionShape *SphereShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) {
  170. return prepare(ShapeBullet::create_shape_sphere(radius * p_implicit_scale[0] + p_extra_edge));
  171. }
  172. /* Box */
  173. BoxShapeBullet::BoxShapeBullet() :
  174. ShapeBullet() {}
  175. void BoxShapeBullet::set_data(const Variant &p_data) {
  176. setup(p_data);
  177. }
  178. Variant BoxShapeBullet::get_data() const {
  179. Vector3 g_half_extents;
  180. B_TO_G(half_extents, g_half_extents);
  181. return g_half_extents;
  182. }
  183. PhysicsServer::ShapeType BoxShapeBullet::get_type() const {
  184. return PhysicsServer::SHAPE_BOX;
  185. }
  186. void BoxShapeBullet::setup(const Vector3 &p_half_extents) {
  187. G_TO_B(p_half_extents, half_extents);
  188. notifyShapeChanged();
  189. }
  190. btCollisionShape *BoxShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) {
  191. return prepare(ShapeBullet::create_shape_box((half_extents * p_implicit_scale) + btVector3(p_extra_edge, p_extra_edge, p_extra_edge)));
  192. }
  193. /* Capsule */
  194. CapsuleShapeBullet::CapsuleShapeBullet() :
  195. ShapeBullet() {}
  196. void CapsuleShapeBullet::set_data(const Variant &p_data) {
  197. Dictionary d = p_data;
  198. ERR_FAIL_COND(!d.has("radius"));
  199. ERR_FAIL_COND(!d.has("height"));
  200. setup(d["height"], d["radius"]);
  201. }
  202. Variant CapsuleShapeBullet::get_data() const {
  203. Dictionary d;
  204. d["radius"] = radius;
  205. d["height"] = height;
  206. return d;
  207. }
  208. PhysicsServer::ShapeType CapsuleShapeBullet::get_type() const {
  209. return PhysicsServer::SHAPE_CAPSULE;
  210. }
  211. void CapsuleShapeBullet::setup(real_t p_height, real_t p_radius) {
  212. radius = p_radius;
  213. height = p_height;
  214. notifyShapeChanged();
  215. }
  216. btCollisionShape *CapsuleShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) {
  217. return prepare(ShapeBullet::create_shape_capsule(radius * p_implicit_scale[0] + p_extra_edge, height * p_implicit_scale[1] + p_extra_edge));
  218. }
  219. /* Cylinder */
  220. CylinderShapeBullet::CylinderShapeBullet() :
  221. ShapeBullet() {}
  222. void CylinderShapeBullet::set_data(const Variant &p_data) {
  223. Dictionary d = p_data;
  224. ERR_FAIL_COND(!d.has("radius"));
  225. ERR_FAIL_COND(!d.has("height"));
  226. setup(d["height"], d["radius"]);
  227. }
  228. Variant CylinderShapeBullet::get_data() const {
  229. Dictionary d;
  230. d["radius"] = radius;
  231. d["height"] = height;
  232. return d;
  233. }
  234. PhysicsServer::ShapeType CylinderShapeBullet::get_type() const {
  235. return PhysicsServer::SHAPE_CYLINDER;
  236. }
  237. void CylinderShapeBullet::setup(real_t p_height, real_t p_radius) {
  238. radius = p_radius;
  239. height = p_height;
  240. notifyShapeChanged();
  241. }
  242. btCollisionShape *CylinderShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) {
  243. return prepare(ShapeBullet::create_shape_cylinder(radius * p_implicit_scale[0] + p_margin, height * p_implicit_scale[1] + p_margin));
  244. }
  245. /* Convex polygon */
  246. ConvexPolygonShapeBullet::ConvexPolygonShapeBullet() :
  247. ShapeBullet() {}
  248. void ConvexPolygonShapeBullet::set_data(const Variant &p_data) {
  249. setup(p_data);
  250. }
  251. void ConvexPolygonShapeBullet::get_vertices(Vector<Vector3> &out_vertices) {
  252. const int n_of_vertices = vertices.size();
  253. out_vertices.resize(n_of_vertices);
  254. for (int i = n_of_vertices - 1; 0 <= i; --i) {
  255. B_TO_G(vertices[i], out_vertices.write[i]);
  256. }
  257. }
  258. Variant ConvexPolygonShapeBullet::get_data() const {
  259. ConvexPolygonShapeBullet *variable_self = const_cast<ConvexPolygonShapeBullet *>(this);
  260. Vector<Vector3> out_vertices;
  261. variable_self->get_vertices(out_vertices);
  262. return out_vertices;
  263. }
  264. PhysicsServer::ShapeType ConvexPolygonShapeBullet::get_type() const {
  265. return PhysicsServer::SHAPE_CONVEX_POLYGON;
  266. }
  267. void ConvexPolygonShapeBullet::setup(const Vector<Vector3> &p_vertices) {
  268. // Make a copy of vertices
  269. const int n_of_vertices = p_vertices.size();
  270. vertices.resize(n_of_vertices);
  271. for (int i = n_of_vertices - 1; 0 <= i; --i) {
  272. G_TO_B(p_vertices[i], vertices[i]);
  273. }
  274. notifyShapeChanged();
  275. }
  276. btCollisionShape *ConvexPolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) {
  277. if (!vertices.size())
  278. // This is necessary since 0 vertices
  279. return prepare(ShapeBullet::create_shape_empty());
  280. btCollisionShape *cs(ShapeBullet::create_shape_convex(vertices));
  281. cs->setLocalScaling(p_implicit_scale);
  282. prepare(cs);
  283. return cs;
  284. }
  285. /* Concave polygon */
  286. ConcavePolygonShapeBullet::ConcavePolygonShapeBullet() :
  287. ShapeBullet(),
  288. meshShape(NULL) {}
  289. ConcavePolygonShapeBullet::~ConcavePolygonShapeBullet() {
  290. if (meshShape) {
  291. delete meshShape->getMeshInterface();
  292. delete meshShape->getTriangleInfoMap();
  293. bulletdelete(meshShape);
  294. }
  295. faces = PoolVector<Vector3>();
  296. }
  297. void ConcavePolygonShapeBullet::set_data(const Variant &p_data) {
  298. setup(p_data);
  299. }
  300. Variant ConcavePolygonShapeBullet::get_data() const {
  301. return faces;
  302. }
  303. PhysicsServer::ShapeType ConcavePolygonShapeBullet::get_type() const {
  304. return PhysicsServer::SHAPE_CONCAVE_POLYGON;
  305. }
  306. void ConcavePolygonShapeBullet::setup(PoolVector<Vector3> p_faces) {
  307. faces = p_faces;
  308. if (meshShape) {
  309. /// Clear previous created shape
  310. delete meshShape->getMeshInterface();
  311. delete meshShape->getTriangleInfoMap();
  312. bulletdelete(meshShape);
  313. }
  314. int src_face_count = faces.size();
  315. if (0 < src_face_count) {
  316. // It counts the faces and assert the array contains the correct number of vertices.
  317. ERR_FAIL_COND(src_face_count % 3);
  318. btTriangleMesh *shapeInterface = bulletnew(btTriangleMesh);
  319. src_face_count /= 3;
  320. PoolVector<Vector3>::Read r = p_faces.read();
  321. const Vector3 *facesr = r.ptr();
  322. btVector3 supVec_0;
  323. btVector3 supVec_1;
  324. btVector3 supVec_2;
  325. for (int i = 0; i < src_face_count; ++i) {
  326. G_TO_B(facesr[i * 3 + 0], supVec_0);
  327. G_TO_B(facesr[i * 3 + 1], supVec_1);
  328. G_TO_B(facesr[i * 3 + 2], supVec_2);
  329. // Inverted from standard godot otherwise btGenerateInternalEdgeInfo generates wrong edge info
  330. shapeInterface->addTriangle(supVec_2, supVec_1, supVec_0);
  331. }
  332. const bool useQuantizedAabbCompression = true;
  333. meshShape = bulletnew(btBvhTriangleMeshShape(shapeInterface, useQuantizedAabbCompression));
  334. if (GLOBAL_DEF("physics/3d/smooth_trimesh_collision", false)) {
  335. btTriangleInfoMap *triangleInfoMap = new btTriangleInfoMap();
  336. btGenerateInternalEdgeInfo(meshShape, triangleInfoMap);
  337. }
  338. } else {
  339. meshShape = NULL;
  340. ERR_PRINT("The faces count are 0, the mesh shape cannot be created");
  341. }
  342. notifyShapeChanged();
  343. }
  344. btCollisionShape *ConcavePolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) {
  345. btCollisionShape *cs = ShapeBullet::create_shape_concave(meshShape);
  346. if (!cs)
  347. // This is necessary since if 0 faces the creation of concave return NULL
  348. cs = ShapeBullet::create_shape_empty();
  349. cs->setLocalScaling(p_implicit_scale);
  350. prepare(cs);
  351. cs->setMargin(0);
  352. return cs;
  353. }
  354. /* Height map shape */
  355. HeightMapShapeBullet::HeightMapShapeBullet() :
  356. ShapeBullet() {}
  357. void HeightMapShapeBullet::set_data(const Variant &p_data) {
  358. ERR_FAIL_COND(p_data.get_type() != Variant::DICTIONARY);
  359. Dictionary d = p_data;
  360. ERR_FAIL_COND(!d.has("width"));
  361. ERR_FAIL_COND(!d.has("depth"));
  362. ERR_FAIL_COND(!d.has("heights"));
  363. real_t l_min_height = 0.0;
  364. real_t l_max_height = 0.0;
  365. // If specified, min and max height will be used as precomputed values
  366. if (d.has("min_height"))
  367. l_min_height = d["min_height"];
  368. if (d.has("max_height"))
  369. l_max_height = d["max_height"];
  370. ERR_FAIL_COND(l_min_height > l_max_height);
  371. int l_width = d["width"];
  372. int l_depth = d["depth"];
  373. // TODO This code will need adjustments if real_t is set to `double`,
  374. // because that precision is unnecessary for a heightmap and Bullet doesn't support it...
  375. PoolVector<real_t> l_heights;
  376. Variant l_heights_v = d["heights"];
  377. if (l_heights_v.get_type() == Variant::POOL_REAL_ARRAY) {
  378. // Ready-to-use heights can be passed
  379. l_heights = l_heights_v;
  380. } else if (l_heights_v.get_type() == Variant::OBJECT) {
  381. // If an image is passed, we have to convert it to a format Bullet supports.
  382. // this would be expensive to do with a script, so it's nice to have it here.
  383. Ref<Image> l_image = l_heights_v;
  384. ERR_FAIL_COND(l_image.is_null());
  385. // Float is the only common format between Godot and Bullet that can be used for decent collision.
  386. // (Int16 would be nice too but we still don't have it)
  387. // We could convert here automatically but it's better to not be intrusive and let the caller do it if necessary.
  388. ERR_FAIL_COND(l_image->get_format() != Image::FORMAT_RF);
  389. PoolByteArray im_data = l_image->get_data();
  390. l_heights.resize(l_image->get_width() * l_image->get_height());
  391. PoolRealArray::Write w = l_heights.write();
  392. PoolByteArray::Read r = im_data.read();
  393. float *rp = (float *)r.ptr();
  394. // At this point, `rp` could be used directly for Bullet, but I don't know how safe it would be.
  395. for (int i = 0; i < l_heights.size(); ++i) {
  396. w[i] = rp[i];
  397. }
  398. } else {
  399. ERR_EXPLAIN("Expected PoolRealArray or float Image.");
  400. ERR_FAIL();
  401. }
  402. ERR_FAIL_COND(l_width <= 0);
  403. ERR_FAIL_COND(l_depth <= 0);
  404. ERR_FAIL_COND(l_heights.size() != (l_width * l_depth));
  405. // Compute min and max heights if not specified.
  406. if (!d.has("min_height") && !d.has("max_height")) {
  407. PoolVector<real_t>::Read r = heights.read();
  408. int heights_size = heights.size();
  409. for (int i = 0; i < heights_size; ++i) {
  410. real_t h = r[i];
  411. if (h < l_min_height)
  412. l_min_height = h;
  413. else if (h > l_max_height)
  414. l_max_height = h;
  415. }
  416. }
  417. setup(l_heights, l_width, l_depth, l_min_height, l_max_height);
  418. }
  419. Variant HeightMapShapeBullet::get_data() const {
  420. ERR_FAIL_V(Variant());
  421. }
  422. PhysicsServer::ShapeType HeightMapShapeBullet::get_type() const {
  423. return PhysicsServer::SHAPE_HEIGHTMAP;
  424. }
  425. void HeightMapShapeBullet::setup(PoolVector<real_t> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height) {
  426. // TODO cell size must be tweaked using localScaling, which is a shared property for all Bullet shapes
  427. // If this array is resized outside of here, it should be preserved due to CoW
  428. heights = p_heights;
  429. width = p_width;
  430. depth = p_depth;
  431. min_height = p_min_height;
  432. max_height = p_max_height;
  433. notifyShapeChanged();
  434. }
  435. btCollisionShape *HeightMapShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) {
  436. btCollisionShape *cs(ShapeBullet::create_shape_height_field(heights, width, depth, min_height, max_height));
  437. cs->setLocalScaling(p_implicit_scale);
  438. prepare(cs);
  439. return cs;
  440. }
  441. /* Ray shape */
  442. RayShapeBullet::RayShapeBullet() :
  443. ShapeBullet(),
  444. length(1),
  445. slips_on_slope(false) {}
  446. void RayShapeBullet::set_data(const Variant &p_data) {
  447. Dictionary d = p_data;
  448. setup(d["length"], d["slips_on_slope"]);
  449. }
  450. Variant RayShapeBullet::get_data() const {
  451. Dictionary d;
  452. d["length"] = length;
  453. d["slips_on_slope"] = slips_on_slope;
  454. return d;
  455. }
  456. PhysicsServer::ShapeType RayShapeBullet::get_type() const {
  457. return PhysicsServer::SHAPE_RAY;
  458. }
  459. void RayShapeBullet::setup(real_t p_length, bool p_slips_on_slope) {
  460. length = p_length;
  461. slips_on_slope = p_slips_on_slope;
  462. notifyShapeChanged();
  463. }
  464. btCollisionShape *RayShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) {
  465. return prepare(ShapeBullet::create_shape_ray(length * p_implicit_scale[1] + p_extra_edge, slips_on_slope));
  466. }