fix(export): keep the <UDIM> name only when it round-trips to the file name

The length limit cuts the longer placeholder at a different place than the tile number,
so a long template got a <UDIM> name that matched none of the files written. A name is
now kept only when putting the tile number back gives the file's own name.
This commit is contained in:
bflatastic committed 2026-11-02 13:31:22 +07:00
1 parent 3b1160def5
commit 5e75a592b2
2 files changed
+21 -2

No files matched your search

+3 -2
View File
@@ -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", "<UDIM>")
});
+18
View File
@@ -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::<Vec<_>>()
};
let placeholder = Some("Body_<UDIM>.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();