From 9e465417296a69ea610d621754ac2d8cd8f5bdda Mon Sep 17 00:00:00 2001 From: mosure Date: Mon, 15 Sep 2025 21:19:57 -0500 Subject: [PATCH 1/3] feat: bindgroup rebinding --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/render/mod.rs | 109 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 109 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3664efa2..ca88699e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1341,7 +1341,7 @@ dependencies = [ [[package]] name = "bevy_gaussian_splatting" -version = "5.1.0" +version = "5.2.0" dependencies = [ "base64 0.22.1", "bevy 0.16.1", diff --git a/Cargo.toml b/Cargo.toml index 8ce6d8a9..d9dfb7d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_gaussian_splatting" description = "bevy gaussian splatting render pipeline plugin" -version = "5.1.0" +version = "5.2.0" edition = "2024" rust-version = "1.85.0" authors = ["mosure "] diff --git a/src/render/mod.rs b/src/render/mod.rs index 913ca9cd..b3f665d7 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -6,7 +6,7 @@ use std::{ use bevy::{ prelude::*, - asset::{load_internal_asset, weak_handle}, + asset::{load_internal_asset, weak_handle, AssetEvent, AssetId}, core_pipeline::{ core_3d::Transparent3d, prepass::{ @@ -137,15 +137,25 @@ where app.add_plugins(MorphPlugin::::default()); app.add_plugins(SortPlugin::::default()); + app.init_resource::>(); + app.add_systems(PostUpdate, queue_planar_storage_rebinds::); if let Some(render_app) = app.get_sub_app_mut(RenderApp) { render_app .add_render_command::>() .init_resource::() - .add_systems(ExtractSchedule, extract_gaussians::) + .init_resource::>() + .add_systems( + ExtractSchedule, + ( + extract_gaussians::, + extract_planar_storage_rebind_queue::, + ), + ) .add_systems( Render, ( + refresh_planar_storage_bind_groups::.in_set(RenderSet::PrepareBindGroups), queue_gaussian_bind_group::.in_set(RenderSet::PrepareBindGroups), queue_gaussian_view_bind_groups::.in_set(RenderSet::PrepareBindGroups), queue_gaussian_compute_view_bind_groups::.in_set(RenderSet::PrepareBindGroups), @@ -246,6 +256,101 @@ where } +#[derive(Resource)] +struct PlanarStorageRebindQueue { + handles: Vec>, + marker: std::marker::PhantomData, +} + +impl Default for PlanarStorageRebindQueue { + fn default() -> Self { + Self { + handles: Vec::new(), + marker: std::marker::PhantomData, + } + } +} + +impl Clone for PlanarStorageRebindQueue { + fn clone(&self) -> Self { + Self { + handles: self.handles.clone(), + marker: std::marker::PhantomData, + } + } +} + +impl PlanarStorageRebindQueue { + fn push_unique(&mut self, id: AssetId) { + if !self.handles.iter().any(|existing| *existing == id) { + self.handles.push(id); + } + } +} + +fn queue_planar_storage_rebinds( + mut events: EventReader>, + mut queue: ResMut>, +) { + for event in events.read() { + match event { + AssetEvent::Modified { id } | AssetEvent::LoadedWithDependencies { id } => { + queue.push_unique(*id); + } + AssetEvent::Removed { id } => { + queue.handles.retain(|handle_id| handle_id != id); + } + AssetEvent::Added { .. } | AssetEvent::Unused { .. } => {} + } + } +} + +fn extract_planar_storage_rebind_queue( + mut commands: Commands, + mut main_world: ResMut, +) { + let mut queue = main_world.resource_mut::>(); + commands.insert_resource(queue.clone()); + queue.handles.clear(); +} + +fn refresh_planar_storage_bind_groups( + mut commands: Commands, + render_device: Res, + gpu_planars: Res>, + bind_group_layouts: Res>, + mut queue: ResMut>, + query: Query<(Entity, &R::PlanarTypeHandle)>, +) where + R::GpuPlanarType: GpuPlanarStorage, +{ + if queue.handles.is_empty() { + return; + } + + let layout = &bind_group_layouts.bind_group_layout; + let handles = queue.handles.clone(); + queue.handles.clear(); + + for id in handles { + for (entity, planar_handle) in query.iter() { + if planar_handle.handle().id() != id { + continue; + } + + if let Some(gpu_planar) = gpu_planars.get(planar_handle.handle()) { + let bind_group = gpu_planar.bind_group(render_device.as_ref(), layout); + + commands.entity(entity).insert(PlanarStorageBindGroup:: { + bind_group, + phantom: std::marker::PhantomData, + }); + } + } + } +} + + #[derive(Bundle)] pub struct GpuCloudBundle { pub aabb: Aabb, From 659513d7186b826e954fe06a2d47ac84c52bab7e Mon Sep 17 00:00:00 2001 From: mosure Date: Mon, 15 Sep 2025 21:43:14 -0500 Subject: [PATCH 2/3] docs: simplify readme --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index f8593975..0218c59a 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,6 @@ [![test](https://github.com/mosure/bevy_gaussian_splatting/workflows/test/badge.svg)](https://github.com/Mosure/bevy_gaussian_splatting/actions?query=workflow%3Atest) [![GitHub License](https://img.shields.io/github/license/mosure/bevy_gaussian_splatting)](https://raw.githubusercontent.com/mosure/bevy_gaussian_splatting/main/LICENSE-MIT) -[![GitHub Last Commit](https://img.shields.io/github/last-commit/mosure/bevy_gaussian_splatting)](https://github.com/mosure/bevy_gaussian_splatting) -[![GitHub Releases](https://img.shields.io/github/v/release/mosure/bevy_gaussian_splatting?include_prereleases&sort=semver)](https://github.com/mosure/bevy_gaussian_splatting/releases) -[![GitHub Issues](https://img.shields.io/github/issues/mosure/bevy_gaussian_splatting)](https://github.com/mosure/bevy_gaussian_splatting/issues) -[![Average time to resolve an issue](https://isitmaintained.com/badge/resolution/mosure/bevy_gaussian_splatting.svg)](http://isitmaintained.com/project/mosure/bevy_gaussian_splatting) [![crates.io](https://img.shields.io/crates/v/bevy_gaussian_splatting.svg)](https://crates.io/crates/bevy_gaussian_splatting) bevy gaussian splatting render pipeline plugin. view the [live demo](https://mosure.github.io/bevy_gaussian_splatting?input_cloud=https://mitchell.mosure.me/go_trimmed.ply) From 41341278f7d0d3245d2f9518cc2867a02d6487b0 Mon Sep 17 00:00:00 2001 From: mosure Date: Mon, 15 Sep 2025 22:08:34 -0500 Subject: [PATCH 3/3] fix: lint --- src/render/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index b3f665d7..6c5c0371 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -282,7 +282,7 @@ impl Clone for PlanarStorageRebindQueue { impl PlanarStorageRebindQueue { fn push_unique(&mut self, id: AssetId) { - if !self.handles.iter().any(|existing| *existing == id) { + if !self.handles.contains(&id) { self.handles.push(id); } }