mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:42:27 +00:00
Select FBX layer zero and require indexed data
This commit is contained in:
1 parent
1fdc42e5d6
commit
df7cc68b6f
2 files changed
+12
-2
No files matched your search
@@ -867,7 +867,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,
|
||||
@@ -876,7 +876,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))
|
||||
}
|
||||
|
||||
@@ -627,3 +627,13 @@ fn fbx6_model_holds_its_mesh() {
|
||||
assert_eq!(d.unit_scale(), Some(100.0));
|
||||
}
|
||||
}
|
||||
|
||||
#[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());
|
||||
}
|
||||
Reference in new issue
Block a user