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 <noreply@anthropic.com>
This commit is contained in:
vangel76andClaude Sonnet 5.5 committed 2026-11-03 23:25:06 +01:00
1 parent 9dc33d894e
commit e840fa65ec
14 files changed
+58 -2

No files matched your search

+37
View File
@@ -37,6 +37,15 @@ pub fn specs() -> Vec<CommandSpec> {
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<Value> {
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<Value> {
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.
+1
View File
@@ -663,6 +663,7 @@ pub const TABLE: &[(&str, &str)] = &[
),
("Redo", "إعادة"),
("Reimport mesh", "إعادة استيراد المجسم"),
("Change mesh...", "تغيير المجسم..."),
("Relative to the bounding box diagonal.", "نسبة إلى قطر المربع المحيط."),
("Remove", "إزالة"),
("Remove channel", "إزالة القناة"),
+1
View File
@@ -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"),
+1
View File
@@ -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"),
+1
View File
@@ -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"),
+1
View File
@@ -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"),
+1
View File
@@ -678,6 +678,7 @@ pub const TABLE: &[(&str, &str)] = &[
),
("Redo", "やり直し"),
("Reimport mesh", "メッシュを再インポート"),
("Change mesh...", "メッシュを変更..."),
("Relative to the bounding box diagonal.", "バウンディングボックスの対角線に対する相対値。"),
("Remove", "削除"),
("Remove channel", "チャンネルを削除"),
+1
View File
@@ -669,6 +669,7 @@ pub const TABLE: &[(&str, &str)] = &[
),
("Redo", "다시 실행"),
("Reimport mesh", "메시 다시 가져오기"),
("Change mesh...", "메시 변경..."),
("Relative to the bounding box diagonal.", "바운딩 박스 대각선 기준입니다."),
("Remove", "제거"),
("Remove channel", "채널 제거"),
+1
View File
@@ -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"),
+1
View File
@@ -618,6 +618,7 @@ pub const TABLE: &[(&str, &str)] = &[
),
("Redo", "重做"),
("Reimport mesh", "重新导入网格"),
("Change mesh...", "更换网格..."),
("Relative to the bounding box diagonal.", "相对于包围盒对角线。"),
("Remove", "移除"),
("Remove channel", "移除通道"),
+1
View File
@@ -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")),
+7
View File
@@ -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,
}
}
+2 -1
View File
@@ -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`).
+2 -1
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%).**
**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