|
| 1 | +# Comprehensive FBX Structure Redesign |
| 2 | + |
| 3 | +Based on an in-depth analysis of the ufbx crate API, I have completely redesigned the `struct Fbx` to better capture the rich data that FBX files provide. This document outlines the major improvements and new capabilities. |
| 4 | + |
| 5 | +## 🚀 Major Improvements |
| 6 | + |
| 7 | +### 1. **Scene Hierarchy Preservation** |
| 8 | +- **Before**: Flattened scene with basic transform handling |
| 9 | +- **After**: Full scene hierarchy with proper parent-child relationships |
| 10 | + - `nodes: Vec<FbxNode>` - Complete node hierarchy |
| 11 | + - `root_node_ids: Vec<u32>` - Multiple root support |
| 12 | + - `node_indices: HashMap<u32, usize>` - Fast node lookup |
| 13 | + |
| 14 | +### 2. **Rich Data Structures** |
| 15 | + |
| 16 | +#### **FbxNode** - Complete Scene Node |
| 17 | +```rust |
| 18 | +pub struct FbxNode { |
| 19 | + pub name: String, |
| 20 | + pub id: u32, |
| 21 | + pub parent_id: Option<u32>, |
| 22 | + pub children_ids: Vec<u32>, |
| 23 | + pub local_transform: Transform, |
| 24 | + pub world_transform: Transform, |
| 25 | + pub visible: bool, |
| 26 | + pub mesh_id: Option<usize>, |
| 27 | + pub light_id: Option<usize>, |
| 28 | + pub camera_id: Option<usize>, |
| 29 | + pub material_ids: Vec<usize>, |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +#### **FbxMaterial** - Enhanced PBR Materials |
| 34 | +```rust |
| 35 | +pub struct FbxMaterial { |
| 36 | + pub name: String, |
| 37 | + pub base_color: Color, |
| 38 | + pub metallic: f32, |
| 39 | + pub roughness: f32, |
| 40 | + pub emission: Color, |
| 41 | + pub normal_scale: f32, |
| 42 | + pub alpha: f32, |
| 43 | + pub textures: HashMap<FbxTextureType, FbxTexture>, |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +#### **FbxLight** - Comprehensive Lighting |
| 48 | +```rust |
| 49 | +pub struct FbxLight { |
| 50 | + pub name: String, |
| 51 | + pub light_type: FbxLightType, // Directional, Point, Spot, Area, Volume |
| 52 | + pub color: Color, |
| 53 | + pub intensity: f32, |
| 54 | + pub cast_shadows: bool, |
| 55 | + pub inner_angle: Option<f32>, |
| 56 | + pub outer_angle: Option<f32>, |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +#### **FbxCamera** - Camera Support |
| 61 | +```rust |
| 62 | +pub struct FbxCamera { |
| 63 | + pub name: String, |
| 64 | + pub projection_mode: FbxProjectionMode, // Perspective, Orthographic |
| 65 | + pub field_of_view_deg: f32, |
| 66 | + pub aspect_ratio: f32, |
| 67 | + pub near_plane: f32, |
| 68 | + pub far_plane: f32, |
| 69 | + pub focal_length_mm: f32, |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +#### **FbxTexture** - Texture Information |
| 74 | +```rust |
| 75 | +pub struct FbxTexture { |
| 76 | + pub name: String, |
| 77 | + pub filename: String, |
| 78 | + pub absolute_filename: String, |
| 79 | + pub uv_set: String, |
| 80 | + pub uv_transform: Mat4, |
| 81 | + pub wrap_u: FbxWrapMode, |
| 82 | + pub wrap_v: FbxWrapMode, |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +### 3. **Animation System** |
| 87 | + |
| 88 | +#### **FbxAnimStack** - Animation Timeline |
| 89 | +```rust |
| 90 | +pub struct FbxAnimStack { |
| 91 | + pub name: String, |
| 92 | + pub time_begin: f64, |
| 93 | + pub time_end: f64, |
| 94 | + pub layers: Vec<FbxAnimLayer>, |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +#### **FbxAnimLayer** - Animation Layers |
| 99 | +```rust |
| 100 | +pub struct FbxAnimLayer { |
| 101 | + pub name: String, |
| 102 | + pub weight: f32, |
| 103 | + pub additive: bool, |
| 104 | + pub property_animations: Vec<FbxPropertyAnim>, |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +#### **FbxSkeleton** - Skeletal Animation |
| 109 | +```rust |
| 110 | +pub struct FbxSkeleton { |
| 111 | + pub name: String, |
| 112 | + pub root_bone: FbxBone, |
| 113 | + pub bones: Vec<FbxBone>, |
| 114 | + pub bone_indices: HashMap<String, usize>, |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +### 4. **Enhanced Metadata** |
| 119 | +```rust |
| 120 | +pub struct FbxMeta { |
| 121 | + pub creator: Option<String>, |
| 122 | + pub creation_time: Option<String>, |
| 123 | + pub original_application: Option<String>, |
| 124 | + pub version: Option<u32>, // NEW |
| 125 | + pub time_mode: Option<String>, // NEW |
| 126 | + pub time_protocol: Option<String>, // NEW |
| 127 | +} |
| 128 | +``` |
| 129 | + |
| 130 | +### 5. **Comprehensive Asset Labels** |
| 131 | +Extended `FbxAssetLabel` to support all new data types: |
| 132 | +- `Node(usize)` - Individual scene nodes |
| 133 | +- `Light(usize)` - Light definitions |
| 134 | +- `Camera(usize)` - Camera definitions |
| 135 | +- `Texture(usize)` - Texture references |
| 136 | +- `AnimationStack(usize)` - Animation stacks |
| 137 | +- `DefaultScene` - Main scene |
| 138 | +- `RootNode` - Scene root |
| 139 | + |
| 140 | +### 6. **Convenience Methods** |
| 141 | +Added comprehensive API for working with the scene hierarchy: |
| 142 | + |
| 143 | +```rust |
| 144 | +impl Fbx { |
| 145 | + pub fn get_node(&self, id: u32) -> Option<&FbxNode> |
| 146 | + pub fn get_node_by_name(&self, name: &str) -> Option<&FbxNode> |
| 147 | + pub fn get_root_nodes(&self) -> impl Iterator<Item = &FbxNode> |
| 148 | + pub fn get_children(&self, node_id: u32) -> Vec<&FbxNode> |
| 149 | + pub fn get_parent(&self, node_id: u32) -> Option<&FbxNode> |
| 150 | + pub fn get_mesh_nodes(&self) -> impl Iterator<Item = &FbxNode> |
| 151 | + pub fn get_light_nodes(&self) -> impl Iterator<Item = &FbxNode> |
| 152 | + pub fn get_camera_nodes(&self) -> impl Iterator<Item = &FbxNode> |
| 153 | + pub fn get_animation_time_range(&self) -> Option<(f64, f64)> |
| 154 | + pub fn has_animations(&self) -> bool |
| 155 | + pub fn has_skeletons(&self) -> bool |
| 156 | +} |
| 157 | +``` |
| 158 | + |
| 159 | +## 🎯 Data Organization |
| 160 | + |
| 161 | +The new `Fbx` struct is organized into logical sections: |
| 162 | + |
| 163 | +1. **Scene Structure** - Node hierarchy and relationships |
| 164 | +2. **Geometry and Visual Assets** - Meshes, materials, textures, lights, cameras |
| 165 | +3. **Animation Data** - Animation stacks, clips, skeletons |
| 166 | +4. **Bevy Scene Conversion** - Ready-to-use Bevy scenes and materials |
| 167 | +5. **Quick Lookups** - Hash maps for efficient name-based access |
| 168 | +6. **Scene Information** - Axis systems, units, timing, metadata |
| 169 | +7. **Legacy Compatibility** - Backwards compatibility support |
| 170 | +8. **Debug Information** - Raw data for development |
| 171 | + |
| 172 | +## 🔧 Technical Improvements |
| 173 | + |
| 174 | +### Type Safety |
| 175 | +- Changed IDs from `u64` to `u32` to match ufbx exactly |
| 176 | +- Added proper enum types for light types, projection modes, etc. |
| 177 | +- Strong typing for texture types and wrap modes |
| 178 | + |
| 179 | +### Performance |
| 180 | +- Efficient lookup tables for all named objects |
| 181 | +- Hierarchical data structures for fast traversal |
| 182 | +- Indexed access patterns |
| 183 | + |
| 184 | +### Extensibility |
| 185 | +- Modular design allows future expansion |
| 186 | +- TODO markers for future features (texture processing, advanced materials, etc.) |
| 187 | +- Clean separation between FBX data and Bevy conversions |
| 188 | + |
| 189 | +## 🚧 Implementation Status |
| 190 | + |
| 191 | +### ✅ Completed |
| 192 | +- Scene hierarchy processing |
| 193 | +- Basic mesh extraction and conversion |
| 194 | +- Node relationship preservation |
| 195 | +- Material and texture data structures |
| 196 | +- Animation data structures |
| 197 | +- Comprehensive API design |
| 198 | +- Asset label system |
| 199 | + |
| 200 | +### 🔄 TODO (Marked for Future Development) |
| 201 | +- Full texture processing and loading |
| 202 | +- Advanced material property extraction from FBX |
| 203 | +- Animation curve processing |
| 204 | +- Skeletal animation support |
| 205 | +- Light and camera processing |
| 206 | +- Advanced metadata extraction |
| 207 | + |
| 208 | +## 🎉 Benefits |
| 209 | + |
| 210 | +1. **Complete FBX Support**: The structure can now represent the full richness of FBX files |
| 211 | +2. **Proper Scene Hierarchy**: Maintains parent-child relationships and scene structure |
| 212 | +3. **Future-Proof**: Designed to accommodate all FBX features as they're implemented |
| 213 | +4. **Developer Friendly**: Rich API for accessing and manipulating FBX data |
| 214 | +5. **Bevy Integration**: Seamless conversion to Bevy's asset system |
| 215 | +6. **Performance**: Efficient data structures and lookup mechanisms |
| 216 | + |
| 217 | +This redesign transforms bevy_fbx from a basic mesh loader into a comprehensive FBX processing system that can handle the full complexity of modern FBX files while maintaining clean integration with Bevy's asset pipeline. |
0 commit comments