diff options
author | Sergej Reich <sergej.reich@googlemail.com> | 2013-02-16 20:17:45 +0400 |
---|---|---|
committer | Sergej Reich <sergej.reich@googlemail.com> | 2013-02-16 20:17:45 +0400 |
commit | fda8927d01ba719963154a56b45952ee541a869d (patch) | |
tree | 481a8081680c63988e3690ca6998025ffc2d891b /source/blender/blenkernel/intern | |
parent | d9cc542728aa45aa3615b1396e5a147ec5c08cfa (diff) |
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.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 38 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/rigidbody.c | 22 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 2 |
3 files changed, 35 insertions, 27 deletions
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 4b940fa8274..117e9fe280c 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -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) { diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 9ae82422ca2..26f0c25617f 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -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); diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 269751e79d4..ede0925e01f 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -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); |