Skip to content

Commit

Permalink
Fix georeference, incapsulate asset loading plugins
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Della Vedova <[email protected]>
  • Loading branch information
luca-della-vedova committed Feb 26, 2024
1 parent 43f7983 commit 24c1c72
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 102 deletions.
10 changes: 10 additions & 0 deletions rmf_site_editor/src/asset_loaders.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::SdfPlugin;
use bevy::prelude::*;
/// A plugin used to consolidate asset loaders for types supported in the Gazebo / ROS ecosystem.
pub struct AssetLoadersPlugin;

impl Plugin for AssetLoadersPlugin {
fn build(&self, app: &mut App) {
app.add_plugins((bevy_stl::StlPlugin, bevy_obj::ObjPlugin, SdfPlugin));
}
}
5 changes: 4 additions & 1 deletion rmf_site_editor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use wasm_bindgen::prelude::*;
pub mod aabb;
pub mod animate;

pub mod asset_loaders;
use asset_loaders::*;

pub mod keyboard;
use keyboard::*;

Expand Down Expand Up @@ -174,11 +177,11 @@ impl Plugin for SiteEditor {
app.insert_resource(DirectionalLightShadowMap { size: 2048 })
.add_state::<AppState>()
.add_plugins((
AssetLoadersPlugin,
LogHistoryPlugin,
AabbUpdatePlugin,
EguiPlugin,
KeyboardInputPlugin,
SdfPlugin,
MainMenuPlugin,
WorkcellEditorPlugin,
SitePlugin,
Expand Down
45 changes: 22 additions & 23 deletions rmf_site_editor/src/osm_slippy_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
use std::{f32::consts::PI, io::Write, path::PathBuf};

use bevy::{
asset::io::{AssetReaderError, Reader, VecReader},
asset::{
io::{AssetReaderError, Reader, VecReader},
AssetPath,
},
prelude::{Mesh, Vec2},
render::{mesh::Indices, render_resource::PrimitiveTopology},
};
Expand Down Expand Up @@ -75,35 +78,31 @@ impl TryFrom<PathBuf> for OSMTile {
type Error = String;

fn try_from(p: PathBuf) -> Result<Self, Self::Error> {
let (zoom, xtile, ytile) = p.components().collect_tuple().ok_or(
"Invalid path when converting to OSMTile, three elements are required".to_owned(),
)?;
let (zoom, xtile, ytile) = p
.components()
.map(|c| c.as_os_str().to_string_lossy())
.collect_tuple()
.ok_or(
"Invalid path when converting to OSMTile, three elements are required".to_owned(),
)?;
let ytile = ytile.strip_suffix(".png").ok_or("Suffix not found")?;
dbg!(&zoom, &xtile, &ytile);
Ok(OSMTile {
xtile: xtile
.as_os_str()
.to_string_lossy()
.parse::<i32>()
.map_err(|e| e.to_string())?,
ytile: ytile
.as_os_str()
.to_string_lossy()
.parse::<i32>()
.map_err(|e| e.to_string())?,
zoom: zoom
.as_os_str()
.to_string_lossy()
.parse::<i32>()
.map_err(|e| e.to_string())?,
xtile: xtile.parse::<i32>().map_err(|e| e.to_string())?,
ytile: ytile.parse::<i32>().map_err(|e| e.to_string())?,
zoom: zoom.parse::<i32>().map_err(|e| e.to_string())?,
})
}
}

impl From<OSMTile> for PathBuf {
fn from(t: OSMTile) -> Self {
[t.zoom, t.xtile, t.ytile]
impl From<&OSMTile> for AssetPath<'_> {
fn from(t: &OSMTile) -> Self {
let mut path: PathBuf = [t.zoom, t.xtile, t.ytile]
.iter()
.map(|v| v.to_string())
.collect()
.collect();
path.set_extension("png");
AssetPath::from(path).with_source("osm-tile")
}
}

Expand Down
5 changes: 2 additions & 3 deletions rmf_site_editor/src/site/georeference.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use bevy::{prelude::*, window::PrimaryWindow};
use bevy::{asset::AssetPath, prelude::*, window::PrimaryWindow};
use bevy_egui::{egui, EguiContexts};
use bevy_mod_raycast::primitives::rays::Ray3d;
use camera_controls::{CameraControls, ProjectionMode};
use rmf_site_format::{GeographicComponent, GeographicOffset};
use std::collections::HashSet;
use std::path::PathBuf;
use utm::*;

use crate::{
Expand Down Expand Up @@ -297,7 +296,7 @@ fn spawn_tile(
};
let quad_handle = meshes.add(mesh);

let texture_handle: Handle<Image> = asset_server.load(PathBuf::from(tile.clone()));
let texture_handle: Handle<Image> = asset_server.load(AssetPath::from(&tile));
let material_handle = materials.add(StandardMaterial {
base_color_texture: Some(texture_handle.clone()),
alpha_mode: AlphaMode::Blend,
Expand Down
1 change: 0 additions & 1 deletion rmf_site_editor/src/site/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ impl Plugin for SitePlugin {
.add_event::<UpdateFuelCache>()
.add_event::<SetFuelApiKey>()
.add_event::<MergeGroups>()
.add_plugins((bevy_stl::StlPlugin, bevy_obj::ObjPlugin))
.add_plugins((
ChangePlugin::<AssociatedGraphs<Entity>>::default(),
RecallPlugin::<RecallAssociatedGraphs<Entity>>::default(),
Expand Down
1 change: 0 additions & 1 deletion rmf_site_editor/src/site_asset_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ impl Plugin for SiteAssetIoPlugin {
// the asset server is constructed and added the resource manager
app.register_asset_source(
"search",
//AssetSourceBuilder::platform_default("assets", None),
BevyAssetSource::build().with_reader(|| {
Box::new(SiteAssetReader::new(|path: &Path| {
// Order should be:
Expand Down
73 changes: 0 additions & 73 deletions rmf_site_editor/src/urdf_loader.rs

This file was deleted.

0 comments on commit 24c1c72

Please sign in to comment.