Skip to content

Commit

Permalink
chore(Bevy): Update to bevy 0.13 (kaosat-dev#136)
Browse files Browse the repository at this point in the history
* chore(crates): updated crates to Bevy 0.13
   * updated deps
   * updated / changed code where relevant
   * updated README files
   * bumped version numbers for upcoming release
   * updated rust-toolchain
   * updated assets where relevant
   * closes kaosat-dev#132 
* feat(bevy_gltf_components): 
  * added GltfProcessed flag component to improve performance of iteration over added<gltfExtras>
  * closes kaosat-dev#144 
  * light & shadow processing is now integrated,  to match  lights coming from Blender: you can now control whether 
  lights cast shadows, the cascade resolution , background color etc  from Blender
   * closes kaosat-dev#155 

* feat(bevy_registry_export): added boilerplate to make registry path relative to assets folder 
  * closes kaosat-dev#137 
* feat(tools): added boilerplate for internal tools
   * clean zip file generator for blender add-on releases
   * example gltf file generator
* feat(lighting): added components, exporter support & testing for blender-configurable shadows
   * added BlenderLightShadows component to bevy_gltf_components
   * added writing shadow information to gltf_auto_export
   * updated tests
   * closes kaosat-dev#157 

Co-authored-by: Jan Hohenheim <[email protected]>
  • Loading branch information
kaosat-dev and janhohenheim authored Mar 4, 2024
1 parent 9cb9dda commit 09915f5
Show file tree
Hide file tree
Showing 146 changed files with 7,017 additions and 2,170 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
key: ubuntu-latest-cargo-lint-${{ hashFiles('**/Cargo.toml') }}
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.75.0
toolchain: 1.76.0
components: rustfmt, clippy
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
Expand Down
28 changes: 11 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
[workspace]
members = [
"crates/bevy_gltf_components",
"crates/bevy_gltf_blueprints",
"crates/bevy_gltf_save_load",
"crates/bevy_registry_export",

"examples/common/",

"examples/bevy_gltf_components/basic/",
"examples/bevy_gltf_blueprints/basic/",
"examples/bevy_gltf_blueprints/basic_xpbd_physics/",
"examples/bevy_gltf_blueprints/animation/",
"examples/bevy_gltf_blueprints/multiple_levels_multiple_blendfiles",
"examples/bevy_gltf_blueprints/materials/",
"examples/bevy_gltf_save_load/basic/",
"examples/bevy_registry_export/basic",

"testing/bevy_example"
"crates/*",
"examples/common*",
"examples/bevy_gltf_components/*",
"examples/bevy_gltf_blueprints/*",
"examples/bevy_gltf_save_load/*",
"examples/bevy_registry_export/*",
"testing/bevy_example/",
]
resolver = "2"

Expand All @@ -30,6 +20,10 @@ match_same_arms = "warn"
semicolon_if_nothing_returned = "warn"

#### --------------------Dev/ debug-------------------------------
# Enable a small amount of optimization in debug mode
[profile.dev]
opt-level = 1

# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"]
opt-level = 3
Expand Down
13 changes: 6 additions & 7 deletions crates/bevy_gltf_blueprints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_gltf_blueprints"
version = "0.8.0"
version = "0.9.0"
authors = ["Mark 'kaosat-dev' Moissette"]
description = "Adds the ability to define Blueprints/Prefabs for [Bevy](https://bevyengine.org/) inside gltf files and spawn them in Bevy."
homepage = "https://github.com/kaosat-dev/Blender_bevy_components_workflow"
Expand All @@ -13,10 +13,9 @@ license = "MIT OR Apache-2.0"
[lints]
workspace = true

[dev-dependencies]
bevy = { version = "0.12", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf", "bevy_animation", "animation"] }

[dependencies]
bevy_gltf_components = "0.4"
#bevy_gltf_components = { path = "../bevy_gltf_components" }
bevy = { version = "0.12", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf", "bevy_animation", "animation"] }
bevy_gltf_components = { version = "0.5", path = "../bevy_gltf_components" }
bevy = { version = "0.13", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf", "bevy_animation", "animation"] }

[dev-dependencies]
bevy = { version = "0.13", default-features = false, features = ["dynamic_linking"] }
9 changes: 5 additions & 4 deletions crates/bevy_gltf_blueprints/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Here's a minimal usage example:
```toml
# Cargo.toml
[dependencies]
bevy="0.12"
bevy_gltf_blueprints = { version = "0.8"}
bevy="0.13"
bevy_gltf_blueprints = { version = "0.9"}

```

Expand Down Expand Up @@ -64,7 +64,7 @@ fn spawn_blueprint(
Add the following to your `[dependencies]` section in `Cargo.toml`:

```toml
bevy_gltf_blueprints = "0.8"
bevy_gltf_blueprints = "0.9"
```

Or use `cargo add`:
Expand Down Expand Up @@ -346,9 +346,10 @@ The main branch is compatible with the latest Bevy release, while the branch `be
Compatibility of `bevy_gltf_blueprints` versions:
| `bevy_gltf_blueprints` | `bevy` |
| :-- | :-- |
| `0.9` | `0.13` |
| `0.3 - 0.8` | `0.12` |
| `0.1 - 0.2` | `0.11` |
| branch `main` | `0.12` |
| branch `main` | `0.13` |
| branch `bevy_main` | `main` |


Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_gltf_blueprints/src/copy_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ impl CopyComponents {
};

for (component, type_id) in components {
let type_registry: &AppTypeRegistry = world.resource();
let type_registry = type_registry.clone();
let type_registry = type_registry.read();
let source = component
.reflect(world.get_entity(self.source).unwrap())
.unwrap()
Expand All @@ -90,7 +93,7 @@ impl CopyComponents {
// println!("contains typeid {:?} {}", type_id, destination.contains_type_id(type_id));
// we only want to copy components that are NOT already in the destination (ie no overwriting existing components)
if !destination.contains_type_id(type_id) {
component.insert(&mut destination, &*source);
component.insert(&mut destination, &*source, &type_registry);
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions crates/bevy_gltf_blueprints/src/materials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ pub struct MaterialInfo {
pub(crate) fn materials_inject(
mut blueprints_config: ResMut<BluePrintsConfig>,
material_infos: Query<(&MaterialInfo, &Children), Added<MaterialInfo>>,
with_materials_and_meshes: Query<(
With<Parent>,
With<Handle<StandardMaterial>>,
With<Handle<Mesh>>,
)>,
with_materials_and_meshes: Query<
(),
(
With<Parent>,
With<Handle<StandardMaterial>>,
With<Handle<Mesh>>,
),
>,
models: Res<Assets<bevy::gltf::Gltf>>,

asset_server: Res<AssetServer>,
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_gltf_components/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_gltf_components"
version = "0.4.0"
version = "0.5.0"
authors = ["Mark 'kaosat-dev' Moissette"]
description = "Allows you to define [Bevy](https://bevyengine.org/) components direclty inside gltf files and instanciate the components on the Bevy side."
homepage = "https://github.com/kaosat-dev/Blender_bevy_components_workflow"
Expand All @@ -13,10 +13,10 @@ license = "MIT OR Apache-2.0"
[lints]
workspace = true

[dev-dependencies]
bevy = { version = "0.12", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf"] }

[dependencies]
bevy = { version = "0.12", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf"] }
bevy = { version = "0.13", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf"] }
serde = "1.0.188"
ron = "0.8.1"

[dev-dependencies]
bevy = { version = "0.13", default-features = false, features = ["dynamic_linking"] }
19 changes: 15 additions & 4 deletions crates/bevy_gltf_components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Here's a minimal usage example:
```toml
# Cargo.toml
[dependencies]
bevy="0.12"
bevy_gltf_components = { version = "0.4"}
bevy="0.13"
bevy_gltf_components = { version = "0.5"}

```

Expand Down Expand Up @@ -60,7 +60,7 @@ bevy_gltf_components = { version = "0.4"}
Add the following to your `[dependencies]` section in `Cargo.toml`:

```toml
bevy_gltf_components = "0.4"
bevy_gltf_components = "0.5"
```

Or use `cargo add`:
Expand Down Expand Up @@ -104,6 +104,16 @@ Typically , the order of systems should be

***bevy_gltf_components (GltfComponentsSet::Injection)*** => ***replace_proxies***

## Additional features

- as of version 0.5 , this crate also includes automatic handling of lights in gltf files, to attempt to match Blender's eevee rendering as close as possible:
* **BlenderLightShadows** (automatically generated by the gltf_auto_export Blender add-on) allows you to toggle light's shadows on/off in Blender and have matching
behaviour in Bevy
* **BlenderBackgroundShader** aka background color is also automatically set on the Bevy side
* **BlenderShadowSettings** sets the cascade_size on the bevy side to match the one configured in Blender

If these components are present in your gltf file, they will be handled automatically by this crate, will be ignored otherwise.

## Examples

https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/basic
Expand All @@ -117,9 +127,10 @@ The main branch is compatible with the latest Bevy release, while the branch `be
Compatibility of `bevy_gltf_components` versions:
| `bevy_gltf_components` | `bevy` |
| :-- | :-- |
| `0.5` | `0.13` |
| `0.2 - 0.4` | `0.12` |
| `0.1` | `0.11` |
| branch `main` | `0.12` |
| branch `main` | `0.13` |
| branch `bevy_main` | `main` |


Expand Down
8 changes: 8 additions & 0 deletions crates/bevy_gltf_components/src/blender_settings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use bevy::prelude::*;

mod lighting;
pub use lighting::*;

pub(crate) fn plugin(app: &mut App) {
app.add_plugins(lighting::plugin);
}
97 changes: 97 additions & 0 deletions crates/bevy_gltf_components/src/blender_settings/lighting.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
use bevy::pbr::DirectionalLightShadowMap;
use bevy::prelude::*;

use crate::GltfComponentsSet;

pub(crate) fn plugin(app: &mut App) {
app.register_type::<BlenderBackgroundShader>()
.register_type::<BlenderShadowSettings>()
.register_type::<BlenderLightShadows>()
.add_systems(
Update,
(process_lights, process_shadowmap, process_background_shader)
.after(GltfComponentsSet::Injection),
);
}

#[derive(Component, Reflect, Default, Debug, PartialEq, Clone)]
#[reflect(Component)]
#[non_exhaustive]
/// The properties of a light's shadow , to enable controlling per light shadows from Blender
pub struct BlenderLightShadows {
pub enabled: bool,
pub buffer_bias: f32,
}

/// The background color as described by Blender's [background shader](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/background.html).
#[derive(Component, Reflect, Default, Debug, PartialEq, Clone)]
#[reflect(Component)]
#[non_exhaustive]
pub struct BlenderBackgroundShader {
pub color: Color,
pub strength: f32,
}

/// The settings used by EEVEE's [shadow rendering](https://docs.blender.org/manual/en/latest/render/eevee/render_settings/shadows.html).
#[derive(Component, Reflect, Default, Debug, PartialEq, Clone)]
#[reflect(Component)]
#[non_exhaustive]
pub struct BlenderShadowSettings {
pub cascade_size: usize,
}

fn process_lights(
mut directional_lights: Query<
(&mut DirectionalLight, Option<&BlenderLightShadows>),
Added<DirectionalLight>,
>,
mut spot_lights: Query<(&mut SpotLight, Option<&BlenderLightShadows>), Added<SpotLight>>,
mut point_lights: Query<(&mut PointLight, Option<&BlenderLightShadows>), Added<PointLight>>,
) {
for (mut light, blender_light_shadows) in directional_lights.iter_mut() {
if let Some(blender_light_shadows) = blender_light_shadows {
light.shadows_enabled = blender_light_shadows.enabled;
} else {
light.shadows_enabled = true;
}
}
for (mut light, blender_light_shadows) in spot_lights.iter_mut() {
if let Some(blender_light_shadows) = blender_light_shadows {
light.shadows_enabled = blender_light_shadows.enabled;
} else {
light.shadows_enabled = true;
}
}

for (mut light, blender_light_shadows) in point_lights.iter_mut() {
if let Some(blender_light_shadows) = blender_light_shadows {
light.shadows_enabled = blender_light_shadows.enabled;
} else {
light.shadows_enabled = true;
}
}
}

fn process_shadowmap(
shadowmaps: Query<&BlenderShadowSettings, Added<BlenderShadowSettings>>,
mut commands: Commands,
) {
for shadowmap in shadowmaps.iter() {
commands.insert_resource(DirectionalLightShadowMap {
size: shadowmap.cascade_size,
});
}
}

fn process_background_shader(
background_shaders: Query<&BlenderBackgroundShader, Added<BlenderBackgroundShader>>,
mut commands: Commands,
) {
for background_shader in background_shaders.iter() {
commands.insert_resource(AmbientLight {
color: background_shader.color,
// Just a guess, see <https://github.com/bevyengine/bevy/issues/12280>
brightness: background_shader.strength * 400.0,
});
}
}
32 changes: 23 additions & 9 deletions crates/bevy_gltf_components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ pub use ronstring_to_reflect_component::*;
pub mod process_gltfs;
pub use process_gltfs::*;

pub mod blender_settings;

use bevy::{
app::Startup,
ecs::system::{Res, Resource},
ecs::{
component::Component,
reflect::ReflectComponent,
system::{Res, Resource},
},
log::warn,
prelude::{App, IntoSystemConfigs, Plugin, SystemSet, Update},
reflect::Reflect,
};

/// A Bevy plugin for extracting components from gltf files and automatically adding them to the relevant entities
Expand Down Expand Up @@ -47,6 +54,11 @@ use bevy::{
///}
/// ```

/// this is a flag component to tag a processed gltf, to avoid processing things multiple times
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub struct GltfProcessed;

#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)]
/// systemset to order your systems after the component injection when needed
pub enum GltfComponentsSet {
Expand Down Expand Up @@ -76,13 +88,15 @@ fn check_for_legacy_mode(gltf_components_config: Res<GltfComponentsConfig>) {

impl Plugin for ComponentsFromGltfPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(GltfComponentsConfig {
legacy_mode: self.legacy_mode,
})
.add_systems(Startup, check_for_legacy_mode)
.add_systems(
Update,
(add_components_from_gltf_extras).in_set(GltfComponentsSet::Injection),
);
app.add_plugins(blender_settings::plugin)
.register_type::<GltfProcessed>()
.insert_resource(GltfComponentsConfig {
legacy_mode: self.legacy_mode,
})
.add_systems(Startup, check_for_legacy_mode)
.add_systems(
Update,
(add_components_from_gltf_extras).in_set(GltfComponentsSet::Injection),
);
}
}
Loading

0 comments on commit 09915f5

Please sign in to comment.