mirror of https://codeberg.org/topola/topola.git
feat(topola-egui): Add showing of triangulation constraints to debug overlay
This commit is contained in:
parent
f3245b9607
commit
3e322d7b34
|
|
@ -167,6 +167,7 @@ pub struct ViewActions {
|
|||
pub show_ratsnest: Switch,
|
||||
pub show_navmesh: Switch,
|
||||
pub show_triangulation: Switch,
|
||||
pub show_triangulation_constraints: Switch,
|
||||
pub show_pathfinding_scores: Switch,
|
||||
pub show_topo_navmesh: Switch,
|
||||
pub show_bboxes: Switch,
|
||||
|
|
@ -182,6 +183,10 @@ impl ViewActions {
|
|||
show_navmesh: Action::new_keyless(tr.text("tr-menu-view-show-navmesh")).into_switch(),
|
||||
show_triangulation: Action::new_keyless(tr.text("tr-menu-view-show-triangulation"))
|
||||
.into_switch(),
|
||||
show_triangulation_constraints: Action::new_keyless(
|
||||
tr.text("tr-menu-view-show-triangulation-constraints"),
|
||||
)
|
||||
.into_switch(),
|
||||
show_pathfinding_scores: Action::new_keyless(
|
||||
tr.text("tr-menu-view-show-pathfinding-scores"),
|
||||
)
|
||||
|
|
@ -216,6 +221,8 @@ impl ViewActions {
|
|||
self.show_navmesh.checkbox(ui, &mut menu_bar.show_navmesh);
|
||||
self.show_triangulation
|
||||
.checkbox(ui, &mut menu_bar.show_triangulation);
|
||||
self.show_triangulation_constraints
|
||||
.checkbox(ui, &mut menu_bar.show_triangulation_constraints);
|
||||
self.show_pathfinding_scores
|
||||
.checkbox(ui, &mut menu_bar.show_pathfinding_scores);
|
||||
self.show_topo_navmesh
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ pub struct MenuBar {
|
|||
pub show_ratsnest: bool,
|
||||
pub show_navmesh: bool,
|
||||
pub show_triangulation: bool,
|
||||
pub show_triangulation_constraints: bool,
|
||||
pub show_pathfinding_scores: bool,
|
||||
pub show_topo_navmesh: bool,
|
||||
pub show_bboxes: bool,
|
||||
|
|
@ -52,6 +53,7 @@ impl MenuBar {
|
|||
show_ratsnest: true,
|
||||
show_navmesh: false,
|
||||
show_triangulation: false,
|
||||
show_triangulation_constraints: false,
|
||||
show_pathfinding_scores: false,
|
||||
show_topo_navmesh: false,
|
||||
show_bboxes: false,
|
||||
|
|
|
|||
|
|
@ -438,6 +438,28 @@ impl Viewport {
|
|||
}
|
||||
}
|
||||
|
||||
if menu_bar.show_triangulation_constraints {
|
||||
if let Some(activity) = workspace.interactor.maybe_activity() {
|
||||
if let Some(thetastar) = activity.maybe_thetastar() {
|
||||
let navmesh = thetastar.graph();
|
||||
|
||||
for (from_weight, to_weight) in navmesh.constraints() {
|
||||
let from = from_weight.pos + [100.0, 100.0].into();
|
||||
let to = to_weight.pos + [100.0, 100.0].into();
|
||||
|
||||
painter.paint_edge(
|
||||
from,
|
||||
to,
|
||||
egui::Stroke::new(
|
||||
1.0,
|
||||
egui::Color32::from_rgb(255, 255, 0),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if menu_bar.show_topo_navmesh {
|
||||
if let Some(navmesh) = workspace
|
||||
.interactor
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ tr-menu-view-zoom-to-fit = Zoom to Fit
|
|||
tr-menu-view-show-ratsnest = Show Ratsnest
|
||||
tr-menu-view-show-navmesh = Show Navmesh
|
||||
tr-menu-view-show-triangulation = Show Triangulation
|
||||
tr-menu-view-show-triangulation-constraints = Show Triangulation Constraints
|
||||
tr-menu-view-show-pathfinding-scores = Show Pathfinding Scores
|
||||
tr-menu-view-show-topo-navmesh = Show Topological Navmesh
|
||||
tr-menu-view-show-bboxes = Show BBoxes
|
||||
|
|
|
|||
|
|
@ -170,6 +170,9 @@ pub struct Navmesh {
|
|||
/// Original triangulation stored for debugging purposes.
|
||||
// XXX: Maybe have a way to compile this out in release?
|
||||
triangulation: Triangulation<TrianvertexNodeIndex, TrianvertexWeight, ()>,
|
||||
// Original triangulation constraints stored for debugging purposes.
|
||||
// XXX: Maybe have a way to compile this out in release?
|
||||
constraints: Vec<(TrianvertexWeight, TrianvertexWeight)>,
|
||||
}
|
||||
|
||||
impl Navmesh {
|
||||
|
|
@ -182,6 +185,7 @@ impl Navmesh {
|
|||
) -> Result<Self, NavmeshError> {
|
||||
let mut triangulation: Triangulation<TrianvertexNodeIndex, TrianvertexWeight, ()> =
|
||||
Triangulation::new(layout.drawing().geometry().graph().node_bound());
|
||||
let mut constraints = vec![];
|
||||
|
||||
let layer = layout.drawing().primitive(origin).layer();
|
||||
let maybe_net = layout.drawing().primitive(origin).maybe_net();
|
||||
|
|
@ -203,8 +207,7 @@ impl Navmesh {
|
|||
}
|
||||
PrimitiveIndex::LoneLooseSeg(seg) => {
|
||||
let (from_dot, to_dot) = layout.drawing().primitive(seg).joints();
|
||||
|
||||
triangulation.add_constraint_edge(
|
||||
let (from_weight, to_weight) = (
|
||||
TrianvertexWeight {
|
||||
node: from_dot.into(),
|
||||
pos: from_dot.primitive(layout.drawing()).shape().center(),
|
||||
|
|
@ -213,7 +216,11 @@ impl Navmesh {
|
|||
node: to_dot.into(),
|
||||
pos: to_dot.primitive(layout.drawing()).shape().center(),
|
||||
},
|
||||
)?;
|
||||
);
|
||||
|
||||
triangulation
|
||||
.add_constraint_edge(from_weight.clone(), to_weight.clone())?;
|
||||
constraints.push((from_weight, to_weight));
|
||||
}
|
||||
PrimitiveIndex::SeqLooseSeg(seg) => {
|
||||
let (from_joint, to_joint) = layout.drawing().primitive(seg).joints();
|
||||
|
|
@ -229,8 +236,7 @@ impl Navmesh {
|
|||
|
||||
let to_bend = layout.drawing().primitive(to_joint).bend();
|
||||
let to_dot = layout.drawing().primitive(to_bend).core();
|
||||
|
||||
triangulation.add_constraint_edge(
|
||||
let (from_weight, to_weight) = (
|
||||
TrianvertexWeight {
|
||||
node: from_dot.into(),
|
||||
pos: from_dot.primitive(layout.drawing()).shape().center(),
|
||||
|
|
@ -239,7 +245,11 @@ impl Navmesh {
|
|||
node: to_dot.into(),
|
||||
pos: to_dot.primitive(layout.drawing()).shape().center(),
|
||||
},
|
||||
)?;
|
||||
);
|
||||
|
||||
triangulation
|
||||
.add_constraint_edge(from_weight.clone(), to_weight.clone())?;
|
||||
constraints.push((from_weight, to_weight));
|
||||
}
|
||||
PrimitiveIndex::FixedBend(bend) => {
|
||||
triangulation.add_vertex(TrianvertexWeight {
|
||||
|
|
@ -297,7 +307,14 @@ impl Navmesh {
|
|||
}
|
||||
}
|
||||
|
||||
Self::new_from_triangulation(layout, triangulation, origin, destination, options)
|
||||
Self::new_from_triangulation(
|
||||
layout,
|
||||
triangulation,
|
||||
origin,
|
||||
destination,
|
||||
constraints,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
fn new_from_triangulation(
|
||||
|
|
@ -305,6 +322,7 @@ impl Navmesh {
|
|||
triangulation: Triangulation<TrianvertexNodeIndex, TrianvertexWeight, ()>,
|
||||
origin: FixedDotIndex,
|
||||
destination: FixedDotIndex,
|
||||
constraints: Vec<(TrianvertexWeight, TrianvertexWeight)>,
|
||||
options: RouterOptions,
|
||||
) -> Result<Self, NavmeshError> {
|
||||
let mut graph: UnGraph<NavnodeWeight, (), usize> = UnGraph::default();
|
||||
|
|
@ -398,6 +416,7 @@ impl Navmesh {
|
|||
destination,
|
||||
destination_navnode: NavnodeIndex(destination_navnode.unwrap()),
|
||||
triangulation,
|
||||
constraints,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue