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
This commit is contained in:
parent
851dfa5a31
commit
68bb7ed4cc
|
@ -1,15 +1,28 @@
|
|||
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),
|
||||
(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)]
|
||||
|
@ -28,21 +41,36 @@ pub struct BlenderShadowSettings {
|
|||
}
|
||||
|
||||
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>>,
|
||||
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 in directional_lights.iter_mut() {
|
||||
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 in spot_lights.iter_mut() {
|
||||
}
|
||||
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 in point_lights.iter_mut() {
|
||||
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>>,
|
||||
|
|
|
@ -11,7 +11,11 @@ pub mod blender_settings;
|
|||
|
||||
use bevy::{
|
||||
app::Startup,
|
||||
ecs::{component::Component, reflect::ReflectComponent, system::{Res, Resource}},
|
||||
ecs::{
|
||||
component::Component,
|
||||
reflect::ReflectComponent,
|
||||
system::{Res, Resource},
|
||||
},
|
||||
log::warn,
|
||||
prelude::{App, IntoSystemConfigs, Plugin, SystemSet, Update},
|
||||
reflect::Reflect,
|
||||
|
|
|
@ -3623,6 +3623,31 @@
|
|||
"type": "object",
|
||||
"typeInfo": "Struct"
|
||||
},
|
||||
"bevy_gltf_components::blender_settings::lighting::BlenderLightShadows": {
|
||||
"additionalProperties": false,
|
||||
"isComponent": true,
|
||||
"isResource": false,
|
||||
"properties": {
|
||||
"buffer_bias": {
|
||||
"type": {
|
||||
"$ref": "#/$defs/f32"
|
||||
}
|
||||
},
|
||||
"enabled": {
|
||||
"type": {
|
||||
"$ref": "#/$defs/bool"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"enabled",
|
||||
"buffer_bias"
|
||||
],
|
||||
"short_name": "BlenderLightShadows",
|
||||
"title": "bevy_gltf_components::blender_settings::lighting::BlenderLightShadows",
|
||||
"type": "object",
|
||||
"typeInfo": "Struct"
|
||||
},
|
||||
"bevy_gltf_components::blender_settings::lighting::BlenderShadowSettings": {
|
||||
"additionalProperties": false,
|
||||
"isComponent": true,
|
||||
|
|
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 602 KiB After Width: | Height: | Size: 626 KiB |
|
@ -15,6 +15,7 @@ from ..modules.bevy_scene_components import upsert_scene_components
|
|||
def auto_export(changes_per_scene, changed_export_parameters, addon_prefs):
|
||||
# have the export parameters (not auto export, just gltf export) have changed: if yes (for example switch from glb to gltf, compression or not, animations or not etc), we need to re-export everything
|
||||
print ("changed_export_parameters", changed_export_parameters)
|
||||
|
||||
try:
|
||||
file_path = bpy.data.filepath
|
||||
# Get the folder
|
||||
|
@ -38,6 +39,10 @@ def auto_export(changes_per_scene, changed_export_parameters, addon_prefs):
|
|||
if export_scene_settings:
|
||||
# inject/ update scene components
|
||||
upsert_scene_components(bpy.context.scene, bpy.context.scene.world, main_scene_names)
|
||||
#inject/ update light shadow information
|
||||
for light in bpy.data.lights:
|
||||
enabled = 'true' if light.use_shadow else 'false'
|
||||
light['BlenderLightShadows'] = f"(enabled: {enabled}, buffer_bias: {light.shadow_buffer_bias})"
|
||||
|
||||
# export
|
||||
if export_blueprints:
|
||||
|
|
Loading…
Reference in New Issue