diff --git a/src/auto_collider.rs b/src/auto_collider.rs new file mode 100644 index 0000000..2c6b4a8 --- /dev/null +++ b/src/auto_collider.rs @@ -0,0 +1,60 @@ +use bevy::{prelude::*, utils::HashMap}; +use bevy_rapier3d::prelude::*; +use multimap::MultiMap; + +#[derive(Default)] +pub struct MeshColliderGenerator { + colliders: HashMap, Collider>, + pending: MultiMap, Entity>, +} + +#[derive(Component)] +#[component(storage = "SparseSet")] +pub struct AttachCollider; + +pub fn attach_collider_system( + mut commands: Commands, + mut state: ResMut, + mut mesh_events: EventReader>, + meshes: Res>, + query: Query<(Entity, &Handle), (Added, Without)>, +) { + for (entity, mesh) in query.iter() { + state.pending.insert(mesh.clone(), entity); + } + + for event in mesh_events.iter() { + if let AssetEvent::Created { handle } = event { + if let Some(v) = state.pending.remove(handle) { + let collider = match state.colliders.entry(handle.clone()) { + bevy::utils::hashbrown::hash_map::Entry::Occupied(e) => e.get().clone(), + bevy::utils::hashbrown::hash_map::Entry::Vacant(e) => { + if let Some(mesh) = meshes.get(handle) { + // TODO: calculate decomposition in background + // TODO2: meh think again, the hex tiles are already convex... + // let collider = Collider::bevy_mesh_convex_decomposition(mesh).unwrap(); + let collider = Collider::bevy_mesh(mesh).unwrap(); + info!("convex decomposition done."); + e.insert(collider).clone() + } else { + panic!("could not get mesh instance after Created event!?"); + } + } + }; + + for entity in v.iter() { + commands.entity(*entity).insert(collider.clone()); + } + } + } + } +} + +pub struct AutoColliderPlugin; + +impl Plugin for AutoColliderPlugin { + fn build(&self, app: &mut App) { + app.add_system(attach_collider_system) + .init_resource::(); + } +} diff --git a/src/fx.rs b/src/fx.rs new file mode 100644 index 0000000..cf30dd1 --- /dev/null +++ b/src/fx.rs @@ -0,0 +1,235 @@ +use bevy::prelude::*; +use bevy_rapier3d::prelude::*; +use rand::prelude::*; + +#[derive(Component, Default)] +#[component(storage = "SparseSet")] +pub struct DoRotate { + pub progress: f32, +} + +pub fn rotate_system( + mut commands: Commands, + time: Res