From c363aa41b19d96e8d28935cc284c641cf01a71f0 Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 7 May 2024 19:38:19 +0200 Subject: [PATCH] fix NoShadowCaster/Receiver with loaded gltf scenes --- src/commands.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 368e318..86f020c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -847,26 +847,33 @@ pub fn hide_colliders(mut q_mesh: Query<(&mut Visibility, &Name), (Added>>, - q_parents: Query<(Option<&Parent>, Option<&actor::Player>)>, + q_parents: Query<(Option<&Parent>, Option<&actor::Player>, Option<&NotShadowCaster>, Option<&NotShadowReceiver>)>, ) { // Add "PlayerCollider" component to the player's collider mesh entity for (child_entity, child_name, child_parent) in &mut q_mesh { - if child_name.as_str() == "Collider" { - // get the root parent - let mut get_parent = q_parents.get(child_parent.get()); - while let Ok((parent_maybe, _)) = get_parent { - if let Some(parent) = parent_maybe { - get_parent = q_parents.get(parent.get()); - } else { - break; - } + // get the root parent + let mut get_parent = q_parents.get(child_parent.get()); + while let Ok((parent_maybe, _, _, _)) = get_parent { + if let Some(parent) = parent_maybe { + get_parent = q_parents.get(parent.get()); + } else { + break; } + } + + if let Ok((_, player, noshadowcast, noshadowrecv)) = get_parent { + let childcmd = &mut commands.entity(child_entity); // If the root parent is the player, add PlayerCollider to the collider mesh - if let Ok((_, player)) = get_parent { - if player.is_some() { - commands.entity(child_entity).insert(actor::PlayerCollider); - } + if player.is_some() && child_name.as_str() == "Collider" { + childcmd.insert(actor::PlayerCollider); + } + + if noshadowcast.is_some() { + childcmd.insert(NotShadowCaster); + } + if noshadowrecv.is_some() { + childcmd.insert(NotShadowReceiver); } } }