This commit is contained in:
Brandon Thomas
2024-03-27 15:57:02 -04:00
parent d44170e8f4
commit 012f23ba94
4 changed files with 32 additions and 35 deletions
+1 -1
View File
@@ -34,6 +34,7 @@ mod ui;
pub mod viewport;
mod world_grid;
use crate::material::MaterialPlugin;
pub use crate::{
anim::AnimPlugin,
bvh::BvhPlugin,
@@ -52,7 +53,6 @@ pub use crate::{
viewport::ViewportSize,
world_grid::WorldGridPlugin,
};
use crate::material::MaterialPlugin;
#[cfg(feature = "wasm")]
mod wasm;
+19 -20
View File
@@ -1,38 +1,37 @@
use crate::material::short_material::ShortMaterial;
use bevy::app::{App, Plugin, PostUpdate};
use bevy::asset::{Assets, Handle};
use bevy::pbr::StandardMaterial;
use bevy::prelude::{Commands, Entity, Query, ResMut};
use space_editor::prelude::EditorRegistryExt;
use crate::material::short_material::ShortMaterial;
pub mod short_material;
pub struct MaterialPlugin;
impl Plugin for MaterialPlugin {
fn build(&self, app: &mut App) {
app.register_type::<ShortMaterial>()
.editor_registry::<ShortMaterial>();
fn build(&self, app: &mut App) {
app.register_type::<ShortMaterial>()
.editor_registry::<ShortMaterial>();
app.add_systems(PostUpdate, apply_short_materials);
}
app.add_systems(PostUpdate, apply_short_materials);
}
}
fn apply_short_materials(
mut commands: Commands,
q_mats: Query<(Entity, &Handle<StandardMaterial>, &ShortMaterial)>,
mut materials: ResMut<Assets<StandardMaterial>>,
mut commands: Commands,
q_mats: Query<(Entity, &Handle<StandardMaterial>, &ShortMaterial)>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
for (entity, handle, short) in q_mats.iter() {
let Some(material) = materials.get_mut(handle) else {
continue;
};
for (entity, handle, short) in q_mats.iter() {
let Some(material) = materials.get_mut(handle) else {
continue;
};
material.base_color = short.base_color;
material.perceptual_roughness = short.perceptual_roughness;
material.metallic = short.metallic;
material.reflectance = short.reflectance;
material.base_color = short.base_color;
material.perceptual_roughness = short.perceptual_roughness;
material.metallic = short.metallic;
material.reflectance = short.reflectance;
commands.entity(entity).remove::<ShortMaterial>();
}
commands.entity(entity).remove::<ShortMaterial>();
}
}
+11 -12
View File
@@ -4,23 +4,22 @@ use bevy::prelude::{Color, Component, Reflect};
use bevy::ecs::reflect::ReflectComponent;
use bevy::reflect::std_traits::ReflectDefault;
#[derive(Reflect, Default, Clone, Component)]
#[reflect(Default, Component)]
pub struct ShortMaterial {
pub base_color: Color,
pub perceptual_roughness: f32,
pub metallic: f32,
pub reflectance: f32,
pub base_color: Color,
pub perceptual_roughness: f32,
pub metallic: f32,
pub reflectance: f32,
}
impl ShortMaterial {
pub fn new(material: &StandardMaterial) -> Self {
Self {
base_color: material.base_color,
perceptual_roughness: material.perceptual_roughness,
metallic: material.metallic,
reflectance: material.reflectance,
pub fn new(material: &StandardMaterial) -> Self {
Self {
base_color: material.base_color,
perceptual_roughness: material.perceptual_roughness,
metallic: material.metallic,
reflectance: material.reflectance,
}
}
}
}
+1 -2
View File
@@ -20,11 +20,11 @@ use space_editor::{
};
use wasm_bindgen::prelude::*;
use crate::material::short_material::ShortMaterial;
use crate::{
interaction::Selection,
wasm::{self, StaticBuffer, WasmMessageBuffer},
};
use crate::material::short_material::ShortMaterial;
pub struct InspectorPlugin;
@@ -572,7 +572,6 @@ fn auto_serialize_asset<T: Asset + Reflect + GetTypeRegistration>(
ev_update_description.send(UpdateEntityDescription);
}
fn serialize_standart_materal(
r_selection: Option<Res<Selection>>,
q_m: Query<&Handle<StandardMaterial>>,