Skip to content

Commit abb707e

Browse files
committed
List only the installed environments, start new projects with Three-Point Studio and wrap environment names
With the starter folder installed, the environment picker and the Assets panel list its environments instead of the six drawn ones; display.set still takes the drawn names, so older projects keep theirs. project.new, project.sample and file.new start with Three-Point Studio when its file is there. Environment tile names wrap onto two lines, so Studio Small 08 and Studio Small 03 are told apart.
1 parent e11f222 commit abb707e

17 files changed

Lines changed: 186 additions & 40 deletions

File tree

‎apps/texturecraft/src/main.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,11 @@ fn main() {
397397
prefs.apply_resource_limits();
398398
let mut session = initial_session(&args);
399399
session.starter_dir = texturecraft_engine::starter_environment_loader::starter_assets_dir();
400+
401+
// A mesh given on the command line and a control run's project are new projects
402+
if session.project_open && session.path.is_none() {
403+
session.start_with_starter_environment();
404+
}
400405
if let Some(warning) = session.load_starter_environment() {
401406
session.log.warn("Project", warning);
402407
}

‎crates/automation/src/headless.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ impl Headless {
203203
let stem = Path::new(path).file_stem().and_then(|s| s.to_str()).unwrap_or("Untitled");
204204
let mut next = Session::from_mesh_bytes(&f.name, &f.bytes, resolution.unwrap_or(2048), name.unwrap_or(stem))?;
205205
next.log.warnings("Importer", f.warnings);
206-
Ok(self.replace(next))
206+
self.session.switch_to(next);
207+
self.session.start_with_starter_environment();
208+
Ok(self.inspect())
207209
}
208210

209211
/// Mesh file `path` with the files it references next to it (a `.gltf`'s buffers and images, a

‎crates/core/src/starter_environment.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const fn toward(elevation_deg: f32, azimuth_deg: f32, scale: f32) -> StarterKeyL
3131
StarterKeyLight::Toward { elevation_deg, azimuth_deg, scale }
3232
}
3333

