From 6fed02c608fa6d6238c63081eca11c2bbab826ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sun, 3 Apr 2022 11:52:59 +0200 Subject: [PATCH 1/2] gltf: add a name to nodes without names --- crates/bevy_gltf/src/loader.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index a4f0aa98d8846..5d61f356f0920 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -518,15 +518,21 @@ async fn load_gltf<'a, 'b>( Ok(()) } +fn node_name(node: &Node) -> Name { + let name = node + .name() + .map(|s| s.to_string()) + .unwrap_or_else(|| format!("bevy-gltf-node-{}", node.index())); + Name::new(name) +} + fn paths_recur(node: Node, current_path: &[Name], paths: &mut HashMap>) { - if let Some(name) = node.name() { - let mut path = current_path.to_owned(); - path.push(Name::new(name.to_string())); - for child in node.children() { - paths_recur(child, &path, paths); - } - paths.insert(node.index(), path); + let mut path = current_path.to_owned(); + path.push(node_name(&node)); + for child in node.children() { + paths_recur(child, &path, paths); } + paths.insert(node.index(), path); } /// Loads a glTF texture as a bevy [`Image`] and returns it together with its label. @@ -678,9 +684,7 @@ fn load_node( Mat4::from_cols_array_2d(&transform.matrix()), ))); - if let Some(name) = gltf_node.name() { - node.insert(Name::new(name.to_string())); - } + node.insert(node_name(gltf_node)); // create camera node if let Some(camera) = gltf_node.camera() { From e3c82d59a717553cd6718ace144748fbef004a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Mon, 4 Apr 2022 21:26:35 +0200 Subject: [PATCH 2/2] change name --- crates/bevy_gltf/src/loader.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 5d61f356f0920..4680cce54844d 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -522,7 +522,7 @@ fn node_name(node: &Node) -> Name { let name = node .name() .map(|s| s.to_string()) - .unwrap_or_else(|| format!("bevy-gltf-node-{}", node.index())); + .unwrap_or_else(|| format!("GltfNode{}", node.index())); Name::new(name) }