├── .editorconfig ├── .github ├── FUNDING.yml └── workflows │ └── ci.yml ├── .gitignore ├── CONTRIBUTING.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── assets └── cube.fbx ├── dev_docs ├── custom_material_design.md └── fbx_tree_printer.rs ├── examples ├── cube.rs └── scene_viewer.rs ├── scripts ├── test_wasm.html └── test_wasm.sh └── src ├── data.rs ├── fbx_transform.rs ├── lib.rs ├── loader.rs ├── material_loader.rs └── utils ├── fbx_extend.rs ├── mod.rs └── triangulate.rs /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_size = 4 6 | indent_style = tab 7 | end_of_line = crlf 8 | max_line_length = 80 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [*.rs] 13 | indent_size = 4 14 | indent_style = space 15 | 16 | [*.toml] 17 | indent_size = 2 18 | indent_style = space 19 | 20 | [*.yml] 21 | indent_size = 2 22 | indent_style = space 23 | 24 | [*.md] 25 | indent_style = space 26 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [nicopap, HeavyRain266] 2 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Continous Integration 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | 9 | env: 10 | CARGO_TERM_COLORS: always 11 | 12 | jobs: 13 | clippy_check: 14 | name: Clippy 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Checkout sources 18 | uses: actions/checkout@v3 19 | - name: Cache 20 | uses: actions/cache@v2 21 | with: 22 | path: | 23 | ~/.cargo/bin/ 24 | ~/.cargo/registry/index/ 25 | ~/.cargo/registry/cache/ 26 | ~/.cargo/git/db/ 27 | target/ 28 | key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.toml') }} 29 | - name: Install stable toolchain 30 | uses: actions-rs/toolchain@v1 31 | with: 32 | toolchain: stable 33 | profile: minimal 34 | components: clippy 35 | override: true 36 | - name: Install Dependencies 37 | run: sudo apt-get update; sudo apt-get install pkg-config libx11-dev libasound2-dev libudev-dev 38 | - name: Run clippy 39 | uses: actions-rs/clippy-check@v1 40 | with: 41 | token: ${{ secrets.GITHUB_TOKEN }} 42 | args: --examples -- -D warnings 43 | - name: Run clippy for optional features 44 | uses: actions-rs/clippy-check@v1 45 | with: 46 | token: ${{ secrets.GITHUB_TOKEN }} 47 | args: --examples --features maya_3dsmax_pbr -- -D warnings 48 | 49 | format: 50 | name: Format 51 | runs-on: ubuntu-latest 52 | steps: 53 | - name: Checkout sources 54 | uses: actions/checkout@v2 55 | - name: Install stable toolchain 56 | uses: actions-rs/toolchain@v1 57 | with: 58 | toolchain: stable 59 | profile: minimal 60 | components: rustfmt 61 | override: true 62 | - name: Run cargo fmt 63 | uses: actions-rs/cargo@v1 64 | with: 65 | command: fmt 66 | args: --all -- --check 67 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Cargo 2 | /target 3 | Cargo.lock 4 | 5 | # Nix/NixOS 6 | .envrc # direnv 7 | shell.nix 8 | flake.nix 9 | flake.lock 10 | 11 | # VScode 12 | .vscode 13 | 14 | # Jetbrains 15 | .idea 16 | .fleet 17 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ### About 4 | 5 | FBX is a very widely used and flexible file format. 6 | We currently expect most models **to not load properly**. 7 | We cannot test how `bevy_mod_fbx` handles the export formats of every software out there. 8 | If your model loads properly, thank your lucky start, 9 | if you encounter any issue please do the following: 10 | 11 | - Try opening the model using the `scene_viewer` (run `cargo run --example scene_viewer --release -- /path/to/file.fbx`) 12 | (if your file has textures, make sure to enable the correct file formats using `--features bevy/png bevy/jpg bevy/tga` etc.) 13 | - If it fails, open an [issue] on our Github repo with a screenshot in the scene viewer 14 | and a screenshot of how the model should look like 15 | - Ideally provide a download link to your FBX model 16 | 17 | #### What have to be done 18 | 19 | - [ ] Proper handling of Coordinate system 20 | - [ ] Support `bevy_animation` as optional feature ([#13]) 21 | - [ ] Provide examples with usage of complex scenes ([#6]) 22 | - [ ] Convert lambert into PBR and load materials ([#12]) 23 | - [ ] Expand/rewrite triangulator ([#11]) 24 | 25 | #### Commiting changes 26 | 27 | Before you commit any changes, ensure that `rustfmt` is installed and then run `cargo fmt`. 28 | 29 | #### Further troubleshooting tools 30 | 31 | If you want to help us figure out how to load a particularly tricky model, 32 | the following tools may be useful: 33 | 34 | - 35 | - 36 | - Use the `profile` feature with the [profiling] instructions from Bevy Engine 37 | 38 | ### Licensing 39 | 40 | Unless you explicitly state otherwise, 41 | any contribution intentionally submitted for inclusion in the work by you, 42 | as defined in the Apache-2.0 license, shall be dual licensed 43 | as in the [License](#license) section, 44 | without any additional terms or conditions. 45 | 46 | [issue]: https://github.com/HeavyRain266/bevy_mod_fbx/issues/new/choose 47 | [profiling]: https://github.com/bevyengine/bevy/blob/main/docs/profiling.md 48 | 49 | [#13]: https://github.com/HeavyRain266/bevy_mod_fbx/issues/13 50 | [#6]: https://github.com/HeavyRain266/bevy_mod_fbx/issues/6 51 | [#12]: https://github.com/HeavyRain266/bevy_mod_fbx/issues/12 52 | [#11]: https://github.com/HeavyRain266/bevy_mod_fbx/issues/11 53 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bevy_mod_fbx" 3 | authors = ["Nicola Papale", "HeavyRain266"] 4 | description = "Autodesk Filmbox (*.fbx) loader for Bevy Engine" 5 | license = "MIT OR Apache-2.0" 6 | readme = "README.md" 7 | keywords = ["bevy", "bevy_plugin", "fbx_loader"] 8 | categories = ["game-development"] 9 | repository = "https://github.com/nicopap/bevy_mod_fbx" 10 | exclude = ["assets/**/*", "scripts/**/*", ".github/**/*"] 11 | version = "0.4.0" 12 | edition = "2021" 13 | 14 | [features] 15 | profile = [] 16 | maya_3dsmax_pbr = [] 17 | 18 | [dependencies] 19 | rgb = "0.8" 20 | anyhow = "1.0.58" 21 | glam = { version = "0.23", features = ["mint"] } 22 | mint = "0.5" 23 | # fbxcel-dom = { version = "0.0.9", path = "../fbxcel-dom" } 24 | fbxcel-dom = "0.0.9" 25 | 26 | [dependencies.bevy] 27 | version = "0.10" 28 | default-features = false 29 | features = [ 30 | "bevy_pbr", 31 | "bevy_asset", 32 | "bevy_render", 33 | "bevy_scene", 34 | ] 35 | 36 | [dev-dependencies.bevy] 37 | version = "0.10" 38 | default-features = false 39 | features = [ 40 | "x11", #"wayland", 41 | 42 | "tga", "dds", 43 | "bevy_pbr", 44 | "bevy_render", 45 | "bevy_winit", 46 | "bevy_scene", 47 | "filesystem_watcher", 48 | "bevy_core_pipeline" 49 | ] 50 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bevy_mod_fbx 2 | 3 | Autodesk Filmbox (*.fbx) loader for Bevy Engine. 4 | 5 | **Special Credit**: Thanks to the original author HeavyRain266 for starting the project. 6 | `bevy_mod_fbx` is now maintained by someone else. 7 | 8 | ### Features 9 | 10 | - Load meshes, textures & material properties 11 | - Supported material properties: 12 | - normal maps 13 | - occlusion maps 14 | - diffuse texture 15 | - Maya PBR material support 16 | - Scene tree transform hierarchy support 17 | 18 | #### Planned features 19 | 20 | - Skeleton rig imports 21 | - `bevy_animation` support 22 | - Optional lambert material shader support 23 | - Optional phong shading model support 24 | - Extended compatibility: 25 | - `IndexToDirect` 26 | - Handle file-based axis properties 27 | - Handle backed cameras & lights 28 | - N-gon triangulation 29 | 30 | ### Limitations 31 | 32 | - FBX v7.4 & 7.5 are the only supported versions 33 | - FBX doesn't support multiple scenes in single file, use multiple files instead 34 | - There are no plans for loading ASCII format, export FBX as binary v7.4/7.5 35 | - There is no support for complex shapes at the moment, see [#11] 36 | 37 | ### Cargo features 38 | 39 | #### `profile` 40 | 41 | Enables spans, in combination with bevy's `bevy/trace` feature, 42 | you can generate profiling reports you can open with any trace reading software. 43 | Useful for debugging why your assets are so slow to load. 44 | 45 | #### `maya_3dsmax_pbr` 46 | 47 | Enable handling of Maya's PBR material extension for FBX (presumebly also 3DS max). 48 | This is highly experimental and only tested with a single model! 49 | Please report if your model's materials do not load properly. 50 | 51 | This material loader do not work with every type of texture files, 52 | the textures must be readable from CPU and have each component (color channel) 53 | be exactly 8 bits (such as PNG). 54 | 55 | ### Examples 56 | 57 | - `cube`: Load simple cube with point light 58 | - `scene_viewer`: Load any FBX files from `/path/to/file.fbx`, defaults to `assets/cube.fbx` 59 | 60 | Run example: 61 | 62 | ```sh 63 | # Regular dev build 64 | cargo run --example 65 | 66 | # Faster asset loading 67 | cargu run --example --release --features bevy/dynamic 68 | ``` 69 | 70 | ### Version matrix 71 | 72 | | bevy | bevy_mod_fbx | 73 | |------|--------------| 74 | | 0.10 | 0.4 | 75 | | 0.9 | 0.3 | 76 | | 0.8 | 0.1.0-dev | 77 | 78 | ## Contributing 79 | 80 | See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed informations. 81 | 82 | ## License 83 | 84 | Original loader and triangulation code (`loader.rs` and `triangulate.rs`) from [fbx_viewer] by YOSHIOKA Takuma. 85 | Original scene viewer code (`scene_viewer.rs`) from [scene_viewer] by Bevy contributors. 86 | All additions and modifications authored by `bevy_mod_fbx` contributors (see git log). 87 | 88 | Code copyrights go to their respective authors. 89 | 90 | All code in `bevy_mod_fbx` is licensed under either: 91 | 92 | - Apache License 2.0 93 | - MIT License 94 | 95 | at your option. 96 | 97 | [#11]: https://github.com/HeavyRain266/bevy_mod_fbx/issues/11 98 | 99 | [fbx_viewer]: https://github.com/lo48576/fbx-viewer/ 100 | [bevy_scene_viewer]: https://github.com/bevyengine/bevy/blob/115211161b783a2f5c39346caeb8ee6b3b202bef/examples/tools/scene_viewer.rs 101 | -------------------------------------------------------------------------------- /assets/cube.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicopap/bevy_mod_fbx/22666481afa537803a35b769e4289204fd5046c1/assets/cube.fbx -------------------------------------------------------------------------------- /dev_docs/custom_material_design.md: -------------------------------------------------------------------------------- 1 | # Custom materials 2 | 3 | FBX is a widespread standard. 4 | Each individual software that works with FBX has their own material definition, 5 | implemented as custom extensions to the basic FBX model. 6 | 7 | It is likely that the library user will want to load a material type that we, 8 | as library developers, did not or couldn't anticipate. 9 | 10 | To still allow them to load their material types, we define an API 11 | for the user to provide their own material loader. 12 | 13 | ## API requirements 14 | 15 | * Provide default loaders for lambert/phong 16 | * Provide loader attempt order, so that the first to "win" is the one loaded. 17 | Loader should be able to say "I can't load that", to let other loaders try 18 | * Ability to load assets like `Image`s 19 | * _Direct access to `Image`_ (not just `Handle`) so that they 20 | can be combined (in the case of Maya's PBR, reflection and metalicness 21 | maps are two different textures, they need to be combined for bevy's PBR) 22 | * This requires ability to register `Handle`s 23 | (maybe? Could we provide an untyped `Handle` registration API?) 24 | * Should be able to separate async operations from pure operations 25 | For example, the loader could give a list of asset paths to load 26 | and a function that takes the deserialized typed assets from those paths 27 | and return a new asset. 28 | (because `async` fundamentally composes poorly with combinators like 29 | `Iterator` or `Option` and `Result`) 30 | * Loader should be able to take a single `MaterialHandle` from `fbxcell_dom` lib 31 | and return a sort of material component. 32 | * (optional) Ability to load other types of assets 33 | * (optional) Ability to return more than just bevy's `StandardMaterial` PBR shader 34 | * (optional) Provide loaders for FBX extensions like Maya's PBR 35 | 36 | ## How to solve this 37 | 38 | Ideally, bevy provides a **composable loader API**. 39 | 40 | However, let's point out there are two types of asset composition: 41 | * Taking multiple assets and combining them into one, 42 | such as with the reflection/metalicness map example from earlier. 43 | * I guess we could just create a new component that creates the new 44 | texture based on the two old ones after loading and replace them 45 | with the combined version? 46 | * Taking handles to existing assets and using them in new assets. 47 | 48 | But we are working with today's bevy, so we have to go with a bespoke solution. 49 | 50 | ### Design 51 | 52 | See https://github.com/HeavyRain266/bevy_mod_fbx/issues/18 53 | 54 | Maybe we should _delegate_ fbx material loading to a different `AssetLoader`? 55 | How would that work? I'd like to be able to give it a `MaterialHandle`, 56 | not a file path or a `Vec`. 57 | 58 | #### Proper handling of `Handle`s 59 | 60 | **Problem**: We want to cache textures with a globally identifying name, 61 | so that it's possible to re-use the same handle instead of loading it 62 | again. 63 | But lose the exact mapping of fbxcel `TextureHandle` to label after running 64 | `preprocess_textures`. 65 | How to reconciliate? 66 | 67 | - If we pre-process, we lose the 1-to-1 mapping between `TextureHandle` and 68 | bevy `Handle`. 69 | - We generally want to "store" the `Image`s as they are output by the 70 | `preprocess_textures` function. 71 | - The caching requires 72 | - **being executed before the image is loaded** 73 | - a `&mut` access to the `scene` in the loader 74 | - a `&mut` access to the `LoadContext` to create the asset 75 | 76 | **Solution**: Split the list of loaded textures in two. 77 | 78 | The resulting code is still very awkward, but it's still better than before. 79 | 80 | This is hopeless anyway (well it depends) because merging two different textures 81 | requires being able to read and edit the texture format, which is far from trivial 82 | in bevy. -------------------------------------------------------------------------------- /dev_docs/fbx_tree_printer.rs: -------------------------------------------------------------------------------- 1 | fn print_children(depth: usize, children: Children) { 2 | let show_depth = depth * 3; 3 | for child in children { 4 | print!("{space:>depth$}", space = "", depth = show_depth); 5 | if child.name().len() > 1 { 6 | print!("{name} ", name = child.name(),); 7 | } 8 | let attr_display = |att: &AttributeValue| match att { 9 | AttributeValue::Bool(v) => v.to_string(), 10 | AttributeValue::I16(v) => v.to_string(), 11 | AttributeValue::I32(v) => v.to_string(), 12 | AttributeValue::I64(v) => v.to_string(), 13 | AttributeValue::F32(v) => v.to_string(), 14 | AttributeValue::F64(v) => v.to_string(), 15 | AttributeValue::ArrBool(_) => "[bool]".to_owned(), 16 | AttributeValue::ArrI32(_) => "[i32]".to_owned(), 17 | AttributeValue::ArrI64(_) => "[i64]".to_owned(), 18 | AttributeValue::ArrF32(_) => "[f32]".to_owned(), 19 | AttributeValue::ArrF64(_) => "[f64]".to_owned(), 20 | AttributeValue::String(s) => s.clone(), 21 | AttributeValue::Binary(_) => "[u8]".to_owned(), 22 | }; 23 | print!("["); 24 | for (i, attr) in child.attributes().iter().map(attr_display).enumerate() { 25 | // if matches!(i, 1 | 2 | 3) { 26 | // continue; 27 | // } 28 | if i == 0 { 29 | print!("{attr}: "); 30 | } else { 31 | print!("{attr}, "); 32 | } 33 | } 34 | println!("]"); 35 | if child.children().next().is_some() { 36 | println!("{:>depth$}{{", "", depth = show_depth); 37 | } 38 | print_children(depth + 1, child.children()); 39 | if child.children().next().is_some() { 40 | println!("{:>depth$}}}", "", depth = show_depth); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /examples/cube.rs: -------------------------------------------------------------------------------- 1 | use bevy::{ 2 | log::{Level, LogPlugin}, 3 | prelude::*, 4 | render::camera::ScalingMode, 5 | window::{close_on_esc, WindowResolution}, 6 | }; 7 | use bevy_mod_fbx::FbxPlugin; 8 | 9 | #[derive(Component)] 10 | pub struct Spin; 11 | 12 | fn main() { 13 | let mut app = App::new(); 14 | 15 | app.add_plugins( 16 | DefaultPlugins 17 | .set(LogPlugin { 18 | level: Level::INFO, 19 | filter: "bevy_mod_fbx=trace,wgpu=warn".to_owned(), 20 | }) 21 | .set(WindowPlugin { 22 | primary_window: Some(Window { 23 | title: "Spinning Cube".into(), 24 | resolution: WindowResolution::new(756., 574.), 25 | ..default() 26 | }), 27 | ..default() 28 | }), 29 | ) 30 | .add_plugin(FbxPlugin) 31 | .add_startup_system(setup) 32 | .add_system(spin_cube) 33 | .add_system(close_on_esc); 34 | 35 | app.run(); 36 | } 37 | 38 | fn spin_cube(time: Res