DEVELOPMENT ENVIRONMENT

~liljamo/bevy_dice

9b789f83e054ec16cbd104a355c8f3136f476baf — Jonni Liljamo a day ago 6de3acb
feat: allow setting the die weight/mass
2 files changed, 17 insertions(+), 0 deletions(-)

M crates/bevy_dice/src/lib.rs
M crates/bevy_dice_demo/src/main.rs
M crates/bevy_dice/src/lib.rs => crates/bevy_dice/src/lib.rs +8 -0
@@ 55,6 55,8 @@ pub struct DicePluginConfig {
    pub override_face_positions: HashMap<DieVariant, HashMap<u8, u8>>,
    /// Scale overrides, used to size the dice.
    pub override_scales: HashMap<DieVariant, f32>,
    /// Weight overrides, used to set die weights (mass).
    pub override_weights: HashMap<DieVariant, f32>,
}

#[derive(Reflect, Debug, Clone, Copy, PartialEq, Eq, Hash)]


@@ 154,6 156,11 @@ fn throw_die(
        None => Vec3::splat(1.0),
    };

    let mass = match r_config.override_weights.get(&trigger.variant) {
        Some(mass) => Mass(*mass),
        None => Mass(1.0),
    };

    let mut die = commands.spawn((
        Visibility::Inherited,
        // Place the mesh in a child to allow correcting the rotation.


@@ 175,6 182,7 @@ fn throw_die(
        RigidBody::Dynamic,
        Collider::convex_hull_from_mesh(mesh).unwrap(),
        angular_velocity,
        mass,
        Die::new(trigger.id),
    ));


M crates/bevy_dice_demo/src/main.rs => crates/bevy_dice_demo/src/main.rs +9 -0
@@ 165,6 165,15 @@ fn setup(
            (DieVariant::D12, 0.8),
            (DieVariant::D20, 0.8),
        ]),
        override_weights: HashMap::from([
            (DieVariant::D4, 10.0),
            (DieVariant::D6, 10.0),
            (DieVariant::D8, 10.0),
            (DieVariant::D10, 10.0),
            (DieVariant::D10P, 10.0),
            (DieVariant::D12, 10.0),
            (DieVariant::D20, 10.0),
        ]),
    });
}