Improve quick brush creation workflow

This commit is contained in:
Rbanh committed 2026-06-06 14:16:12 -04:00
1 parent f09d35e54e
commit 48b1448c57
9 files changed
+701 -61

No files matched your search

+5
View File
@@ -50,6 +50,10 @@ pub enum EditorCommand {
snapshot: EditorEntitySnapshot,
entity: Option<Entity>,
},
SpawnMany {
snapshots: Vec<EditorEntitySnapshot>,
entities: Vec<Entity>,
},
Despawn {
snapshot: EditorEntitySnapshot,
entity: Option<Entity>,
@@ -160,6 +164,7 @@ impl EditorCommand {
pub fn label(&self) -> &'static str {
match self {
EditorCommand::Spawn { .. } => "Spawn",
EditorCommand::SpawnMany { .. } => "Spawn Brushes",
EditorCommand::Despawn { .. } => "Delete",
EditorCommand::Duplicate { .. } => "Duplicate",
EditorCommand::Rename { .. } => "Rename",
+45
View File
@@ -274,6 +274,34 @@ pub fn spawn_with_history(world: &mut World, mut snapshot: EditorEntitySnapshot)
entity
}
pub fn spawn_many_with_history(
world: &mut World,
snapshots: impl IntoIterator<Item = EditorEntitySnapshot>,
) -> Vec<Entity> {
let mut snapshots: Vec<EditorEntitySnapshot> = snapshots.into_iter().collect();
if snapshots.is_empty() {
return Vec::new();
}
let mut sibling_index = next_sibling_index(world, None);
for snapshot in &mut snapshots {
snapshot.hierarchy_sibling_index = sibling_index;
sibling_index += 1;
}
let entities: Vec<Entity> = snapshots
.iter()
.map(|snapshot| spawn_snapshot(world, snapshot))
.collect();
push_history(
world,
EditorCommand::SpawnMany {
snapshots,
entities: entities.clone(),
},
);
select_many(world, &entities);
entities
}
pub fn delete_entities_with_history(world: &mut World, entities: &[Entity]) {
let mut deleted = Vec::new();
for entity in entities {
@@ -752,6 +780,12 @@ fn undo_command(world: &mut World, command: &mut EditorCommand) {
despawn_entity(world, entity.take());
clear_selection(world);
}
EditorCommand::SpawnMany { entities, .. } => {
for entity in std::mem::take(entities) {
despawn_entity(world, Some(entity));
}
clear_selection(world);
}
EditorCommand::Despawn { snapshot, entity } => {
let spawned = spawn_snapshot(world, snapshot);
*entity = Some(spawned);
@@ -847,6 +881,17 @@ fn redo_command(world: &mut World, command: &mut EditorCommand) {
*entity = Some(spawned);
select_one(world, spawned);
}
EditorCommand::SpawnMany {
snapshots,
entities,
} => {
let spawned: Vec<Entity> = snapshots
.iter()
.map(|snapshot| spawn_snapshot(world, snapshot))
.collect();
*entities = spawned.clone();
select_many(world, &spawned);
}
EditorCommand::Despawn { entity, .. } => {
despawn_entity(world, entity.take());
clear_selection(world);
+82
View File
@@ -16,6 +16,7 @@ use crate::selection::ViewportClick;
use crate::state::PlayPossession;
use crate::viewport::actor_icons::ActorIconSettings;
use crate::viewport::brush_edit::BrushEditMode;
use crate::viewport::brush_tool::{BrushToolPhase, BrushToolState};
use crate::viewport::{
snap_translation, viewport_ground_position, EditorViewportMode, ViewportDisplayMode,
ViewportSettings,
@@ -109,6 +110,7 @@ pub fn viewport_tab_ui(
}
scene_view_overlay_toolbar(world, ui.ctx(), rect);
scene_view_brush_draw_hints(world, ui.ctx(), rect);
scene_view_mode_badge(world, ui.ctx(), rect);
scene_view_brush_mode_badge(world, ui.ctx(), rect);
scene_view_gi_badge(world, ui.ctx(), rect);
@@ -177,6 +179,86 @@ fn scene_view_brush_mode_badge(world: &World, ctx: &egui::Context, scene_rect: e
});
}
fn scene_view_brush_draw_hints(world: &World, ctx: &egui::Context, scene_rect: egui::Rect) {
let Some(tool) = world.get_resource::<BrushToolState>() else {
return;
};
if !tool.active {
return;
}
let hint = match tool.phase {
BrushToolPhase::Outline if tool.vertices.len() < 3 => "Place points".to_string(),
BrushToolPhase::Outline => "Set height".to_string(),
BrushToolPhase::Height => format!("{:.1}m", tool.height),
};
egui::Area::new(egui::Id::new("scene_view_brush_draw_hints"))
.fixed_pos(scene_rect.left_top() + egui::vec2(8.0, 52.0))
.interactable(false)
.show(ctx, |ui| {
egui::Frame::new()
.fill(egui::Color32::from_rgba_unmultiplied(18, 22, 26, 220))
.stroke(egui::Stroke::new(
1.0,
egui::Color32::from_rgba_unmultiplied(95, 150, 190, 180),
))
.corner_radius(egui::CornerRadius::same(4))
.inner_margin(egui::Margin::symmetric(8, 6))
.show(ui, |ui| {
ui.horizontal(|ui| {
ui.label(
egui::RichText::new("Draw Brush")
.color(egui::Color32::from_rgb(170, 220, 255))
.strong(),
);
ui.label(
egui::RichText::new(format!("{} pts", tool.vertices.len()))
.color(egui::Color32::from_rgb(190, 200, 205))
.small(),
);
ui.label(
egui::RichText::new(hint)
.color(egui::Color32::from_rgb(150, 220, 170))
.small(),
);
});
ui.add_space(4.0);
ui.horizontal_wrapped(|ui| match tool.phase {
BrushToolPhase::Outline => {
key_hint(ui, "LMB", "Point");
key_hint(ui, "Enter", "Height");
key_hint(ui, "Backspace", "Remove");
key_hint(ui, "Esc", "Cancel");
key_hint(ui, "RMB", "Cancel");
}
BrushToolPhase::Height => {
key_hint(ui, "Mouse Up/Down", "Height");
key_hint(ui, "Enter", "Create");
key_hint(ui, "LMB", "Create");
key_hint(ui, "Backspace", "Outline");
key_hint(ui, "Esc", "Cancel");
key_hint(ui, "RMB", "Cancel");
}
});
});
});
}
fn key_hint(ui: &mut egui::Ui, key: &str, label: &str) {
ui.horizontal(|ui| {
ui.label(
egui::RichText::new(key)
.monospace()
.color(egui::Color32::from_rgb(232, 238, 242))
.background_color(egui::Color32::from_rgba_unmultiplied(45, 52, 58, 220)),
);
ui.label(
egui::RichText::new(label)
.color(egui::Color32::from_rgb(190, 200, 205))
.small(),
);
});
}
fn scene_view_gi_badge(world: &World, ctx: &egui::Context, scene_rect: egui::Rect) {
let Some(profile) = world.get_resource::<settings::ActiveCameraRenderProfile>() else {
return;
+319 -41
View File
@@ -3,11 +3,12 @@
use bevy::prelude::*;
use bevy_egui::{egui, EguiContexts};
use shared::{
brush_math::validate_floor_polygon, ActorKind, BrushDesc, EditorVisibility, MaterialDesc,
brush_math::{decompose_floor_polygon_to_convex, BrushPolygonError},
ActorKind, BrushDesc, EditorVisibility, MaterialDesc,
};
use crate::camera::EditorCamera;
use crate::history::{spawn_with_history, EditorEntitySnapshot};
use crate::history::{spawn_many_with_history, EditorEntitySnapshot};
use crate::operators::{ActiveOperator, OperatorPhase, OperatorStatus};
use crate::scene_io::SceneIo;
use crate::selection::ViewportClick;
@@ -16,21 +17,35 @@ use crate::ui::{viewport_keyboard_shortcuts_active, UiState};
use crate::viewport::{scene_view_ray, snap_translation, ViewportDisplayMode, ViewportSettings};
const DEFAULT_BRUSH_HEIGHT: f32 = 2.5;
const MIN_BRUSH_HEIGHT: f32 = 0.1;
const HEIGHT_PIXELS_TO_WORLD: f32 = 0.03;
const MIN_COMMIT_VERTICES: usize = 3;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BrushToolPhase {
Outline,
Height,
}
#[derive(Resource, Debug, Clone)]
pub struct BrushToolState {
pub active: bool,
pub phase: BrushToolPhase,
pub vertices: Vec<Vec3>,
pub height: f32,
height_anchor_pointer_y: Option<f32>,
height_anchor_value: f32,
}
impl Default for BrushToolState {
fn default() -> Self {
Self {
active: false,
phase: BrushToolPhase::Outline,
vertices: Vec::new(),
height: DEFAULT_BRUSH_HEIGHT,
height_anchor_pointer_y: None,
height_anchor_value: DEFAULT_BRUSH_HEIGHT,
}
}
}
@@ -38,13 +53,47 @@ impl Default for BrushToolState {
impl BrushToolState {
pub fn start(&mut self) {
self.active = true;
self.phase = BrushToolPhase::Outline;
self.vertices.clear();
self.height = DEFAULT_BRUSH_HEIGHT;
self.height_anchor_pointer_y = None;
self.height_anchor_value = DEFAULT_BRUSH_HEIGHT;
}
pub fn cancel(&mut self) {
self.active = false;
self.phase = BrushToolPhase::Outline;
self.vertices.clear();
self.height = DEFAULT_BRUSH_HEIGHT;
self.height_anchor_pointer_y = None;
self.height_anchor_value = DEFAULT_BRUSH_HEIGHT;
}
fn start_height_phase(&mut self, pointer_pos: Option<egui::Pos2>) {
self.phase = BrushToolPhase::Height;
self.height = DEFAULT_BRUSH_HEIGHT;
self.height_anchor_value = DEFAULT_BRUSH_HEIGHT;
self.height_anchor_pointer_y = pointer_pos.map(|pos| pos.y);
}
fn return_to_outline_phase(&mut self) {
self.phase = BrushToolPhase::Outline;
self.height = DEFAULT_BRUSH_HEIGHT;
self.height_anchor_pointer_y = None;
self.height_anchor_value = DEFAULT_BRUSH_HEIGHT;
}
fn update_height_from_pointer(&mut self, pointer_pos: Option<egui::Pos2>) {
if self.phase != BrushToolPhase::Height {
return;
}
let Some(pointer_pos) = pointer_pos else {
return;
};
let anchor_y = self.height_anchor_pointer_y.get_or_insert(pointer_pos.y);
let height =
self.height_anchor_value + (*anchor_y - pointer_pos.y) * HEIGHT_PIXELS_TO_WORLD;
self.height = quantize_height(height);
}
}
@@ -62,12 +111,12 @@ impl Plugin for BrushToolPlugin {
pub fn start_draw_brush_tool(world: &mut World) {
world.resource_mut::<BrushToolState>().start();
world.resource_mut::<SceneIo>().status =
"Draw Brush: click floor points, Enter creates brush".to_string();
"Draw Brush: click floor points, Enter sets height".to_string();
if let Some(mut active_operator) = world.get_resource_mut::<ActiveOperator>() {
set_brush_tool_status(
&mut active_operator,
OperatorPhase::Preview,
"Click floor points, Enter creates brush, Esc cancels",
"Click floor points, Enter sets height, Esc cancels",
);
}
if let Some(mut viewport_click) = world.get_resource_mut::<ViewportClick>() {
@@ -105,11 +154,11 @@ fn brush_tool_input(
if keyboard_available && keys.just_pressed(KeyCode::KeyB) {
tool.start();
scene_io.status = "Draw Brush: click floor points, Enter creates brush".to_string();
scene_io.status = "Draw Brush: click floor points, Enter sets height".to_string();
set_brush_tool_status(
&mut active_operator,
OperatorPhase::Preview,
"Click floor points, Enter creates brush, Esc cancels",
"Click floor points, Enter sets height, Esc cancels",
);
viewport_click.0 = None;
return Ok(());
@@ -118,6 +167,7 @@ fn brush_tool_input(
if !tool.active {
return Ok(());
}
tool.update_height_from_pointer(ui_state.viewport_pointer_pos);
if (!egui_keyboard_busy && keys.just_pressed(KeyCode::Escape))
|| buttons.just_pressed(MouseButton::Right)
@@ -130,48 +180,83 @@ fn brush_tool_input(
}
if !egui_keyboard_busy && keys.just_pressed(KeyCode::Backspace) {
tool.vertices.pop();
set_brush_tool_status(
&mut active_operator,
OperatorPhase::Preview,
brush_tool_hint(tool.vertices.len()),
);
if tool.phase == BrushToolPhase::Height {
tool.return_to_outline_phase();
} else {
tool.vertices.pop();
}
let status = draw_brush_status(&tool);
scene_io.status = status.clone();
set_brush_tool_status(&mut active_operator, OperatorPhase::Preview, status);
viewport_click.0 = None;
return Ok(());
}
if tool.phase == BrushToolPhase::Height {
if buttons.just_pressed(MouseButton::Left)
|| (!egui_keyboard_busy && keys.just_pressed(KeyCode::Enter))
{
match brush_snapshots_from_points(&tool.vertices, tool.height) {
Ok(snapshots) => {
let brush_count = snapshots.len();
let height = tool.height;
commands.queue(move |world: &mut World| {
spawn_many_with_history(world, snapshots);
});
tool.cancel();
scene_io.status = brush_created_status(brush_count, height);
set_brush_tool_status(
&mut active_operator,
OperatorPhase::Committed,
brush_committed_status(brush_count, height),
);
}
Err(error) => {
let message = format!("Draw Brush failed: {error}");
warn!("{message}; points={:?}", tool.vertices);
scene_io.status = message.clone();
set_brush_tool_status(&mut active_operator, OperatorPhase::Blocked, message);
}
}
viewport_click.0 = None;
return Ok(());
}
viewport_click.0 = None;
let status = draw_brush_status(&tool);
scene_io.status = status.clone();
set_brush_tool_status(&mut active_operator, OperatorPhase::Preview, status);
return Ok(());
}
if let Some(pointer_pos) = viewport_click.0.take() {
if let Some(mut point) =
pointer_floor_position(&cameras, pointer_pos, ui_state.viewport_rect)
{
point = snap_translation(point, &settings);
tool.vertices.push(point);
scene_io.status = format!("Draw Brush: {} point(s)", tool.vertices.len());
set_brush_tool_status(
&mut active_operator,
OperatorPhase::Preview,
brush_tool_hint(tool.vertices.len()),
);
let status = draw_brush_status(&tool);
scene_io.status = status.clone();
set_brush_tool_status(&mut active_operator, OperatorPhase::Preview, status);
}
}
if !egui_keyboard_busy && keys.just_pressed(KeyCode::Enter) {
match brush_snapshot_from_points(&tool.vertices, tool.height) {
Ok(snapshot) => {
commands.queue(move |world: &mut World| {
spawn_with_history(world, snapshot);
});
tool.cancel();
scene_io.status = "Brush created".to_string();
match decompose_floor_polygon_to_convex(&tool.vertices) {
Ok(parts) => {
let part_count = parts.len();
tool.start_height_phase(ui_state.viewport_pointer_pos);
scene_io.status = draw_brush_status(&tool);
set_brush_tool_status(
&mut active_operator,
OperatorPhase::Committed,
"Committed brush.draw",
OperatorPhase::Preview,
height_phase_status(part_count, tool.height),
);
}
Err(error) => {
scene_io.status = format!("Draw Brush failed: {error}");
set_brush_tool_status(&mut active_operator, OperatorPhase::Blocked, error);
let message = format!("Draw Brush failed: {}", floor_polygon_error_message(error));
warn!("{message}; points={:?}", tool.vertices);
scene_io.status = message.clone();
set_brush_tool_status(&mut active_operator, OperatorPhase::Blocked, message);
}
}
}
@@ -182,6 +267,7 @@ fn brush_tool_input(
fn draw_brush_tool_preview(
tool: Res<BrushToolState>,
ui_state: Res<UiState>,
settings: Res<ViewportSettings>,
cameras: Query<(&Camera, &GlobalTransform), With<EditorCamera>>,
mut gizmos: Gizmos,
) {
@@ -189,15 +275,20 @@ fn draw_brush_tool_preview(
return;
}
let mut points = tool.vertices.clone();
if let Some(pointer_pos) = ui_state.viewport_pointer_pos {
if let Some(point) = pointer_floor_position(&cameras, pointer_pos, ui_state.viewport_rect) {
points.push(point);
if tool.phase == BrushToolPhase::Outline {
if let Some(pointer_pos) = ui_state.viewport_pointer_pos {
if let Some(mut point) =
pointer_floor_position(&cameras, pointer_pos, ui_state.viewport_rect)
{
point = snap_translation(point, &settings);
points.push(point);
}
}
}
if points.is_empty() {
return;
}
let color = Color::srgb(0.2, 0.72, 1.0);
let color = brush_preview_color(&points);
for point in &points {
gizmos.sphere(*point + Vec3::Y * 0.02, 0.08, color);
gizmos.line(*point, *point + Vec3::Y * tool.height, color);
@@ -219,6 +310,11 @@ fn draw_brush_tool_preview(
first + Vec3::Y * tool.height,
color,
);
if let Ok(parts) = decompose_floor_polygon_to_convex(&points) {
if parts.len() > 1 {
draw_decomposition_preview(&parts, tool.height, &mut gizmos);
}
}
}
}
@@ -240,11 +336,31 @@ fn pointer_floor_position(
Some(ray.origin + direction * t.max(0.0))
}
fn brush_snapshot_from_points(
fn brush_snapshots_from_points(
points: &[Vec3],
height: f32,
) -> Result<Vec<EditorEntitySnapshot>, String> {
let parts = decompose_floor_polygon_to_convex(points).map_err(floor_polygon_error_message)?;
let part_count = parts.len();
parts
.iter()
.enumerate()
.map(|(index, part)| {
let name = if part_count == 1 {
"Brush".to_string()
} else {
format!("Brush Part {}", index + 1)
};
brush_snapshot_from_convex_points(part, height, name)
})
.collect()
}
fn brush_snapshot_from_convex_points(
points: &[Vec3],
height: f32,
name: String,
) -> Result<EditorEntitySnapshot, String> {
validate_floor_polygon(points).map_err(|error| format!("{error:?}"))?;
let center = polygon_center(points);
let local_points: Vec<Vec3> = points.iter().map(|point| *point - center).collect();
let brush = BrushDesc::extruded_prism(&local_points, height)
@@ -253,7 +369,7 @@ fn brush_snapshot_from_points(
actor_id: None,
actor_kind: ActorKind::Brush,
actor_name: None,
name: Some("Brush".to_string()),
name: Some(name),
transform: Transform::from_translation(center),
primitive: None,
brush: Some(brush),
@@ -287,12 +403,115 @@ fn polygon_center(points: &[Vec3]) -> Vec3 {
sum / points.len() as f32
}
fn quantize_height(height: f32) -> f32 {
((height.max(MIN_BRUSH_HEIGHT) * 10.0).round() / 10.0).max(MIN_BRUSH_HEIGHT)
}
fn brush_tool_hint(vertex_count: usize) -> String {
match vertex_count {
0 => "Click first floor point".to_string(),
1 => "Click second floor point".to_string(),
2 => "Click third floor point".to_string(),
count => format!("{count} points, Enter creates brush"),
count => format!("{count} points, Enter sets height"),
}
}
fn draw_brush_status(tool: &BrushToolState) -> String {
if tool.phase == BrushToolPhase::Height {
let part_count = decompose_floor_polygon_to_convex(&tool.vertices)
.map(|parts| parts.len())
.unwrap_or(1);
return height_phase_status(part_count, tool.height);
}
let points = &tool.vertices;
if points.len() < MIN_COMMIT_VERTICES {
return format!("Draw Brush: {}", brush_tool_hint(points.len()));
}
match decompose_floor_polygon_to_convex(points) {
Ok(parts) if parts.len() == 1 => {
format!("Draw Brush: {} points, Enter creates brush", points.len())
}
Ok(parts) => format!(
"Draw Brush: {} points, Enter creates {} convex brush parts",
points.len(),
parts.len()
),
Err(error) => format!("Draw Brush blocked: {}", floor_polygon_error_message(error)),
}
}
fn height_phase_status(part_count: usize, height: f32) -> String {
if part_count == 1 {
format!("Draw Brush height: {height:.1}m, Enter/LMB creates brush")
} else {
format!("Draw Brush height: {height:.1}m, Enter/LMB creates {part_count} convex parts")
}
}
fn brush_created_status(brush_count: usize, height: f32) -> String {
if brush_count == 1 {
format!("Brush created at {height:.1}m")
} else {
format!("Brush created as {brush_count} convex parts at {height:.1}m")
}
}
fn brush_committed_status(brush_count: usize, height: f32) -> String {
if brush_count == 1 {
format!("Committed brush.draw ({height:.1}m)")
} else {
format!("Committed brush.draw ({brush_count} parts, {height:.1}m)")
}
}
fn brush_preview_color(points: &[Vec3]) -> Color {
if points.len() < MIN_COMMIT_VERTICES {
return Color::srgb(0.2, 0.72, 1.0);
}
match decompose_floor_polygon_to_convex(points) {
Ok(_) => Color::srgb(0.2, 0.72, 1.0),
Err(_) => Color::srgb(1.0, 0.25, 0.2),
}
}
fn draw_decomposition_preview(parts: &[Vec<Vec3>], height: f32, gizmos: &mut Gizmos) {
let color = Color::srgb(0.15, 1.0, 0.65);
for part in parts {
for window in part.windows(2) {
gizmos.line(
window[0] + Vec3::Y * 0.04,
window[1] + Vec3::Y * 0.04,
color,
);
gizmos.line(
window[0] + Vec3::Y * height,
window[1] + Vec3::Y * height,
color,
);
}
if let (Some(first), Some(last)) = (part.first(), part.last()) {
gizmos.line(*last + Vec3::Y * 0.04, *first + Vec3::Y * 0.04, color);
gizmos.line(*last + Vec3::Y * height, *first + Vec3::Y * height, color);
}
}
}
fn floor_polygon_error_message(error: BrushPolygonError) -> String {
match error {
BrushPolygonError::TooFewVertices => {
"need at least three points before creating a brush".into()
}
BrushPolygonError::NonFiniteVertex => "one or more points are not finite".into(),
BrushPolygonError::DuplicateVertex => {
"two points overlap; remove or move the duplicate point".into()
}
BrushPolygonError::ZeroArea => "polygon area is zero; points must enclose an area".into(),
BrushPolygonError::SelfIntersecting => {
"polygon edges cross; draw points around the perimeter in order".into()
}
BrushPolygonError::NonConvex => {
"concave outline could not be decomposed into convex brush parts".into()
}
}
}
@@ -316,7 +535,7 @@ mod tests {
#[test]
fn brush_snapshot_centers_polygon_points() {
let snapshot = brush_snapshot_from_points(
let snapshots = brush_snapshots_from_points(
&[
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(2.0, 0.0, 0.0),
@@ -326,6 +545,8 @@ mod tests {
3.0,
)
.expect("valid brush");
assert_eq!(snapshots.len(), 1);
let snapshot = &snapshots[0];
assert_eq!(snapshot.actor_kind, ActorKind::Brush);
assert_eq!(snapshot.transform.translation, Vec3::new(1.0, 0.0, 1.0));
@@ -333,8 +554,8 @@ mod tests {
}
#[test]
fn brush_snapshot_rejects_non_convex_polygon() {
let result = brush_snapshot_from_points(
fn brush_snapshot_decomposes_non_convex_polygon() {
let snapshots = brush_snapshots_from_points(
&[
Vec3::new(-1.0, 0.0, -1.0),
Vec3::new(1.0, 0.0, -1.0),
@@ -343,8 +564,65 @@ mod tests {
Vec3::new(-1.0, 0.0, 1.0),
],
2.0,
)
.expect("concave brush parts");
assert_eq!(snapshots.len(), 2);
assert!(snapshots.iter().all(|snapshot| snapshot.brush.is_some()));
}
#[test]
fn brush_snapshot_reports_actionable_invalid_polygon_reason() {
let result = brush_snapshots_from_points(
&[
Vec3::new(-1.0, 0.0, -1.0),
Vec3::new(1.0, 0.0, 1.0),
Vec3::new(1.0, 0.0, -1.0),
Vec3::new(-1.0, 0.0, 1.0),
],
2.0,
);
assert!(result.is_err());
assert_eq!(
result.unwrap_err(),
"polygon edges cross; draw points around the perimeter in order"
);
}
#[test]
fn draw_brush_status_explains_invalid_shape() {
let mut tool = BrushToolState::default();
tool.vertices = vec![
Vec3::new(-1.0, 0.0, -1.0),
Vec3::new(1.0, 0.0, -1.0),
Vec3::new(-1.0, 0.0, 1.0),
Vec3::new(1.0, 0.0, 1.0),
];
let status = draw_brush_status(&tool);
assert!(status.contains("polygon edges cross"));
}
#[test]
fn height_phase_status_reports_height_and_part_count() {
let mut tool = BrushToolState {
active: true,
phase: BrushToolPhase::Height,
height: 4.2,
vertices: vec![
Vec3::new(-1.0, 0.0, -1.0),
Vec3::new(1.0, 0.0, -1.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(1.0, 0.0, 1.0),
Vec3::new(-1.0, 0.0, 1.0),
],
..Default::default()
};
tool.height = quantize_height(tool.height);
let status = draw_brush_status(&tool);
assert!(status.contains("4.2m"));
assert!(status.contains("2 convex parts"));
}
}