mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-28 17:19:24 +01:00
Take a set's shared bake fingerprints once for all its maps, once per Mesh Map Bakers frame
This commit is contained in:
1 parent
67c8ec6470
commit
6399d00822
2 files changed
+20
-13
No files matched your search
@@ -9,6 +9,12 @@ use crate::{Result, Session};
|
||||
impl Session {
|
||||
/// What a bake of `map` on texture set `texture_set` would read now
|
||||
pub fn bake_source(&self, texture_set: usize, map: BakedMap) -> Result<BakeSource> {
|
||||
let map_settings = self.doc.project.texture_set(texture_set)?.map_settings_fingerprint(map);
|
||||
Ok(BakeSource { map_settings, ..self.set_bake_source(texture_set)? })
|
||||
}
|
||||
|
||||
/// What a bake of any map of texture set `texture_set` would read now, without the map's own settings (0)
|
||||
fn set_bake_source(&self, texture_set: usize) -> Result<BakeSource> {
|
||||
let set = self.doc.project.texture_set(texture_set)?;
|
||||
let from_high = !set.bake.high_poly.use_low_as_high && !self.doc.bake_meshes.high.is_empty();
|
||||
let high_poly = match from_high {
|
||||
@@ -18,13 +24,7 @@ impl Session {
|
||||
let reads_cage = from_high && set.bake.cage.kind == CageType::CustomFile;
|
||||
let cage = self.doc.bake_meshes.cage.as_ref().filter(|_| reads_cage).map_or(0, |cage| cage.fingerprint);
|
||||
|
||||
Ok(BakeSource {
|
||||
low_poly: self.low_poly_fingerprint(),
|
||||
high_poly,
|
||||
cage,
|
||||
settings: set.bake_settings_fingerprint(),
|
||||
map_settings: set.map_settings_fingerprint(map),
|
||||
})
|
||||
Ok(BakeSource { low_poly: self.low_poly_fingerprint(), high_poly, cage, settings: set.bake_settings_fingerprint(), map_settings: 0 })
|
||||
}
|
||||
|
||||
/// What changed since `map` of texture set `texture_set` was baked; empty when up to date, not baked or without a record
|
||||
@@ -37,7 +37,13 @@ impl Session {
|
||||
|
||||
/// The out-of-date maps of texture set `texture_set`, each with what changed
|
||||
pub fn out_of_date_maps(&self, texture_set: usize) -> BTreeMap<BakedMap, Vec<BakeChange>> {
|
||||
BakedMap::ALL.into_iter().map(|map| (map, self.bake_changes(texture_set, map))).filter(|(_, changes)| !changes.is_empty()).collect()
|
||||
let Ok(set) = self.doc.project.texture_set(texture_set) else { return BTreeMap::new() };
|
||||
let mut records = set.bake_sources.iter().filter(|(map, _)| set.baked.contains(map)).peekable();
|
||||
|
||||
// The fingerprints every map of the set shares are taken once
|
||||
let Some(shared) = records.peek().and_then(|_| self.set_bake_source(texture_set).ok()) else { return BTreeMap::new() };
|
||||
let changes = records.map(|(map, record)| (*map, record.changes(&BakeSource { map_settings: set.map_settings_fingerprint(*map), ..shared })));
|
||||
changes.filter(|(_, changes)| !changes.is_empty()).collect()
|
||||
}
|
||||
|
||||
/// Fingerprint of the low poly's own geometry (computed once per loaded mesh)
|
||||
|
||||
@@ -94,8 +94,10 @@ pub(super) fn show(app: &mut TextureCraftApp, ui: &mut Ui, settings: &mut BakeSe
|
||||
let mut check_drag: Option<bool> = ui.data(|data| data.get_temp(check_drag_id));
|
||||
let drag_from: Option<Pos2> = ui.data(|data| data.get_temp(drag_from_id));
|
||||
let texture_set = app.session.ts();
|
||||
let out_of_date = app.session.out_of_date_maps(texture_set);
|
||||
for map in BakedMap::ALL {
|
||||
match ui.push_id(map, |ui| row(app, ui, map, settings, map == selected, &mut check_drag, drag_from)).inner {
|
||||
let changes = out_of_date.get(&map).map_or(&[][..], Vec::as_slice);
|
||||
match ui.push_id(map, |ui| row(app, ui, (map, changes), settings, map == selected, &mut check_drag, drag_from)).inner {
|
||||
Some(RowClick::Row) => {
|
||||
app.ui.selected_baked_map = Some(map);
|
||||
app.ui.dock.focus(Panel::MeshMapSettings);
|
||||
@@ -255,11 +257,11 @@ fn copy_items(app: &mut TextureCraftApp, ui: &mut Ui, opener: &egui::Response, w
|
||||
}
|
||||
}
|
||||
|
||||
/// One baker row: its hover icons end in the Auto-rebake toggle, which stays while on, and an out-of-date map's thumbnail carries a clock (`check_drag`: the state a pressed check gives those the pointer then crosses; `drag_from`: where that drag's pointer was last frame); returns what was clicked, if not the check
|
||||
/// One baker row: its hover icons end in the Auto-rebake toggle, which stays while on, and an out-of-date map's thumbnail carries a clock naming its `changes` (`check_drag`: the state a pressed check gives those the pointer then crosses; `drag_from`: where that drag's pointer was last frame); returns what was clicked, if not the check
|
||||
fn row(
|
||||
app: &mut TextureCraftApp,
|
||||
ui: &mut Ui,
|
||||
map: BakedMap,
|
||||
(map, changes): (BakedMap, &[BakeChange]),
|
||||
settings: &mut BakeSettings,
|
||||
is_selected: bool,
|
||||
check_drag: &mut Option<bool>,
|
||||
@@ -296,9 +298,8 @@ fn row(
|
||||
thumbnail(ui, thumbnail_rect, texture.as_ref());
|
||||
|
||||
let texture_set = app.session.ts();
|
||||
let changes = app.session.bake_changes(texture_set, map);
|
||||
if !changes.is_empty() {
|
||||
out_of_date_mark(ui, thumbnail_rect, name, &changes);
|
||||
out_of_date_mark(ui, thumbnail_rect, name, changes);
|
||||
}
|
||||
|
||||
// From the right: sync (with several sets), Auto-rebake, bolt, eye; Auto-rebake alone stays while on
|
||||
|
||||
Reference in new issue
Block a user