Merge branch 'codex/fbx-rotation-options' into codex/fbx-integration

# Conflicts:
#	crates/mesh/src/tests/fbx.rs
This commit is contained in:
Dylan M. Taylor committed 2026-11-15 18:29:07 +00:00
commit 7f147091ea
2 files changed
+29 -3

No files matched your search

+16 -3
View File
@@ -659,9 +659,9 @@ fn euler(d: [f64; 3], order: i64) -> Mat4 {
}
/// A Model's local transform: `T · Roff · Rp · Rpre · R · Rpost⁻¹ · Rp⁻¹ · Soff · Sp · S · Sp⁻¹`.
fn model_local(p: &Props) -> Mat4 {
fn model_local(p: &Props, apply_inactive_rotation: bool) -> Mat4 {
let order = p.f("RotationOrder").map_or(0, |o| o as i64);
let active = p.f("RotationActive").is_some_and(|a| a != 0.0);
let active = apply_inactive_rotation || p.f("RotationActive").is_some_and(|a| a != 0.0);
let (pre, post) =
if active { (euler(p.v3("PreRotation", [0.0; 3]), 0), transpose(&euler(p.v3("PostRotation", [0.0; 3]), 0))) } else { (IDENTITY, IDENTITY) };
let rp = p.v3("RotationPivot", [0.0; 3]);
@@ -692,6 +692,14 @@ fn geometric(p: &Props) -> Option<Mat4> {
Some(chain(&[translate(t), euler(r, 0), scale(s)]))
}
/// Optional FBX scene compatibility behavior.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct SceneOptions {
/// Apply pre/post rotations even when `RotationActive` is missing or zero. Some importers
/// retain these values regardless of the flag.
pub apply_inactive_rotation: bool,
}
impl Document {
/// The top-level record of this name.
pub fn top(&self, name: &str) -> Option<&Record> {
@@ -741,6 +749,11 @@ impl Document {
/// The scene the records describe. `resolve` is asked for texture image files (see the
/// module documentation).
pub fn scene(&self, limits: &Limits, resolve: Resolver) -> Result<Scene> {
self.scene_with_options(limits, resolve, &SceneOptions::default())
}
/// Build a scene with explicitly selected compatibility behavior.
pub fn scene_with_options(&self, limits: &Limits, resolve: Resolver, options: &SceneOptions) -> Result<Scene> {
if self.version != 0 && self.version < 6000 {
return Err(crate::Error::Unsupported(format!(
"FBX {}.{} (only FBX 6.x and 7.x files are read)",
@@ -782,7 +795,7 @@ impl Document {
node_of.insert(*id, b.scene.nodes.len());
b.scene.nodes.push(Node {
name: short_name(o.first_str().unwrap_or("")).to_string(),
transform: model_local(&Props::of(o)),
transform: model_local(&Props::of(o), options.apply_inactive_rotation),
..Node::default()
});
}
+13
View File
@@ -740,3 +740,16 @@ fn diffuse_materials_preserve_factors_and_texture_candidates() {
let embedded = document(embedded_text.as_bytes()).diffuse_materials(&Limits::default(), &mut |_| None).unwrap();
assert_eq!(embedded.iter().find(|m| m.name == "Red").unwrap().image.as_deref(), Some(&b"embedded"[..]));
}
#[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 } } }";
let doc = document(text.as_bytes());
let normal = doc.scene(&Limits::default(), &mut no_external).unwrap();
let options = crate::fbx::SceneOptions { apply_inactive_rotation: true };
let legacy = doc.scene_with_options(&Limits::default(), &mut no_external, &options).unwrap();
let p = [1.0, 0.0, 0.0];
assert_eq!(transform_point(&normal.nodes[0].transform, p), p);
let turned = transform_point(&legacy.nodes[0].transform, p);
assert!((turned[0]).abs() < 1e-12 && (turned[1] - 1.0).abs() < 1e-12);
}