mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-29 22:57:00 +00:00
Compare commits
5 Commits
f1f1ed9cfc
...
dfe6096831
Author | SHA1 | Date | |
---|---|---|---|
|
dfe6096831 | ||
|
6c34ab8bd6 | ||
|
bb4b07b7af | ||
|
f438116ece | ||
|
ada54450a5 |
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "bevy_gltf_blueprints"
|
||||
version = "0.10.0"
|
||||
version = "0.10.2"
|
||||
authors = ["Mark 'kaosat-dev' Moissette"]
|
||||
description = "Adds the ability to define Blueprints/Prefabs for Bevy inside gltf files and spawn them in Bevy."
|
||||
homepage = "https://github.com/kaosat-dev/Blender_bevy_components_workflow"
|
||||
|
@ -224,7 +224,7 @@ Typically , the order of systems should be
|
||||
|
||||
***bevy_gltf_components (GltfComponentsSet::Injection)*** => ***bevy_gltf_blueprints (GltfBlueprintsSet::Spawn, GltfBlueprintsSet::AfterSpawn)*** => ***replace_proxies***
|
||||
|
||||
see https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/basic for how to set it up correctly
|
||||
see an example [here](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/basic) for how to set it up correctly
|
||||
|
||||
|
||||
|
||||
@ -278,9 +278,9 @@ pub fn animation_change_on_proximity_foxes(
|
||||
}
|
||||
```
|
||||
|
||||
see https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/animation for how to set it up correctly
|
||||
see [here](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/animation) for how to set it up correctly
|
||||
|
||||
particularly from https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/animation/game/in_game.rs
|
||||
particularly from [here](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/animation/src/game/in_game.rs)
|
||||
|
||||
|
||||
## Materials
|
||||
@ -301,7 +301,7 @@ material_library_folder: "materials".into() //defaults to "materials" the folder
|
||||
```bevy_gltf_blueprints``` currently does NOT take care of loading those at runtime
|
||||
|
||||
|
||||
see https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/materials for how to set it up correctly
|
||||
see an example [here](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/materials) for how to set it up correctly
|
||||
|
||||
Generating optimised blueprints and material libraries can be automated using the latests version of the [Blender plugin](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/tools/gltf_auto_export)
|
||||
|
||||
@ -326,15 +326,15 @@ As it create custom properties that are writen in real **ron** file format inste
|
||||
|
||||
## Examples
|
||||
|
||||
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/basic
|
||||
* [basic](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/basic)
|
||||
|
||||
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/basic_xpbd_physics
|
||||
* [xbpd](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/basic_xpbd_physics)
|
||||
|
||||
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/animation
|
||||
* [animation](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/animation)
|
||||
|
||||
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/materials
|
||||
* [materials](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/materials)
|
||||
|
||||
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/multiple_levels_multiple_blendfiles
|
||||
* [multiple_levels_multiple_blendfiles](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/multiple_levels_multiple_blendfiles)
|
||||
|
||||
|
||||
## Compatible Bevy versions
|
||||
|
@ -19,7 +19,11 @@ pub use copy_components::*;
|
||||
use core::fmt;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use bevy::{prelude::*, render::primitives::Aabb, utils::HashMap};
|
||||
use bevy::{
|
||||
prelude::*,
|
||||
render::{primitives::Aabb, view::VisibilitySystems},
|
||||
utils::HashMap,
|
||||
};
|
||||
use bevy_gltf_components::{ComponentsFromGltfPlugin, GltfComponentsSet};
|
||||
|
||||
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)]
|
||||
@ -174,10 +178,11 @@ impl Plugin for BlueprintsPlugin {
|
||||
.in_set(GltfBlueprintsSet::Spawn),
|
||||
)
|
||||
.add_systems(
|
||||
Update,
|
||||
PostUpdate,
|
||||
(spawned_blueprint_post_process, apply_deferred)
|
||||
.chain()
|
||||
.in_set(GltfBlueprintsSet::AfterSpawn),
|
||||
.in_set(GltfBlueprintsSet::AfterSpawn)
|
||||
.before(VisibilitySystems::CheckVisibility),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
use bevy::pbr::DirectionalLightShadowMap;
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::render_asset::RenderAssetUsages;
|
||||
use bevy::render::render_resource::{
|
||||
Extent3d, TextureDimension, TextureFormat, TextureViewDescriptor, TextureViewDimension,
|
||||
};
|
||||
use std::iter;
|
||||
|
||||
use crate::GltfComponentsSet;
|
||||
|
||||
@ -84,14 +89,66 @@ fn process_shadowmap(
|
||||
}
|
||||
|
||||
fn process_background_shader(
|
||||
background_shaders: Query<&BlenderBackgroundShader, Added<BlenderBackgroundShader>>,
|
||||
background_shaders: Query<Ref<BlenderBackgroundShader>>,
|
||||
cameras: Query<(Entity, Ref<Camera3d>)>,
|
||||
mut images: ResMut<Assets<Image>>,
|
||||
mut commands: Commands,
|
||||
mut env_map_handle: Local<Option<Handle<Image>>>,
|
||||
) {
|
||||
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,
|
||||
let Ok(background_shader) = background_shaders.get_single() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let env_map_handle = env_map_handle.get_or_insert_with(|| {
|
||||
let size = Extent3d {
|
||||
width: 1,
|
||||
height: 6,
|
||||
depth_or_array_layers: 1,
|
||||
};
|
||||
let dimension = TextureDimension::D2;
|
||||
const SIDES_PER_CUBE: usize = 6;
|
||||
let data: Vec<_> = iter::repeat(background_shader.color.as_rgba_u8())
|
||||
.take(SIDES_PER_CUBE)
|
||||
.flatten()
|
||||
.collect();
|
||||
let format = TextureFormat::Rgba8UnormSrgb;
|
||||
let asset_usage = RenderAssetUsages::RENDER_WORLD;
|
||||
|
||||
let mut image = Image::new(size, dimension, data, format, asset_usage);
|
||||
|
||||
// Source: https://github.com/bevyengine/bevy/blob/85b488b73d6f6e75690962fba67a144d9beb6b88/examples/3d/skybox.rs#L152-L160
|
||||
image.reinterpret_stacked_2d_as_array(image.height() / image.width());
|
||||
image.texture_view_descriptor = Some(TextureViewDescriptor {
|
||||
dimension: Some(TextureViewDimension::Cube),
|
||||
..default()
|
||||
});
|
||||
|
||||
images.add(image)
|
||||
});
|
||||
// Don't need the handle to be &mut
|
||||
let env_map_handle = &*env_map_handle;
|
||||
|
||||
if background_shader.is_added() {
|
||||
// We're using an environment map, so we don't need the ambient light
|
||||
commands.remove_resource::<AmbientLight>();
|
||||
}
|
||||
|
||||
let is_bg_outdated = background_shader.is_changed();
|
||||
if is_bg_outdated {
|
||||
let color = background_shader.color * background_shader.strength;
|
||||
commands.insert_resource(ClearColor(color));
|
||||
}
|
||||
let camera_entities = cameras
|
||||
.iter()
|
||||
.filter_map(|(entity, cam)| (is_bg_outdated || cam.is_changed()).then_some(entity));
|
||||
|
||||
for camera_entity in camera_entities {
|
||||
// See https://github.com/KhronosGroup/glTF-Blender-IO/blob/8573cc0dfb612091bfc1bcf6df55c18a44b9668a/addons/io_scene_gltf2/blender/com/gltf2_blender_conversion.py#L19
|
||||
const PBR_WATTS_TO_LUMENS: f32 = 683.0;
|
||||
commands.entity(camera_entity).insert(EnvironmentMapLight {
|
||||
diffuse_map: env_map_handle.clone(),
|
||||
specular_map: env_map_handle.clone(),
|
||||
intensity: background_shader.strength * PBR_WATTS_TO_LUMENS,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user