Fix #109108: Animated body collision geometry have unapplied scale for the first frame #115730

Open
himisa wants to merge 2 commits from himisa/blender:fix_rigid_first_frame_bug into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
1 changed files with 12 additions and 4 deletions

View File

@ -1748,7 +1748,10 @@ static void rigidbody_update_sim_world(Scene *scene, RigidBodyWorld *rbw)
rigidbody_update_ob_array(rbw);
}
static void rigidbody_update_sim_ob(Depsgraph *depsgraph, Object *ob, RigidBodyOb *rbo)
static void rigidbody_update_sim_ob(Depsgraph *depsgraph,
Object *ob,
RigidBodyOb *rbo,
bool rescale)
{
/* only update if rigid body exists */
if (rbo->shared->physics_object == nullptr) {
@ -1778,7 +1781,7 @@ static void rigidbody_update_sim_ob(Depsgraph *depsgraph, Object *ob, RigidBodyO
}
}
if (!(rbo->flag & RBO_FLAG_KINEMATIC)) {
if (rescale || !(rbo->flag & RBO_FLAG_KINEMATIC)) {
/* update scale for all non kinematic objects */
float new_scale[3], old_scale[3];
mat4_to_size(new_scale, ob->object_to_world);
@ -1852,7 +1855,7 @@ static void rigidbody_update_simulation(Depsgraph *depsgraph,
if (ob->type == OB_MESH) {
/* validate that we've got valid object set up here... */
RigidBodyOb *rbo = ob->rigidbody_object;
bool rescale = false;
/* TODO: remove this whole block once we are sure we never get nullptr rbo here anymore. */
/* This cannot be done in CoW evaluation context anymore... */
if (rbo == nullptr) {
@ -1865,6 +1868,7 @@ static void rigidbody_update_simulation(Depsgraph *depsgraph,
*/
ob->rigidbody_object = BKE_rigidbody_create_object(scene, ob, RBO_TYPE_ACTIVE);
rigidbody_validate_sim_object(rbw, ob, true);
rescale = true;
rbo = ob->rigidbody_object;
}
@ -1878,14 +1882,18 @@ static void rigidbody_update_simulation(Depsgraph *depsgraph,
* calls RB_body_set_collision_shape().
* This results in the collision shape being created twice, which is unnecessary. */
rigidbody_validate_sim_object(rbw, ob, true);
rescale = true;
}
else if (rbo->flag & RBO_FLAG_NEEDS_VALIDATE) {
rigidbody_validate_sim_object(rbw, ob, false);
rescale = true;
}
/* refresh shape... */
if (rbo->flag & RBO_FLAG_NEEDS_RESHAPE) {
/* mesh/shape data changed, so force shape refresh */
rigidbody_validate_sim_shape(rbw, ob, true);
rescale = true;
/* now tell RB sim about it */
/* XXX: we assume that this can only get applied for active/passive shapes
* that will be included as rigid-bodies. */
@ -1899,7 +1907,7 @@ static void rigidbody_update_simulation(Depsgraph *depsgraph,
rbo->flag &= ~(RBO_FLAG_NEEDS_VALIDATE | RBO_FLAG_NEEDS_RESHAPE);
/* update simulation object... */
rigidbody_update_sim_ob(depsgraph, ob, rbo);
rigidbody_update_sim_ob(depsgraph, ob, rbo, rescale);
}
}
FOREACH_COLLECTION_OBJECT_RECURSIVE_END;