Skip to content

Commit 1a1841b

Browse files
committed
Add bevy_fbx, an fbx loader based on ufbx
1 parent a16adc7 commit 1a1841b

File tree

13 files changed

+526
-1
lines changed

13 files changed

+526
-1
lines changed

Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ default = [
138138
"bevy_gilrs",
139139
"bevy_gizmos",
140140
"bevy_gltf",
141+
"bevy_fbx",
141142
"bevy_input_focus",
142143
"bevy_log",
143144
"bevy_mesh_picking_backend",
@@ -227,6 +228,8 @@ bevy_gilrs = ["bevy_internal/bevy_gilrs"]
227228

228229
# [glTF](https://www.khronos.org/gltf/) support
229230
bevy_gltf = ["bevy_internal/bevy_gltf", "bevy_asset", "bevy_scene", "bevy_pbr"]
231+
# [FBX](https://www.autodesk.com/products/fbx)
232+
bevy_fbx = ["bevy_internal/bevy_fbx", "bevy_asset", "bevy_scene", "bevy_pbr", "bevy_animation"]
230233

231234
# Adds PBR rendering
232235
bevy_pbr = [
@@ -1125,6 +1128,17 @@ description = "Loads and renders a glTF file as a scene, including the gltf extr
11251128
category = "3D Rendering"
11261129
wasm = true
11271130

1131+
[[example]]
1132+
name = "load_fbx"
1133+
path = "examples/3d/load_fbx.rs"
1134+
doc-scrape-examples = true
1135+
1136+
[package.metadata.example.load_fbx]
1137+
name = "Load FBX"
1138+
description = "Loads and renders an FBX file as a scene"
1139+
category = "3D Rendering"
1140+
wasm = false
1141+
11281142
[[example]]
11291143
name = "query_gltf_primitives"
11301144
path = "examples/3d/query_gltf_primitives.rs"

assets/models/cube/cube.fbx

25.8 KB
Binary file not shown.

crates/bevy_fbx/Cargo.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[package]
2+
name = "bevy_fbx"
3+
version = "0.16.0-dev"
4+
edition = "2024"
5+
description = "Bevy Engine FBX loading"
6+
homepage = "https://bevyengine.org"
7+
repository = "https://github.com/bevyengine/bevy"
8+
license = "MIT OR Apache-2.0"
9+
keywords = ["bevy"]
10+
11+
[dependencies]
12+
bevy_app = { path = "../bevy_app", version = "0.16.0-dev" }
13+
bevy_asset = { path = "../bevy_asset", version = "0.16.0-dev" }
14+
bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev" }
15+
bevy_scene = { path = "../bevy_scene", version = "0.16.0-dev", features = ["bevy_render"] }
16+
bevy_render = { path = "../bevy_render", version = "0.16.0-dev" }
17+
bevy_pbr = { path = "../bevy_pbr", version = "0.16.0-dev" }
18+
bevy_mesh = { path = "../bevy_mesh", version = "0.16.0-dev" }
19+
bevy_transform = { path = "../bevy_transform", version = "0.16.0-dev" }
20+
bevy_math = { path = "../bevy_math", version = "0.16.0-dev" }
21+
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev" }
22+
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
23+
bevy_platform = { path = "../bevy_platform", version = "0.16.0-dev", default-features = false, features = ["std"] }
24+
bevy_animation = { path = "../bevy_animation", version = "0.16.0-dev" }
25+
thiserror = "1"
26+
tracing = { version = "0.1", default-features = false, features = ["std"] }
27+
ufbx = "0.8"
28+
29+
[dev-dependencies]
30+
bevy_log = { path = "../bevy_log", version = "0.16.0-dev" }
31+
32+
[lints]
33+
workspace = true
34+
35+
[package.metadata.docs.rs]
36+
rustdoc-args = ["-Zunstable-options", "--generate-link-to-definition"]
37+
all-features = true

crates/bevy_fbx/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Bevy FBX Loader
2+
3+
This crate provides basic support for importing FBX files into Bevy using the [`ufbx`](https://github.com/ufbx/ufbx-rust) library.
4+
5+
The loader converts meshes contained in an FBX scene into Bevy [`Mesh`] assets and groups them into a [`Scene`].

crates/bevy_fbx/src/label.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//! Labels that can be used to load part of an FBX asset
2+
3+
use bevy_asset::AssetPath;
4+
5+
/// Labels that can be used to load part of an FBX
6+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7+
pub enum FbxAssetLabel {
8+
/// `Scene{}`: FBX Scene as a Bevy [`Scene`](bevy_scene::Scene)
9+
Scene(usize),
10+
/// `Mesh{}`: FBX Mesh as a Bevy [`Mesh`](bevy_mesh::Mesh)
11+
Mesh(usize),
12+
/// `Material{}`: FBX material as a Bevy [`StandardMaterial`](bevy_pbr::StandardMaterial)
13+
Material(usize),
14+
/// `Animation{}`: FBX animation as a Bevy [`AnimationClip`](bevy_animation::AnimationClip)
15+
Animation(usize),
16+
/// `Skeleton{}`: FBX skeleton as a Bevy [`Skeleton`](crate::Skeleton)
17+
Skeleton(usize),
18+
/// `DefaultMaterial`: fallback material used when no material is present
19+
DefaultMaterial,
20+
}
21+
22+
impl core::fmt::Display for FbxAssetLabel {
23+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
24+
match self {
25+
FbxAssetLabel::Scene(index) => f.write_str(&format!("Scene{index}")),
26+
FbxAssetLabel::Mesh(index) => f.write_str(&format!("Mesh{index}")),
27+
FbxAssetLabel::Material(index) => f.write_str(&format!("Material{index}")),
28+
FbxAssetLabel::Animation(index) => f.write_str(&format!("Animation{index}")),
29+
FbxAssetLabel::Skeleton(index) => f.write_str(&format!("Skeleton{index}")),
30+
FbxAssetLabel::DefaultMaterial => f.write_str("DefaultMaterial"),
31+
}
32+
}
33+
}
34+
35+
impl FbxAssetLabel {
36+
/// Add this label to an asset path
37+
pub fn from_asset(&self, path: impl Into<AssetPath<'static>>) -> AssetPath<'static> {
38+
path.into().with_label(self.to_string())
39+
}
40+
}
41+

0 commit comments

Comments
 (0)