34+
/// The environment a new project starts with when its file is installed (else the drawn default stays)
35+
pub const NEW_PROJECT_ENVIRONMENT: &str = "Three-Point Studio";
36+
3437
/// Starter environments, in menu order (after the drawn ones): photographed maps, then our own studio rigs at one brightness
3538
pub const STARTER_ENVIRONMENTS: [StarterEnvironment; 20] = [
3639
StarterEnvironment {

‎crates/engine/src/file_cmds.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ fn new_from_mesh(session: &mut Session, params: &Value) -> Result<Value> {
783783
}
784784

785785
session.switch_to(next);
786+
session.start_with_starter_environment();
786787

787788
Ok(crate::inspect::session(session))
788789
}
@@ -793,6 +794,11 @@ fn open(s: &mut Session, p: &Value) -> Result<Value> {
793794
let next = native::open_path(path)?;
794795
s.switch_to(next);
795796

797+
// A mesh file opens as a new project, without a saved environment
798+
if s.path.is_none() {
799+
s.start_with_starter_environment();
800+
}
801+
796802
let warning = s.load_starter_environment();
797803
let mut reply = crate::inspect::session(s);
798804
if let Some(warning) = warning {

‎crates/engine/src/project_cmds.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ fn new(s: &mut Session, p: &Value) -> Result<Value> {
6161
next.apply_template(t);
6262
}
6363
s.switch_to(next);
64+
s.start_with_starter_environment();
6465
Ok(crate::inspect::session(s))
6566
}
6667

@@ -132,6 +133,7 @@ fn sample(s: &mut Session, _: &Value) -> Result<Value> {
132133
let mut next = sample_session(2048, 1024)?;
133134
next.log.performance(format!("Sample project setup and mesh-map baking completed in {} ms", started.elapsed().as_millis()));
134135
s.switch_to(next);
136+
s.start_with_starter_environment();
135137
Ok(crate::inspect::session(s))
136138
}
137139

‎crates/engine/src/starter_environment_loader.rs‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::sync::Arc;
55

66
use texturecraft_compose::ImageRes;
77
use texturecraft_compose::starter_registry::StarterRegistry;
8-
use texturecraft_core::starter_environment::StarterEnvironment;
8+
use texturecraft_core::starter_environment::{NEW_PROJECT_ENVIRONMENT, StarterEnvironment};
99

1010
use crate::Session;
1111

@@ -85,6 +85,20 @@ impl Session {
8585
pub fn load_starter_environment(&self) -> Option<String> {
8686
ensure_loaded(StarterRegistry::global(), self.starter_dir.as_deref(), &self.doc.project.display.environment)
8787
}
88+
89+
/// A new project starts lit by [`NEW_PROJECT_ENVIRONMENT`] when the starter folder has it, else keeps the drawn default
90+
pub fn start_with_starter_environment(&mut self) {
91+
let Some(entry) = StarterEnvironment::find(NEW_PROJECT_ENVIRONMENT) else { return };
92+
if !self.starter_dir.as_deref().is_some_and(|dir| environment_path(dir, entry).is_file()) {
93+
return;
94+
}
95+
96+
let drawn = std::mem::replace(&mut self.doc.project.display.environment, NEW_PROJECT_ENVIRONMENT.to_owned());
97+
if let Some(warning) = self.load_starter_environment() {
98+
self.log.warn("Project", &warning);
99+
self.doc.project.display.environment = drawn;
100+
}
101+
}
88102
}
89103

90104
#[cfg(test)]
@@ -131,4 +145,28 @@ mod tests {
131145
assert!(registry.get(entry.name).is_none());
132146
assert!(ensure_loaded(&registry, None, "Studio Soft").is_none());
133147
}
148+
149+
/// A new project (or an opened mesh) starts with the installed starter environment; without the starter folder it keeps the drawn default
150+
#[test]
151+
fn a_new_project_starts_with_the_installed_starter_environment() {
152+
let dir = tempfile::tempdir().unwrap();
153+
let mut without_folder = Session::closed().unwrap();
154+
crate::execute(&mut without_folder, "project.new", &serde_json::Value::Null).unwrap();
155+
let drawn_default = without_folder.doc.project.display.environment.clone();
156+
157+
let mut session = Session::closed().unwrap();
158+
session.starter_dir = Some(dir.path().to_path_buf());
159+
write_hdr(dir.path(), StarterEnvironment::find(NEW_PROJECT_ENVIRONMENT).unwrap(), 1.0);
160+
crate::execute(&mut session, "project.new", &serde_json::Value::Null).unwrap();
161+
162+
assert_eq!(session.doc.project.display.environment, NEW_PROJECT_ENVIRONMENT);
163+
assert_ne!(drawn_default, NEW_PROJECT_ENVIRONMENT);
164+
assert!(!session.modified, "the starting environment is not an edit");
165+
166+
// A mesh file opened on its own is a new project too
167+
let mesh = dir.path().join("triangle.obj");
168+
std::fs::write(&mesh, "v 0 0 0\nv 1 0 0\nv 0 1 0\nvt 0 0\nvt 1 0\nvt 0 1\nf 1/1 2/2 3/3\n").unwrap();
169+
crate::execute(&mut session, "file.open", &serde_json::json!({ "path": mesh })).unwrap();
170+
assert_eq!(session.doc.project.display.environment, NEW_PROJECT_ENVIRONMENT);
171+
}
134172
}

‎crates/engine/src/view_cmds.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ mod tests {
676676
assert_eq!((d.env_alignment, d.shadow_mode), (EnvAlignment::Camera, ShadowMode::Intensive));
677677
}
678678

679-
// Starter environments registered in the process-wide registry by this binary's tests: Satara Night only (Venice Sunset must stay unloaded)
679+
// Starter environments registered in the process-wide registry by this binary's tests: Satara Night and Three-Point Studio only (Venice Sunset must stay unloaded)
680680

681681
/// A starter environment is a valid pick: its file is read from the session's starter folder into the image every renderer resolves
682682
#[test]

‎crates/ui-egui/src/environment_picker.rs‎

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use egui::{Sense, Stroke, Ui};
44
use egui_phosphor::regular as ic;
55
use texturecraft_engine::core::project::{DisplaySettings, ENV_RESOURCE_PREFIX};
66
use texturecraft_engine::core::starter_environment::StarterEnvironment;
7-
use texturecraft_render::ibl::ENVIRONMENTS;
87

98
use crate::TextureCraftApp;
109
use crate::i18n::tr;
@@ -80,56 +79,53 @@ fn grid(app: &mut TextureCraftApp, ui: &mut Ui, display: &mut DisplaySettings, p
8079
let starter_dir = app.session.starter_dir.clone();
8180
let starters = app.starter_environments.in_folder(starter_dir.as_deref());
8281
let mut picked = None;
82+
8383
egui::ScrollArea::vertical().max_height(PICKER_HEIGHT).show(ui, |ui| {
8484
ui.set_min_height(PICKER_HEIGHT);
8585
crate::shelf::tiles(ui, |ui| {
86-
for name in ENVIRONMENTS.into_iter().filter(|name| query_field::matches(&words, name)) {
87-
let response =
88-
crate::shelf::tile(ui, &mut app.thumbs, |ui, thumbs| thumbs.environment(ui.ctx(), name), || ShelfPreview::Environment(name), name, None);
89-
if display.environment == name {
90-
ui.painter().rect_stroke(response.rect, TILE_ROUNDING, Stroke::new(CURRENT_OUTLINE_WIDTH, tokens.accent), egui::StrokeKind::Inside);
91-
}
92-
if response.clicked() {
86+
for name in crate::starter_environments::drawn_listed(&starters).iter().copied().filter(|name| query_field::matches(&words, name)) {
87+
let response = crate::shelf::environment_tile(
88+
ui,
89+
&mut app.thumbs,
90+
|ui, thumbs| thumbs.environment(ui.ctx(), name),
91+
|| ShelfPreview::Environment(name),
92+
name,
93+
);
94+
if is_picked(ui, &response, display.environment == name, &tokens) {
9395
picked = Some(name.to_owned());
9496
}
9597
}
98+
9699
// Installed starter environments exist only with a starter folder
97100
for (entry, dir) in starters.iter().filter_map(|entry| Some((entry, starter_dir.as_deref()?))) {
98101
let label = tr(entry.name);
99102
if !query_field::matches(&words, entry.name) && !query_field::matches(&words, label) {
100103
continue;
101104
}
102105

103-
let response = crate::shelf::tile(
106+
let response = crate::shelf::environment_tile(
104107
ui,
105108
&mut app.thumbs,
106109
|ui, thumbs| thumbs.starter_environment(ui.ctx(), entry, dir),
107110
|| ShelfPreview::StarterEnvironment { entry, dir: dir.to_path_buf() },
108111
label,
109-
None,
110112
);
111-
if display.environment == entry.name {
112-
ui.painter().rect_stroke(response.rect, TILE_ROUNDING, Stroke::new(CURRENT_OUTLINE_WIDTH, tokens.accent), egui::StrokeKind::Inside);
113-
}
114-
if response.clicked() {
113+
if is_picked(ui, &response, display.environment == entry.name, &tokens) {
115114
picked = Some(entry.name.to_owned());
116115
}
117116
}
117+
118118
for name in hdrs.iter().filter(|name| query_field::matches(&words, name)) {
119119
let Some(image) = app.session.images.get(name).cloned() else { continue };
120-
let response = crate::shelf::tile(
120+
let response = crate::shelf::environment_tile(
121121
ui,
122122
&mut app.thumbs,
123123
|ui, thumbs| Some(thumbs.image(ui.ctx(), name, &image)),
124124
|| ShelfPreview::Image(name.clone(), image.clone()),
125125
name,
126-
None,
127126
);
128127
let key = format!("{ENV_RESOURCE_PREFIX}{name}");
129-
if display.environment == key {
130-
ui.painter().rect_stroke(response.rect, TILE_ROUNDING, Stroke::new(CURRENT_OUTLINE_WIDTH, tokens.accent), egui::StrokeKind::Inside);
131-
}
132-
if response.clicked() {
128+
if is_picked(ui, &response, display.environment == key, &tokens) {
133129
picked = Some(key);
134130
}
135131
}
@@ -149,3 +145,12 @@ fn grid(app: &mut TextureCraftApp, ui: &mut Ui, display: &mut DisplaySettings, p
149145
}
150146
import
151147
}
148+
149+
/// Outlines the tile of the environment in use; true when the tile was clicked
150+
fn is_picked(ui: &Ui, response: &egui::Response, current: bool, tokens: &Tokens) -> bool {
151+
if current {
152+
ui.painter().rect_stroke(response.rect, TILE_ROUNDING, Stroke::new(CURRENT_OUTLINE_WIDTH, tokens.accent), egui::StrokeKind::Inside);
153+
}
154+
155+
response.clicked()
156+
}

‎crates/ui-egui/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ mod texture_set_settings;
210210
pub mod theme;
211211
pub mod thumbs;
212212
mod tile_edits;
213+
mod tile_label;
213214
mod tile_picture;
214215
pub mod titlebar;
215216
pub mod toast_action;

‎crates/ui-egui/src/shelf.rs‎

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::shelf_preview::ShelfPreview;
1616
use crate::shelf_view::ShelfView;
1717
use crate::theme::Tokens;
1818
use crate::thumbs::Thumbs;
19+
use crate::tile_label::TileLabel;
1920
use crate::widgets::dnd_release;
2021

2122
/// The gap between tiles in points (their sizes are [`ShelfView`]'s)
@@ -546,7 +547,7 @@ fn entry_tile(app: &mut TextureCraftApp, ui: &mut Ui, ctx: &egui::Context, entry
546547
ShelfEntry::SavedBrush { path: Some(path), .. } => Some(thumbs.saved_brush_preview(path, &session.images)),
547548
_ => entry.preview(session),
548549
},
549-
entry.label(),
550+
entry.tile_label(),
550551
asset.as_ref(),
551552
view,
552553
);
@@ -585,22 +586,39 @@ pub(crate) fn tile(
585586
label: &str,
586587
drag: Option<&Asset>,
587588
) -> egui::Response {
588-
tile_in_view(ui, thumbs, texture, |_| Some(preview()), label, drag, ShelfView::Medium)
589+
tile_in_view(ui, thumbs, texture, |_| Some(preview()), TileLabel::one_line(label), drag, ShelfView::Medium)
589590
}
590591

591-
/// [`tile`] at `view`'s size: a grid tile with the name under the thumbnail, or a list row with it beside; `preview` runs on hover
592+
/// [`tile`] for an environment, whose name may wrap onto two lines ("Studio Small 08" and "Studio Small 03" differ at the end)
593+
pub(crate) fn environment_tile(
594+
ui: &mut Ui,
595+
thumbs: &mut Thumbs,
596+
texture: impl FnOnce(&Ui, &mut Thumbs) -> Option<egui::TextureHandle>,
597+
preview: impl FnOnce() -> ShelfPreview,
598+
label: &str,
599+
) -> egui::Response {
600+
tile_in_view(ui, thumbs, texture, |_| Some(preview()), TileLabel::two_lines(label), None, ShelfView::Medium)
601+
}
602+
603+
/// [`tile`] at `view`'s size: a grid tile with the name under the thumbnail (taller per extra line), or a list row with it beside
592604
fn tile_in_view(
593605
ui: &mut Ui,
594606
thumbs: &mut Thumbs,
595607
texture: impl FnOnce(&Ui, &mut Thumbs) -> Option<egui::TextureHandle>,
596608
preview: impl FnOnce(&mut Thumbs) -> Option<ShelfPreview>,
597-
label: &str,
609+
label: TileLabel<'_>,
598610
drag: Option<&Asset>,
599611
view: ShelfView,
600612
) -> egui::Response {
601613
let tokens = Tokens::get(ui.ctx());
602614
let sense = if drag.is_some() { Sense::click_and_drag() } else { Sense::click() };
603-
let (rect, response) = ui.allocate_exact_size(view.tile_size(ui.available_width()), sense);
615+
let TileLabel { text: label, lines } = label;
616+
let label_lines = if view.name_beside() { 1 } else { lines.max(1) };
617+
let extra_lines = label_lines - 1;
618+
let extra_height =
619+
if extra_lines > 0 { ui.ctx().fonts_mut(|fonts| fonts.row_height(&egui::FontId::proportional(LABEL_FONT_SIZE))) * extra_lines as f32 } else { 0.0 };
620+
let size = view.tile_size(ui.available_width()) + egui::vec2(0.0, extra_height);
621+
let (rect, response) = ui.allocate_exact_size(size, sense);
604622
response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, label));
605623
let texture = if ui.is_rect_visible(rect) { texture(ui, thumbs) } else { None };
606624
if let Some(asset) = drag
@@ -618,11 +636,13 @@ fn tile_in_view(
618636
thumbnail(painter, texture.as_ref(), image_rect, &tokens);
619637
if view.name_beside() {
620638
let left = image_rect.right() + crate::shelf_view::LIST_NAME_GAP;
621-
let galley = painter.layout_job(one_line(label, rect.right() - left - LABEL_MARGIN, tokens.text));
639+
let galley = painter.layout_job(label_job(label, rect.right() - left - LABEL_MARGIN, 1, tokens.text));
622640
painter.galley(egui::pos2(left, rect.center().y - galley.size().y * 0.5), galley, tokens.text);
623641
} else {
624-
let galley = painter.layout_job(one_line(label, rect.width() - LABEL_MARGIN, tokens.text));
625-
painter.galley(egui::pos2(rect.center().x - galley.size().x * 0.5, image_rect.bottom() + LABEL_GAP), galley, tokens.text);
642+
let galley = painter.layout_job(label_job(label, rect.width() - LABEL_MARGIN, label_lines, tokens.text));
643+
// A centred job's rows sit around x = 0, so its rect may start left of it
644+
let left = rect.center().x - galley.size().x * 0.5 - galley.rect.min.x;
645+
painter.galley(egui::pos2(left, image_rect.bottom() + LABEL_GAP), galley, tokens.text);
626646
}
627647

628648
let big = if response.hovered() { preview(thumbs).and_then(|preview| big_preview(ui, thumbs, || preview)) } else { None };
@@ -637,10 +657,13 @@ fn randomness_badge(painter: &egui::Painter, thumbnail: egui::Rect) {
637657
}
638658
}
639659

640-
/// A tile label on one line, cut with "…" past `width` points (the hover popup shows the whole name)
641-
fn one_line(label: &str, width: f32, color: Color32) -> egui::text::LayoutJob {
660+
/// A tile label on up to `lines` lines (centred when more than one) of `width` points, the last cut with "…" (the hover popup shows the whole name)
661+
fn label_job(label: &str, width: f32, lines: usize, color: Color32) -> egui::text::LayoutJob {
642662
let mut job = egui::text::LayoutJob::single_section(label.to_string(), egui::TextFormat::simple(egui::FontId::proportional(LABEL_FONT_SIZE), color));
643-
job.wrap = egui::text::TextWrapping::truncate_at_width(width);
663+
job.wrap = egui::text::TextWrapping { max_rows: lines, ..egui::text::TextWrapping::truncate_at_width(width) };
664+
if lines > 1 {
665+
job.halign = egui::Align::Center;
666+
}
644667
job
645668
}
646669

@@ -788,7 +811,7 @@ mod tests {
788811
let width = 60.0;
789812
let mut laid_out = None;
790813
let mut output = egui::Context::default().run_ui(egui::RawInput::default(), |ui| {
791-
laid_out = Some(ui.painter().layout_job(one_line("Steel Painted Rust Leaks Extra", width, Color32::WHITE)));
814+
laid_out = Some(ui.painter().layout_job(label_job("Steel Painted Rust Leaks Extra", width, 1, Color32::WHITE)));
792815
});
793816

794817
// The font atlas upload is not under test
@@ -797,9 +820,30 @@ mod tests {
797820

798821
assert_eq!(galley.rows.len(), 1);
799822
assert!(galley.size().x <= width);
823+
assert!(galley.rect.min.x >= 0.0, "a one-line label starts where it is painted, as list rows expect");
800824
assert_eq!(galley.rows[0].glyphs.last().map(|glyph| glyph.chr), Some('…'));
801825
}
802826

827+
/// Environment names that differ only at the end ("Studio Small 08", "Studio Small 03") keep that end on a second line
828+
#[test]
829+
fn an_environment_tile_label_wraps_instead_of_cutting_its_end() {
830+
let width = ShelfView::Medium.tile_size(0.0).x - LABEL_MARGIN;
831+
let mut laid_out = None;
832+
let mut output = egui::Context::default().run_ui(egui::RawInput::default(), |ui| {
833+
let label = TileLabel::two_lines("Studio Small 08");
834+
laid_out = Some(ui.painter().layout_job(label_job(label.text, width, label.lines, Color32::WHITE)));
835+
});
836+
837+
// The font atlas upload is not under test
838+
output.textures_delta.clear();
839+
let galley = laid_out.unwrap();
840+
841+
assert!(galley.rows.len() > 1);
842+
assert!(galley.size().x <= width);
843+
let shown: String = galley.rows.iter().flat_map(|row| row.glyphs.iter().map(|glyph| glyph.chr)).collect();
844+
assert!(shown.ends_with("08"), "{shown}");
845+
}
846+
803847
/// Saved smart materials in a location added in Settings > Libraries are listed with the library folder's
804848
#[cfg(not(target_arch = "wasm32"))]
805849
#[test]

0 commit comments

Comments
 (0)