Skip to content

Commit

Permalink
refactor: load remote splat file (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
cs50victor authored Feb 19, 2024
1 parent 7a7c04e commit f66746f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
2 changes: 0 additions & 2 deletions crates/bevy_remote_asset/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// derived from https://github.com/johanhelsing/bevy_web_asset

mod web_asset_plugin;
mod web_asset_source;

Expand Down
22 changes: 22 additions & 0 deletions crates/bevy_remote_asset/src/web_asset_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ impl WebAssetReader {
}

async fn get<'a>(path: PathBuf) -> Result<Box<Reader<'a>>, AssetReaderError> {
println!("get");

use std::{
future::Future,
io,
Expand Down Expand Up @@ -59,6 +61,7 @@ async fn get<'a>(path: PathBuf) -> Result<Box<Reader<'a>>, AssetReaderError> {
format!("non-utf8 path: {}", path.display()),
))
})?;

let mut response = ContinuousPoll(surf::get(str_path)).await.map_err(|err| {
AssetReaderError::Io(io::Error::new(
io::ErrorKind::Other,
Expand All @@ -71,6 +74,25 @@ async fn get<'a>(path: PathBuf) -> Result<Box<Reader<'a>>, AssetReaderError> {
))
})?;

if response.status() == StatusCode::Found {
if let Some(uri) = response.header("Location") {
let uri = uri.as_str();
response = ContinuousPoll(surf::get(uri)).await.map_err(|err| {
AssetReaderError::Io(io::Error::new(
io::ErrorKind::Other,
format!(
"unexpected status code {} while loading {}: {}",
err.status(),
path.display(),
err.into_inner(),
),
))
})?;
};
}

println!("{}", response.status());

match response.status() {
StatusCode::Ok => Ok(Box::new(VecReader::new(
ContinuousPoll(response.body_bytes())
Expand Down
28 changes: 12 additions & 16 deletions new_media/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,33 @@ use bevy_panorbit_camera::PanOrbitCamera;

use bevy_gaussian_splatting::{GaussianCloud, GaussianSplattingBundle};

pub fn setup_gaussian_cloud(
pub fn setup_gaussian_cloud(mut commands: Commands, asset_server: Res<AssetServer>) {
let cloud = asset_server.load::<GaussianCloud>("https://huggingface.co/datasets/cs50victor/splats/resolve/main/train/point_cloud/iteration_7000/point_cloud.gcloud");

log::info!("loading {}", cloud.id());

let gs = GaussianSplattingBundle { cloud, ..default() };
commands.spawn((gs, Name::new("gaussian_cloud")));
}

pub fn setup_camera(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut gaussian_assets: ResMut<Assets<GaussianCloud>>,
mut scene_controller: ResMut<bevy_headless::SceneInfo>,
mut images: ResMut<Assets<Image>>,
export_sources: ResMut<Assets<ImageExportSource>>,
) {
// let remote_file = Some("https://huggingface.co/datasets/cs50victor/splats/resolve/main/train/point_cloud/iteration_7000/point_cloud.gcloud");
// TODO: figure out how to load remote files later
let splat_file = "splats/garden/point_cloud/iteration_7000/point_cloud.gcloud";
log::info!("loading {}", splat_file);
// let cloud = asset_server.load(splat_file.to_string());

let cloud = gaussian_assets.add(GaussianCloud::test_model());

let render_target = bevy_headless::setup_render_target(
let target = bevy_headless::setup_render_target(
&mut commands,
&mut images,
&mut scene_controller,
export_sources,
);

let gs = GaussianSplattingBundle { cloud, ..default() };
commands.spawn((gs, Name::new("gaussian_cloud")));

commands.spawn((
Camera3dBundle {
transform: Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)),
tonemapping: Tonemapping::None,
camera: Camera { target: render_target, ..default() },
camera: Camera { target, ..default() },
..default()
},
PanOrbitCamera {
Expand Down
9 changes: 5 additions & 4 deletions new_media/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod asset;
mod controls;
mod server;

use asset::setup_gaussian_cloud;
use asset::{setup_camera, setup_gaussian_cloud};
use bevy::{
app::{App as Engine, ScheduleRunnerPlugin, Startup, Update},
core_pipeline::clear_color::ClearColor,
Expand All @@ -29,6 +29,8 @@ fn main() {
.filter_module("new_media", log::LevelFilter::Info)
.filter_module("bevy", log::LevelFilter::Info)
.filter_module("bevy_headless", log::LevelFilter::Info)
.filter_module("bevy_remote_asset", log::LevelFilter::Info)
.filter_module("bevy_remote_asset", log::LevelFilter::Debug)
.filter_module("bevy_ws_server", log::LevelFilter::Info)
.filter_module("bevy_ws_server", log::LevelFilter::Debug)
.init();
Expand All @@ -39,7 +41,6 @@ fn main() {
Engine::new()
.insert_resource(bevy_headless::SceneInfo::new(config.width, config.height))
.init_resource::<WorldControlChannel>()
// .insert_resource(ClearColor(Color::rgb_u8(255, 255, 255)))
.insert_resource(ClearColor(Color::rgb_u8(0, 0, 0)))
.add_plugins((
WebAssetPlugin,
Expand All @@ -49,7 +50,7 @@ fn main() {
PanOrbitCameraPlugin,
GaussianSplattingPlugin,
))
.add_systems(Startup, (start_ws, setup_gaussian_cloud))
.add_systems(Update, (receive_message,update_world_from_input))
.add_systems(Startup, (start_ws, setup_camera, setup_gaussian_cloud))
.add_systems(Update, (receive_message, update_world_from_input))
.run();
}

0 comments on commit f66746f

Please sign in to comment.