Skip to content

Commit

Permalink
feat(wasm): get wasm build to work
Browse files Browse the repository at this point in the history
  • Loading branch information
kpbaks committed Apr 6, 2024
1 parent b01dab1 commit 1e07f18
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/target
.direnv/
**/dist/
*.wasm

*.log
# pixi environments
Expand Down
30 changes: 30 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/gbpplanner-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ leafwing-input-manager = "0.13.3"
bevy_infinite_grid = { git = "https://github.com/AU-Master-Thesis/bevy_infinite_grid", branch = "bevy-v0.13.0" }
# bevy_mesh_terrain = "0.6.1"

bevy_asset_loader = "0.20.0"

bevy_file_dialog = "0.5.0"

heck = "0.5.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/gbpplanner-rs/assets/shaders/line_material.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ fn fragment(
mesh: VertexOutput,
) -> @location(0) vec4<f32> {
return material.color;
}
}
2 changes: 1 addition & 1 deletion crates/gbpplanner-rs/build/macos/create_icns_linux.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/usr/bin/env sh

rm -rf AppIcon.iconset/*
mkdir -p AppIcon.iconset
Expand Down
12 changes: 6 additions & 6 deletions crates/gbpplanner-rs/build/web/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ body {
}

.game-container {
/* width: 100%; */
/* height: 100%; */
width: 800px;
height: 600px;
width: 100%;
height: 100%;
/* width: 800px; */
/* height: 600px; */
display: flex;
justify-content: center;
align-items: center;
Expand Down Expand Up @@ -52,6 +52,6 @@ body {

#bevy {
z-index: 2;
/* width: 100% !important; */
/* height: 100% !important; */
width: 100% !important;
height: 100% !important;
}
14 changes: 14 additions & 0 deletions crates/gbpplanner-rs/src/asset_loader.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// https://github.com/marcelchampagne/bevy-basics/blob/main/episode-3/src/asset_loader.rs
use bevy::{math::primitives::Rectangle, prelude::*};
use bevy_asset_loader::prelude::*;

use crate::{
config::Config,
Expand Down Expand Up @@ -31,15 +32,28 @@ pub struct Materials {
pub obstacle: Handle<StandardMaterial>,
}

#[derive(AssetCollection, Resource)]
pub struct ImageAssets {
#[asset(path = "imgs/junction.png")]
pub obstacle_image_raw: Handle<Image>,
#[asset(path = "imgs/junction_sdf.png")]
pub obstacle_image_sdf: Handle<Image>,
}

/// **Bevy** [`Resource`] to hold all assets in a common place
/// Good practice to load assets once, and then reference them by their
/// [`Handle`]s
#[derive(Resource, Debug, Default)]
pub struct SceneAssets {
// #[asset(path = "fonts/JetBrainsMonoNerdFont-Regular.ttf")]
pub main_font: Handle<Font>,
// #[asset(path = "models/roomba.glb#Scene0")]
pub roomba: Handle<Scene>,
// #[asset(path = "models/roomba.glb#Scene0")]
pub object: Handle<Scene>,
// #[asset(path = "imgs/junction.png")]
pub obstacle_image_raw: Handle<Image>,
// #[asset(path = "imgs/junction_sdf.png")]
pub obstacle_image_sdf: Handle<Image>,
pub meshes: Meshes,
pub materials: Materials,
Expand Down
6 changes: 3 additions & 3 deletions crates/gbpplanner-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ pub(crate) mod macros;
use std::path::PathBuf;

use bevy::{
core::FrameCount,
prelude::*,
window::{WindowMode, WindowTheme},
asset::AssetMetaCheck, core::FrameCount, prelude::*, window::{WindowMode, WindowTheme}
};
// use bevy_dev_console::prelude::*;
use bevy_mod_picking::DefaultPickingPlugins;
Expand Down Expand Up @@ -215,6 +213,8 @@ fn main() -> anyhow::Result<()> {
.insert_resource(config)
.insert_resource(formation)
.insert_resource(environment)
.insert_resource(AssetMetaCheck::Never) // needed for wasm build to work

.add_plugins(EntropyPlugin::<WyRand>::default())
.add_plugins((
DefaultPlugins.set(
Expand Down
6 changes: 5 additions & 1 deletion crates/gbpplanner-rs/src/planner/spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ fn place_unplanned_waypoint(

/// Every [`ObstacleFactor`] has a static reference to the obstacle image.
static OBSTACLE_IMAGE: OnceLock<Image> = OnceLock::new();
// static OBSTACLE_IMAGE: OnceLock<Image> =
// OnceLock::new().get_or_init(|| include_bytes!("./assets/imgs/junction_sdf.png"));

/// Component attached to an entity that spawns formations.
#[derive(Component)]
Expand Down Expand Up @@ -171,7 +173,7 @@ fn setup(mut commands: Commands, formation_group: Res<FormationGroup>) {
/// spawn.
/// Assumes that the `FormationGroup` resource has been initialised, and does
/// not change during the program's execution.
#[derive(Event)]
#[derive(Debug, Event)]
pub struct FormationSpawnEvent {
pub formation_group_index: usize,
}
Expand Down Expand Up @@ -216,12 +218,14 @@ fn spawn_formation(
) {
// only continue if the image has been loaded
let Some(image) = image_assets.get(&scene_assets.obstacle_image_sdf) else {
error!("obstacle sdf not loaded yet");
return;
};

let _ = OBSTACLE_IMAGE.get_or_init(|| image.clone());

for event in spawn_event_reader.read() {
warn!("new formation spawn event received: {:?}", event);
let formation = &formation_group.formations[event.formation_group_index];
let first_wp = formation.waypoints.first();

Expand Down
4 changes: 2 additions & 2 deletions crates/gbpplanner-rs/src/planner/visualiser/factorgraphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ fn create_factorgraph_visualizer(
let [x, y] = variable.estimated_position();
let transform = Vec3::new(x as f32, config.visualisation.height.objects, y as f32);
let robottracker = RobotTracker {
robot_id: *robot_id,
robot_id: *robot_id,
variable_index: index.into(),
order: i,
order: i,
};

debug!(
Expand Down

0 comments on commit 1e07f18

Please sign in to comment.