MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / swap_extension

Function swap_extension

native/shared/src/models.rs:1846–1856  ·  view source on GitHub ↗

Replace the extension on a URI (keeps directories / query strings untouched). Used to fall back from `foo.png` → `foo.dds` when a glTF references a PNG URI that isn't on disk but the DDS sibling is.

(uri: &str, new_ext: &str)

Source from the content-addressed store, hash-verified

1844/// untouched). Used to fall back from `foo.png` → `foo.dds` when a
1845/// glTF references a PNG URI that isn't on disk but the DDS sibling is.
1846fn swap_extension(uri: &str, new_ext: &str) -> String {
1847 let q = uri.find('?').unwrap_or(uri.len());
1848 let (path, query) = uri.split_at(q);
1849 let new_path = match path.rfind('.') {
1850 Some(dot) if dot > path.rfind('/').unwrap_or(0) => {
1851 format!("{}.{}", &path[..dot], new_ext)
1852 }
1853 _ => format!("{}.{}", path, new_ext),
1854 };
1855 format!("{}{}", new_path, query)
1856}
1857
1858/// Decode a texture byte slice into RGBA8 pixels + dimensions. Tries
1859/// DDS first when the URI extension suggests it (for asset packs like

Callers 1

load_gltf_with_texturesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected