Skip to content

Add bevy_fbx, an FBX loader based on ufbx #19534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ default = [
"bevy_gilrs",
"bevy_gizmos",
"bevy_gltf",
"bevy_fbx",
"bevy_input_focus",
"bevy_log",
"bevy_mesh_picking_backend",
Expand Down Expand Up @@ -227,6 +228,8 @@ bevy_gilrs = ["bevy_internal/bevy_gilrs"]

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

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

[[example]]
name = "load_fbx"
path = "examples/3d/load_fbx.rs"
doc-scrape-examples = true

[package.metadata.example.load_fbx]
name = "Load FBX"
description = "Loads and renders an FBX file as a scene"
category = "3D Rendering"
wasm = false

[[example]]
name = "query_gltf_primitives"
path = "examples/3d/query_gltf_primitives.rs"
Expand Down
Binary file added assets/models/cube/cube.fbx
Binary file not shown.
37 changes: 37 additions & 0 deletions crates/bevy_fbx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "bevy_fbx"
version = "0.16.0-dev"
edition = "2024"
description = "Bevy Engine FBX loading"
homepage = "https://bevyengine.org"
repository = "https://github.com/bevyengine/bevy"
license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[dependencies]
bevy_app = { path = "../bevy_app", version = "0.16.0-dev" }
bevy_asset = { path = "../bevy_asset", version = "0.16.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev" }
bevy_scene = { path = "../bevy_scene", version = "0.16.0-dev", features = ["bevy_render"] }
bevy_render = { path = "../bevy_render", version = "0.16.0-dev" }
bevy_pbr = { path = "../bevy_pbr", version = "0.16.0-dev" }
bevy_mesh = { path = "../bevy_mesh", version = "0.16.0-dev" }
bevy_transform = { path = "../bevy_transform", version = "0.16.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.16.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
bevy_platform = { path = "../bevy_platform", version = "0.16.0-dev", default-features = false, features = ["std"] }
bevy_animation = { path = "../bevy_animation", version = "0.16.0-dev" }
thiserror = "1"
tracing = { version = "0.1", default-features = false, features = ["std"] }
ufbx = "0.8"

[dev-dependencies]
bevy_log = { path = "../bevy_log", version = "0.16.0-dev" }

[lints]
workspace = true

[package.metadata.docs.rs]
rustdoc-args = ["-Zunstable-options", "--generate-link-to-definition"]
all-features = true
5 changes: 5 additions & 0 deletions crates/bevy_fbx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Bevy FBX Loader

This crate provides basic support for importing FBX files into Bevy using the [`ufbx`](https://github.com/ufbx/ufbx-rust) library.

The loader converts meshes contained in an FBX scene into Bevy [`Mesh`] assets and groups them into a [`Scene`].
41 changes: 41 additions & 0 deletions crates/bevy_fbx/src/label.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! Labels that can be used to load part of an FBX asset

use bevy_asset::AssetPath;

/// Labels that can be used to load part of an FBX
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FbxAssetLabel {
/// `Scene{}`: FBX Scene as a Bevy [`Scene`](bevy_scene::Scene)
Scene(usize),
/// `Mesh{}`: FBX Mesh as a Bevy [`Mesh`](bevy_mesh::Mesh)
Mesh(usize),
/// `Material{}`: FBX material as a Bevy [`StandardMaterial`](bevy_pbr::StandardMaterial)
Material(usize),
/// `Animation{}`: FBX animation as a Bevy [`AnimationClip`](bevy_animation::AnimationClip)
Animation(usize),
/// `Skeleton{}`: FBX skeleton as a Bevy [`Skeleton`](crate::Skeleton)
Skeleton(usize),
/// `DefaultMaterial`: fallback material used when no material is present
DefaultMaterial,
}

impl core::fmt::Display for FbxAssetLabel {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
FbxAssetLabel::Scene(index) => f.write_str(&format!("Scene{index}")),
FbxAssetLabel::Mesh(index) => f.write_str(&format!("Mesh{index}")),
FbxAssetLabel::Material(index) => f.write_str(&format!("Material{index}")),
FbxAssetLabel::Animation(index) => f.write_str(&format!("Animation{index}")),
FbxAssetLabel::Skeleton(index) => f.write_str(&format!("Skeleton{index}")),
FbxAssetLabel::DefaultMaterial => f.write_str("DefaultMaterial"),
}
}
}

impl FbxAssetLabel {
/// Add this label to an asset path
pub fn from_asset(&self, path: impl Into<AssetPath<'static>>) -> AssetPath<'static> {
path.into().with_label(self.to_string())
}
}

Loading
Loading