Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update polyanya and support radius on outer edges #64

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ default-features = false
optional = true

[dependencies.polyanya]
version = "0.11.0"
version = "0.11.1"

[dependencies.bevy]
version = "0.14.0"
Expand Down
51 changes: 48 additions & 3 deletions examples/helpers/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub enum UiSettings {
Simplify,
MergeSteps,
AgentRadius,
AgentRadiusOuter,
Cache,
}

Expand All @@ -17,6 +18,7 @@ pub enum UiSettingsButtons {
MergeStepsDec,
AgentRadiusInc,
AgentRadiusDec,
AgentRadiusOuterToggle,
ToggleCache,
}

Expand Down Expand Up @@ -170,6 +172,34 @@ pub fn setup_settings<const WITH_CACHE: bool>(mut commands: Commands) {
button(" - ", UiSettingsButtons::AgentRadiusDec, parent);
button(" + ", UiSettingsButtons::AgentRadiusInc, parent);
});
parent
.spawn((
ButtonBundle {
style: Style {
margin: UiRect::px(30.0, 30.0, 10.0, 30.0),
border: UiRect::all(Val::Px(1.0)),
justify_content: JustifyContent::Center,
height: Val::Px(30.0),
align_items: AlignItems::Center,
..default()
},
border_color: BorderColor(palettes::tailwind::GRAY_500.into()),
border_radius: BorderRadius::all(Val::Px(10.0)),
image: UiImage::default().with_color(palettes::tailwind::GRAY_700.into()),
..default()
},
UiSettingsButtons::AgentRadiusOuterToggle,
UiSettings::AgentRadiusOuter,
))
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"Agent Radius on Outer Edges",
TextStyle {
font_size: 20.0,
..default()
},
));
});
if WITH_CACHE {
parent
.spawn((
Expand Down Expand Up @@ -223,11 +253,12 @@ pub fn display_settings(
UiSettings::AgentRadius => {
text.sections[1].value = format!("{:.1}", settings.agent_radius)
}
UiSettings::AgentRadiusOuter => (),
UiSettings::Cache => (),
}
}
}
if example_settings.is_changed() {
if example_settings.is_changed() || settings.is_changed() {
for (mut color, param) in &mut buttons {
match param {
UiSettings::Simplify => (),
Expand All @@ -240,6 +271,13 @@ pub fn display_settings(
palettes::tailwind::RED_600.into()
}
}
UiSettings::AgentRadiusOuter => {
*color = if settings.agent_radius_on_outer_edge {
palettes::tailwind::GREEN_400.into()
} else {
palettes::tailwind::RED_600.into()
}
}
}
}
}
Expand Down Expand Up @@ -279,15 +317,22 @@ pub fn update_settings<const STEP: u32>(
UiSettingsButtons::ToggleCache => {
example_settings.cache_enabled = !example_settings.cache_enabled;
}
UiSettingsButtons::AgentRadiusOuterToggle => {
settings.agent_radius_on_outer_edge = !settings.agent_radius_on_outer_edge;
}
}
}
Interaction::Hovered => {
if !matches!(button, UiSettingsButtons::ToggleCache) {
if !matches!(button, UiSettingsButtons::ToggleCache)
&& !matches!(button, UiSettingsButtons::AgentRadiusOuterToggle)
{
*color = palettes::tailwind::GRAY_600.into();
}
}
Interaction::None => {
if !matches!(button, UiSettingsButtons::ToggleCache) {
if !matches!(button, UiSettingsButtons::ToggleCache)
&& !matches!(button, UiSettingsButtons::AgentRadiusOuterToggle)
{
*color = palettes::tailwind::GRAY_700.into();
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ pub struct NavMeshSettings {
pub scale: Vec2,
/// Agent radius used to inflate the obstacles.
pub agent_radius: f32,
/// If the agent radius should be applied to the outer edges of the navmesh.
///
/// When using layers, this can block stitching them together.
pub agent_radius_on_outer_edge: bool,
}

impl Default for NavMeshSettings {
Expand All @@ -116,6 +120,7 @@ impl Default for NavMeshSettings {
stitches: vec![],
scale: Vec2::ONE,
agent_radius: 0.0,
agent_radius_on_outer_edge: false,
}
}
}
Expand Down Expand Up @@ -168,6 +173,7 @@ fn build_navmesh<T: ObstacleSource>(
let mut base = settings.fixed;
base.set_agent_radius(settings.agent_radius);
base.set_agent_radius_simplification(settings.simplify);
base.agent_radius_on_outer_edge(settings.agent_radius_on_outer_edge);
let obstacle_polys = cached_obstacles
.iter()
.flat_map(|(transform, obstacle)| {
Expand Down