Process lights coming from Blender

This commit is contained in:
Jan Hohenheim 2024-03-03 23:22:08 +01:00
parent e68b230fc9
commit f9cc374ce8
No known key found for this signature in database
34 changed files with 3067 additions and 566 deletions

View File

@ -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_registry_export/basic"
"crates/*",
"examples/common",
"examples/bevy_gltf_components/*",
"examples/bevy_gltf_blueprints/*",
"examples/bevy_gltf_save_load/*",
"examples/bevy_registry_export/*",
"testing/bevy_registry_export/*",
]
resolver = "2"
@ -30,13 +20,14 @@ 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
[profile.dev.package.bevy]
features = ["dynamic"]
#### --------------------Production/ release-------------------------------
[profile.release]
strip = "debuginfo"

View File

@ -13,10 +13,9 @@ license = "MIT OR Apache-2.0"
[lints]
workspace = true
[dev-dependencies]
[dependencies]
bevy_gltf_components = { version = "0.4", path = "../bevy_gltf_components" }
bevy = { version = "0.13", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf", "bevy_animation", "animation"] }
[dependencies]
#bevy_gltf_components = "0.3"
bevy_gltf_components = { 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"] }

View File

@ -13,10 +13,10 @@ license = "MIT OR Apache-2.0"
[lints]
workspace = true
[dev-dependencies]
bevy = { version = "0.13", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf"] }
[dependencies]
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"] }

View File

@ -0,0 +1,8 @@
use bevy::prelude::*;
mod lighting;
pub use lighting::*;
pub(crate) fn plugin(app: &mut App) {
app.add_plugins(lighting::plugin);
}

View File

@ -0,0 +1,69 @@
use bevy::pbr::DirectionalLightShadowMap;
use bevy::prelude::*;
pub(crate) fn plugin(app: &mut App) {
app.register_type::<BlenderBackgroundShader>()
.register_type::<BlenderShadowSettings>()
.add_systems(
Update,
(process_lights, process_shadowmap, process_background_shader),
);
}
/// 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, Added<DirectionalLight>>,
mut spot_lights: Query<&mut SpotLight, Added<SpotLight>>,
mut point_lights: Query<&mut PointLight, Added<PointLight>>,
) {
for mut light in directional_lights.iter_mut() {
light.shadows_enabled = true;
}
for mut light in spot_lights.iter_mut() {
light.shadows_enabled = true;
}
for mut light in point_lights.iter_mut() {
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,
});
}
}

View File

