Skip to content

Commit

Permalink
Fix scene issues in blender
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim committed Jan 22, 2024
1 parent 54233dd commit 3355ade
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 58 deletions.
Binary file modified assets/scenes/old_town.glb
Binary file not shown.
Binary file modified resources/half_timbered_house.blend
Binary file not shown.
Binary file modified resources/old_town.blend
Binary file not shown.
5 changes: 2 additions & 3 deletions src/level_instantiation/spawning.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::level_instantiation::spawning::animation_link::link_animations;
use crate::level_instantiation::spawning::despawn::{despawn, Despawn};
use crate::level_instantiation::spawning::post_spawn_modification::{
despawn_removed, set_color, set_hidden, set_shadows,
despawn_removed, set_hidden, set_shadows,
};
use crate::GameState;
pub(crate) use animation_link::AnimationEntityLink;
Expand Down Expand Up @@ -40,8 +40,7 @@ pub(crate) fn spawning_plugin(app: &mut App) {
)
.add_systems(
Update,
(set_hidden, despawn_removed, set_color, set_shadows)
.run_if(in_state(GameState::Playing)),
(set_hidden, despawn_removed, set_shadows).run_if(in_state(GameState::Playing)),
);
}

Expand Down
50 changes: 0 additions & 50 deletions src/level_instantiation/spawning/post_spawn_modification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use anyhow::{Context, Result};
use bevy::pbr::NotShadowCaster;
use bevy::prelude::*;
use bevy_mod_sysfail::*;
use regex::Regex;
use std::sync::LazyLock;

pub(crate) fn set_hidden(mut added_name: Query<(&Name, &mut Visibility), Added<Name>>) {
#[cfg(feature = "tracing")]
Expand All @@ -30,54 +28,6 @@ pub(crate) fn despawn_removed(
}
}

static COLOR_REGEX: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"\[color:\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)\]")
.expect("Failed to compile color regex")
});

#[sysfail(log(level = "error"))]
pub(crate) fn set_color(
added_name: Query<(&Name, &Children), Added<Name>>,
material_handles: Query<&Handle<StandardMaterial>>,
mut standard_materials: ResMut<Assets<StandardMaterial>>,
) -> Result<()> {
#[cfg(feature = "tracing")]
let _span = info_span!("set_color").entered();
for (name, children) in added_name.iter() {
if let Some(captures) = COLOR_REGEX.captures(&name.to_lowercase()) {
let color = Color::rgba_u8(
captures[1]
.parse()
.with_context(|| format!("Failed to parse r component in color: {}", name))?,
captures[2]
.parse()
.with_context(|| format!("Failed to parse g component in color: {}", name))?,
captures[3]
.parse()
.with_context(|| format!("Failed to parse b component in color: {}", name))?,
captures[4]
.parse()
.with_context(|| format!("Failed to parse a component in color: {}", name))?,
);
let material_handle = children
.iter()
.filter_map(|entity| material_handles.get(*entity).ok())
.next()
.with_context(|| {
format!(
"Failed to find child containing material handle when setting color on: {}",
name,
)
})?;
let material = standard_materials
.get_mut(material_handle)
.context("Failed to get standard material from handle")?;
material.base_color = color;
}
}
Ok(())
}

#[sysfail(log(level = "error"))]
pub(crate) fn set_shadows(
mut commands: Commands,
Expand Down
6 changes: 1 addition & 5 deletions src/shader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::extra_unused_type_parameters)]
use crate::file_system_interaction::asset_loading::TextureAssets;
use crate::GameState;
use anyhow::{Result};
use anyhow::Result;

use bevy::pbr::{MaterialPipeline, MaterialPipelineKey};
use bevy::prelude::*;
Expand All @@ -12,10 +12,6 @@ use bevy::render::render_resource::{
AsBindGroup, RenderPipelineDescriptor, ShaderRef, SpecializedMeshPipelineError,
};





/// Handles instantiation of shaders. The shaders can be found in the [`shaders`](https://github.com/janhohenheim/foxtrot/tree/main/assets/shaders) directory.
/// Shaders are stored in [`Material`]s which can be used on objects by attaching a `Handle<Material>` to an entity.
/// The handles can be stored and retrieved in the [`Materials`] resource.
Expand Down

0 comments on commit 3355ade

Please sign in to comment.