diff --git a/crates/mesh/src/fbx.rs b/crates/mesh/src/fbx.rs index 7d22950e7..d0f918cb1 100644 --- a/crates/mesh/src/fbx.rs +++ b/crates/mesh/src/fbx.rs @@ -731,6 +731,8 @@ pub struct SceneOptions { pub apply_inactive_rotation: bool, /// Refuse malformed geometry arrays and accept an unterminated final polygon. pub strict_geometry: bool, + /// If a model names several parents, use the last connection. + pub prefer_last_parent: bool, } impl Document { @@ -840,7 +842,11 @@ impl Document { if let (Some(ci), Some(pi)) = (node_of.get(c), node_of.get(p)) && ci != pi { - parent.entry(*ci).or_insert(*pi); + if options.prefer_last_parent { + parent.insert(*ci, *pi); + } else { + parent.entry(*ci).or_insert(*pi); + } } } for i in 0..b.scene.nodes.len() { diff --git a/crates/mesh/src/tests/fbx.rs b/crates/mesh/src/tests/fbx.rs index 29ca82a14..d6acb3123 100644 --- a/crates/mesh/src/tests/fbx.rs +++ b/crates/mesh/src/tests/fbx.rs @@ -784,3 +784,14 @@ fn strict_ascii_reports_unbalanced_and_unterminated_records() { } assert!(read_document(b"Objects: { A: 1", &Limits::default()).is_ok()); } + +#[test] +fn scene_option_selects_the_last_parent_connection() { + let text = "FBXHeaderExtension: { FBXVersion: 7400 } Objects: { Model: 1, \"Model::A\", \"Null\" {} Model: 2, \"Model::B\", \"Null\" {} Model: 3, \"Model::Child\", \"Null\" {} } Connections: { C: \"OO\",3,1 C: \"OO\",3,2 }"; + let doc = document(text.as_bytes()); + let options = crate::fbx::SceneOptions { prefer_last_parent: true, ..Default::default() }; + let scene = doc.scene_with_options(&Limits::default(), &mut no_external, &options).unwrap(); + assert!(scene.nodes[1].children.contains(&2)); + let default = doc.scene(&Limits::default(), &mut no_external).unwrap(); + assert!(default.nodes[0].children.contains(&2)); +}