Crates.io | bevy_blender |
lib.rs | bevy_blender |
version | 0.10.0 |
source | src |
created_at | 2021-06-28 05:15:21.700569 |
updated_at | 2024-09-25 02:44:55.446088 |
description | bevy_blender is a Bevy library that allows you to use assets created in Blender directly from the .blend file |
homepage | |
repository | https://github.com/jeraldamo/bevy_blender |
max_upload_size | |
id | 415653 |
size | 9,410,053 |
bevy_blender is a Bevy library that allows you to use assets created in Blender directly from the .blend file.
This project is in maintenance mode for the time being. It is in a place that I am happy with, and it does all that I currently need it to do. I will address issues with easy fixes, and I will manage PRs if anybody wants to add more features (or make fixes). It has been fun though, and I will probably come back to it in the future.
Both of these projects are neat, but do not serve my desired use case. They both act as extensions of the Bevy game engine, using Blender almost as a front-end framework. I simply want to create assets in Blender and have a ridiculously easy way to access those assets in Bevy with a minimal amount of middle work.
bevy_blender
to your Cargo.toml
dependencies.bevy_blender::BlenderPlugin
plugin to the bevy App
bevy_blender makes use of Bevy's asset server. If Bevy detects that you are using a .blend file as an asset, bevy_blender will load every supported asset into the asset server. If you have a .blend file with a large asset that you do not wish to be loaded, you must prepend that asset's name with an underscore.
If the asset name in Blender starts with an underscore, it will not be loaded. You can use this to have extra assets in the .blend file that you do not want loaded to the AssetServer.
AssetServer
)AssetServer
); if a nodes based material exists, a warning will be given and a default clay-like material will be added to the asset server with the same name.BlenderObjectBundle
); the object's mesh and material will be pulled from the asset server, and if the Blender object did not have a material attached to it, a default pink material will be given.fn main() {
App::build()
.add_plugin(bevy_blender::BlenderPlugin)
.add_startup_system(setup.system())
// ...
.run();
}
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
// Spawn the Suzanne Blender object with children and its Blender transform
spawn_blender_object(&mut commands, &asset_server, "demo.blend", "Suzanne", true, None);
.expect("Error spawning Blender object");
// Spawn the Suzanne mesh with the Red material
commands.spawn_bundle(PbrBundle {
mesh: asset_server.load(blender_mesh!("demo.blend", "Suzanne")),
material: asset_server.load(blender_material!("demo.blend", "Red")),
..Default::default()
})
// ...
}
A suite of examples can be found in examples/
. Currently, there are three examples, one that shows how to import just a mesh, one that shows how to import just a material, and one that shows how to import whole objects. Simply run cargo run --example=object
(or example=mesh
, or example=material
) to execute it. This will import assets from a .blend file located at assets/demo.blend
. For example, running the materials example should look like this:
This project is essentially where I want to take it, at least for the near future. I am currently looking into creating an Open Shading Language based renderer for Bevy, which will open up the possibility to use Cycles materials. I will also be looking at the possibility of updating the Blend crate, as it has not been updated in a couple years. Doing this will allow me to provide better error handling and recovery from it as well (currently it panics at every error). Other tasks I might shoot for in the future are to apply modifiers before importing the mesh, adding first class hot reloading support, and add import support for textures, lighting, rigging, animations, and blend shapes,
If you have other ideas for how this project could be used, please let me know! I would also be more than happy if anybody were to submit a PR addressing these (or other) features
I am using X version of Bevy and Y version of Blender, which version of bevy_blender should I use?
bevy_blender Version | Supported Bevy Versions* | Supported Blender Versions* |
---|---|---|
0.1 | 0.5.x | <=2.93 |
0.7 | <=0.7.x | <=3.1 |
* Versions have not been exhaustively tested and assumptions have been made based off of available documentation.
These benchmarks are provided to give you an idea of relative time needed for importing Blender assets. All benchmarks were run on a computer with the following specs:
Note that the specs of the individual computer you are using will drastically change these numbers. However, this data should give you an idea of how one asset might load as compared to another. You can get these numbers on your machine by running cargo bench
.
Blender Version | Number of tris | Benchmarked import time |
---|---|---|
3.1 | 192 | 596us +- 26us |
3.1 | 768 | 2.3ms +- 109us |
3.1 | 3072 | 11.2ms +- 475us |
3.1 | 12288 | 48.0ms +- 1.3ms |
3.1 | 49125 | 205.8ms +- 4.4ms |