Skip to content

Commit 86a0dd7

Browse files
committed
Fix frustum culling
Former-commit-id: 52911ea
1 parent 3f27c0e commit 86a0dd7

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9012daf0fa8b9edf79357dae9782bb57349ead07
1+
fbcb45c48a2f7d1b4ca0489bc3c88ece57745805
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
40150e84e30b04e7bbcc6e63d051a5fa5c02a729
1+
f4d227b6f3d4864327321e6b0fccbdb056a359c3
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
use crate::movement::character_controller::FloatHeight;
22
use bevy::prelude::*;
3+
use bevy::render::view::NoFrustumCulling;
34
use bevy_tnua::controller::TnuaController;
45
use bevy_xpbd_3d::prelude::*;
56

67
/// Shift models down because XPBD will make controllers float,
78
/// but our models definitely should not be floating!
89
pub(crate) fn offset_models_to_controller(
9-
controllers: Query<
10-
(&Transform, &FloatHeight, &Children),
11-
(Added<TnuaController>, With<Collider>),
12-
>,
10+
mut commands: Commands,
11+
controllers: Query<(Entity, &Transform, &FloatHeight), (Added<TnuaController>, With<Collider>)>,
1312
mut transforms: Query<&mut Transform, Without<Collider>>,
13+
children_q: Query<&Children>,
1414
) {
15-
for (transform, float_height, children) in controllers.iter() {
15+
for (entity, transform, float_height) in controllers.iter() {
1616
let offset = (float_height.0 / transform.scale.y) * 2.;
17+
let children = children_q.get(entity).unwrap();
1718
for child in children.iter() {
1819
if let Ok(mut model_transform) = transforms.get_mut(*child) {
1920
model_transform.translation.y -= offset;
2021
}
2122
}
23+
24+
// Frustum culling is erroneous for animated models because the AABB is not updated.
25+
commands.entity(entity).insert(NoFrustumCulling);
26+
for entity in children_q.iter_descendants(entity) {
27+
commands.entity(entity).insert(NoFrustumCulling);
28+
}
2229
}
2330
}

0 commit comments

Comments
 (0)