diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-06-08 20:26:46 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-06-12 23:36:43 +0300 |
commit | 77879ac038e3576eeeeb651ce78706cb95399098 (patch) | |
tree | e3816728abb2e98b92c4c639f356afba0a8dd3b6 /source/blender/blenkernel/intern/rigidbody.c | |
parent | 6700c02e53ed02fbabc36cd6763f65f74e2ab304 (diff) |
Fix T55376: instanced collection render visibility ignored.
For physics simulation it's still fuzzy though, but this needs bigger
design for how it works with view layers and visibility.
Diffstat (limited to 'source/blender/blenkernel/intern/rigidbody.c')
-rw-r--r-- | source/blender/blenkernel/intern/rigidbody.c | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index f7628d081a6..cb5887c07af 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -1202,17 +1202,20 @@ void BKE_rigidbody_remove_constraint(Scene *scene, Object *ob) /* Update object array and rigid body count so they're in sync with the rigid body group */ static void rigidbody_update_ob_array(RigidBodyWorld *rbw) { - const ListBase objects = BKE_collection_object_cache_get(rbw->group); - int i, n; - - n = BLI_listbase_count(&objects); + int n = 0; + FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(rbw->group, object) + { + (void)object; + n++; + } + FOREACH_COLLECTION_OBJECT_RECURSIVE_END; if (rbw->numbodies != n) { rbw->numbodies = n; rbw->objects = realloc(rbw->objects, sizeof(Object *) * rbw->numbodies); } - i = 0; + int i = 0; FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(rbw->group, object) { rbw->objects[i] = object; @@ -1241,7 +1244,7 @@ static void rigidbody_update_sim_world(Scene *scene, RigidBodyWorld *rbw) rigidbody_update_ob_array(rbw); } -static void rigidbody_update_sim_ob(struct Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, Object *ob, RigidBodyOb *rbo) +static void rigidbody_update_sim_ob(Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, Object *ob, RigidBodyOb *rbo) { float loc[3]; float rot[4]; @@ -1330,7 +1333,7 @@ static void rigidbody_update_sim_ob(struct Depsgraph *depsgraph, Scene *scene, R * * \param rebuild Rebuild entire simulation */ -static void rigidbody_update_simulation(struct Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, bool rebuild) +static void rigidbody_update_simulation(Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, bool rebuild) { /* update world */ if (rebuild) @@ -1437,8 +1440,10 @@ static void rigidbody_update_simulation(struct Depsgraph *depsgraph, Scene *scen FOREACH_COLLECTION_OBJECT_RECURSIVE_END; } -static void rigidbody_update_simulation_post_step(ViewLayer *view_layer, RigidBodyWorld *rbw) +static void rigidbody_update_simulation_post_step(Depsgraph *depsgraph, RigidBodyWorld *rbw) { + ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); + FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(rbw->group, ob) { Base *base = BKE_view_layer_base_find(view_layer, ob); @@ -1567,7 +1572,7 @@ void BKE_rigidbody_cache_reset(RigidBodyWorld *rbw) /* Rebuild rigid body world */ /* NOTE: this needs to be called before frame update to work correctly */ -void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, Scene *scene, float ctime) +void BKE_rigidbody_rebuild_world(Depsgraph *depsgraph, Scene *scene, float ctime) { RigidBodyWorld *rbw = scene->rigidbody_world; PointCache *cache; @@ -1579,8 +1584,15 @@ void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, Scene *scene, floa cache = rbw->pointcache; /* flag cache as outdated if we don't have a world or number of objects in the simulation has changed */ - const ListBase objects = BKE_collection_object_cache_get(rbw->group); - if (rbw->physics_world == NULL || rbw->numbodies != BLI_listbase_count(&objects)) { + int n = 0; + FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(rbw->group, object) + { + (void)object; + n++; + } + FOREACH_COLLECTION_OBJECT_RECURSIVE_END; + + if (rbw->physics_world == NULL || rbw->numbodies != n) { cache->flag |= PTCACHE_OUTDATED; } @@ -1596,7 +1608,7 @@ void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, Scene *scene, floa } /* Run RigidBody simulation for the specified physics world */ -void BKE_rigidbody_do_simulation(struct Depsgraph *depsgraph, Scene *scene, float ctime) +void BKE_rigidbody_do_simulation(Depsgraph *depsgraph, Scene *scene, float ctime) { float timestep; RigidBodyWorld *rbw = scene->rigidbody_world; @@ -1648,8 +1660,7 @@ void BKE_rigidbody_do_simulation(struct Depsgraph *depsgraph, Scene *scene, floa /* step simulation by the requested timestep, steps per second are adjusted to take time scale into account */ RB_dworld_step_simulation(rbw->physics_world, timestep, INT_MAX, 1.0f / (float)rbw->steps_per_second * min_ff(rbw->time_scale, 1.0f)); - ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); - rigidbody_update_simulation_post_step(view_layer, rbw); + rigidbody_update_simulation_post_step(depsgraph, rbw); /* write cache for current frame */ BKE_ptcache_validate(cache, (int)ctime); @@ -1686,8 +1697,8 @@ void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime) void BKE_rigidbody_aftertrans_update(Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle) {} bool BKE_rigidbody_check_sim_running(RigidBodyWorld *rbw, float ctime) { return false; } void BKE_rigidbody_cache_reset(RigidBodyWorld *rbw) {} -void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, Scene *scene, float ctime) {} -void BKE_rigidbody_do_simulation(struct Depsgraph *depsgraph, Scene *scene, float ctime) {} +void BKE_rigidbody_rebuild_world(Depsgraph *depsgraph, Scene *scene, float ctime) {} +void BKE_rigidbody_do_simulation(Depsgraph *depsgraph, Scene *scene, float ctime) {} #if defined(__GNUC__) || defined(__clang__) # pragma GCC diagnostic pop @@ -1698,7 +1709,7 @@ void BKE_rigidbody_do_simulation(struct Depsgraph *depsgraph, Scene *scene, floa /* -------------------- */ /* Depsgraph evaluation */ -void BKE_rigidbody_rebuild_sim(struct Depsgraph *depsgraph, +void BKE_rigidbody_rebuild_sim(Depsgraph *depsgraph, Scene *scene) { float ctime = DEG_get_ctime(depsgraph); @@ -1709,7 +1720,7 @@ void BKE_rigidbody_rebuild_sim(struct Depsgraph *depsgraph, } } -void BKE_rigidbody_eval_simulation(struct Depsgraph *depsgraph, +void BKE_rigidbody_eval_simulation(Depsgraph *depsgraph, Scene *scene) { float ctime = DEG_get_ctime(depsgraph); @@ -1720,7 +1731,7 @@ void BKE_rigidbody_eval_simulation(struct Depsgraph *depsgraph, } } -void BKE_rigidbody_object_sync_transforms(struct Depsgraph *depsgraph, +void BKE_rigidbody_object_sync_transforms(Depsgraph *depsgraph, Scene *scene, Object *ob) { |