GithubHelp home page GithubHelp logo

nicopap / bevy_mod_fbx Goto Github PK

View Code? Open in Web Editor NEW
18.0 2.0 4.0 120 KB

Autodesk Filmbox (*.fbx) loader for Bevy Engine

License: Apache License 2.0

Rust 97.02% HTML 0.34% Shell 2.64%
bevy bevy-plugin fbx loader

bevy_mod_fbx's People

Contributors

heavyrain266 avatar nicopap avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bevy_mod_fbx's Issues

Incorporate in Space_editor

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

Support user-provided material loader

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.

Prepare custom FBX scenes for complex examples

This is tracking issue for myself or anyone with access to closed source software which uses FBX SDK for exporting, such as:

  • Cinema4D S26
  • Rhinoceros 7
  • Autodesk Maya 2022
  • Autodesk 3ds Max 2022

(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:

  • Isometric room
  • Old vehicle (like multicar/fiat 125p)
  • Simple biome (textured/low poly)
  • Simple viking village (low poly, entities)
  • Post-apo village/city (like Jackson or part of Boston/Seattle but low poly/voxel)

Replace `trace` logs with tracing spans

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.

Use fbx global_config axis to properly rotate scenes

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.

Solutions

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

Load the scene tree

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.

Switch to bevy_math

Ideal integration requires rewrite of all math related code in data, utils and triangulator to use bevy_math instead of cgmath.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.