Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle aabb updates (e.g. gaussian particle movements) #131

Open
github-actions bot opened this issue Dec 18, 2024 · 0 comments
Open

handle aabb updates (e.g. gaussian particle movements) #131

github-actions bot opened this issue Dec 18, 2024 · 0 comments
Assignees
Labels

Comments

@github-actions
Copy link

// TODO: handle aabb updates (e.g. gaussian particle movements)

};


#[derive(Default)]
pub struct GaussianCloudPlugin;

impl Plugin for GaussianCloudPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(
            PostUpdate,
            (
                calculate_bounds.in_set(VisibilitySystems::CalculateBounds),
                check_visibility::<With<GaussianCloudHandle>>.in_set(VisibilitySystems::CheckVisibility),
            )
        );
    }
}


// TODO: handle aabb updates (e.g. gaussian particle movements)
#[allow(clippy::type_complexity)]
pub fn calculate_bounds(
    mut commands: Commands,
    gaussian_clouds: Res<Assets<GaussianCloud>>,
    without_aabb: Query<
        (
            Entity,
            &GaussianCloudHandle,
        ),
        (
            Without<Aabb>,
            Without<NoFrustumCulling>,
        ),
    >,
) {
    for (entity, cloud_handle) in &without_aabb {
        if let Some(cloud) = gaussian_clouds.get(cloud_handle) {
            if let Some(aabb) = cloud.compute_aabb() {
                commands.entity(entity).try_insert(aabb);
            }
        }
    }
}


#[derive(
    Component,
    Clone,
    Debug,
    Default,
    PartialEq,
    Reflect,
)]
#[reflect(Component, Default)]
#[require(
    GaussianCloudSettings,
    SyncToRenderWorld,
    Transform,
    Visibility,
)]
pub struct GaussianCloudHandle(pub Handle<GaussianCloud>);

impl From<Handle<GaussianCloud>> for GaussianCloudHandle {
    fn from(handle: Handle<GaussianCloud>) -> Self {
        Self(handle)
    }
}

impl From<GaussianCloudHandle> for AssetId<GaussianCloud> {
    fn from(handle: GaussianCloudHandle) -> Self {
        handle.0.id()
    }
}

impl From<&GaussianCloudHandle> for AssetId<GaussianCloud> {
    fn from(handle: &GaussianCloudHandle) -> Self {
        handle.0.id()
    }
}


#[cfg(feature = "f16")]
#[derive(
    Asset,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant