From 818f05566eaa73c27e2fb884555d1eb8e31be646 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 18:43:10 +0000 Subject: [PATCH 1/2] Allow last FBX parent connection to win --- crates/mesh/src/fbx.rs | 8 +++++++- crates/mesh/src/tests/fbx.rs | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/mesh/src/fbx.rs b/crates/mesh/src/fbx.rs index a2e97f59c..3b37e8e59 100644 --- a/crates/mesh/src/fbx.rs +++ b/crates/mesh/src/fbx.rs @@ -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() { diff --git a/crates/mesh/src/tests/fbx.rs b/crates/mesh/src/tests/fbx.rs index 7f19c7d52..c044df5b0 100644 --- a/crates/mesh/src/tests/fbx.rs +++ b/crates/mesh/src/tests/fbx.rs @@ -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)); +} From 39b7076b0421ef056d5d57bd1e08cb65d21e0332 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 18:50:08 +0000 Subject: [PATCH 2/2] Allow object-only FBX hierarchy connections --- crates/mesh/src/fbx.rs | 21 +++++++++++++++++++-- crates/mesh/src/tests/fbx.rs | 10 ++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/mesh/src/fbx.rs b/crates/mesh/src/fbx.rs index 3b37e8e59..8f0b17c3c 100644 --- a/crates/mesh/src/fbx.rs +++ b/crates/mesh/src/fbx.rs @@ -681,6 +681,8 @@ pub struct SceneOptions { pub strict_geometry: bool, /// If a model names several parents, use the last connection. pub prefer_last_parent: bool, + /// Restrict model hierarchy, geometry and material links to object connections. + pub only_object_connections: bool, } impl Document { @@ -748,10 +750,12 @@ impl Document { let mut b = Build { limits, strict_geometry: options.strict_geometry, + only_object_connections: options.only_object_connections, budget: Budget { left: Cell::new(self.left), limit: limits.max_data_bytes }, resolve, by_key: objects.children.iter().filter_map(|o| Some((key(o.props.first())?, o))).collect(), children: HashMap::new(), + object_children: HashMap::new(), scene: Scene::default(), material_of: HashMap::new(), texture_of: HashMap::new(), @@ -764,8 +768,14 @@ impl Document { let mut links: Vec<(Key, Key)> = vec![]; for e in self.top("Connections").into_iter().flat_map(|c| c.children.iter()).filter(|e| e.name == "C" || e.name == "Connect") { let (Some(child), Some(parent)) = (key(e.props.get(1)), key(e.props.get(2))) else { continue }; - links.push((child, parent)); + let object = e.str_at(0) == Some("OO"); + if !options.only_object_connections || object { + links.push((child, parent)); + } b.children.entry(parent).or_default().push((child, e.str_at(3))); + if options.only_object_connections && object { + b.object_children.entry(parent).or_default().push((child, e.str_at(3))); + } } let models: Vec<(Key, &Record)> = @@ -965,10 +975,12 @@ fn material(name: &str, record: &Record) -> Material { struct Build<'a, 'r> { limits: &'a Limits, strict_geometry: bool, + only_object_connections: bool, budget: Budget, resolve: Resolver<'r>, by_key: HashMap, &'a Record>, children: HashMap, Vec<(Key<'a>, Option<&'a str>)>>, + object_children: HashMap, Vec<(Key<'a>, Option<&'a str>)>>, scene: Scene, material_of: HashMap, usize>, texture_of: HashMap, Option>, @@ -983,7 +995,12 @@ struct Build<'a, 'r> { impl<'a> Build<'a, '_> { /// The objects of `kind` connected under `id`, with the property each connects to. fn children_of(&self, id: Key<'a>, kind: &str) -> Vec<(Key<'a>, Option<&'a str>)> { - let all = self.children.get(&id).map(Vec::as_slice).unwrap_or_default(); + let source = if self.only_object_connections && matches!(kind, "Geometry" | "Material" | "NodeAttribute") { + &self.object_children + } else { + &self.children + }; + let all = source.get(&id).map(Vec::as_slice).unwrap_or_default(); all.iter().filter(|l| self.by_key.get(&l.0).is_some_and(|o| o.name == kind)).copied().collect() } diff --git a/crates/mesh/src/tests/fbx.rs b/crates/mesh/src/tests/fbx.rs index c044df5b0..679cb0124 100644 --- a/crates/mesh/src/tests/fbx.rs +++ b/crates/mesh/src/tests/fbx.rs @@ -662,3 +662,13 @@ fn scene_option_selects_the_last_parent_connection() { let default = doc.scene(&Limits::default(), &mut no_external).unwrap(); assert!(default.nodes[0].children.contains(&2)); } + +#[test] +fn object_only_hierarchy_ignores_property_connections() { + let text = "FBXHeaderExtension: { FBXVersion: 7400 } Objects: { Model: 1, \"Model::A\", \"Null\" {} Model: 2, \"Model::B\", \"Null\" {} } Connections: { C: \"OP\",2,1,\"SomeProperty\" }"; + let doc = document(text.as_bytes()); + let options = crate::fbx::SceneOptions { only_object_connections: true, ..Default::default() }; + let scene = doc.scene_with_options(&Limits::default(), &mut no_external, &options).unwrap(); + assert_eq!(scene.roots.len(), 2); + assert_eq!(doc.scene(&Limits::default(), &mut no_external).unwrap().roots.len(), 1); +}