Merge pull request #257 from Rebornim/feat/bake-mode-layout

Bake mode: mesh map bakers list and per-map settings
This commit is contained in:
Chris Hassebrook authored and GitHub committed 2026-11-05 16:23:21 -05:00
commit 966d3a7252
22 files changed
+508 -151

No files matched your search

+23 -8
View File
@@ -1,10 +1,12 @@
//! Bake Mode presentation; persisted settings live in core and edits use engine commands
mod bake_paint_brush;
mod breadcrumb;
mod common_settings;
pub use bake_paint_brush::BakePaintBrush;
mod controls;
mod map_settings;
mod mesh_map_bakers;
use egui::{Ui, vec2};
use serde_json::json;
@@ -37,19 +39,32 @@ pub fn texture_sets(app: &mut TextureCraftApp, ui: &mut Ui) {
});
}
pub fn bake_body(app: &mut TextureCraftApp, ui: &mut Ui) {
edit_settings(app, ui, "bake_maps", |_, ui, settings| {
for map in BakedMap::ALL {
ui.push_id(map, |ui| map_settings::show(ui, map, &mut settings.maps));
ui.add_space(6.0);
}
});
/// The Mesh Map Bakers panel: which maps bake and which one Mesh Map Settings shows
pub fn mesh_map_bakers_panel(app: &mut TextureCraftApp, ui: &mut Ui) {
edit_settings(app, ui, "mesh_map_bakers", mesh_map_bakers::show);
}
pub fn settings_body(app: &mut TextureCraftApp, ui: &mut Ui) {
/// The Mesh Map Settings panel: the breadcrumb, then the selected map's parameters
pub fn mesh_map_settings_panel(app: &mut TextureCraftApp, ui: &mut Ui) {
let Some(texture_set) = app.session.doc.project.texture_sets.get(app.session.ts()) else { return };
let selected = selected_map(app.ui.selected_baked_map, &texture_set.bake);
breadcrumb::show(app, ui, selected);
ui.separator();
edit_settings(app, ui, "mesh_map_settings", |_, ui, settings| ui.push_id(selected, |ui| map_settings::show(ui, selected, &mut settings.maps)).inner);
}
/// The Common Settings panel: output, high poly, cage and skew settings
pub fn common_settings_panel(app: &mut TextureCraftApp, ui: &mut Ui) {
edit_settings(app, ui, "bake_common_settings", common_settings::show);
}
/// The map whose settings show: the chosen one, else the first enabled map, else Normal
fn selected_map(selection: Option<BakedMap>, settings: &BakeSettings) -> BakedMap {
selection.or_else(|| settings.maps.enabled().next()).unwrap_or(BakedMap::Normal)
}
/// Draw `contents` over a copy of the active set's bake settings and run `bake.settings` on change
fn edit_settings(app: &mut TextureCraftApp, ui: &mut Ui, scroll_id: &str, contents: impl FnOnce(&mut TextureCraftApp, &mut Ui, &mut BakeSettings)) {
let set_index = app.session.ts();
let Some(before) = app.session.doc.project.texture_sets.get(set_index).map(|texture_set| texture_set.bake.clone()) else { return };
@@ -0,0 +1,35 @@
use egui::{RichText, Ui};
use egui_phosphor::regular as icon;
use serde_json::json;
use texturecraft_engine::core::BakedMap;
use crate::TextureCraftApp;
use crate::i18n::{baked_map_label, tr};
/// The texture set and selected map above Mesh Map Settings, each behind a dropdown to switch it
pub(super) fn show(app: &mut TextureCraftApp, ui: &mut Ui, selected: BakedMap) {
let active_set = app.session.ts();
let set_names: Vec<String> = app.session.doc.project.texture_sets.iter().map(|texture_set| texture_set.name.clone()).collect();
ui.horizontal(|ui| {
ui.menu_button(icon::CARET_RIGHT, |ui| {
for (set_index, name) in set_names.iter().enumerate() {
if ui.selectable_label(set_index == active_set, name).clicked() {
app.run("textureSet.select", json!({ "ts": set_index }));
ui.close();
}
}
});
ui.label(set_names.get(active_set).map_or("", String::as_str));
ui.menu_button(icon::CARET_RIGHT, |ui| {
for map in BakedMap::ALL {
if ui.selectable_label(map == selected, tr(baked_map_label(map))).clicked() {
app.ui.selected_baked_map = Some(map);
ui.close();
}
}
});
ui.label(RichText::new(tr(baked_map_label(selected))).strong());
});
}
@@ -9,10 +9,12 @@ use texturecraft_engine::core::{
BakeAntialiasing, BakePaintTarget, BakeResolution, BakeSettings, CageType, CommonBakeSettings, MeshMatchMode, SkewCorrectionMethod,
};
/// The output and high-poly sections, then cage (needs a high poly) and skew (needs a distance cage)
pub(super) fn show(app: &mut TextureCraftApp, ui: &mut Ui, settings: &mut BakeSettings) {
ui.push_id("common", |ui| {
// Restore Defaults keeps whether the texture set is included in the bake
let is_enabled = settings.common.is_enabled;
if section(ui, tr("Common Parameters"), None, |ui| {
if section(ui, tr("Common Parameters"), |ui| {
output_size(ui, &mut settings.common);
choice(
ui,
@@ -31,9 +33,10 @@ pub(super) fn show(app: &mut TextureCraftApp, ui: &mut Ui, settings: &mut BakeSe
settings.common = CommonBakeSettings { is_enabled, ..CommonBakeSettings::default() };
}
});
ui.add_space(8.0);
ui.push_id("high_poly", |ui| {
if section(ui, tr("High-Poly Parameters"), None, |ui| {
if section(ui, tr("High-Poly Parameters"), |ui| {
ui.checkbox(&mut settings.high_poly.use_low_as_high, tr("Use Low Poly Mesh as High Poly Mesh"));
high_poly_files(app, ui);
if !app.session.bake_meshes.high.is_empty() {
@@ -52,10 +55,11 @@ pub(super) fn show(app: &mut TextureCraftApp, ui: &mut Ui, settings: &mut BakeSe
settings.high_poly = Default::default();
}
});
if !app.session.bake_meshes.high.is_empty() {
ui.add_space(8.0);
ui.push_id("cage", |ui| {
if section(ui, tr("Cage"), None, |ui| {
if section(ui, tr("Cage"), |ui| {
choice(
ui,
tr("Cage Type"),
@@ -76,10 +80,11 @@ pub(super) fn show(app: &mut TextureCraftApp, ui: &mut Ui, settings: &mut BakeSe
settings.cage = Default::default();
}
});
if settings.cage.kind == CageType::DistanceBased {
ui.add_space(8.0);
ui.push_id("skew", |ui| {
if section(ui, tr("Skew Correction"), None, |ui| {
if section(ui, tr("Skew Correction"), |ui| {
choice(
ui,
tr("Skew Correction Method"),
+17 -45
View File
@@ -3,63 +3,35 @@ use crate::theme::{Tokens, caption};
use egui::collapsing_header::CollapsingState;
use egui::{RichText, Ui};
pub(super) fn section_header(ui: &mut Ui, title: &str, mut is_enabled: Option<&mut bool>, collapsing_state: Option<&mut CollapsingState>) -> bool {
/// A section's title bar with its chevron; clicking it opens or closes the section
fn section_header(ui: &mut Ui, title: &str, collapsing_state: &mut CollapsingState) {
let tokens = Tokens::get(ui.ctx());
let text_color = if is_enabled.as_deref().copied().unwrap_or(true) { tokens.text_strong } else { tokens.text_dim };
let mut checkbox_rect = None;
let mut arrow_rect = None;
let header = egui::Frame::NONE.fill(tokens.row).corner_radius(tokens.cr()).inner_margin(egui::Margin::symmetric(8, 4)).show(ui, |ui| {
ui.set_min_width(ui.available_width());
ui.horizontal(|ui| {
ui.set_min_height(ui.spacing().interact_size.y);
let checkbox = is_enabled.as_deref_mut().map(|is_enabled| ui.checkbox(is_enabled, ""));
let title_response = ui.add(egui::Label::new(caption(title).color(text_color)).selectable(false));
if let Some(checkbox) = checkbox {
checkbox_rect = Some(checkbox.rect);
checkbox.labelled_by(title_response.id);
}
if collapsing_state.is_some() {
arrow_rect = Some(
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.allocate_exact_size(egui::vec2(ui.spacing().indent, ui.spacing().icon_width), egui::Sense::hover()).0
})
.inner,
);
}
});
ui.add(egui::Label::new(caption(title).color(tokens.text_strong)).selectable(false));
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.allocate_exact_size(egui::vec2(ui.spacing().indent, ui.spacing().icon_width), egui::Sense::hover()).0
})
.inner
})
.inner
});
if let (Some(collapsing_state), Some(arrow_rect)) = (collapsing_state, arrow_rect) {
let mut toggle_rect = header.response.rect;
if let Some(checkbox_rect) = checkbox_rect {
let checkbox_margin = ui.spacing().item_spacing.x * 0.5;
if ui.style().right_to_left {
toggle_rect.max.x = checkbox_rect.left() - checkbox_margin;
} else {
toggle_rect.min.x = checkbox_rect.right() + checkbox_margin;
}
}
let response = ui.interact(toggle_rect, ui.make_persistent_id("section_header"), egui::Sense::click());
if response.clicked() {
collapsing_state.toggle(ui);
}
let chevron = crate::widgets::section_chevron(ui, collapsing_state.is_open());
ui.put(arrow_rect, egui::Label::new(chevron).selectable(false));
let response = ui.interact(header.response.rect, ui.make_persistent_id("section_header"), egui::Sense::click());
if response.clicked() {
collapsing_state.toggle(ui);
}
is_enabled.as_deref().copied().unwrap_or(true)
let chevron = crate::widgets::section_chevron(ui, collapsing_state.is_open());
ui.put(header.inner, egui::Label::new(chevron).selectable(false));
}
pub(super) fn section(ui: &mut Ui, title: &str, is_enabled: Option<&mut bool>, contents: impl FnOnce(&mut Ui)) -> bool {
/// A collapsible section with `contents` and Restore Defaults; returns whether that was clicked
pub(super) fn section(ui: &mut Ui, title: &str, contents: impl FnOnce(&mut Ui)) -> bool {
let mut collapsing_state = CollapsingState::load_with_default_open(ui.ctx(), ui.make_persistent_id("section"), true);
if !section_header(ui, title, is_enabled, Some(&mut collapsing_state)) {
collapsing_state.store(ui.ctx());
return false;
}
section_header(ui, title, &mut collapsing_state);
collapsing_state
.show_body_unindented(ui, |ui| {
+21 -19
View File
@@ -1,32 +1,34 @@
use super::controls::{choice, integer, number, section, section_header};
use crate::i18n::{baked_map_label, tr};
use super::controls::{choice, hint, integer, number};
use crate::i18n::tr;
use egui::Ui;
use texturecraft_engine::core::{
AmbientOcclusionAttenuation, AmbientOcclusionSettings, BackfaceMode, BakedMap, BentNormalSettings, CurvatureMethod, CurvatureSettings, HeightNormalization,
HeightSettings, IdColorGenerator, IdColorSource, IdSettings, MapSettings, MeshMapSettings, PositionAxis, PositionMode, PositionNormalizationScale,
PositionSettings, RayDistribution, RaySettings, SelfOcclusion, ThicknessNormalization, ThicknessSettings,
HeightSettings, IdColorGenerator, IdColorSource, IdSettings, MeshMapSettings, PositionAxis, PositionMode, PositionNormalizationScale, PositionSettings,
RayDistribution, RaySettings, SelfOcclusion, ThicknessNormalization, ThicknessSettings,
};
/// Draw `map`'s parameters with Restore Defaults; maps without parameters say so
pub(super) fn show(ui: &mut Ui, map: BakedMap, settings: &mut MeshMapSettings) {
match map {
BakedMap::Normal | BakedMap::WorldNormal | BakedMap::Opacity => {
let mut is_enabled = settings.is_enabled(map);
section_header(ui, tr(baked_map_label(map)), Some(&mut is_enabled), None);
settings.set_enabled(map, is_enabled);
}
BakedMap::Id => baker(ui, map, &mut settings.id, id),
BakedMap::AmbientOcclusion => baker(ui, map, &mut settings.ao, ambient_occlusion),
BakedMap::Curvature => baker(ui, map, &mut settings.curvature, curvature),
BakedMap::Position => baker(ui, map, &mut settings.position, position),
BakedMap::Thickness => baker(ui, map, &mut settings.thickness, thickness),
BakedMap::Height => baker(ui, map, &mut settings.height, height),
BakedMap::BentNormal => baker(ui, map, &mut settings.bent_normal, bent_normal),
BakedMap::Normal | BakedMap::WorldNormal | BakedMap::Opacity => hint(ui, tr("No Parameters")),
BakedMap::Id => parameters(ui, &mut settings.id.parameters, id),
BakedMap::AmbientOcclusion => parameters(ui, &mut settings.ao.parameters, ambient_occlusion),
BakedMap::Curvature => parameters(ui, &mut settings.curvature.parameters, curvature),
BakedMap::Position => parameters(ui, &mut settings.position.parameters, position),
BakedMap::Thickness => parameters(ui, &mut settings.thickness.parameters, thickness),
BakedMap::Height => parameters(ui, &mut settings.height.parameters, height),
BakedMap::BentNormal => parameters(ui, &mut settings.bent_normal.parameters, bent_normal),
}
}
fn baker<T: Default>(ui: &mut Ui, map: BakedMap, settings: &mut MapSettings<T>, controls: impl FnOnce(&mut Ui, &mut T)) {
if section(ui, tr(baked_map_label(map)), Some(&mut settings.is_enabled), |ui| controls(ui, &mut settings.parameters)) {
settings.parameters = T::default();
/// A map's controls, then a right-aligned Restore Defaults that resets only its parameters
fn parameters<T: Default>(ui: &mut Ui, parameters: &mut T, controls: impl FnOnce(&mut Ui, &mut T)) {
controls(ui, parameters);
ui.add_space(6.0);
let restore = ui.with_layout(egui::Layout::right_to_left(egui::Align::Min), |ui| ui.button(tr("Restore Defaults"))).inner;
if restore.clicked() {
*parameters = T::default();
}
}
@@ -0,0 +1,75 @@
use egui::{Align, Layout, RichText, Sense, Stroke, Ui, UiBuilder, vec2};
use egui_phosphor::regular as icon;
use texturecraft_engine::core::{BakeSettings, BakedMap};
use crate::TextureCraftApp;
use crate::docking::Panel;
use crate::i18n::{baked_map_label, tr};
use crate::theme::Tokens;
/// Height of one baker row, in points
const ROW_HEIGHT: f32 = 24.0;
/// Inset of a row's checkbox and name from its left edge, in points
const ROW_INSET: f32 = 6.0;
/// The Common Settings button, Check All, and one row per map (checkbox enables, click selects)
pub(super) fn show(app: &mut TextureCraftApp, ui: &mut Ui, settings: &mut BakeSettings) {
if ui.button(format!("{} {}", icon::GEAR, tr("Common Settings"))).clicked() {
app.ui.dock.focus(Panel::CommonSettings);
}
ui.add_space(4.0);
check_all(ui, settings);
ui.separator();
let selected = super::selected_map(app.ui.selected_baked_map, settings);
for map in BakedMap::ALL {
if ui.push_id(map, |ui| row(ui, map, settings, map == selected)).inner {
app.ui.selected_baked_map = Some(map);
app.ui.dock.focus(Panel::MeshMapSettings);
}
}
}
/// Enable every map, or disable them all when every map is already enabled
fn check_all(ui: &mut Ui, settings: &mut BakeSettings) {
let enabled_count = BakedMap::ALL.into_iter().filter(|map| settings.maps.is_enabled(*map)).count();
let mut all_enabled = enabled_count == BakedMap::ALL.len();
let some_enabled = enabled_count > 0 && !all_enabled;
if ui.add(egui::Checkbox::new(&mut all_enabled, tr("Check All")).indeterminate(some_enabled)).changed() {
for map in BakedMap::ALL {
settings.maps.set_enabled(map, all_enabled);
}
}
}
/// One baker row; returns whether the row (not its checkbox) was clicked
fn row(ui: &mut Ui, map: BakedMap, settings: &mut BakeSettings, is_selected: bool) -> bool {
let tokens = Tokens::get(ui.ctx());
let name = tr(baked_map_label(map));
let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), ROW_HEIGHT), Sense::click());
response.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, is_selected, name));
let painter = ui.painter();
if is_selected {
painter.rect_filled(rect, tokens.cr(), tokens.row_selected);
painter.rect_stroke(rect, tokens.cr(), Stroke::new(1.0, tokens.accent), egui::StrokeKind::Inside);
} else if response.hovered() {
painter.rect_filled(rect, tokens.cr(), tokens.row_hover);
}
painter.hline(rect.x_range(), rect.bottom(), Stroke::new(1.0, tokens.separator));
// Added after the row's own response, so the checkbox takes the clicks over it
let content_rect = rect.shrink2(vec2(ROW_INSET, 0.0));
let mut content = ui.new_child(UiBuilder::new().max_rect(content_rect).layout(Layout::left_to_right(Align::Center)));
let mut is_enabled = settings.maps.is_enabled(map);
let checkbox = content.checkbox(&mut is_enabled, "");
let text = if is_selected { RichText::new(name).strong() } else { RichText::new(name) };
let label = content.add(egui::Label::new(text).selectable(false).truncate());
if checkbox.labelled_by(label.id).changed() {
settings.maps.set_enabled(map, is_enabled);
}
response.clicked()
}
+84 -37
View File
@@ -24,8 +24,12 @@ use crate::theme::Tokens;
pub enum Panel {
Viewport,
Assets,
BakeMaps,
BakeSettings,
// Saved layouts name the bake panels by their earlier names
#[serde(rename = "BakeMaps")]
MeshMapSettings,
#[serde(rename = "BakeSettings")]
CommonSettings,
MeshMapBakers,
TextureSetList,
Layers,
TextureSetSettings,
@@ -37,14 +41,15 @@ pub enum Panel {
}
/// Window ▸ Views items and the panels they show or hide.
pub const VIEWS: [(&str, Panel); 11] = [
pub const VIEWS: [(&str, Panel); 12] = [
("ui.view.assets", Panel::Assets),
("ui.view.bakeMaps", Panel::BakeMaps),
("ui.view.bakeSettings", Panel::BakeSettings),
("ui.view.bakeMaps", Panel::MeshMapSettings),
("ui.view.bakeSettings", Panel::CommonSettings),
("ui.view.display", Panel::Display),
("ui.view.history", Panel::History),
("ui.view.layers", Panel::Layers),
("ui.view.log", Panel::Log),
("ui.view.meshMapBakers", Panel::MeshMapBakers),
("ui.view.properties", Panel::Properties),
("ui.view.shader", Panel::Shader),
("ui.view.textureSetList", Panel::TextureSetList),
@@ -59,17 +64,18 @@ pub fn view_panel(id: &str) -> Option<Panel> {
impl Panel {
pub(crate) fn available_in(self, mode: crate::state::Mode) -> bool {
match self {
Self::BakeMaps | Self::BakeSettings => mode == crate::state::Mode::Baking,
Self::MeshMapSettings | Self::CommonSettings | Self::MeshMapBakers => mode == crate::state::Mode::Baking,
Self::Assets | Self::Layers | Self::Properties | Self::TextureSetSettings => mode != crate::state::Mode::Baking,
_ => true,
}
}
pub const ALL: [Panel; 12] = [
pub const ALL: [Panel; 13] = [
Panel::Viewport,
Panel::Assets,
Panel::BakeMaps,
Panel::BakeSettings,
Panel::MeshMapSettings,
Panel::CommonSettings,
Panel::MeshMapBakers,
Panel::TextureSetList,
Panel::Layers,
Panel::TextureSetSettings,
@@ -84,8 +90,9 @@ impl Panel {
match self {
Panel::Viewport => "Viewport",
Panel::Assets => "Assets",
Panel::BakeMaps => "Bake Maps",
Panel::BakeSettings => "Settings",
Panel::MeshMapSettings => "Mesh Map Settings",
Panel::CommonSettings => "Common Settings",
Panel::MeshMapBakers => "Mesh Map Bakers",
Panel::TextureSetList => "Texture Sets",
Panel::Layers => "Layers",
Panel::TextureSetSettings => "Texture Set Settings",
@@ -122,8 +129,8 @@ fn tabs(panels: &[Panel]) -> Node<Panel> {
Node::Tabs { panels: panels.to_vec(), active: 0 }
}
fn split(axis: SplitAxis, ratio: f32, first: Node<Panel>, second: Node<Panel>) -> Node<Panel> {
Node::Split { axis, size: SplitSize::Ratio(ratio), first: Box::new(first), second: Box::new(second) }
fn split(axis: SplitAxis, size: SplitSize, first: Node<Panel>, second: Node<Panel>) -> Node<Panel> {
Node::Split { axis, size, first: Box::new(first), second: Box::new(second) }
}
/// The default: assets left of the viewport; texture set list, layers (tabbed with the texture
@@ -131,9 +138,14 @@ fn split(axis: SplitAxis, ratio: f32, first: Node<Panel>, second: Node<Panel>) -
/// shader, history and log are closed and open as floating windows.
pub fn default_workspace() -> Workspace {
use Panel::*;
let column =
split(SplitAxis::Vertical, 0.125, tabs(&[TextureSetList]), split(SplitAxis::Vertical, 0.57, tabs(&[Layers, TextureSetSettings]), tabs(&[Properties])));
let root = split(SplitAxis::Horizontal, 0.115, tabs(&[Assets]), split(SplitAxis::Horizontal, 0.78, tabs(&[Viewport]), column));
let column = split(
SplitAxis::Vertical,
SplitSize::Ratio(0.125),
tabs(&[TextureSetList]),
split(SplitAxis::Vertical, SplitSize::Ratio(0.57), tabs(&[Layers, TextureSetSettings]), tabs(&[Properties])),
);
let root =
split(SplitAxis::Horizontal, SplitSize::Ratio(0.115), tabs(&[Assets]), split(SplitAxis::Horizontal, SplitSize::Ratio(0.78), tabs(&[Viewport]), column));
let mut workspace = Workspace::new(Layout { root: Some(root), floating: Vec::new() });
for panel in Panel::ALL {
if let Some(rect) = panel.float_rect() {
@@ -149,7 +161,7 @@ pub fn default_workspace() -> Workspace {
workspace.hidden.push((panel, location));
}
}
for panel in [BakeMaps, BakeSettings] {
for panel in [MeshMapSettings, CommonSettings, MeshMapBakers] {
workspace.hidden.push((
panel,
Location {
@@ -206,17 +218,28 @@ pub fn validate(workspace: &Workspace) -> Result<(), String> {
// ---------------------------------------------------------------------------------------------
// The live dock
/// Width of the bake layout's texture set and mesh map bakers column, in points
const BAKERS_COLUMN_WIDTH: f32 = 200.0;
/// Width of the bake layout's common and mesh map settings column, in points
const SETTINGS_COLUMN_WIDTH: f32 = 330.0;
/// Height of the log under the bake layout's columns, in points
const BAKING_LOG_HEIGHT: f32 = 160.0;
/// Share of the first bake column the texture set list takes above the mesh map bakers
const TEXTURE_SET_LIST_SHARE: f32 = 0.4;
/// The dock layout (part of `UiState`; serialized as a craft-ui `Workspace`).
#[derive(Clone, Debug)]
pub struct Dock {
workspace: Workspace,
/// A panel to bring in front of the other floating windows on the next frame.
raise: Option<Panel>,
/// A saved layout could not be read, so this is the painting default in its place
replaced_unreadable: bool,
}
impl Default for Dock {
fn default() -> Self {
Dock { workspace: default_workspace(), raise: None }
Dock { workspace: default_workspace(), raise: None, replaced_unreadable: false }
}
}
@@ -240,18 +263,27 @@ impl<'de> Deserialize<'de> for Dock {
}
impl Dock {
/// The dock for a saved layout; the default when it is not a valid workspace.
/// The dock for a saved layout; the default, marked as a replacement, when it is not a valid workspace
pub fn from_value(value: Value) -> Dock {
let unreadable = Dock { replaced_unreadable: true, ..Dock::default() };
let default = default_workspace();
let loaded = serde_json::from_value::<Workspace>(value).ok();
let Some(mut workspace) = loaded.filter(|w| validate(w).is_ok()) else { return Dock::default() };
let Some(mut workspace) = loaded.filter(|w| validate(w).is_ok()) else { return unreadable };
workspace.reconcile(|_| true, permissions, &default);
if validate(&workspace).is_err() {
return Dock::default();
return unreadable;
}
Dock { workspace, raise: None }
Dock { workspace, raise: None, replaced_unreadable: false }
}
/// Whether a saved layout could not be read and this dock is the painting default instead
pub(crate) fn replaced_unreadable(&self) -> bool {
self.replaced_unreadable
}
/// Texture sets over the bakers, the two settings tabs, the log under both, then the viewport
pub(crate) fn for_baking() -> Self {
let mut workspace = default_workspace();
for panel in [Panel::Assets, Panel::Layers, Panel::TextureSetSettings, Panel::Properties] {
@@ -259,17 +291,19 @@ impl Dock {
workspace.hidden.push((panel, location));
}
}
workspace.hidden.retain(|(panel, _)| !matches!(panel, Panel::BakeMaps | Panel::BakeSettings));
workspace.layout = Layout {
root: Some(Node::Split {
axis: SplitAxis::Horizontal,
size: SplitSize::FixedFirst(320.0),
first: Box::new(tabs(&[Panel::TextureSetList, Panel::BakeSettings, Panel::BakeMaps])),
second: Box::new(tabs(&[Panel::Viewport])),
}),
floating: Vec::new(),
};
Dock { workspace, raise: None }
let bake_panels = [Panel::MeshMapSettings, Panel::CommonSettings, Panel::MeshMapBakers, Panel::Log];
workspace.hidden.retain(|(panel, _)| !bake_panels.contains(panel));
let gutter_width = f32::from(crate::theme::GUTTER);
let list_column = split(SplitAxis::Vertical, SplitSize::Ratio(TEXTURE_SET_LIST_SHARE), tabs(&[Panel::TextureSetList]), tabs(&[Panel::MeshMapBakers]));
let settings_column = tabs(&[Panel::CommonSettings, Panel::MeshMapSettings]);
let columns = split(SplitAxis::Horizontal, SplitSize::FixedFirst(BAKERS_COLUMN_WIDTH), list_column, settings_column);
let columns_over_log = split(SplitAxis::Vertical, SplitSize::FixedSecond(BAKING_LOG_HEIGHT), columns, tabs(&[Panel::Log]));
let columns_width = BAKERS_COLUMN_WIDTH + gutter_width + SETTINGS_COLUMN_WIDTH;
let root = split(SplitAxis::Horizontal, SplitSize::FixedFirst(columns_width), columns_over_log, tabs(&[Panel::Viewport]));
workspace.layout = Layout { root: Some(root), floating: Vec::new() };
Dock { workspace, raise: None, replaced_unreadable: false }
}
pub fn workspace(&self) -> &Workspace {
@@ -401,9 +435,10 @@ impl DockContent<Panel> for Panels<'_> {
return;
}
egui::Frame::new().inner_margin(Margin::symmetric(8, 4)).show(ui, |ui| match panel {
Panel::BakeMaps => crate::bake_mode::bake_body(app, ui),
Panel::MeshMapSettings => crate::bake_mode::mesh_map_settings_panel(app, ui),
Panel::Assets => crate::shelf::body(app, ui),
Panel::BakeSettings => crate::bake_mode::settings_body(app, ui),
Panel::CommonSettings => crate::bake_mode::common_settings_panel(app, ui),
Panel::MeshMapBakers => crate::bake_mode::mesh_map_bakers_panel(app, ui),
Panel::TextureSetList if app.ui.mode == crate::state::Mode::Baking => crate::bake_mode::texture_sets(app, ui),
Panel::TextureSetList => crate::dock::texture_set_list(app, ui),
Panel::Layers => crate::dock::layers(app, ui),
@@ -425,8 +460,6 @@ impl DockContent<Panel> for Panels<'_> {
fn logical_label(&self, panel: &Panel) -> String {
match panel {
Panel::Properties => crate::dock::properties_title(self.app),
Panel::BakeMaps => tr("Bake Maps").to_string(),
Panel::BakeSettings => tr("Settings").to_string(),
p => tr(p.name()).to_string(),
}
}
@@ -475,6 +508,20 @@ mod tests {
assert_eq!(back, dock);
}
#[test]
fn the_bake_dock_round_trips_with_the_log_under_both_settings_columns() {
let dock = Dock::for_baking();
assert!(validate(dock.workspace()).is_ok());
assert_eq!(
panels_of(dock.workspace()),
[Panel::TextureSetList, Panel::MeshMapBakers, Panel::CommonSettings, Panel::MeshMapSettings, Panel::Log, Panel::Viewport]
);
assert!(dock.is_visible(Panel::CommonSettings) && !dock.is_visible(Panel::MeshMapSettings));
let back: Dock = serde_json::from_str(&serde_json::to_string(&dock).unwrap()).unwrap();
assert_eq!(back, dock);
}
#[test]
fn unreadable_layouts_become_the_default() {
for text in [
+5 -1
View File
@@ -963,7 +963,11 @@ pub const TABLE: &[(&str, &str)] = &[
("Average Normals", "توسيط النواظم"),
("BBox", "صندوق الإحاطة"),
("BSphere", "كرة الإحاطة"),
("Bake Maps", "خبز الخرائط"),
("Mesh Map Bakers", "مُخبِزات خرائط المجسم"),
("Common Settings", "الإعدادات المشتركة"),
("Mesh Map Settings", "إعدادات خرائط المجسم"),
("Check All", "تحديد الكل"),
("No Parameters", "لا توجد معلمات"),
("Bake Selected Textures ({n})", "خبز الخامات المحددة ({n})"),
("By Mesh Name", "حسب اسم المجسم"),
("Cage", "القفص"),
+5 -1
View File
@@ -1012,7 +1012,11 @@ pub const TABLE: &[(&str, &str)] = &[
("Average Normals", "Normalen mitteln"),
("BBox", "Begrenzungsrahmen"),
("BSphere", "Begrenzungskugel"),
("Bake Maps", "Maps backen"),
("Mesh Map Bakers", "Mesh-Map-Baker"),
("Common Settings", "Allgemeine Einstellungen"),
("Mesh Map Settings", "Mesh-Map-Einstellungen"),
("Check All", "Alle auswählen"),
("No Parameters", "Keine Parameter"),
("Bake Selected Textures ({n})", "Ausgewählte Texturen backen ({n})"),
("By Mesh Name", "Nach Mesh-Name"),
("Cage", "Käfig"),
+5 -1
View File
@@ -997,7 +997,11 @@ pub const TABLE: &[(&str, &str)] = &[
("Average Normals", "Promediar normales"),
("BBox", "Caja delimitadora"),
("BSphere", "Esfera delimitadora"),
("Bake Maps", "Hornear mapas"),
("Mesh Map Bakers", "Horneadores de mapas de malla"),
("Common Settings", "Ajustes comunes"),
("Mesh Map Settings", "Ajustes de mapas de malla"),
("Check All", "Marcar todo"),
("No Parameters", "Sin parámetros"),
("Bake Selected Textures ({n})", "Hornear texturas seleccionadas ({n})"),
("By Mesh Name", "Por nombre de malla"),
("Cage", "Jaula"),
+5 -1
View File
@@ -1021,7 +1021,11 @@ pub const TABLE: &[(&str, &str)] = &[
("Average Normals", "Moyenne des normales"),
("BBox", "Boîte englobante"),
("BSphere", "Sphère englobante"),
("Bake Maps", "Précalculer les cartes"),
("Mesh Map Bakers", "Précalculateurs de cartes de maillage"),
("Common Settings", "Paramètres communs"),
("Mesh Map Settings", "Paramètres des cartes de maillage"),
("Check All", "Tout cocher"),
("No Parameters", "Aucun paramètre"),
("Bake Selected Textures ({n})", "Précalculer les textures sélectionnées ({n})"),
("By Mesh Name", "Par nom de maillage"),
("Cage", "Cage"),
+5 -1
View File
@@ -1006,7 +1006,11 @@ pub const TABLE: &[(&str, &str)] = &[
("Average Normals", "Normali medie"),
("BBox", "Riquadro di delimitazione"),
("BSphere", "Sfera di delimitazione"),
("Bake Maps", "Bake delle mappe"),
("Mesh Map Bakers", "Baker delle mappe mesh"),
("Common Settings", "Impostazioni comuni"),
("Mesh Map Settings", "Impostazioni mappe mesh"),
("Check All", "Seleziona tutto"),
("No Parameters", "Nessun parametro"),
("Bake Selected Textures ({n})", "Bake texture selezionate ({n})"),
("By Mesh Name", "Per nome della mesh"),
("Cage", "Gabbia"),
+5 -1
View File
@@ -991,7 +991,11 @@ pub const TABLE: &[(&str, &str)] = &[
("Average Normals", "法線を平均化"),
("BBox", "バウンディングボックス"),
("BSphere", "バウンディングスフィア"),
("Bake Maps", "マップをベイク"),
("Mesh Map Bakers", "メッシュマップベイカー"),
("Common Settings", "共通設定"),
("Mesh Map Settings", "メッシュマップ設定"),
("Check All", "すべてチェック"),
("No Parameters", "パラメーターなし"),
("Bake Selected Textures ({n})", "選択したテクスチャをベイク ({n})"),
("By Mesh Name", "メッシュ名で"),
("Cage", "ケージ"),
+5 -1
View File
@@ -976,7 +976,11 @@ pub const TABLE: &[(&str, &str)] = &[
("Average Normals", "노멀 평균화"),
("BBox", "경계 상자"),
("BSphere", "경계 구"),
("Bake Maps", "맵 베이크"),
("Mesh Map Bakers", "메시 맵 베이커"),
("Common Settings", "공통 설정"),
("Mesh Map Settings", "메시 맵 설정"),
("Check All", "모두 선택"),
("No Parameters", "매개변수 없음"),
("Bake Selected Textures ({n})", "선택한 텍스처 베이크 ({n})"),
("By Mesh Name", "메시 이름으로"),
("Cage", "케이지"),
+5 -1
View File
@@ -994,7 +994,11 @@ pub const TABLE: &[(&str, &str)] = &[
("Average Normals", "Normais médias"),
("BBox", "Caixa delimitadora"),
("BSphere", "Esfera delimitadora"),
("Bake Maps", "Bake de mapas"),
("Mesh Map Bakers", "Bakers de mapas de malha"),
("Common Settings", "Configurações comuns"),
("Mesh Map Settings", "Configurações de mapas de malha"),
("Check All", "Marcar todos"),
("No Parameters", "Sem parâmetros"),
("Bake Selected Textures ({n})", "Fazer bake das texturas selecionadas ({n})"),
("By Mesh Name", "Por nome da malha"),
("Cage", "Gaiola"),
+5 -1
View File
@@ -922,7 +922,11 @@ pub const TABLE: &[(&str, &str)] = &[
("Average Normals", "平均法线"),
("BBox", "包围盒"),
("BSphere", "包围球"),
("Bake Maps", "烘焙贴图"),
("Mesh Map Bakers", "网格贴图烘焙器"),
("Common Settings", "通用设置"),
("Mesh Map Settings", "网格贴图设置"),
("Check All", "全选"),
("No Parameters", "无参数"),
("Bake Selected Textures ({n})", "烘焙所选纹理({n})"),
("By Mesh Name", "按网格名称"),
("Cage", "笼形"),
+3 -2
View File
@@ -61,12 +61,13 @@ pub const CATALOG: &[Item] = &[
it("Mode", "Painting", "ui.mode.paint", Some("F9")),
it("Mode", "Rendering (path traced)", "ui.mode.render", Some("F10")),
sub("Window", "Views", "Assets", "ui.view.assets", None),
sub("Window", "Views", "Bake Maps", "ui.view.bakeMaps", None),
sub("Window", "Views", "Settings", "ui.view.bakeSettings", None),
sub("Window", "Views", "Common Settings", "ui.view.bakeSettings", None),
sub("Window", "Views", "Display Settings", "ui.view.display", None),
sub("Window", "Views", "History", "ui.view.history", None),
sub("Window", "Views", "Layers", "ui.view.layers", None),
sub("Window", "Views", "Log", "ui.view.log", None),
sub("Window", "Views", "Mesh Map Bakers", "ui.view.meshMapBakers", None),
sub("Window", "Views", "Mesh Map Settings", "ui.view.bakeMaps", None),
sub("Window", "Views", "Properties", "ui.view.properties", None),
sub("Window", "Views", "Shader Settings", "ui.view.shader", None),
sub("Window", "Views", "Texture Sets", "ui.view.textureSetList", None),
+94 -1
View File
@@ -1,7 +1,7 @@
//! UI state (serde, so the control channel can read and drive it).
use serde::{Deserialize, Serialize};
use texturecraft_engine::core::Channel;
use texturecraft_engine::core::{BakedMap, Channel};
use crate::docking::Dock;
use crate::keymap::Keymap;
@@ -232,6 +232,9 @@ fn default_export_dir() -> String {
}
}
/// The bake layout's version: saved bake docks from an older one load as `Dock::for_baking`
const BAKE_LAYOUT_VERSION: u32 = 1;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct UiState {
pub mode: Mode,
@@ -243,6 +246,12 @@ pub struct UiState {
pub(crate) inactive_mode_dock: Dock,
#[serde(default)]
pub(crate) dock_is_baking: bool,
/// The bake layout version the bake dock was saved with; 0 before versions existed.
#[serde(default)]
pub(crate) bake_layout_version: u32,
/// The mesh map whose settings Mesh Map Settings shows; `None` follows the first enabled map.
#[serde(default)]
pub(crate) selected_baked_map: Option<BakedMap>,
/// Window ▸ Hide UI (Tab): only the viewport.
pub hide_ui: bool,
pub windows: Windows,
@@ -283,7 +292,10 @@ pub struct UiState {
}
impl UiState {
/// Replace an outdated or unreadable saved bake dock by the bake layout, then give the mode its dock
pub(crate) fn sync_mode_dock(&mut self) {
self.reset_outdated_bake_dock();
let baking = self.mode == Mode::Baking;
if baking != self.dock_is_baking {
std::mem::swap(&mut self.dock, &mut self.inactive_mode_dock);
@@ -291,6 +303,17 @@ impl UiState {
}
}
/// Replace a bake dock saved with an older bake layout, or one that could not be read, by the bake default
fn reset_outdated_bake_dock(&mut self) {
let bake_dock = if self.dock_is_baking { &mut self.dock } else { &mut self.inactive_mode_dock };
if self.bake_layout_version >= BAKE_LAYOUT_VERSION && !bake_dock.replaced_unreadable() {
return;
}
*bake_dock = Dock::for_baking();
self.bake_layout_version = BAKE_LAYOUT_VERSION;
}
/// Take `layout`'s panels, windows and view settings, keeping this state's dialogs, export
/// settings and recent files.
pub fn adopt_layout(&mut self, layout: UiState) {
@@ -313,6 +336,8 @@ impl Default for UiState {
dock: Dock::default(),
inactive_mode_dock: Dock::for_baking(),
dock_is_baking: false,
bake_layout_version: BAKE_LAYOUT_VERSION,
selected_baked_map: None,
hide_ui: false,
windows: Windows::default(),
uv_zoom: 1.0,
@@ -364,6 +389,74 @@ mod tests {
assert_eq!(Prefs::default().data_folder, "", "the default is no choice");
}
#[test]
fn a_bake_dock_saved_before_the_bake_layout_version_loads_the_current_bake_layout() {
let old_bake_dock = serde_json::json!({"version": 2, "layout": {"root": {"Split": {"axis": "Horizontal", "size": {"FixedFirst": 320.0},
"first": {"Tabs": {"panels": ["TextureSetList", "BakeSettings", "BakeMaps"], "active": 0}},
"second": {"Tabs": {"panels": ["Viewport"], "active": 0}}}}, "floating": []}});
for dock_is_baking in [false, true] {
let mut painting_dock = Dock::default();
painting_dock.close(crate::docking::Panel::Assets);
let (bake_field, painting_field) = if dock_is_baking { ("dock", "inactive_mode_dock") } else { ("inactive_mode_dock", "dock") };
let mut saved = serde_json::to_value(UiState::default()).unwrap();
let fields = saved.as_object_mut().unwrap();
fields.remove("bake_layout_version");
fields.insert("dock_is_baking".into(), serde_json::json!(dock_is_baking));
fields.insert("mode".into(), serde_json::to_value(if dock_is_baking { Mode::Baking } else { Mode::Painting }).unwrap());
fields.insert(bake_field.into(), old_bake_dock.clone());
fields.insert(painting_field.into(), serde_json::to_value(&painting_dock).unwrap());
let mut ui: UiState = serde_json::from_value(saved).unwrap();
let loaded_bake_dock = if dock_is_baking { &ui.dock } else { &ui.inactive_mode_dock };
assert!(!loaded_bake_dock.is_open(crate::docking::Panel::MeshMapBakers), "the old layout loads without the bakers list");
ui.sync_mode_dock();
let (bake_dock, painting) = if dock_is_baking { (&ui.dock, &ui.inactive_mode_dock) } else { (&ui.inactive_mode_dock, &ui.dock) };
assert_eq!(*bake_dock, Dock::for_baking());
assert_eq!(*painting, painting_dock, "the painting layout is kept");
let mut reloaded: UiState = serde_json::from_value(serde_json::to_value(&ui).unwrap()).unwrap();
reloaded.sync_mode_dock();
assert_eq!(reloaded, ui, "a current layout is not reset again");
}
}
/// The app's own settings store: eframe keeps `UiState` as RON text under a key
#[derive(Default)]
struct MemoryStorage(std::collections::HashMap<String, String>);
impl eframe::Storage for MemoryStorage {
fn get_string(&self, key: &str) -> Option<String> {
self.0.get(key).cloned()
}
fn set_string(&mut self, key: &str, value: String) {
self.0.insert(key.to_string(), value);
}
fn remove_string(&mut self, key: &str) {
self.0.remove(key);
}
fn flush(&mut self) {}
}
#[test]
fn the_bake_layout_survives_a_restart_whichever_mode_was_open() {
for mode in [Mode::Painting, Mode::Baking] {
let mut ui = UiState { mode, ..UiState::default() };
ui.sync_mode_dock();
let mut storage = MemoryStorage::default();
eframe::set_value(&mut storage, "ui", &ui);
let mut restarted: UiState = eframe::get_value(&storage, "ui").unwrap();
restarted.sync_mode_dock();
let bake_dock = if mode == Mode::Baking { &restarted.dock } else { &restarted.inactive_mode_dock };
assert_eq!(*bake_dock, Dock::for_baking(), "{mode:?}");
assert!(bake_dock.is_open(crate::docking::Panel::MeshMapBakers), "{mode:?}");
}
}
#[test]
fn older_saved_state_without_a_dock_loads_the_default_layout() {
let mut v = serde_json::to_value(UiState::default()).unwrap();
+83 -13
View File
@@ -1,3 +1,4 @@
use egui::Role;
use egui_kittest::Harness;
use egui_kittest::kittest::{NodeT, Queryable};
use texturecraft_engine::core::{BakeResolution, BakedMap, CageType, CurvatureMethod, HeightNormalization};
@@ -5,6 +6,7 @@ use texturecraft_ui_egui::TextureCraftApp;
use texturecraft_ui_egui::docking::Panel;
use texturecraft_ui_egui::state::Mode;
/// A bake-mode app with only `map` enabled and Mesh Map Settings in front
fn harness(map: Option<BakedMap>) -> Harness<'static, TextureCraftApp> {
let mut session = texturecraft_engine::sample_session(256, 64).unwrap();
session.doc.project.texture_sets[0].bake = Default::default();
@@ -13,11 +15,29 @@ fn harness(map: Option<BakedMap>) -> Harness<'static, TextureCraftApp> {
let mut harness = Harness::builder().with_size(egui::vec2(1600.0, 1500.0)).build_eframe(|context| TextureCraftApp::new(context, session));
harness.state_mut().ui.mode = Mode::Baking;
harness.run_steps(4);
harness.state_mut().ui.dock.focus(Panel::BakeMaps);
harness.state_mut().ui.dock.focus(Panel::MeshMapSettings);
harness.run_steps(3);
harness
}
/// The maps the first texture set will bake
fn enabled_maps(harness: &Harness<'_, TextureCraftApp>) -> Vec<BakedMap> {
harness.state().session.doc.project.texture_sets[0].bake.maps.enabled().collect()
}
/// Click a map's row in Mesh Map Bakers, which shows its settings
fn select_map(harness: &mut Harness<'_, TextureCraftApp>, name: &str) {
harness.get_by_role_and_label(Role::Button, name).click();
harness.run_steps(3);
}
/// Click a checkbox in Mesh Map Bakers: a map's row or Check All
fn click_checkbox(harness: &mut Harness<'_, TextureCraftApp>, name: &str) {
harness.get_by_role_and_label(Role::CheckBox, name).click();
harness.run_steps(3);
}
/// Scroll the widget labelled `label` into view and click it
fn click(harness: &mut Harness<'_, TextureCraftApp>, label: &str) {
harness.get_by_label(label).scroll_to_me();
harness.run_steps(3);
@@ -29,8 +49,8 @@ fn click(harness: &mut Harness<'_, TextureCraftApp>, label: &str) {
fn output_axes_unlock_independently_and_relock_to_width() {
let mut harness = harness(None);
harness.get_by_label("Texture Sets");
harness.get_by_label("Bake Maps");
harness.state_mut().ui.dock.focus(Panel::BakeSettings);
harness.get_by_label("Mesh Map Settings");
harness.state_mut().ui.dock.focus(Panel::CommonSettings);
harness.run_steps(3);
let width = harness.state().session.doc.project.texture_sets[0].bake.common.resolution.pixels().to_string();
assert!(harness.get_all_by_value(&width).nth(1).unwrap().accesskit_node().is_disabled());
@@ -47,36 +67,86 @@ fn output_axes_unlock_independently_and_relock_to_width() {
click(&mut harness, "Lock Output Size");
assert_eq!(harness.state().session.doc.project.texture_sets[0].bake.common.output_size(), (128, 128));
assert!(harness.get_all_by_value("128").nth(1).unwrap().accesskit_node().is_disabled());
harness.state_mut().ui.dock.focus(Panel::BakeMaps);
harness.state_mut().ui.dock.focus(Panel::MeshMapSettings);
harness.run_steps(3);
harness.state_mut().ui.dock.focus(Panel::BakeSettings);
harness.state_mut().ui.dock.focus(Panel::CommonSettings);
harness.run_steps(3);
assert!(harness.get_all_by_value("128").nth(1).unwrap().accesskit_node().is_disabled());
harness.state_mut().ui.mode = Mode::Painting;
harness.run_steps(3);
assert!(!harness.state().ui.dock.is_open(Panel::BakeSettings));
assert!(!harness.state().ui.dock.is_open(Panel::CommonSettings));
assert!(harness.state().ui.dock.is_open(Panel::Assets));
}
#[test]
fn height_controls_follow_enablement_and_manual_normalization() {
fn height_controls_follow_manual_normalization_and_the_row_checkbox_enables_height() {
let mut harness = harness(None);
assert!(harness.query_by_label("Normalization").is_none());
click(&mut harness, "Height");
assert!(harness.state().session.doc.project.texture_sets[0].bake.maps.height.is_enabled);
select_map(&mut harness, "Height");
assert!(!harness.state().session.doc.project.texture_sets[0].bake.maps.height.is_enabled, "selecting is not enabling");
assert!(harness.query_by_label("Scaling Divisor").is_none());
click(&mut harness, "Normalization");
click(&mut harness, "Manual");
harness.get_by_label("Scaling Divisor");
assert_eq!(harness.state().session.doc.project.texture_sets[0].bake.maps.height.parameters.normalization, HeightNormalization::Manual);
click(&mut harness, "Restore Defaults");
click_checkbox(&mut harness, "Height");
assert!(harness.state().session.doc.project.texture_sets[0].bake.maps.height.is_enabled);
click(&mut harness, "Restore Defaults");
assert!(harness.state().session.doc.project.texture_sets[0].bake.maps.height.is_enabled, "Restore Defaults keeps the map enabled");
assert_eq!(harness.state().session.doc.project.texture_sets[0].bake.maps.height.parameters.normalization, HeightNormalization::RelativeToLowMesh);
assert!(harness.query_by_label("Scaling Divisor").is_none());
click(&mut harness, "Height");
assert!(harness.query_by_label("Normalization").is_none());
click_checkbox(&mut harness, "Height");
assert!(!harness.state().session.doc.project.texture_sets[0].bake.maps.height.is_enabled);
}
#[test]
fn clicking_a_row_shows_that_maps_settings_without_changing_what_bakes() {
let mut harness = harness(Some(BakedMap::Curvature));
harness.state_mut().ui.dock.focus(Panel::CommonSettings);
harness.run_steps(3);
let before = enabled_maps(&harness);
select_map(&mut harness, "Ambient Occlusion");
assert!(harness.state().ui.dock.is_visible(Panel::MeshMapSettings), "selecting a map fronts its settings");
harness.get_by_label("Attenuation");
assert!(harness.query_by_label("Method").is_none());
select_map(&mut harness, "Opacity");
harness.get_by_label("No Parameters");
assert!(harness.query_by_label("Attenuation").is_none());
assert_eq!(enabled_maps(&harness), before);
click(&mut harness, &format!("{} Common Settings", egui_phosphor::regular::GEAR));
assert!(harness.state().ui.dock.is_visible(Panel::CommonSettings));
assert_eq!(enabled_maps(&harness), before);
}
#[test]
fn check_all_enables_every_map_then_disables_them_all() {
let mut harness = harness(Some(BakedMap::Curvature));
click_checkbox(&mut harness, "Check All");
assert_eq!(enabled_maps(&harness), BakedMap::ALL);
click_checkbox(&mut harness, "Check All");
assert!(enabled_maps(&harness).is_empty());
}
#[test]
fn the_breadcrumb_switches_the_shown_map() {
let mut harness = harness(Some(BakedMap::Curvature));
harness.get_by_label("Details");
assert_eq!(harness.get_all_by_role_and_label(Role::Button, "Position").count(), 1, "only the list row before the menu opens");
let dropdowns: Vec<_> = harness.get_all_by_label(egui_phosphor::regular::CARET_RIGHT).collect();
let [_texture_set_dropdown, map_dropdown] = dropdowns.as_slice() else { panic!("the breadcrumb has a texture set and a map dropdown") };
map_dropdown.click();
harness.run_steps(3);
assert_eq!(harness.get_all_by_role_and_label(Role::Button, "Position").count(), 2, "the map menu lists Position");
// The menu draws its items after the list rows
harness.get_all_by_role_and_label(Role::Button, "Position").last().unwrap().click();
harness.run_steps(3);
harness.get_by_label("Normalization Scale");
assert!(harness.query_by_label("Details").is_none());
assert_eq!(enabled_maps(&harness), [BakedMap::Curvature]);
}
#[test]
@@ -102,7 +172,7 @@ fn curvature_controls_follow_the_method_and_notes_visibility_rules() {
#[test]
fn cage_and_skew_controls_require_a_high_poly_and_follow_cage_type() {
let mut harness = harness(None);
harness.state_mut().ui.dock.focus(Panel::BakeSettings);
harness.state_mut().ui.dock.focus(Panel::CommonSettings);
harness.run_steps(3);
assert!(harness.query_by_label("Cage Type").is_none());
assert!(harness.query_by_label("Skew Correction").is_none());
+3 -2
View File
@@ -1,11 +1,12 @@
//! Bake mode: with the skew brush on, dragging in the 2D view paints the skew map, and the
//! brush controls are in the Bake panel.
//! brush controls are in Common Settings.
use egui_kittest::Harness;
use egui_kittest::kittest::Queryable;
use texturecraft_ui_egui::TextureCraftApp;
use texturecraft_ui_egui::state::{Mode, ViewLayout};
/// A bake-mode app with a high poly, the 2D view, and Common Settings in front
fn harness() -> Harness<'static, TextureCraftApp> {
let mut session = texturecraft_engine::sample_session(256, 64).unwrap();
session.add_high_poly_bytes("High.obj", b"v 0 0 0\nv 1 0 0\nv 0 1 0\nf 1 2 3\n".to_vec()).unwrap();
@@ -13,7 +14,7 @@ fn harness() -> Harness<'static, TextureCraftApp> {
h.state_mut().ui.mode = Mode::Baking;
h.state_mut().ui.layout = ViewLayout::Only2D;
h.run_steps(4);
h.state_mut().ui.dock.focus(texturecraft_ui_egui::docking::Panel::BakeSettings);
h.state_mut().ui.dock.focus(texturecraft_ui_egui::docking::Panel::CommonSettings);
h.run_steps(3);
h
}
+11 -9
View File
@@ -14,6 +14,12 @@ use texturecraft_ui_egui::state::Mode;
use texturecraft_ui_egui::theme::Brightness;
use texturecraft_ui_egui::titlebar::TitleBar;
/// Click a map's row in Mesh Map Bakers, which shows its settings
fn select_map(harness: &mut Harness<'_, TextureCraftApp>, name: &str) {
harness.get_by_role_and_label(egui::Role::Button, name).click();
harness.run_steps(3);
}
fn save(h: &mut Harness<'_, TextureCraftApp>, dir: &Path, name: &str) {
h.run_steps(6);
let img = h.render().unwrap_or_else(|e| panic!("{name}: {e}"));
@@ -58,18 +64,16 @@ fn window_snapshots() {
}
harness.state_mut().ui.mode = Mode::Baking;
save(&mut harness, &output_dir, "mode-bake");
harness.state_mut().ui.dock.focus(Panel::BakeMaps);
harness.run_steps(3);
harness.get_by_label("Ambient Occlusion").scroll_to_me();
select_map(&mut harness, "Ambient Occlusion");
save(&mut harness, &output_dir, "mode-bake-maps");
harness.state_mut().ui.prefs.brightness = Brightness::Light;
save(&mut harness, &output_dir, "mode-bake-maps-light");
harness.state_mut().ui.prefs.brightness = Brightness::MediumDark;
harness.get_by_label("Opacity").scroll_to_me();
select_map(&mut harness, "Opacity");
save(&mut harness, &output_dir, "mode-bake-unchecked");
harness.state_mut().ui.dock.focus(Panel::TextureSetList);
save(&mut harness, &output_dir, "bake-texture-sets");
harness.state_mut().ui.dock.focus(Panel::BakeSettings);
harness.state_mut().ui.dock.focus(Panel::CommonSettings);
save(&mut harness, &output_dir, "bake-settings");
harness.state_mut().session.add_high_poly_bytes("High Poly.obj", b"v 0 0 0\nv 1 0 0\nv 0 1 0\nf 1 2 3\n".to_vec()).unwrap();
save(&mut harness, &output_dir, "bake-settings-high-poly");
@@ -90,11 +94,9 @@ fn window_snapshots() {
settings.maps.height.parameters.normalization = HeightNormalization::Manual;
settings.maps.height.parameters.scaling_divisor = 100.0;
}
harness.state_mut().ui.dock.focus(Panel::BakeMaps);
harness.run_steps(3);
harness.get_by_label("Curvature").scroll_to_me();
select_map(&mut harness, "Curvature");
save(&mut harness, &output_dir, "bake-curvature-mesh");
harness.get_by_label("Scaling Divisor").scroll_to_me();
select_map(&mut harness, "Height");
save(&mut harness, &output_dir, "bake-height-manual");
harness.state_mut().session.bake_meshes.high.clear();
harness.state_mut().ui.mode = Mode::Painting;
+5 -2
View File
@@ -2,7 +2,7 @@
Generated by `TC_UPDATE_PARITY=1 cargo test -p texturecraft-ui-egui parity`. Each row is a menu item of the target menu layout with TextureCraft's command id; **live** means the id is implemented. Feature parity beyond menus is tracked in [`ROADMAP.md`](../ROADMAP.md).
**55 of 55 menu items live (100%).**
**58 of 58 menu items live (100%).**
## File
@@ -46,13 +46,16 @@ Generated by `TC_UPDATE_PARITY=1 cargo test -p texturecraft-ui-egui parity`. Eac
| Item | Id | Shortcut | Status |
|---|---|---|---|
| Views ▸ Assets | `ui.view.assets` | | live |
| Views ▸ Common Settings | `ui.view.bakeSettings` | | live |
| Views ▸ Display Settings | `ui.view.display` | | live |
| Views ▸ History | `ui.view.history` | | live |
| Views ▸ Layers | `ui.view.layers` | | live |
| Views ▸ Log | `ui.view.log` | | live |
| Views ▸ Mesh Map Bakers | `ui.view.meshMapBakers` | | live |
| Views ▸ Mesh Map Settings | `ui.view.bakeMaps` | | live |
| Views ▸ Properties | `ui.view.properties` | | live |
| Views ▸ Shader Settings | `ui.view.shader` | | live |
| Views ▸ Texture Set List | `ui.view.textureSetList` | | live |
| Views ▸ Texture Sets | `ui.view.textureSetList` | | live |
| Views ▸ Texture Set Settings | `ui.view.textureSetSettings` | | live |
| Save UI Layout ▸ Save current layout... | `ui.layout.save` | | live |
| Load UI Layout | `ui.layout.load` | | live |