aboutsummaryrefslogtreecommitdiff
path: root/modules/bullet/collision_object_bullet.cpp
diff options
context:
space:
mode:
authorRémi Verschelde2018-01-04 15:26:23 +0100
committerGitHub2018-01-04 15:26:23 +0100
commitf8b58784bc693114ffe9c6b523ae73ecb3472311 (patch)
tree3e0af68946c765a3b354b09ebb2f312afdac3aad /modules/bullet/collision_object_bullet.cpp
parentc4c1ca9cb140f41d718b6456b84900b12ab44b25 (diff)
parentf4b96cc0a97f1f9edd127920ff5995a75c2e6624 (diff)
downloadgodot-f8b58784bc693114ffe9c6b523ae73ecb3472311.tar.gz
godot-f8b58784bc693114ffe9c6b523ae73ecb3472311.tar.zst
godot-f8b58784bc693114ffe9c6b523ae73ecb3472311.zip
Diffstat (limited to 'modules/bullet/collision_object_bullet.cpp')
-rw-r--r--modules/bullet/collision_object_bullet.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/modules/bullet/collision_object_bullet.cpp b/modules/bullet/collision_object_bullet.cpp
index 70d604fa7..1350be20b 100644
--- a/modules/bullet/collision_object_bullet.cpp
+++ b/modules/bullet/collision_object_bullet.cpp
@@ -57,7 +57,8 @@ CollisionObjectBullet::CollisionObjectBullet(Type p_type) :
collisionsEnabled(true),
m_isStatic(false),
bt_collision_object(NULL),
- body_scale(1., 1., 1.) {}
+ body_scale(1., 1., 1.),
+ force_shape_reset(false) {}
CollisionObjectBullet::~CollisionObjectBullet() {
// Remove all overlapping
@@ -88,6 +89,7 @@ btVector3 CollisionObjectBullet::get_bt_body_scale() const {
}
void CollisionObjectBullet::on_body_scale_changed() {
+ force_shape_reset = true;
}
void CollisionObjectBullet::destroyBulletCollisionObject() {
@@ -289,15 +291,27 @@ void RigidCollisionObjectBullet::on_shape_changed(const ShapeBullet *const p_sha
void RigidCollisionObjectBullet::on_shapes_changed() {
int i;
+
// Remove all shapes, reverse order for performance reason (Array resize)
for (i = compoundShape->getNumChildShapes() - 1; 0 <= i; --i) {
compoundShape->removeChildShapeByIndex(i);
}
- // Insert all shapes
ShapeWrapper *shpWrapper;
- const int size = shapes.size();
- for (i = 0; i < size; ++i) {
+ const int shapes_size = shapes.size();
+
+ // Reset shape if required
+ if (force_shape_reset) {
+ for (i = 0; i < shapes_size; ++i) {
+ shpWrapper = &shapes[i];
+ bulletdelete(shpWrapper->bt_shape);
+ }
+ force_shape_reset = false;
+ }
+
+ // Insert all shapes
+
+ for (i = 0; i < shapes_size; ++i) {
shpWrapper = &shapes[i];
if (shpWrapper->active) {
if (!shpWrapper->bt_shape) {