nicopap / bevy_mod_fbx Goto Github PK
View Code? Open in Web Editor NEWAutodesk Filmbox (*.fbx) loader for Bevy Engine
License: Apache License 2.0
Autodesk Filmbox (*.fbx) loader for Bevy Engine
License: Apache License 2.0
Hey @nicopap
Are you interested in incorporating this work into SpaceEditor?
You have done quite a lot and we could help you maintain this up to date and develop there
FBX is extensible, and it seems each vendor provide their own material extension.
For example, maya's PBR is implemented as an extension, it uses custom properties and texture fields unique to their materials.
I expect this is not only true of maya, and I expect that users of this library will want to load any arbitrary materials.
This is why a custom extensible material loader would be useful.
My current take is define a struct
with a few function pointer fields:
/// Load materials from an FBX file.
///
/// Define your own to extend `bevy_fbx`'s material loading capabilities.
#[derive(Clone, Copy)]
pub struct MaterialLoader {
/// The FBX texture field name used by the material you are loading.
///
/// They are loaded by the [`FbxLoader`] and provided to the other functions
/// defined in the rest of this struct, associated with their names in a `HashMap`.
// TODO: probably replace this with a fn(MaterialHandle) -> Vec<TextureHandle>
// and provide a fn that replaces &[&str]
pub to_load: &'static [&'static str],
/// Run some math on the loaded textures, handy if you have to convert between texture
/// formats or swap color channels.
///
/// Set this to None if you don't intend to pre-process textures
/// referenced in the FBX file.
/// This allows caching and re-using of textures, avoiding costly
/// read from disk of the entire texture.
// TODO: consider delegating to this the transform from {str->Image} to {str->Handle<Image>}
#[allow(clippy::type_complexity)]
pub preprocess_textures: Option<fn(MaterialHandle, &mut HashMap<&'static str, Image>)>,
/// Create and return the bevy [`StandardMaterial`] based on the [`Handle<Image>`] loaded
/// from the return value of `preprocess_textures`.
pub with_textures:
fn(MaterialHandle, HashMap<&'static str, Handle<Image>>) -> Option<StandardMaterial>,
}
and provide default implementations for Lambert/Phong and an ultimate white clay fallback. This seems to work quite nicely.
This is tracking issue for myself or anyone with access to closed source software which uses FBX SDK for exporting, such as:
(Blender uses reverse engieered exporter which may cause issues)
I don't really want to vendor different scenes from the internet which may cause issues with licensing which are usually unclear or scenes on various websites are vendored from different ones without any licensing info.
NOTE: Each scene must be <100mb and exported as FBX 7.4 (bin, not ASCII).
Example scenes:
Currently, the fbx scale is hard-coded to 100. It's fine as is, since it's the default, but a file where the scale is different will load incorrectly and appear tinny or giant when it shouldn't.
See:
fbx_validate
should log to console information if given version of given fbx file is supported and exit if not.
Caused by:
0: Failed to load geometry mesh
1: Triangulation failed
2: Unsupported polygon: 6-gon with two or more concave angles
Prevent future naming problems on crates.io.
Bevy uses tracing spans for easier debugging of runtimes.
We use the trace!
macro to check which function we enter/leave. There is absolutely no reason to not use tracing spans instead.
FBX has configurable coordinate space, the file itself specify which axis is up, forward etc. Most things that export to FBX currently uses the same coordinate space as bevy, so no further action is required for most models. But when bevy_mod_fbx encounters a file that doesn't use the same coordinate space as bevy, the model will not look properly forward.
Models in bevy_mod_fbx are already spawned with a parent transform, to accommodate scale declared with UnitScale. So we should probably rotate this transform to properly align the model into the bevy coordinate space.
Issue with that solution is situations where the model is mirrored, in which case we'll probably create a shear, which will prevent using the transform_scale_rotation
methods on GlobalTransform
Currently our dependency fbxcel_dom
doesn't support all kind of normals indexing. Can get sometimes get the following error:
Unsupported reference mode for normals: IndexToDirect
Implementation leads:
FBX has a scene tree similar to bevy's hierarchy. Currently we do not use it in any way.
The scene tree describes transforms applied to objects. The bistro scene relies on it for example to properly rotate the scene.
Bone transforms are (probably) also described in terms of parent/child relationships, so a solid support of the scene tree is a necessary condition to start supporting animations.
fbxcel_dom
currently exposes the scene tree as the Tree
data structure accessible through Document::tree
. An issue I think this has is that it doesn't expose the tree nodes as ObjectHandle
(there is good reasons for this), making it impossible to use the "fallback" values defined at the global level.
Ideal integration requires rewrite of all math related code in data, utils and triangulator to use bevy_math
instead of cgmath.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.