use glam::Vec3;
use crate::{bounds::Aabb, frustum::Frustum, meshes::MeshKey};
use super::node::SceneNode;
#[derive(Debug, Clone, Copy, Default)]
pub struct NodeFilter {
pub exclude_hidden: bool,
pub exclude_hud: bool,
pub require_cast_shadows: bool,
pub require_receive_shadows: bool,
}
impl NodeFilter {
pub fn camera_default() -> Self {
Self {
exclude_hidden: true,
exclude_hud: false,
require_cast_shadows: false,
require_receive_shadows: false,
}
}
pub fn shadow_caster() -> Self {
Self {
exclude_hidden: true,
exclude_hud: true,
require_cast_shadows: true,
require_receive_shadows: false,
}
}
pub fn visible() -> Self {
Self {
exclude_hidden: true,
exclude_hud: false,
require_cast_shadows: false,
require_receive_shadows: false,
}
}
pub fn matches(&self, node: &SceneNode) -> bool {
if self.exclude_hidden && node.flags.hidden {
return false;
}
if self.exclude_hud && node.flags.hud {
return false;
}
if self.require_cast_shadows && !node.flags.cast_shadows {
return false;
}
if self.require_receive_shadows && !node.flags.receive_shadows {
return false;
}
true
}
}
pub trait SpatialQuery {
fn query_frustum(&self, frustum: &Frustum, filter: NodeFilter) -> Vec<MeshKey>;
fn query_envelope(&self, aabb: &Aabb) -> Vec<MeshKey>;
fn nearest(&self, point: Vec3) -> Option<MeshKey>;
}