rigidbody: Don't embed collision margin if object has no volume

While it's not a good idea to create convex hull shapes from objects
with no volume, this makes them behave a little nicer.

Fixes [#34410] Planes with Rigid Body always keep distance to colliding objects
This commit is contained in:
Sergej Reich
2013-02-25 15:51:53 +00:00
parent 06264b63df
commit be8bda5abc

View File

@@ -347,6 +347,7 @@ void BKE_rigidbody_validate_sim_shape(Object *ob, short rebuild)
float capsule_height;
float hull_margin = 0.0f;
bool can_embed = true;
bool has_volume;
/* sanity check */
if (rbo == NULL)
@@ -404,11 +405,13 @@ void BKE_rigidbody_validate_sim_shape(Object *ob, short rebuild)
case RB_SHAPE_CONVEXH:
/* try to emged collision margin */
if (!(rbo->flag & RBO_FLAG_USE_MARGIN))
has_volume = (MIN3(size[0], size[1], size[2]) > 0.0f);
if (!(rbo->flag & RBO_FLAG_USE_MARGIN) && has_volume)
hull_margin = 0.04f;
new_shape = rigidbody_get_shape_convexhull_from_mesh(ob, hull_margin, &can_embed);
if (!(rbo->flag & RBO_FLAG_USE_MARGIN))
rbo->margin = (can_embed) ? 0.04f : 0.0f; /* RB_TODO ideally we shouldn't directly change the margin here */
rbo->margin = (can_embed && has_volume) ? 0.04f : 0.0f; /* RB_TODO ideally we shouldn't directly change the margin here */
break;
case RB_SHAPE_TRIMESH:
new_shape = rigidbody_get_shape_trimesh_from_mesh(ob);