Upgrade to Bevy 0.19 and harden editor workflows
CI / Format, lint, test, build (push) Has been cancelled
CI / Format, lint, test, build (push) Has been cancelled
This commit is contained in:
1 parent
3f85d25cc7
commit
b5e561904c
204 files changed
+6972
-29907
No files matched your search
+25
@@ -0,0 +1,25 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_ufbx::FbxPlugin;
|
||||
|
||||
#[test]
|
||||
fn test_plugin_builds() {
|
||||
let mut app = App::new();
|
||||
app.add_plugins(MinimalPlugins);
|
||||
app.add_plugins(AssetPlugin::default());
|
||||
app.add_plugins(FbxPlugin);
|
||||
|
||||
// If we get here without panic, the plugin is properly set up
|
||||
assert!(true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_loader_registration() {
|
||||
let mut app = App::new();
|
||||
app.add_plugins(MinimalPlugins);
|
||||
app.add_plugins(AssetPlugin::default());
|
||||
app.add_plugins(FbxPlugin);
|
||||
|
||||
// Check that FBX extensions are registered
|
||||
// This is a basic test that the loader is registered
|
||||
assert!(true);
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
//! Integration tests for FBX loading.
|
||||
|
||||
use bevy::asset::{AssetPlugin, AssetServer};
|
||||
use bevy::prelude::*;
|
||||
use bevy_ufbx::{Fbx, FbxPlugin};
|
||||
|
||||
#[test]
|
||||
fn test_plugin_initialization() {
|
||||
let mut app = App::new();
|
||||
|
||||
// Add required plugins
|
||||
app.add_plugins(MinimalPlugins);
|
||||
app.add_plugins(AssetPlugin::default());
|
||||
app.add_plugins(FbxPlugin);
|
||||
|
||||
// Check that the plugin initialized correctly
|
||||
app.update();
|
||||
|
||||
// If we get here without panic, the plugin is working
|
||||
assert!(true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_asset_registration() {
|
||||
let mut app = App::new();
|
||||
|
||||
app.add_plugins(MinimalPlugins);
|
||||
app.add_plugins(AssetPlugin::default());
|
||||
app.add_plugins(FbxPlugin);
|
||||
|
||||
// Check that Fbx asset is registered
|
||||
let asset_server = app.world().resource::<AssetServer>();
|
||||
|
||||
// This would typically be tested by loading an actual FBX file
|
||||
// For now, we just verify the asset server exists
|
||||
assert!(
|
||||
asset_server.mode() == bevy::asset::AssetServerMode::Processed
|
||||
|| asset_server.mode() == bevy::asset::AssetServerMode::Unprocessed
|
||||
);
|
||||
}
|
||||
|
||||
// Test system to verify FBX loading
|
||||
fn check_fbx_loaded(
|
||||
_asset_server: Res<AssetServer>,
|
||||
fbx_assets: Res<Assets<Fbx>>,
|
||||
mut loaded: Local<bool>,
|
||||
) {
|
||||
if *loaded {
|
||||
return;
|
||||
}
|
||||
|
||||
// In a real test, we would load an actual FBX file
|
||||
// For now, we just verify the system can access the resources
|
||||
let _ = fbx_assets.len();
|
||||
*loaded = true;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fbx_loading_system() {
|
||||
let mut app = App::new();
|
||||
|
||||
app.add_plugins(MinimalPlugins);
|
||||
app.add_plugins(AssetPlugin::default());
|
||||
app.add_plugins(FbxPlugin);
|
||||
|
||||
app.add_systems(Update, check_fbx_loaded);
|
||||
|
||||
// Run a few update cycles
|
||||
for _ in 0..3 {
|
||||
app.update();
|
||||
}
|
||||
|
||||
// If we get here without panic, systems are working
|
||||
assert!(true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_plugins() {
|
||||
let mut app = App::new();
|
||||
|
||||
// Test that we can add multiple instances of required plugins
|
||||
app.add_plugins(MinimalPlugins);
|
||||
app.add_plugins(AssetPlugin::default());
|
||||
app.add_plugins(FbxPlugin);
|
||||
|
||||
// Add some standard Bevy plugins that might interact with FBX loading
|
||||
app.init_resource::<Assets<Mesh>>();
|
||||
app.init_resource::<Assets<StandardMaterial>>();
|
||||
|
||||
app.update();
|
||||
|
||||
// Verify resources exist
|
||||
assert!(app.world().get_resource::<Assets<Mesh>>().is_some());
|
||||
assert!(app
|
||||
.world()
|
||||
.get_resource::<Assets<StandardMaterial>>()
|
||||
.is_some());
|
||||
assert!(app.world().get_resource::<Assets<Fbx>>().is_some());
|
||||
}
|
||||
Vendored
+78
@@ -0,0 +1,78 @@
|
||||
//! Tests for FBX asset labels.
|
||||
|
||||
use bevy_ufbx::FbxAssetLabel;
|
||||
|
||||
#[test]
|
||||
fn test_scene_label() {
|
||||
let label = FbxAssetLabel::Scene(0);
|
||||
assert_eq!(label.to_string(), "Scene0");
|
||||
|
||||
let label = FbxAssetLabel::Scene(42);
|
||||
assert_eq!(label.to_string(), "Scene42");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_node_label() {
|
||||
let label = FbxAssetLabel::Node(5);
|
||||
assert_eq!(label.to_string(), "Node5");
|
||||
|
||||
let label = FbxAssetLabel::Node(999);
|
||||
assert_eq!(label.to_string(), "Node999");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mesh_label() {
|
||||
let label = FbxAssetLabel::Mesh(10);
|
||||
assert_eq!(label.to_string(), "Mesh10");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_material_label() {
|
||||
let label = FbxAssetLabel::Material(3);
|
||||
assert_eq!(label.to_string(), "Material3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_texture_label() {
|
||||
let label = FbxAssetLabel::Texture(7);
|
||||
assert_eq!(label.to_string(), "Texture7");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_animation_label() {
|
||||
let label = FbxAssetLabel::Animation(2);
|
||||
assert_eq!(label.to_string(), "Animation2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skin_label() {
|
||||
let label = FbxAssetLabel::Skin(4);
|
||||
assert_eq!(label.to_string(), "Skin4");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_material_label() {
|
||||
let label = FbxAssetLabel::DefaultMaterial;
|
||||
assert_eq!(label.to_string(), "DefaultMaterial");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_label_uniqueness() {
|
||||
// Test that different label types with same index produce different strings
|
||||
let scene = FbxAssetLabel::Scene(1);
|
||||
let node = FbxAssetLabel::Node(1);
|
||||
let mesh = FbxAssetLabel::Mesh(1);
|
||||
|
||||
assert_ne!(scene.to_string(), node.to_string());
|
||||
assert_ne!(scene.to_string(), mesh.to_string());
|
||||
assert_ne!(node.to_string(), mesh.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_label_consistency() {
|
||||
// Test that the same label always produces the same string
|
||||
let label1 = FbxAssetLabel::Material(100);
|
||||
let label2 = FbxAssetLabel::Material(100);
|
||||
|
||||
assert_eq!(label1.to_string(), label2.to_string());
|
||||
}
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
//! Loads every FBX file from the ufbx test suite and verifies our processing
|
||||
//! functions handle them without panicking or returning unexpected errors.
|
||||
//!
|
||||
//! Set the `UFBX_TEST_DATA` environment variable to the path of the
|
||||
//! `ufbx/data` directory before running:
|
||||
//!
|
||||
//! ```sh
|
||||
//! UFBX_TEST_DATA=/tmp/ufbx/data cargo test load_all_ufbx_test_data -- --nocapture
|
||||
//! ```
|
||||
|
||||
use bevy_ufbx::material::create_standard_material;
|
||||
use bevy_ufbx::mesh::group_faces_by_material;
|
||||
use bevy_ufbx::utils::{convert_matrix, convert_transform};
|
||||
use std::collections::HashMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Instant;
|
||||
|
||||
/// Subdirectories that contain binary fuzz/garbage data, not valid FBX files.
|
||||
const SKIP_DIRS: &[&str] = &["fuzz", "cache_fuzz", "obj_fuzz", "mtl_fuzz"];
|
||||
|
||||
fn collect_fbx_files(root: &Path) -> Vec<PathBuf> {
|
||||
let mut files = Vec::new();
|
||||
collect_recursive(root, &mut files);
|
||||
files.sort();
|
||||
files
|
||||
}
|
||||
|
||||
fn collect_recursive(dir: &Path, out: &mut Vec<PathBuf>) {
|
||||
let Ok(entries) = std::fs::read_dir(dir) else {
|
||||
return;
|
||||
};
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
let name = path
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.unwrap_or("");
|
||||
if !SKIP_DIRS.contains(&name) {
|
||||
collect_recursive(&path, out);
|
||||
}
|
||||
} else if path
|
||||
.extension()
|
||||
.and_then(|e| e.to_str())
|
||||
.map(|e| e.eq_ignore_ascii_case("fbx"))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
out.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempt to load an FBX file through the full processing pipeline used by
|
||||
/// our loader, without needing a `LoadContext`.
|
||||
///
|
||||
/// Returns `Ok(())` on success or a human-readable error string.
|
||||
fn try_process_fbx(path: &Path) -> Result<(), String> {
|
||||
let bytes = std::fs::read(path).map_err(|e| format!("read: {e}"))?;
|
||||
|
||||
let root = ufbx::load_memory(
|
||||
&bytes,
|
||||
ufbx::LoadOpts {
|
||||
target_unit_meters: 1.0,
|
||||
target_axes: ufbx::CoordinateAxes::right_handed_y_up(),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.map_err(|e| format!("ufbx: {e:?}"))?;
|
||||
|
||||
let scene: &ufbx::Scene = &*root;
|
||||
|
||||
// --- Nodes / transforms ---
|
||||
for node in scene.nodes.as_ref().iter() {
|
||||
convert_transform(&node.local_transform);
|
||||
convert_matrix(&node.node_to_world);
|
||||
|
||||
// Mesh face grouping (pure data, no LoadContext needed)
|
||||
if let Some(mesh_ref) = node.mesh.as_ref() {
|
||||
let mesh = mesh_ref.as_ref();
|
||||
if mesh.num_vertices > 0 && !mesh.faces.as_ref().is_empty() {
|
||||
group_faces_by_material(mesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Materials ---
|
||||
// Pass an empty texture map; we're testing structural correctness, not
|
||||
// texture path resolution.
|
||||
let no_textures = HashMap::new();
|
||||
for mat in scene.materials.as_ref().iter() {
|
||||
if mat.element.element_id == 0 {
|
||||
continue;
|
||||
}
|
||||
create_standard_material(mat, &no_textures)
|
||||
.map_err(|e| format!("material '{}': {e:?}", mat.element.name))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_all_ufbx_test_data() {
|
||||
let data_dir = match std::env::var("UFBX_TEST_DATA") {
|
||||
Ok(dir) => PathBuf::from(dir),
|
||||
Err(_) => {
|
||||
println!("Skipping: UFBX_TEST_DATA env var not set.");
|
||||
println!("To run: UFBX_TEST_DATA=/path/to/ufbx/data cargo test load_all_ufbx_test_data -- --nocapture");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
assert!(
|
||||
data_dir.is_dir(),
|
||||
"UFBX_TEST_DATA '{}' is not a directory",
|
||||
data_dir.display()
|
||||
);
|
||||
|
||||
let fbx_files = collect_fbx_files(&data_dir);
|
||||
assert!(
|
||||
!fbx_files.is_empty(),
|
||||
"No .fbx files found in '{}'",
|
||||
data_dir.display()
|
||||
);
|
||||
|
||||
println!("Found {} FBX files in {}\n", fbx_files.len(), data_dir.display());
|
||||
|
||||
let mut passed = 0usize;
|
||||
let mut failures: Vec<String> = Vec::new();
|
||||
let total_start = Instant::now();
|
||||
|
||||
for path in &fbx_files {
|
||||
let rel = path.strip_prefix(&data_dir).unwrap_or(path);
|
||||
let t = Instant::now();
|
||||
match try_process_fbx(path) {
|
||||
Ok(()) => {
|
||||
passed += 1;
|
||||
println!(" OK {:>6}ms {}", t.elapsed().as_millis(), rel.display());
|
||||
}
|
||||
Err(e) => {
|
||||
let msg = format!("{} — {}", rel.display(), e);
|
||||
eprintln!("FAIL {:>6}ms {}", t.elapsed().as_millis(), msg);
|
||||
failures.push(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let total = fbx_files.len();
|
||||
println!(
|
||||
"\n{passed}/{total} passed in {:.2}s",
|
||||
total_start.elapsed().as_secs_f64()
|
||||
);
|
||||
|
||||
if !failures.is_empty() {
|
||||
panic!(
|
||||
"\n{} file(s) failed to process:\n {}",
|
||||
failures.len(),
|
||||
failures.join("\n ")
|
||||
);
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
//! Tests for FBX loader settings.
|
||||
|
||||
use bevy::asset::RenderAssetUsages;
|
||||
use bevy_ufbx::FbxLoaderSettings;
|
||||
|
||||
#[test]
|
||||
fn test_loader_settings_default() {
|
||||
let settings = FbxLoaderSettings::default();
|
||||
|
||||
assert_eq!(settings.load_meshes, RenderAssetUsages::default());
|
||||
assert_eq!(settings.load_materials, RenderAssetUsages::default());
|
||||
assert!(settings.load_cameras);
|
||||
assert!(settings.load_lights);
|
||||
assert!(!settings.include_source);
|
||||
assert!(!settings.convert_coordinates);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_loader_settings_custom() {
|
||||
let settings = FbxLoaderSettings {
|
||||
load_meshes: RenderAssetUsages::RENDER_WORLD,
|
||||
load_materials: RenderAssetUsages::MAIN_WORLD,
|
||||
load_cameras: false,
|
||||
load_lights: false,
|
||||
include_source: true,
|
||||
convert_coordinates: true,
|
||||
};
|
||||
|
||||
assert_eq!(settings.load_meshes, RenderAssetUsages::RENDER_WORLD);
|
||||
assert_eq!(settings.load_materials, RenderAssetUsages::MAIN_WORLD);
|
||||
assert!(!settings.load_cameras);
|
||||
assert!(!settings.load_lights);
|
||||
assert!(settings.include_source);
|
||||
assert!(settings.convert_coordinates);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_loader_settings_serialization() {
|
||||
let original = FbxLoaderSettings {
|
||||
load_meshes: RenderAssetUsages::RENDER_WORLD,
|
||||
load_materials: RenderAssetUsages::MAIN_WORLD,
|
||||
load_cameras: false,
|
||||
load_lights: true,
|
||||
include_source: false,
|
||||
convert_coordinates: true,
|
||||
};
|
||||
|
||||
// Serialize
|
||||
let serialized = serde_json::to_string(&original).expect("Failed to serialize");
|
||||
|
||||
// Deserialize
|
||||
let deserialized: FbxLoaderSettings =
|
||||
serde_json::from_str(&serialized).expect("Failed to deserialize");
|
||||
|
||||
// Check equality
|
||||
assert_eq!(deserialized.load_meshes, original.load_meshes);
|
||||
assert_eq!(deserialized.load_materials, original.load_materials);
|
||||
assert_eq!(deserialized.load_cameras, original.load_cameras);
|
||||
assert_eq!(deserialized.load_lights, original.load_lights);
|
||||
assert_eq!(deserialized.include_source, original.include_source);
|
||||
assert_eq!(
|
||||
deserialized.convert_coordinates,
|
||||
original.convert_coordinates
|
||||
);
|
||||
}
|
||||
Vendored
+146
@@ -0,0 +1,146 @@
|
||||
//! Tests for FBX types.
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_ufbx::types::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[test]
|
||||
fn test_handedness_equality() {
|
||||
assert_eq!(Handedness::Right, Handedness::Right);
|
||||
assert_eq!(Handedness::Left, Handedness::Left);
|
||||
assert_ne!(Handedness::Right, Handedness::Left);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fbx_axis_system_creation() {
|
||||
let axis_system = FbxAxisSystem {
|
||||
up: Vec3::Y,
|
||||
front: Vec3::Z,
|
||||
handedness: Handedness::Right,
|
||||
};
|
||||
|
||||
assert_eq!(axis_system.up, Vec3::Y);
|
||||
assert_eq!(axis_system.front, Vec3::Z);
|
||||
assert_eq!(axis_system.handedness, Handedness::Right);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fbx_meta_default() {
|
||||
let meta = FbxMeta::default();
|
||||
|
||||
assert!(meta.creator.is_none());
|
||||
assert!(meta.creation_time.is_none());
|
||||
assert!(meta.original_application.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fbx_wrap_mode_equality() {
|
||||
assert_eq!(FbxWrapMode::Repeat, FbxWrapMode::Repeat);
|
||||
assert_eq!(FbxWrapMode::Clamp, FbxWrapMode::Clamp);
|
||||
assert_ne!(FbxWrapMode::Repeat, FbxWrapMode::Clamp);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fbx_texture_type_hash() {
|
||||
use std::collections::HashSet;
|
||||
|
||||
let mut set = HashSet::new();
|
||||
set.insert(FbxTextureType::BaseColor);
|
||||
set.insert(FbxTextureType::Normal);
|
||||
set.insert(FbxTextureType::Metallic);
|
||||
|
||||
assert!(set.contains(&FbxTextureType::BaseColor));
|
||||
assert!(set.contains(&FbxTextureType::Normal));
|
||||
assert!(set.contains(&FbxTextureType::Metallic));
|
||||
assert!(!set.contains(&FbxTextureType::Roughness));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fbx_light_type_equality() {
|
||||
assert_eq!(FbxLightType::Directional, FbxLightType::Directional);
|
||||
assert_eq!(FbxLightType::Point, FbxLightType::Point);
|
||||
assert_eq!(FbxLightType::Spot, FbxLightType::Spot);
|
||||
assert_ne!(FbxLightType::Point, FbxLightType::Spot);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fbx_projection_mode_equality() {
|
||||
assert_eq!(
|
||||
FbxProjectionMode::Perspective,
|
||||
FbxProjectionMode::Perspective
|
||||
);
|
||||
assert_eq!(
|
||||
FbxProjectionMode::Orthographic,
|
||||
FbxProjectionMode::Orthographic
|
||||
);
|
||||
assert_ne!(
|
||||
FbxProjectionMode::Perspective,
|
||||
FbxProjectionMode::Orthographic
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fbx_interpolation_equality() {
|
||||
assert_eq!(FbxInterpolation::Constant, FbxInterpolation::Constant);
|
||||
assert_eq!(FbxInterpolation::Linear, FbxInterpolation::Linear);
|
||||
assert_eq!(FbxInterpolation::Cubic, FbxInterpolation::Cubic);
|
||||
assert_ne!(FbxInterpolation::Linear, FbxInterpolation::Cubic);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fbx_material_creation() {
|
||||
let material = FbxMaterial {
|
||||
name: "TestMaterial".to_string(),
|
||||
base_color: Color::WHITE,
|
||||
metallic: 0.5,
|
||||
roughness: 0.7,
|
||||
emission: Color::BLACK,
|
||||
normal_scale: 1.0,
|
||||
alpha: 1.0,
|
||||
alpha_cutoff: 0.5,
|
||||
double_sided: false,
|
||||
textures: HashMap::new(),
|
||||
};
|
||||
|
||||
assert_eq!(material.name, "TestMaterial");
|
||||
assert_eq!(material.base_color, Color::WHITE);
|
||||
assert_eq!(material.metallic, 0.5);
|
||||
assert_eq!(material.roughness, 0.7);
|
||||
assert!(!material.double_sided);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fbx_light_creation() {
|
||||
let light = FbxLight {
|
||||
name: "TestLight".to_string(),
|
||||
light_type: FbxLightType::Point,
|
||||
color: Color::WHITE,
|
||||
intensity: 100.0,
|
||||
cast_shadows: true,
|
||||
inner_angle: None,
|
||||
outer_angle: None,
|
||||
};
|
||||
|
||||
assert_eq!(light.name, "TestLight");
|
||||
assert_eq!(light.light_type, FbxLightType::Point);
|
||||
assert!(light.cast_shadows);
|
||||
assert!(light.inner_angle.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fbx_camera_creation() {
|
||||
let camera = FbxCamera {
|
||||
name: "TestCamera".to_string(),
|
||||
projection_mode: FbxProjectionMode::Perspective,
|
||||
field_of_view_deg: 60.0,
|
||||
aspect_ratio: 1.777,
|
||||
near_plane: 0.1,
|
||||
far_plane: 1000.0,
|
||||
focal_length_mm: 35.0,
|
||||
};
|
||||
|
||||
assert_eq!(camera.name, "TestCamera");
|
||||
assert_eq!(camera.projection_mode, FbxProjectionMode::Perspective);
|
||||
assert_eq!(camera.field_of_view_deg, 60.0);
|
||||
assert!((camera.aspect_ratio - 1.777).abs() < 0.001);
|
||||
}
|
||||
Vendored
+96
@@ -0,0 +1,96 @@
|
||||
//! Tests for utility conversion functions.
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_ufbx::utils::{convert_matrix, convert_transform};
|
||||
|
||||
#[test]
|
||||
fn test_convert_matrix() {
|
||||
// Create a simple ufbx matrix
|
||||
let ufbx_matrix = ufbx::Matrix {
|
||||
m00: 1.0,
|
||||
m01: 0.0,
|
||||
m02: 0.0,
|
||||
m03: 10.0,
|
||||
m10: 0.0,
|
||||
m11: 1.0,
|
||||
m12: 0.0,
|
||||
m13: 20.0,
|
||||
m20: 0.0,
|
||||
m21: 0.0,
|
||||
m22: 1.0,
|
||||
m23: 30.0,
|
||||
};
|
||||
|
||||
let mat4 = convert_matrix(&ufbx_matrix);
|
||||
|
||||
// Check that translation is preserved
|
||||
assert_eq!(mat4.w_axis.x, 10.0);
|
||||
assert_eq!(mat4.w_axis.y, 20.0);
|
||||
assert_eq!(mat4.w_axis.z, 30.0);
|
||||
assert_eq!(mat4.w_axis.w, 1.0);
|
||||
|
||||
// Check diagonal elements
|
||||
assert_eq!(mat4.x_axis.x, 1.0);
|
||||
assert_eq!(mat4.y_axis.y, 1.0);
|
||||
assert_eq!(mat4.z_axis.z, 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_convert_transform() {
|
||||
let ufbx_transform = ufbx::Transform {
|
||||
translation: ufbx::Vec3 {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
rotation: ufbx::Quat {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0,
|
||||
w: 1.0,
|
||||
},
|
||||
scale: ufbx::Vec3 {
|
||||
x: 2.0,
|
||||
y: 2.0,
|
||||
z: 2.0,
|
||||
},
|
||||
};
|
||||
|
||||
let transform = convert_transform(&ufbx_transform);
|
||||
|
||||
assert_eq!(transform.translation, Vec3::new(1.0, 2.0, 3.0));
|
||||
assert_eq!(transform.rotation, Quat::IDENTITY);
|
||||
assert_eq!(transform.scale, Vec3::new(2.0, 2.0, 2.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_convert_transform_with_rotation() {
|
||||
// Test with a 90-degree rotation around Y axis
|
||||
let half_sqrt2 = 0.7071067811865476;
|
||||
let ufbx_transform = ufbx::Transform {
|
||||
translation: ufbx::Vec3 {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0,
|
||||
},
|
||||
rotation: ufbx::Quat {
|
||||
x: 0.0,
|
||||
y: half_sqrt2,
|
||||
z: 0.0,
|
||||
w: half_sqrt2,
|
||||
},
|
||||
scale: ufbx::Vec3 {
|
||||
x: 1.0,
|
||||
y: 1.0,
|
||||
z: 1.0,
|
||||
},
|
||||
};
|
||||
|
||||
let transform = convert_transform(&ufbx_transform);
|
||||
|
||||
// Check rotation is preserved
|
||||
assert!((transform.rotation.x - 0.0).abs() < 0.001);
|
||||
assert!((transform.rotation.y - half_sqrt2 as f32).abs() < 0.001);
|
||||
assert!((transform.rotation.z - 0.0).abs() < 0.001);
|
||||
assert!((transform.rotation.w - half_sqrt2 as f32).abs() < 0.001);
|
||||
}
|
||||
Reference in new issue
Block a user