From 6de3acbc21c30f11a38ed6fbca70745fbaaeb280 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Tue, 10 Jun 2025 21:08:26 +0300 Subject: [PATCH] feat: die scaling --- crates/bevy_dice/src/lib.rs | 9 ++++++++- crates/bevy_dice_demo/src/main.rs | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/bevy_dice/src/lib.rs b/crates/bevy_dice/src/lib.rs index c0afec9..303f625 100644 --- a/crates/bevy_dice/src/lib.rs +++ b/crates/bevy_dice/src/lib.rs @@ -53,6 +53,8 @@ pub struct DicePluginConfig { /// /// Can also be used to just override the values of faces. pub override_face_positions: HashMap>, + /// Scale overrides, used to size the dice. + pub override_scales: HashMap, } #[derive(Reflect, Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -147,6 +149,11 @@ fn throw_die( None => Quat::default(), }; + let scale = match r_config.override_scales.get(&trigger.variant) { + Some(scale) => Vec3::splat(*scale), + None => Vec3::splat(1.0), + }; + let mut die = commands.spawn(( Visibility::Inherited, // Place the mesh in a child to allow correcting the rotation. @@ -163,7 +170,7 @@ fn throw_die( rotation: trigger .rotation .unwrap_or_else(|| Quat::from_rng(rng.as_mut())), - ..Default::default() + scale, }, RigidBody::Dynamic, Collider::convex_hull_from_mesh(mesh).unwrap(), diff --git a/crates/bevy_dice_demo/src/main.rs b/crates/bevy_dice_demo/src/main.rs index 8a1a23b..d5f882c 100644 --- a/crates/bevy_dice_demo/src/main.rs +++ b/crates/bevy_dice_demo/src/main.rs @@ -159,6 +159,12 @@ fn setup( (100, 100), ]), )]), + override_scales: HashMap::from([ + (DieVariant::D10, 0.8), + (DieVariant::D10P, 0.8), + (DieVariant::D12, 0.8), + (DieVariant::D20, 0.8), + ]), }); } -- 2.44.1