@ -7,6 +7,8 @@ pub use ronstring_to_reflect_component::*;
pub mod process_gltfs;
pub use process_gltfs::*;
pub mod blender_settings;
use bevy::{
ecs::{component::Component, reflect::ReflectComponent, system::Resource},
prelude::{App, IntoSystemConfigs, Plugin, SystemSet, Update},
@ -74,7 +76,8 @@ impl Default for ComponentsFromGltfPlugin {
impl Plugin for ComponentsFromGltfPlugin {
fn build(&self, app: &mut App) {
app.register_type::<GltfProcessed>()
app.add_plugins(blender_settings::plugin)
.register_type::<GltfProcessed>()
.insert_resource(GltfComponentsConfig {
legacy_mode: self.legacy_mode,
})

View File

@ -13,10 +13,9 @@ license = "MIT OR Apache-2.0"
[lints]
workspace = true
[dev-dependencies]
bevy = { version = "0.13", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf"] }
[dependencies]
bevy = { version = "0.13", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf"] }
#bevy_gltf_blueprints = "0.7"
bevy_gltf_blueprints = { path = "../bevy_gltf_blueprints" }
bevy_gltf_blueprints = { version = "0.8", path = "../bevy_gltf_blueprints" }
[dev-dependencies]
bevy = { version = "0.13", default-features = false, features = ["dynamic_linking"] }

View File

@ -10,12 +10,12 @@ categories = ["game-development"]
edition = "2021"
license = "MIT OR Apache-2.0"
[dev-dependencies]
bevy = { version = "0.13", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf"] }
[dependencies]
bevy = { version = "0.13", default-features = false, features = ["bevy_scene"] }
bevy_reflect = { version = "0.13", default-features = false }
bevy_app = { version = "0.13", default-features = false, features = ["bevy_reflect"] }
bevy_ecs = { version = "0.13", default-features = false, features = ["bevy_reflect"] }
serde_json = "1.0.108"
[dev-dependencies]
bevy = { version = "0.13", default-features = false, features = ["dynamic_linking"] }

View File

@ -17,7 +17,7 @@ pub fn export_types(world: &mut World) {
let asset_root = world.resource::<AssetRoot>();
let registry_save_path = Path::join(&asset_root.0, &config.save_path);
println!("registry_save_path {:?}", registry_save_path);
println!("registry_save_path {}", registry_save_path.display());
let writer = File::create(registry_save_path).expect("should have created schema file");
let types = world.resource_mut::<AppTypeRegistry>();

View File

@ -5,7 +5,7 @@ edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
bevy="0.13"
bevy = { version = "0.13", features = ["dynamic_linking"] }
bevy_gltf_blueprints = { path = "../../../crates/bevy_gltf_blueprints" }
bevy_gltf_worlflow_examples_common = { path = "../../common" }
bevy_rapier3d = { version = "0.25.0", features = ["serde-serialize", "debug-render-3d", "enhanced-determinism"] }

View File

@ -5,7 +5,7 @@ edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
bevy="0.13"
bevy = { version = "0.13", features = ["dynamic_linking"] }
bevy_gltf_blueprints = { path = "../../../crates/bevy_gltf_blueprints" }
bevy_gltf_worlflow_examples_common = { path = "../../common" }
bevy_rapier3d = { version = "0.25.0", features = ["serde-serialize", "debug-render-3d", "enhanced-determinism"] }

View File

@ -5,7 +5,7 @@ edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
bevy="0.13"
bevy = { version = "0.13", features = ["dynamic_linking"] }
bevy_gltf_blueprints = { path = "../../../crates/bevy_gltf_blueprints" }
bevy_gltf_worlflow_examples_common = { path = "../../common", default-features = false, features = ["blueprints", "physics_xpbd"] }
bevy_xpbd_3d = "0.4"

View File

@ -5,7 +5,7 @@ edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
bevy="0.13"
bevy = { version = "0.13", features = ["dynamic_linking"] }
bevy_gltf_blueprints = { path = "../../../crates/bevy_gltf_blueprints" }
bevy_gltf_worlflow_examples_common = { path = "../../common" }
bevy_rapier3d = { version = "0.25.0", features = ["serde-serialize", "debug-render-3d", "enhanced-determinism"] }

View File

@ -5,7 +5,7 @@ edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
bevy="0.13"
bevy = { version = "0.13", features = ["dynamic_linking"] }
bevy_gltf_blueprints = { path = "../../../crates/bevy_gltf_blueprints" }
bevy_gltf_worlflow_examples_common = { path = "../../common" }
bevy_rapier3d = { version = "0.25.0", features = ["serde-serialize", "debug-render-3d", "enhanced-determinism"] }

View File

@ -5,6 +5,6 @@ edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
bevy="0.13"
bevy = { version = "0.13", features = ["dynamic_linking"] }
bevy_gltf_components = { path = "../../../crates/bevy_gltf_components" }
bevy_gltf_worlflow_examples_common = { path = "../../common" }

View File

@ -5,8 +5,7 @@ edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
bevy="0.13"
#bevy_gltf_blueprints = "0.7"
bevy = { version = "0.13", features = ["dynamic_linking"] }
bevy_gltf_blueprints = { path = "../../../crates/bevy_gltf_blueprints" }
bevy_gltf_save_load = { path = "../../../crates/bevy_gltf_save_load" }
bevy_gltf_worlflow_examples_common = { path = "../../common" }

View File

@ -5,7 +5,7 @@ edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
bevy="0.13"
bevy = { version = "0.13", features = ["dynamic_linking"] }
bevy_gltf_blueprints = { path = "../../../crates/bevy_gltf_blueprints" }
bevy_registry_export = { path = "../../../crates/bevy_registry_export" }
bevy_gltf_worlflow_examples_common = { path = "../../common" }

View File

@ -3455,6 +3455,50 @@
"type": "object",
"typeInfo": "Struct"
},
"bevy_gltf_components::blender_settings::lighting::BlenderBackgroundShader": {
"additionalProperties": false,
"isComponent": true,
"isResource": false,
"properties": {
"color": {
"type": {
"$ref": "#/$defs/bevy_render::color::Color"
}
},
"strength": {
"type": {
"$ref": "#/$defs/f32"
}
}
},
"required": [
"color",
"strength"
],
"short_name": "BlenderBackgroundShader",
"title": "bevy_gltf_components::blender_settings::lighting::BlenderBackgroundShader",
"type": "object",
"typeInfo": "Struct"
},
"bevy_gltf_components::blender_settings::lighting::BlenderShadowSettings": {
"additionalProperties": false,
"isComponent": true,
"isResource": false,
"properties": {
"cascade_size": {
"type": {
"$ref": "#/$defs/usize"
}
}
},
"required": [
"cascade_size"
],
"short_name": "BlenderShadowSettings",
"title": "bevy_gltf_components::blender_settings::lighting::BlenderShadowSettings",
"type": "object",
"typeInfo": "Struct"
},
"bevy_gltf_worlflow_examples_common::core::camera::camera_replace_proxies::SSAOSettings": {
"additionalProperties": false,
"isComponent": true,
@ -3512,7 +3556,7 @@
"type": "array",
"typeInfo": "TupleStruct"
},
"bevy_gltf_worlflow_examples_common::core::lighting::lighting_replace_proxies::AmbientLightSettings": {
"bevy_gltf_worlflow_examples_common::core::lighting::lighting_replace_proxies::BlenderBackgroundShader": {
"additionalProperties": false,
"isComponent": true,
"isResource": false,
@ -3532,12 +3576,12 @@
"color",
"brightness"
],
"short_name": "AmbientLightSettings",
"title": "bevy_gltf_worlflow_examples_common::core::lighting::lighting_replace_proxies::AmbientLightSettings",
"short_name": "BlenderBackgroundShader",
"title": "bevy_gltf_worlflow_examples_common::core::lighting::lighting_replace_proxies::BlenderBackgroundShader",
"type": "object",
"typeInfo": "Struct"
},
"bevy_gltf_worlflow_examples_common::core::lighting::lighting_replace_proxies::ShadowmapSettings": {
"bevy_gltf_worlflow_examples_common::core::lighting::lighting_replace_proxies::BlenderShadowSettings": {
"additionalProperties": false,
"isComponent": true,
"isResource": false,
@ -3551,8 +3595,8 @@
"required": [
"size"
],
"short_name": "ShadowmapSettings",
"title": "bevy_gltf_worlflow_examples_common::core::lighting::lighting_replace_proxies::ShadowmapSettings",
"short_name": "BlenderShadowSettings",
"title": "bevy_gltf_worlflow_examples_common::core::lighting::lighting_replace_proxies::BlenderShadowSettings",
"type": "object",
"typeInfo": "Struct"
},

View File

@ -12,7 +12,7 @@ default = ["blueprints", "physics_rapier"]
[dependencies]
bevy="0.13"
bevy = { version = "0.13", features = ["dynamic_linking"] }
bevy_gltf_blueprints = { path = "../../crates/bevy_gltf_blueprints", optional = true }
bevy_rapier3d = { version = "0.25", features = ["serde-serialize", "debug-render-3d", "enhanced-determinism"], optional = true }
bevy_xpbd_3d = { version = "0.4", optional = true }

View File

@ -4,14 +4,14 @@ use bevy::pbr::{CascadeShadowConfig, CascadeShadowConfigBuilder, DirectionalLigh
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub struct AmbientLightSettings {
pub struct BlenderBackgroundShader {
pub color: Color,
pub brightness: f32,
}
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub struct ShadowmapSettings {
pub struct BlenderShadowSettings {
pub size: usize,
}
@ -20,8 +20,8 @@ pub fn lighting_replace_proxies(
mut added_spotlights: Query<&mut SpotLight, Added<SpotLight>>,
mut added_pointlights: Query<&mut PointLight, Added<PointLight>>,
added_ambient_proxies: Query<&AmbientLightSettings, Added<AmbientLightSettings>>,
added_shadowmap_settings: Query<&ShadowmapSettings, Added<ShadowmapSettings>>,
added_ambient_proxies: Query<&BlenderBackgroundShader, Added<BlenderBackgroundShader>>,
added_shadowmap_settings: Query<&BlenderShadowSettings, Added<BlenderShadowSettings>>,
mut commands: Commands,
) {

View File

@ -7,8 +7,8 @@ use bevy::prelude::*;
pub struct LightingPlugin;
impl Plugin for LightingPlugin {
fn build(&self, app: &mut App) {
app.register_type::<AmbientLightSettings>()
.register_type::<ShadowmapSettings>()
app.register_type::<BlenderBackgroundShader>()
.register_type::<BlenderShadowSettings>()
// FIXME: adding these since they are missing
.register_type::<NotShadowCaster>()
.add_systems(PreUpdate, lighting_replace_proxies);

View File

@ -1,2 +1,2 @@
[toolchain]
channel = '1.76.0'
channel = 'stable'

View File

@ -5,12 +5,12 @@ edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
bevy="0.12"
bevy = { version = "0.13", features = ["dynamic_linking"] }
bevy_gltf_blueprints = { path = "../../../crates/bevy_gltf_blueprints" }
bevy_registry_export = { path = "../../../crates/bevy_registry_export" }
bevy_gltf_worlflow_examples_common = { path = "../../../examples/common" }
bevy_rapier3d = { version = "0.23.0", features = [ "serde-serialize", "debug-render-3d", "enhanced-determinism"] }
bevy_asset_loader = { version = "0.18", features = ["standard_dynamic_assets" ]}
bevy_editor_pls = { version = "0.6" }
bevy_rapier3d = { version = "0.25.0", features = ["serde-serialize", "debug-render-3d", "enhanced-determinism"] }
bevy_asset_loader = { version = "0.20", features = ["standard_dynamic_assets"] }
bevy_editor_pls = { version = "0.8" }
rand = "0.8.5"

File diff suppressed because it is too large Load Diff

View File

@ -6,10 +6,7 @@ pub struct CorePlugin;
impl Plugin for CorePlugin {
fn build(&self, app: &mut App) {
app.add_plugins((
ExportRegistryPlugin {
save_path: "assets/registry.json".into(),
..Default::default()
},
ExportRegistryPlugin::default(),
BlueprintsPlugin {
legacy_mode: false,
library_folder: "models/library".into(),

View File

@ -10,10 +10,7 @@ use bevy_gltf_worlflow_examples_common::{AppState, GameState};
pub struct GamePlugin;
impl Plugin for GamePlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
(spawn_test, spawn_test_unregisted_components).run_if(in_state(GameState::InGame)),
)
app.add_systems(Update, spawn_test.run_if(in_state(GameState::InGame)))
.add_systems(OnEnter(AppState::MenuRunning), setup_main_menu)
.add_systems(OnExit(AppState::MenuRunning), teardown_main_menu)
.add_systems(Update, main_menu.run_if(in_state(AppState::MenuRunning)))

View File

@ -1,5 +1,4 @@
use bevy::prelude::*;
use bevy_editor_pls::prelude::*;
use bevy_gltf_worlflow_examples_common::CommonPlugin;
mod core;
@ -15,8 +14,6 @@ fn main() {
App::new()
.add_plugins((
DefaultPlugins.set(AssetPlugin::default()),
// editor
EditorPlugin::default(),
// our custom plugins
CommonPlugin,
CorePlugin, // reusable plugins

View File

@ -3,7 +3,7 @@
expected_custom_property_values = {'AComponentWithAnExtremlyExageratedOrMaybeNotButCouldBeNameOrWut': '',
'Aabb': '(center: Vec3A(x:0.0, y:0.0, z:0.0), half_extents: Vec3A(x:0.0, y:0.0, z:0.0))',
'AdditionalMassProperties': 'Mass(0.0)',
'AmbientLightSettings': '(brightness: 0.0, color: Rgba(red:1.0, green:1.0, blue:0.0, alpha:1.0))',
'BlenderBackgroundShader': '(strength: 0.0, color: Rgba(red:1.0, green:1.0, blue:0.0, alpha:1.0))',
'AnimationPlayer': '(animation: "", paused: true)',
'Animations': '(named_animations: "")',
'AutoAABBCollider': 'Cuboid',
@ -126,7 +126,7 @@ expected_custom_property_values = {'AComponentWithAnExtremlyExageratedOrMaybeNot
'ScreenSpaceAmbientOcclusionSettings': '(quality_level: "")',
'Sensor': '',
'ShadowFilteringMethod': 'Hardware2x2',
'ShadowmapSettings': '(size: 0)',
'BlenderShadowSettings': '(cascade_size: 0)',
'SkinnedMesh': '(inverse_bindposes: Strong(""), joints: [])',
'Sleeping': '(angular_threshold: 0.0, linear_threshold: 0.0, sleeping: true)',
'SolverGroups': '(filters: (0), memberships: (0))',
@ -192,7 +192,7 @@ expected_custom_property_values_randomized = {'AComponentWithAnExtremlyExagerate
'Aabb': '(center: Vec3A(x:0.5714026093482971, y:0.42888906598091125, z:0.5780913233757019), half_extents: '
'Vec3A(x:0.20609822869300842, y:0.8133212327957153, z:0.8235888481140137))',
'AdditionalMassProperties': 'Mass(0.42888906598091125)',
'AmbientLightSettings': '(brightness: 0.5714026093482971, color: Rgba(red:0.42888906598091125, '
'BlenderBackgroundShader': '(strength: 0.5714026093482971, color: Rgba(red:0.42888906598091125, '
'green:0.5780913233757019, blue:0.20609822869300842, alpha:0.8133212327957153))',
'AnimationPlayer': '(animation: "", paused: true)',
'Animations': '(named_animations: "")',
@ -346,7 +346,7 @@ expected_custom_property_values_randomized = {'AComponentWithAnExtremlyExagerate
'ScreenSpaceAmbientOcclusionSettings': '(quality_level: "")',
'Sensor': '',
'ShadowFilteringMethod': 'Jimenez14',
'ShadowmapSettings': '(size: 73)',
'BlenderShadowSettings': '(cascade_size: 73)',
'SkinnedMesh': '(inverse_bindposes: Strong(""), joints: [0, 0])',
'Sleeping': '(angular_threshold: 0.5714026093482971, linear_threshold: 0.42888906598091125, sleeping: true)',
'SolverGroups': '(filters: (73), memberships: (4))',

View File

@ -17,9 +17,9 @@ def upsert_scene_components(scene, world, main_scene_names):
lighting_components = make_empty('lighting_components_'+scene.name, [0,0,0], [0,0,0], [0,0,0], root_collection)
if world is not None:
lighting_components['AmbientLightSettings'] = ambient_color_to_component(world)
lighting_components['BlenderBackgroundShader'] = ambient_color_to_component(world)
lighting_components['ShadowmapSettings'] = scene_shadows_to_component(scene)
lighting_components['BlenderShadowSettings'] = scene_shadows_to_component(scene)
if scene.eevee.use_bloom:
@ -40,22 +40,22 @@ def ambient_color_to_component(world):
color = world.node_tree.nodes['Background'].inputs[0].default_value
strength = world.node_tree.nodes['Background'].inputs[1].default_value
except Exception as ex:
print("failed to parse ambient color: Only backgroud is supported")
print("failed to parse ambient color: Only background is supported")
if color is not None and strength is not None:
colorRgba = "Rgba(red: "+ str(color[0]) + ", green: "+ str(color[1]) + ", blue: " + str(color[2]) + ", alpha: "+ str(color[3]) + ")" # TODO: YIKES clean this up
component = "( color:"+ str(colorRgba) +", brightness:"+str(strength)+")"
colorRgba = f"Rgba(red: {color[0]}, green: {color[1]}, blue: {color[2]}, alpha: {color[3]})"
component = f"( color: {colorRgba}, strength: {strength})"
return component
return None
def scene_shadows_to_component(scene):
cascade_resolution = scene.eevee.shadow_cascade_size
component = "(size: "+ cascade_resolution +")"
cascade_size = scene.eevee.shadow_cascade_size
component = f"(cascade_size: {cascade_size})"
return component
def scene_bloom_to_component(scene):
component = "BloomSettings(intensity: "+ str(scene.eevee.bloom_intensity) +")"
component = f"BloomSettings(intensity: {scene.eevee.bloom_intensity})"
return component
def scene_ao_to_component(scene):