mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 05:14:24 +00:00
Merge branch 'codex/fbx-layer-selection' into codex/fbx-integration
# Conflicts: # crates/mesh/src/tests/fbx.rs
This commit is contained in:
@@ -1095,7 +1095,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,
|
||||
@@ -1104,7 +1104,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))
|
||||
}
|
||||
|
||||
@@ -753,3 +753,13 @@ fn optional_inactive_pre_rotation_keeps_legacy_placements() {
|
||||
let turned = transform_point(&legacy.nodes[0].transform, p);
|
||||
assert!((turned[0]).abs() < 1e-12 && (turned[1] - 1.0).abs() < 1e-12);
|
||||
}
|
||||
|
||||
#[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