Allow last FBX parent connection to win

This commit is contained in:
Dylan M. Taylor committed 2026-11-15 18:43:10 +00:00
1 parent 357dc3fb73
commit 818f05566e
2 files changed
+18 -1

No files matched your search

+7 -1
View File
@@ -679,6 +679,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 {
@@ -788,7 +790,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() {
+11
View File
@@ -651,3 +651,14 @@ fn strict_geometry_rejects_bad_arrays_and_keeps_final_polygon() {
assert!(read_strict(&ASCII.replace("a: 0,1,2,-4,0,1,-5", bad)).is_err());
}
}
#[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));
}