migration to dynamic asset loading
This commit is contained in:
@@ -13,6 +13,10 @@ serde_json = "1.0.115"
|
||||
asset_loader = { path = "../asset_loader" }
|
||||
rayon = "1.10.0"
|
||||
bevy-inspector-egui = "0.25.0"
|
||||
bevy_asset_loader = { version = "0.21.0", features = [
|
||||
"standard_dynamic_assets",
|
||||
"3d",
|
||||
] }
|
||||
|
||||
[features]
|
||||
tracing = ["bevy/trace_tracy"]
|
||||
|
||||
@@ -4,6 +4,43 @@ use bevy::{asset::Asset, reflect::TypePath, render::render_resource::encase::rts
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{biome_asset::BiomeAsset, map::biome_map::BiomeData};
|
||||
use bevy_asset_loader::prelude::*;
|
||||
|
||||
#[derive(AssetCollection, Debug, Clone, Resource)]
|
||||
pub struct BiomePainterAsset {
|
||||
// #[serde(skip)]
|
||||
#[asset(key = "biomes", collection(typed))]
|
||||
pub biomes: Vec<Handle<BiomeAsset>>,
|
||||
// pub biomes_path: Vec<String>,
|
||||
}
|
||||
|
||||
impl BiomePainterAsset {
|
||||
pub fn sample_biome(&self, assets: &Assets<BiomeAsset>, data: &BiomeData) -> AssetId<BiomeAsset> {
|
||||
assert!(self.biomes.length() != 0, "There are no biomes");
|
||||
let mut biome = self.biomes.first().unwrap().id();
|
||||
let mut dist = f32::INFINITY;
|
||||
|
||||
for b in &self.biomes {
|
||||
let asset = assets.get(b.id()).unwrap();
|
||||
let d = asset.distance(data.into());
|
||||
if d < dist {
|
||||
biome = b.id();
|
||||
dist = d;
|
||||
}
|
||||
}
|
||||
|
||||
return biome;
|
||||
}
|
||||
|
||||
pub fn build(&self, assets: &Assets<BiomeAsset>) -> BiomePainter {
|
||||
let mut biomes = Vec::with_capacity(self.biomes.len());
|
||||
for b in &self.biomes {
|
||||
let asset = assets.get(b.id()).unwrap();
|
||||
biomes.push(asset.clone());
|
||||
}
|
||||
return BiomePainter { biomes };
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct BiomePainter {
|
||||
|
||||
Reference in New Issue
Block a user