feat: add support for Voxels collider (#823)

* feat: start adding voxels support and some additional testbed demo settings

* feat: add support for parry’s new Voxels collider shape

* fix voxels demos

* feat: support rectangular voxels and additional voxels initialization

* chore: switch to parry 0.20

* chore: fix cargo doc

* Fix testbed build
This commit is contained in:
Sébastien Crozet
2025-04-24 12:11:53 +02:00
committed by GitHub
parent 1c67c5e7f2
commit e44f636249
27 changed files with 891 additions and 223 deletions

View File

@@ -1,8 +1,9 @@
use std::collections::HashMap;
use indexmap::IndexMap;
use std::ops::RangeInclusive;
#[derive(Clone, PartialEq, Debug, serde::Serialize, serde::Deserialize)]
pub enum SettingValue {
Label(String),
U32 {
value: u32,
range: RangeInclusive<u32>,
@@ -11,11 +12,18 @@ pub enum SettingValue {
value: f32,
range: RangeInclusive<f32>,
},
Bool {
value: bool,
},
String {
value: usize,
range: Vec<String>,
},
}
#[derive(Default, Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ExampleSettings {
values: HashMap<String, SettingValue>,
values: IndexMap<String, SettingValue>,
}
impl ExampleSettings {
@@ -35,6 +43,27 @@ impl ExampleSettings {
self.values.iter_mut()
}
pub fn set_bool(&mut self, key: &str, value: bool) {
self.values
.insert(key.to_string(), SettingValue::Bool { value });
}
pub fn get_or_set_bool(&mut self, key: &'static str, default: bool) -> bool {
let to_insert = SettingValue::Bool { value: default };
let entry = self
.values
.entry(key.to_string())
.or_insert(to_insert.clone());
match entry {
SettingValue::Bool { value } => *value,
_ => {
// The entry doesnt have the right type. Overwrite with the new value.
*entry = to_insert;
default
}
}
}
pub fn set_u32(&mut self, key: &str, value: u32, range: RangeInclusive<u32>) {
self.values
.insert(key.to_string(), SettingValue::U32 { value, range });
@@ -90,6 +119,47 @@ impl ExampleSettings {
}
}
pub fn set_string(&mut self, key: &str, selected: usize, range: Vec<String>) {
self.values.insert(
key.to_string(),
SettingValue::String {
value: selected,
range,
},
);
}
pub fn get_or_set_string(
&mut self,
key: &'static str,
default: usize,
range: Vec<String>,
) -> usize {
let to_insert = SettingValue::String {
value: default,
range,
};
let entry = self
.values
.entry(key.to_string())
.or_insert(to_insert.clone());
match entry {
SettingValue::String { value, .. } => *value,
_ => {
// The entry doesnt have the right type. Overwrite with the new value.
*entry = to_insert;
default
}
}
}
pub fn get_bool(&self, key: &'static str) -> Option<bool> {
match self.values.get(key)? {
SettingValue::Bool { value } => Some(*value),
_ => None,
}
}
pub fn get_u32(&self, key: &'static str) -> Option<u32> {
match self.values.get(key)? {
SettingValue::U32 { value, .. } => Some(*value),
@@ -103,4 +173,23 @@ impl ExampleSettings {
_ => None,
}
}
pub fn get_string_id(&self, key: &'static str) -> Option<usize> {
match self.values.get(key)? {
SettingValue::String { value, .. } => Some(*value),
_ => None,
}
}
pub fn get_string(&self, key: &'static str) -> Option<&str> {
match self.values.get(key)? {
SettingValue::String { value, range } => Some(&range[*value]),
_ => None,
}
}
pub fn set_label(&mut self, key: &'static str, value: impl Into<String>) {
self.values
.insert(key.to_string(), SettingValue::Label(value.into()));
}
}