diff --git a/crates/formats/src/export/mod.rs b/crates/formats/src/export/mod.rs index 1a3d9b89..bda2136e 100644 --- a/crates/formats/src/export/mod.rs +++ b/crates/formats/src/export/mod.rs @@ -535,8 +535,9 @@ pub fn list_outputs(project: &Project, ts: usize, mesh_name: &str, opts: &Export warnings.push(format!("\"{stem}.{ext}\" is produced by more than one map; this one was renamed to \"{name}\"")); } used.insert(name.to_ascii_lowercase()); - // A tile number cut off by the length limit leaves no placeholder: then there is none. - let udim_name = token_stem.filter(|t| t.contains("UDIMTOKEN")).map(|t| { + // Only when putting the tile number back gives this file's name: the length limit cuts the + // longer placeholder elsewhere (or off), and a name may hold the placeholder text itself. + let udim_name = token_stem.filter(|t| tile.is_some_and(|n| t.contains("UDIMTOKEN") && t.replace("UDIMTOKEN", &n.to_string()) == stem)).map(|t| { let renamed = if k > 2 { format!("_{}", k - 1) } else { String::new() }; format!("{t}{renamed}.{ext}").replace("UDIMTOKEN", "") }); diff --git a/crates/formats/src/export/tests.rs b/crates/formats/src/export/tests.rs index c4966585..584a6497 100644 --- a/crates/formats/src/export/tests.rs +++ b/crates/formats/src/export/tests.rs @@ -483,6 +483,24 @@ fn uv_tiles_export_one_file_per_tile_without_padding_across() { assert_eq!((atlas.len(), atlas[0].name.as_str(), atlas[0].width, atlas[0].height), (1, "Body_Set_color.png", 2 * RES, RES)); } +#[test] +fn the_udim_name_is_the_file_name_with_its_tile_number_as_placeholder() { + let mut project = Project::new("p", "builtin:udim_plane"); + let mut ts = TextureSet::new("Body", 0, RES); + ts.uv_tiles = vec![1001, 1002]; + ts.channels = vec![(Channel::BaseColor, ChannelFormat::default_for(Channel::BaseColor))]; + project.texture_sets.push(ts); + let udim_names = |file: String| { + let channels = vec![(Dest::R, SourceRef::Channel { channel: Channel::BaseColor, component: 0 })]; + let preset = ExportPreset { name: "t".into(), maps: vec![MapSpec { file, format: FileFormat::Png, bit_depth: 8, channels }] }; + list_outputs(&project, 0, "m", &ExportOptions::new(preset)).unwrap().into_iter().map(|f| f.udim_name).collect::>() + }; + let placeholder = Some("Body_.png".to_string()); + assert_eq!(udim_names("$textureSet_$udim".into()), [placeholder.clone(), placeholder]); + // The length limit cuts the longer placeholder where it doesn't cut the tile number: none then. + assert_eq!(udim_names(format!("{}_$udim_$textureSet", "a".repeat(MAX_STEM - 10))), [None, None]); +} + #[test] fn lobe_channels_export_as_document_maps_and_gltf_extension_maps() { let mut channels = default_channels();