-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read the FBX transform tree and assign entities for each node in the hierarchy, computing and setting the bevy `Transform` according to FBX's completely insane transform propagation algorithm. Also a few unrelated things (I'm sorry) This is also a first step toward loading skeleton rigs. - Correct the way the scene's `UnitScaleFactor` is applied: instead of dividing the vertices position by it, we just add the scale to the root node of the scene, this also requires dividing by default by 100.0 the scale of all FBX files. - Add a tool to print the FBX file content in the `dev_docs` directory - Add a "Contributing" section to the README - Fixes #26 - The Bistro scene's normals are broken, but this is a bevy bug: bevyengine/bevy#5514
- Loading branch information
Showing
12 changed files
with
731 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
fn print_children(depth: usize, children: Children) { | ||
let show_depth = depth * 3; | ||
for child in children { | ||
print!("{space:>depth$}", space = "", depth = show_depth); | ||
if child.name().len() > 1 { | ||
print!("{name} ", name = child.name(),); | ||
} | ||
let attr_display = |att: &AttributeValue| match att { | ||
AttributeValue::Bool(v) => v.to_string(), | ||
AttributeValue::I16(v) => v.to_string(), | ||
AttributeValue::I32(v) => v.to_string(), | ||
AttributeValue::I64(v) => v.to_string(), | ||
AttributeValue::F32(v) => v.to_string(), | ||
AttributeValue::F64(v) => v.to_string(), | ||
AttributeValue::ArrBool(_) => "[bool]".to_owned(), | ||
AttributeValue::ArrI32(_) => "[i32]".to_owned(), | ||
AttributeValue::ArrI64(_) => "[i64]".to_owned(), | ||
AttributeValue::ArrF32(_) => "[f32]".to_owned(), | ||
AttributeValue::ArrF64(_) => "[f64]".to_owned(), | ||
AttributeValue::String(s) => s.clone(), | ||
AttributeValue::Binary(_) => "[u8]".to_owned(), | ||
}; | ||
print!("["); | ||
for (i, attr) in child.attributes().iter().map(attr_display).enumerate() { | ||
// if matches!(i, 1 | 2 | 3) { | ||
// continue; | ||
// } | ||
if i == 0 { | ||
print!("{attr}: "); | ||
} else { | ||
print!("{attr}, "); | ||
} | ||
} | ||
println!("]"); | ||
if child.children().next().is_some() { | ||
println!("{:>depth$}{{", "", depth = show_depth); | ||
} | ||
print_children(depth + 1, child.children()); | ||
if child.children().next().is_some() { | ||
println!("{:>depth$}}}", "", depth = show_depth); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,54 @@ | ||
use bevy::{ | ||
asset::Handle, | ||
pbr::StandardMaterial, | ||
prelude::{Handle, Image, Mesh, StandardMaterial, Transform}, | ||
reflect::TypeUuid, | ||
render::{mesh::Mesh as BevyMesh, texture::Image}, | ||
utils::{HashMap, HashSet}, | ||
utils::HashMap, | ||
}; | ||
use fbxcel_dom::v7400::object::ObjectId; | ||
|
||
#[derive(Debug, Clone, TypeUuid)] | ||
#[uuid = "966d55c0-515b-4141-97a1-de30ac8ee44c"] | ||
pub struct FbxMesh { | ||
pub name: Option<String>, | ||
pub bevy_mesh_handles: Vec<Handle<BevyMesh>>, | ||
pub bevy_mesh_handles: Vec<Handle<Mesh>>, | ||
pub materials: Vec<Handle<StandardMaterial>>, | ||
} | ||
|
||
/// The data loaded from a FBX scene. | ||
/// | ||
/// Note that the loader spawns a [`Scene`], with all the | ||
/// FBX nodes spawned as entities (with their corresponding [`Name`] set) | ||
/// in the ECS, | ||
/// and you should absolutely use the ECS entities over | ||
/// manipulating this data structure. | ||
/// It is provided publicly, because it might be a good store for strong handles. | ||
/// | ||
/// [`Scene`]: bevy::scene::Scene | ||
/// [`Name`]: bevy::core::Name | ||
#[derive(Default, Debug, Clone, TypeUuid)] | ||
#[uuid = "e87d49b6-8d6a-43c7-bb33-5315db8516eb"] | ||
pub struct FbxScene { | ||
pub name: Option<String>, | ||
pub bevy_meshes: HashMap<Handle<BevyMesh>, String>, | ||
pub bevy_meshes: HashMap<Handle<Mesh>, String>, | ||
pub materials: HashMap<String, Handle<StandardMaterial>>, | ||
pub textures: HashMap<String, Handle<Image>>, | ||
pub meshes: HashSet<Handle<FbxMesh>>, | ||
pub meshes: HashMap<ObjectId, Handle<FbxMesh>>, | ||
pub hierarchy: HashMap<ObjectId, FbxObject>, | ||
pub roots: Vec<ObjectId>, | ||
} | ||
|
||
/// An FBX object in the scene tree. | ||
/// | ||
/// This serves as a node in the transform hierarchy. | ||
#[derive(Default, Debug, Clone)] | ||
pub struct FbxObject { | ||
pub name: Option<String>, | ||
pub transform: Transform, | ||
/// The children of this node. | ||
/// | ||
/// # Notes | ||
/// Not all [`ObjectId`] declared as child of an `FbxObject` | ||
/// are relevant to Bevy. | ||
/// Meaning that you won't find the `ObjectId` in `hierarchy` or `meshes` | ||
/// `HashMap`s of the [`FbxScene`] structure. | ||
pub children: Vec<ObjectId>, | ||
} |
Oops, something went wrong.