Merge pull request #1712 from storytold/codex/fbx-layer-selection

Select FBX layer zero and require indexed data
This commit is contained in:
FredApps authored and GitHub committed 2026-11-16 01:30:36 +01:00
commit 91a03d4564
2 files changed
+12 -2

No files matched your search

+2 -2
View File
@@ -899,7 +899,7 @@ struct Layer {
impl Layer {
/// The layer and its flat array of `width` numbers per entry.
fn of(geom: &Record, element: &str, data: &str, index: &[&str], width: usize) -> Option<(Layer, Vec<f64>)> {
let e = geom.child(element)?;
let e = geom.children_named(element).min_by_key(|e| e.props.first().and_then(Prop::as_i64) != Some(0))?;
let mapping = match e.child("MappingInformationType").and_then(|m| m.str_at(0)).unwrap_or("ByPolygonVertex") {
"ByPolygonVertex" => Mapping::PolygonVertex,
"ByVertex" | "ByVertice" | "ByControlPoint" => Mapping::Vertex,
@@ -908,7 +908,7 @@ impl Layer {
_ => return None,
};
let reference = e.child("ReferenceInformationType").and_then(|m| m.str_at(0)).unwrap_or("Direct");
let index = (reference != "Direct").then(|| index.iter().find_map(|n| e.child(n)).map(Record::ints)).flatten();
let index = if matches!(reference, "IndexToDirect" | "Index") { Some(index.iter().find_map(|n| e.child(n))?.ints()) } else { None };
let data = e.child(data)?.floats();
Some((Layer { mapping, index, len: data.len() / width }, data))
}
+10
View File
@@ -628,6 +628,16 @@ fn fbx6_model_holds_its_mesh() {
}
}
#[test]
fn layer_zero_takes_precedence_and_an_indexed_layer_needs_indices() {
let layer_one = "LayerElementUV: 1 { MappingInformationType: \"ByPolygonVertex\" ReferenceInformationType: \"Direct\" UV: 0.25,0.25, 0.25,0.25, 0.25,0.25, 0.25,0.25, 0.25,0.25, 0.25,0.25, 0.25,0.25 }\n";
let text = ASCII.replace("LayerElementUV: 0 {", &format!("{layer_one} LayerElementUV: 0 {{"));
let scene = parse(text.as_bytes()).unwrap();
assert_eq!(scene.meshes[0].uv_sets[0][0], [0.0, 1.0]);
let missing = ASCII.replace("UVIndex: *7", "UnusedIndex: *7");
assert!(parse(missing.as_bytes()).unwrap().meshes[0].uv_sets.is_empty());
}
#[test]
fn optional_inactive_pre_rotation_keeps_legacy_placements() {
let text = "FBXHeaderExtension: { FBXVersion: 7400 } Objects: { Model: 1, \"Model::A\", \"Null\" { Properties70: { P: \"PreRotation\", \"\", \"\", \"\", 0,0,90 } } }";