From e840fa65ec7a9da478ef78b8feafa2f595db2874 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Tue, 3 Nov 2026 23:25:06 +0100 Subject: [PATCH] Add Edit > Change mesh... (file.changeMesh) to move a project onto another mesh Reimport mesh only re-read the project's own copy of the mesh, so there was no way to put the layers on a different mesh. The new command takes a mesh file, keeps layers, texture sets and settings, and carries painted strokes over by default. Co-Authored-By: Claude Sonnet 5.5 --- crates/engine/src/file_cmds.rs | 37 ++++++++++++++++++++++++++++++ crates/ui-egui/src/i18n/ar.rs | 1 + crates/ui-egui/src/i18n/de.rs | 1 + crates/ui-egui/src/i18n/es.rs | 1 + crates/ui-egui/src/i18n/fr.rs | 1 + crates/ui-egui/src/i18n/it.rs | 1 + crates/ui-egui/src/i18n/ja.rs | 1 + crates/ui-egui/src/i18n/ko.rs | 1 + crates/ui-egui/src/i18n/pt_br.rs | 1 + crates/ui-egui/src/i18n/zh_hans.rs | 1 + crates/ui-egui/src/menus.rs | 1 + crates/ui-egui/src/windows.rs | 7 ++++++ docs/features.md | 3 ++- docs/parity.md | 3 ++- 14 files changed, 58 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/file_cmds.rs b/crates/engine/src/file_cmds.rs index 78916328..d8165f51 100644 --- a/crates/engine/src/file_cmds.rs +++ b/crates/engine/src/file_cmds.rs @@ -37,6 +37,15 @@ pub fn specs() -> Vec { always, reimport ), + cmd!( + "file.changeMesh", + "Change mesh...", + ["Edit"], + None, + "{path: the new mesh file, preserveStrokes?: bool (painted pixels follow the surface where the UVs differ; default true)} → {preserved?: texels re-projected}. Keeps layers, texture sets and settings; texture sets map to the new mesh by material index", + always, + change_mesh + ), cmd!( "file.exportTextures", "Export textures", @@ -413,6 +422,13 @@ fn reimport(s: &mut Session, p: &Value) -> Result { s.reimport_mesh(file, crate::commands::boolp(p, "preserveStrokes").unwrap_or(false)) } +#[cfg(not(target_arch = "wasm32"))] +fn change_mesh(s: &mut Session, p: &Value) -> Result { + let path = native::path_param(p, "path", "file.changeMesh")?; + let file = native::read_mesh("file.changeMesh", path)?; + s.reimport_mesh(Some(file), crate::commands::boolp(p, "preserveStrokes").unwrap_or(true)) +} + #[cfg(not(target_arch = "wasm32"))] impl Session { /// Replace the mesh with `file` (or re-read the project's own copy) and keep the project: @@ -679,6 +695,27 @@ mod tests { let _ = std::fs::remove_dir_all(&dir); } + /// A project built on one mesh moves to another mesh file with its layers intact, even when + /// it carries its own copy of the mesh (a plain reimport would only re-read that copy). + #[test] + fn change_mesh_swaps_the_mesh_and_keeps_the_layers() { + let dir = std::env::temp_dir().join(format!("tc_change_mesh_{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let quad = dir.join("quad.obj"); + std::fs::write(&quad, "v 0 0 0\nv 1 0 0\nv 1 1 0\nv 0 1 0\nvt 0 0\nvt 1 0\nvt 1 1\nvt 0 1\nf 1/1 2/2 3/3 4/4\n").unwrap(); + let tri = dir.join("tri.obj"); + std::fs::write(&tri, "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(); + let mut s = Session::from_mesh_bytes("quad.obj", &std::fs::read(&quad).unwrap(), 128, "quad").unwrap(); + crate::execute(&mut s, "layer.add.fill", &json!({"color": [1.0, 0.0, 0.0]})).unwrap(); + let layers = s.doc.project.layers.len(); + assert!(crate::execute(&mut s, "file.changeMesh", &json!({})).is_err(), "a path is required"); + crate::execute(&mut s, "file.changeMesh", &json!({"path": tri.display().to_string()})).unwrap(); + assert_eq!(s.mesh.triangle_count(), 1, "the new mesh is in use"); + assert_eq!(s.doc.project.mesh_file, "tri.obj"); + assert_eq!(s.doc.project.layers.len(), layers, "the layers stay"); + std::fs::remove_dir_all(&dir).ok(); + } + #[test] fn unnamed_parts_keep_their_names_and_masks_through_save_and_reopen() { // A GLB quad whose mesh and node have no name: its one part is named after the file. diff --git a/crates/ui-egui/src/i18n/ar.rs b/crates/ui-egui/src/i18n/ar.rs index 939b0b3c..89fadc94 100644 --- a/crates/ui-egui/src/i18n/ar.rs +++ b/crates/ui-egui/src/i18n/ar.rs @@ -663,6 +663,7 @@ pub const TABLE: &[(&str, &str)] = &[ ), ("Redo", "إعادة"), ("Reimport mesh", "إعادة استيراد المجسم"), + ("Change mesh...", "تغيير المجسم..."), ("Relative to the bounding box diagonal.", "نسبة إلى قطر المربع المحيط."), ("Remove", "إزالة"), ("Remove channel", "إزالة القناة"), diff --git a/crates/ui-egui/src/i18n/de.rs b/crates/ui-egui/src/i18n/de.rs index ae02fbd2..de7ee6f2 100644 --- a/crates/ui-egui/src/i18n/de.rs +++ b/crates/ui-egui/src/i18n/de.rs @@ -702,6 +702,7 @@ pub const TABLE: &[(&str, &str)] = &[ ), ("Redo", "Wiederholen"), ("Reimport mesh", "Mesh neu importieren"), + ("Change mesh...", "Mesh ändern..."), ("Relative to the bounding box diagonal.", "Relativ zur Diagonale des Begrenzungsrahmens."), ("Remove", "Entfernen"), ("Remove channel", "Kanal entfernen"), diff --git a/crates/ui-egui/src/i18n/es.rs b/crates/ui-egui/src/i18n/es.rs index 00964af6..5a9941a3 100644 --- a/crates/ui-egui/src/i18n/es.rs +++ b/crates/ui-egui/src/i18n/es.rs @@ -690,6 +690,7 @@ pub const TABLE: &[(&str, &str)] = &[ ), ("Redo", "Rehacer"), ("Reimport mesh", "Reimportar malla"), + ("Change mesh...", "Cambiar malla..."), ("Relative to the bounding box diagonal.", "Relativo a la diagonal del cuadro delimitador."), ("Remove", "Quitar"), ("Remove channel", "Quitar canal"), diff --git a/crates/ui-egui/src/i18n/fr.rs b/crates/ui-egui/src/i18n/fr.rs index f9fa0d3b..e0df73be 100644 --- a/crates/ui-egui/src/i18n/fr.rs +++ b/crates/ui-egui/src/i18n/fr.rs @@ -705,6 +705,7 @@ pub const TABLE: &[(&str, &str)] = &[ ), ("Redo", "Rétablir"), ("Reimport mesh", "Réimporter le maillage"), + ("Change mesh...", "Changer le maillage..."), ("Relative to the bounding box diagonal.", "Relatif à la diagonale de la boîte englobante."), ("Remove", "Supprimer"), ("Remove channel", "Supprimer le canal"), diff --git a/crates/ui-egui/src/i18n/it.rs b/crates/ui-egui/src/i18n/it.rs index 765f5e8c..409aa31f 100644 --- a/crates/ui-egui/src/i18n/it.rs +++ b/crates/ui-egui/src/i18n/it.rs @@ -699,6 +699,7 @@ pub const TABLE: &[(&str, &str)] = &[ ), ("Redo", "Ripeti"), ("Reimport mesh", "Reimporta mesh"), + ("Change mesh...", "Cambia mesh..."), ("Relative to the bounding box diagonal.", "Relativa alla diagonale del bounding box."), ("Remove", "Rimuovi"), ("Remove channel", "Rimuovi canale"), diff --git a/crates/ui-egui/src/i18n/ja.rs b/crates/ui-egui/src/i18n/ja.rs index 41f6a048..69c32d77 100644 --- a/crates/ui-egui/src/i18n/ja.rs +++ b/crates/ui-egui/src/i18n/ja.rs @@ -678,6 +678,7 @@ pub const TABLE: &[(&str, &str)] = &[ ), ("Redo", "やり直し"), ("Reimport mesh", "メッシュを再インポート"), + ("Change mesh...", "メッシュを変更..."), ("Relative to the bounding box diagonal.", "バウンディングボックスの対角線に対する相対値。"), ("Remove", "削除"), ("Remove channel", "チャンネルを削除"), diff --git a/crates/ui-egui/src/i18n/ko.rs b/crates/ui-egui/src/i18n/ko.rs index 9f6aabbe..0edab0f6 100644 --- a/crates/ui-egui/src/i18n/ko.rs +++ b/crates/ui-egui/src/i18n/ko.rs @@ -669,6 +669,7 @@ pub const TABLE: &[(&str, &str)] = &[ ), ("Redo", "다시 실행"), ("Reimport mesh", "메시 다시 가져오기"), + ("Change mesh...", "메시 변경..."), ("Relative to the bounding box diagonal.", "바운딩 박스 대각선 기준입니다."), ("Remove", "제거"), ("Remove channel", "채널 제거"), diff --git a/crates/ui-egui/src/i18n/pt_br.rs b/crates/ui-egui/src/i18n/pt_br.rs index 67b4697b..253b263c 100644 --- a/crates/ui-egui/src/i18n/pt_br.rs +++ b/crates/ui-egui/src/i18n/pt_br.rs @@ -687,6 +687,7 @@ pub const TABLE: &[(&str, &str)] = &[ ), ("Redo", "Refazer"), ("Reimport mesh", "Reimportar malha"), + ("Change mesh...", "Alterar malha..."), ("Relative to the bounding box diagonal.", "Relativo à diagonal da caixa delimitadora."), ("Remove", "Remover"), ("Remove channel", "Remover canal"), diff --git a/crates/ui-egui/src/i18n/zh_hans.rs b/crates/ui-egui/src/i18n/zh_hans.rs index 73e05b93..50fe1c66 100644 --- a/crates/ui-egui/src/i18n/zh_hans.rs +++ b/crates/ui-egui/src/i18n/zh_hans.rs @@ -618,6 +618,7 @@ pub const TABLE: &[(&str, &str)] = &[ ), ("Redo", "重做"), ("Reimport mesh", "重新导入网格"), + ("Change mesh...", "更换网格..."), ("Relative to the bounding box diagonal.", "相对于包围盒对角线。"), ("Remove", "移除"), ("Remove channel", "移除通道"), diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 09f19c07..8c1ce538 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -56,6 +56,7 @@ pub const CATALOG: &[Item] = &[ sep("Edit"), it("Edit", "Project Configuration...", "ui.projectConfig", None), it("Edit", "Reimport mesh", "file.reimportMesh", Some("Ctrl+Shift+R")), + it("Edit", "Change mesh...", "file.changeMesh", None), it("Edit", "Settings...", "ui.settings", None), it("Mode", "Bake Mesh Maps", "ui.mode.bake", Some("F8")), it("Mode", "Painting", "ui.mode.paint", Some("F9")), diff --git a/crates/ui-egui/src/windows.rs b/crates/ui-egui/src/windows.rs index 8ecab281..08e4a756 100644 --- a/crates/ui-egui/src/windows.rs +++ b/crates/ui-egui/src/windows.rs @@ -1138,6 +1138,13 @@ pub fn file_action(app: &mut TextureCraftApp, _ctx: &egui::Context, id: &str) -> app.run("file.reimportMesh", json!({"path": path, "preserveStrokes": true})); true } + "file.changeMesh" => { + // Layers and texture sets stay; the strokes follow the surface onto the new mesh. + if let Some(p) = rfd::FileDialog::new().add_filter(tr("3D meshes"), &texturecraft_engine::formats::mesh_import::MESH_EXTENSIONS).pick_file() { + app.run("file.changeMesh", json!({"path": p.display().to_string()})); + } + true + } _ => false, } } diff --git a/docs/features.md b/docs/features.md index fcbaca5f..2e6a9881 100644 --- a/docs/features.md +++ b/docs/features.md @@ -80,7 +80,8 @@ Everything TextureCraft does today, by area. What's still missing is in [`ROADMA - **Open** glTF/GLB, FBX (binary and ASCII), COLLADA, **USD** (usda, usdc, usdz), **Alembic**, OBJ, PLY and STL, or a built-in mesh; UVs are generated when a mesh has none. A `.gltf`'s buffers and images and a loose USD layer's textures are read from its folder and kept in the project. - Reimport a changed mesh and your painted strokes stay on the surface. + Reimport a changed mesh and your painted strokes stay on the surface. **Edit ▸ Change mesh...** + (`file.changeMesh`) moves the project onto a different mesh file and keeps its layers. - **UDIM / UV tiles:** detected on import or switched on later, with a resolution per tile (blurs, other filters and height-to-normal slopes keep their size in UV space at any tile resolution) and one texture per tile on export (`$udim`). diff --git a/docs/parity.md b/docs/parity.md index d6543d54..7724e50f 100644 --- a/docs/parity.md +++ b/docs/parity.md @@ -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%).** +**56 of 56 menu items live (100%).** ## File @@ -31,6 +31,7 @@ Generated by `TC_UPDATE_PARITY=1 cargo test -p texturecraft-ui-egui parity`. Eac | Redo | `edit.redo` | Ctrl+Y | live | | Project Configuration... | `ui.projectConfig` | | live | | Reimport mesh | `file.reimportMesh` | Ctrl+Shift+R | live | +| Change mesh... | `file.changeMesh` | | live | | Settings... | `ui.settings` | | live | ## Mode