Expand description
§bevy_blender
bevy_blender is a Bevy library that allows you to use assets created in Blender directly from the .blend file.
§Usage
- Add
bevy_blender
to yourCargo.toml
dependencies. - Add
bevy_blender::BlenderPlugin
plugin to the bevyApp
- Load Blender assets (see examples)
§Supported Assets
- Meshes (using
AssetServer
) - Basic. not node-based, materials (using
AssetServer
) - Objects (using
BlenderObjectBundle
)
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.
§Example
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 open a .blend file located at assets/demo.blend
.
Macros§
- blender_
material - Takes a .blend file location and a material name and generates an appropriate asset_loader string. For example, blender_material!(“demo.blend”, “Material”) turns to “demo.blend#MAMaterial”.
- blender_
mesh - Takes a .blend file location and a mesh name and generates an appropriate asset_loader string. For example, blender_mesh!(“demo.blend”, “Suzanne”) turns to “demo.blend#MESuzanne”.
Structs§
- Blender
Object Bundle - A component bundle for Blender Object entities modeled after bevy_pbr::MaterialMeshBundle
- Blender
Plugin - Plugin for Bevy that allows for interaction with .blend files
Enums§
- Bevy
Blender Error - bevy_blender errors
Functions§
- get_
blend_ version - Takes a blend::Blend struct and returns the correct version tuple
- right_
hand_ zup_ to_ right_ hand_ yup - Takes a right handed, z up transformation matrix (Blender) and returns a right handed, y up (Bevy) version of it
- spawn_
blender_ object - Creates a BlenderObjectBundle for the object “root_object_name” and spaws it. This object will maintain its Blender transform and will have its material applied (if it is not nodes-based). If “spawn_children” is true, then all of the object’s children will also be created as BlenderObjectBundles and spawed as children of the root object. If parent_transform is Some(t), then t will be used as it’s transform. If parent_transform is None, then the object’s Blender transform will be used (and converted to the Bevy coordinate system).