rigidbody: Further fix for background scenes
Since rigid bodies need their world to be be updated correctly we now pass it alongside the parent scene in scene_update_tagged_recursive(). Add BKE_object_handle_update_ex() as well as other object functions that take a RigidBodyWorld for this. Ideally this shouldn't be needed but we'd have to restructure scene handling for that. It's not a small taks however and definitely not something that can be done before release. Thanks to Campbell for review.
This commit is contained in:
@@ -50,6 +50,7 @@ struct RenderData;
|
||||
struct rctf;
|
||||
struct MovieClip;
|
||||
struct Main;
|
||||
struct RigidBodyWorld;
|
||||
|
||||
void BKE_object_workob_clear(struct Object *workob);
|
||||
void BKE_object_workob_calc_parent(struct Scene *scene, struct Object *ob, struct Object *workob);
|
||||
@@ -100,7 +101,9 @@ int BKE_object_pose_context_check(struct Object *ob);
|
||||
struct Object *BKE_object_pose_armature_get(struct Object *ob);
|
||||
|
||||
void BKE_object_where_is_calc(struct Scene *scene, struct Object *ob);
|
||||
void BKE_object_where_is_calc_ex(struct Scene *scene, struct RigidBodyWorld *rbw, struct Object *ob);
|
||||
void BKE_object_where_is_calc_time(struct Scene *scene, struct Object *ob, float ctime);
|
||||
void BKE_object_where_is_calc_time_ex(struct Scene *scene, struct RigidBodyWorld *rbw, struct Object *ob, float ctime);
|
||||
void BKE_object_where_is_calc_simul(struct Scene *scene, struct Object *ob);
|
||||
void BKE_object_where_is_calc_mat4(struct Scene *scene, struct Object *ob, float obmat[4][4]);
|
||||
|
||||
@@ -146,6 +149,7 @@ void BKE_object_tfm_protected_restore(struct Object *ob,
|
||||
const short protectflag);
|
||||
|
||||
void BKE_object_handle_update(struct Scene *scene, struct Object *ob);
|
||||
void BKE_object_handle_update_ex(struct Scene *scene, struct RigidBodyWorld *rbw, struct Object *ob);
|
||||
void BKE_object_sculpt_modifiers_changed(struct Object *ob);
|
||||
|
||||
int BKE_object_obdata_texspace_get(struct Object *ob, short **r_texflag, float **r_loc, float **r_size, float **r_rot);
|
||||
|
@@ -89,7 +89,7 @@ void BKE_rigidbody_remove_constraint(struct Scene *scene, struct Object *ob);
|
||||
/* Simulation */
|
||||
|
||||
void BKE_rigidbody_aftertrans_update(struct Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle);
|
||||
void BKE_rigidbody_sync_transforms(struct Scene *scene, struct Object *ob, float ctime);
|
||||
void BKE_rigidbody_sync_transforms(struct RigidBodyWorld *rbw, struct Object *ob, float ctime);
|
||||
void BKE_rigidbody_cache_reset(struct RigidBodyWorld *rbw);
|
||||
void BKE_rigidbody_do_simulation(struct Scene *scene, float ctime);
|
||||
|
||||
|
@@ -58,6 +58,7 @@
|
||||
#include "DNA_world_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_property_types.h"
|
||||
#include "DNA_rigidbody_types.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_math.h"
|
||||
@@ -2116,7 +2117,8 @@ static int where_is_object_parslow(Object *ob, float obmat[4][4], float slowmat[
|
||||
return 1;
|
||||
}
|
||||
|
||||
void BKE_object_where_is_calc_time(Scene *scene, Object *ob, float ctime)
|
||||
/* note, scene is the active scene while actual_scene is the scene the object resides in */
|
||||
void BKE_object_where_is_calc_time_ex(Scene *scene, RigidBodyWorld *rbw, Object *ob, float ctime)
|
||||
{
|
||||
if (ob == NULL) return;
|
||||
|
||||
@@ -2143,7 +2145,7 @@ void BKE_object_where_is_calc_time(Scene *scene, Object *ob, float ctime)
|
||||
}
|
||||
|
||||
/* read values pushed into RBO from sim/cache... */
|
||||
BKE_rigidbody_sync_transforms(scene, ob, ctime);
|
||||
BKE_rigidbody_sync_transforms(rbw, ob, ctime);
|
||||
|
||||
/* solve constraints */
|
||||
if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) {
|
||||
@@ -2159,6 +2161,11 @@ void BKE_object_where_is_calc_time(Scene *scene, Object *ob, float ctime)
|
||||
else ob->transflag &= ~OB_NEG_SCALE;
|
||||
}
|
||||
|
||||
void BKE_object_where_is_calc_time(Scene *scene, Object *ob, float ctime)
|
||||
{
|
||||
BKE_object_where_is_calc_time_ex(scene, NULL, ob, ctime);
|
||||
}
|
||||
|
||||
/* get object transformation matrix without recalculating dependencies and
|
||||
* constraints -- assume dependencies are already solved by depsgraph.
|
||||
* no changes to object and it's parent would be done.
|
||||
@@ -2180,9 +2187,13 @@ void BKE_object_where_is_calc_mat4(Scene *scene, Object *ob, float obmat[4][4])
|
||||
}
|
||||
}
|
||||
|
||||
void BKE_object_where_is_calc(struct Scene *scene, Object *ob)
|
||||
void BKE_object_where_is_calc_ex(Scene *scene, RigidBodyWorld *rbw, Object *ob)
|
||||
{
|
||||
BKE_object_where_is_calc_time(scene, ob, BKE_scene_frame_get(scene));
|
||||
BKE_object_where_is_calc_time_ex(scene, rbw, ob, BKE_scene_frame_get(scene));
|
||||
}
|
||||
void BKE_object_where_is_calc(Scene *scene, Object *ob)
|
||||
{
|
||||
BKE_object_where_is_calc_time_ex(scene, NULL, ob, BKE_scene_frame_get(scene));
|
||||
}
|
||||
|
||||
void BKE_object_where_is_calc_simul(Scene *scene, Object *ob)
|
||||
@@ -2618,12 +2629,8 @@ int BKE_object_parent_loop_check(const Object *par, const Object *ob)
|
||||
|
||||
/* the main object update call, for object matrix, constraints, keys and displist (modifiers) */
|
||||
/* requires flags to be set! */
|
||||
|
||||
/* WARNING: "scene" here may not be the scene object actually resides in.
|
||||
* When dealing with background-sets, "scene" is actually the active scene.
|
||||
* e.g. "scene" <-- set 1 <-- set 2 ("ob" lives here) <-- set 3 <-- ... <-- set n
|
||||
*/
|
||||
void BKE_object_handle_update(Scene *scene, Object *ob)
|
||||
/* Ideally we shouldn't have to pass the rigid body world, but need bigger restructuring to avoid id */
|
||||
void BKE_object_handle_update_ex(Scene *scene, RigidBodyWorld *rbw, Object *ob)
|
||||
{
|
||||
if (ob->recalc & OB_RECALC_ALL) {
|
||||
/* speed optimization for animation lookups */
|
||||
@@ -2664,7 +2671,7 @@ void BKE_object_handle_update(Scene *scene, Object *ob)
|
||||
copy_m4_m4(ob->obmat, ob->proxy_from->obmat);
|
||||
}
|
||||
else
|
||||
BKE_object_where_is_calc(scene, ob);
|
||||
BKE_object_where_is_calc_ex(scene, rbw, ob);
|
||||
}
|
||||
|
||||
if (ob->recalc & OB_RECALC_DATA) {
|
||||
@@ -2818,6 +2825,15 @@ void BKE_object_handle_update(Scene *scene, Object *ob)
|
||||
// printf("set proxy pointer for later group stuff %s\n", ob->id.name);
|
||||
}
|
||||
}
|
||||
/* WARNING: "scene" here may not be the scene object actually resides in.
|
||||
* When dealing with background-sets, "scene" is actually the active scene.
|
||||
* e.g. "scene" <-- set 1 <-- set 2 ("ob" lives here) <-- set 3 <-- ... <-- set n
|
||||
* rigid bodies depend on their world so use BKE_object_handle_update_ex() to also pass along the corrent rigid body world
|
||||
*/
|
||||
void BKE_object_handle_update(Scene *scene, Object *ob)
|
||||
{
|
||||
BKE_object_handle_update_ex(scene, NULL, ob);
|
||||
}
|
||||
|
||||
void BKE_object_sculpt_modifiers_changed(Object *ob)
|
||||
{
|
||||
|
@@ -1130,31 +1130,23 @@ static void rigidbody_update_simulation_post_step(RigidBodyWorld *rbw)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Sync rigid body and object transformations */
|
||||
void BKE_rigidbody_sync_transforms(Scene *scene, Object *ob, float ctime)
|
||||
void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime)
|
||||
{
|
||||
RigidBodyWorld *rbw = scene->rigidbody_world;
|
||||
RigidBodyOb *rbo = ob->rigidbody_object;
|
||||
bool world_ok = true;
|
||||
|
||||
/* keep original transform for kinematic and passive objects */
|
||||
if ((rbo == NULL) || (rbo->flag & RBO_FLAG_KINEMATIC) || (rbo->type == RBO_TYPE_PASSIVE))
|
||||
if (ELEM(NULL, rbw, rbo) || rbo->flag & RBO_FLAG_KINEMATIC || rbo->type == RBO_TYPE_PASSIVE)
|
||||
return;
|
||||
|
||||
/* "scene" may not be the one where object + rigidbody sim actually reside
|
||||
* due to the quirks of how background-sets eval works [#33970]
|
||||
*/
|
||||
if (rbw) {
|
||||
/* 1) no cache exists before startframe */
|
||||
/* 2) keep original transform when simulation is muted */
|
||||
world_ok = (ctime > rbw->pointcache->startframe) && !(rbw->flag & RBW_FLAG_MUTED);
|
||||
}
|
||||
|
||||
/* use rigid body transform after cache start frame if objects is not being transformed */
|
||||
if (world_ok && !((ob->flag & SELECT) && (G.moving & G_TRANSFORM_OBJ))) {
|
||||
if (ctime > rbw->pointcache->startframe && !(ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ)) {
|
||||
float mat[4][4], size_mat[4][4], size[3];
|
||||
|
||||
/* keep original transform when the simulation is muted */
|
||||
if (rbw->flag & RBW_FLAG_MUTED)
|
||||
return;
|
||||
|
||||
normalize_qt(rbo->orn); // RB_TODO investigate why quaternion isn't normalized at this point
|
||||
quat_to_mat4(mat, rbo->orn);
|
||||
copy_v3_v3(mat[3], rbo->pos);
|
||||
|
@@ -1129,7 +1129,7 @@ static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scen
|
||||
for (base = scene->base.first; base; base = base->next) {
|
||||
Object *ob = base->object;
|
||||
|
||||
BKE_object_handle_update(scene_parent, ob);
|
||||
BKE_object_handle_update_ex(scene_parent, scene->rigidbody_world, ob);
|
||||
|
||||
if (ob->dup_group && (ob->transflag & OB_DUPLIGROUP))
|
||||
group_handle_recalc_and_update(scene_parent, ob, ob->dup_group);
|
||||
|
Reference in New Issue
Block a user