From 7cdc2351ba9fc248196c1b02d35b66574a513d1c Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Tue, 11 Feb 2020 09:31:49 -0800 Subject: [PATCH] add default to MeshEntity --- examples/simple_new.rs | 11 ++---- examples/simple_new_graph.rs | 37 ++++--------------- examples/texture_new.rs | 4 +- examples/ui_new.rs | 4 +- src/asset/mod.rs | 10 +++++ src/ecs/default_archetypes.rs | 5 ++- src/render/render_graph_2/renderable.rs | 17 ++++++++- src/render/render_graph_2/uniform.rs | 1 + .../uniforms/standard_material.rs | 10 +++++ 9 files changed, 56 insertions(+), 43 deletions(-) diff --git a/examples/simple_new.rs b/examples/simple_new.rs index 2eaff4c31d..1ff841722a 100644 --- a/examples/simple_new.rs +++ b/examples/simple_new.rs @@ -23,22 +23,19 @@ fn setup(world: &mut World) { mesh: plane_handle.clone(), material: StandardMaterial { albedo: math::vec4(0.1, 0.2, 0.1, 1.0), - everything_is_red: true, + everything_is_red: false, }, - shader_uniforms: ShaderUniforms::new(), - local_to_world: LocalToWorld::identity(), - translation: Translation::new(0.0, 0.0, 0.0), + ..Default::default() }) // cube .add_archetype(NewMeshEntity { mesh: cube_handle.clone(), material: StandardMaterial { albedo: math::vec4(0.5, 0.3, 0.3, 1.0), - everything_is_red: true, + everything_is_red: false, }, - shader_uniforms: ShaderUniforms::new(), - local_to_world: LocalToWorld::identity(), translation: Translation::new(0.0, 0.0, 1.0), + ..Default::default() }) // light .add_archetype(LightEntity { diff --git a/examples/simple_new_graph.rs b/examples/simple_new_graph.rs index 953f169fd6..b42129be95 100644 --- a/examples/simple_new_graph.rs +++ b/examples/simple_new_graph.rs @@ -77,44 +77,28 @@ fn setup(world: &mut World) { mesh: plane_handle.clone(), material: StandardMaterial { albedo: math::vec4(0.1, 0.2, 0.1, 1.0), + everything_is_red: false, }, - shader_uniforms: ShaderUniforms { - uniform_selectors: vec![ - uniform_selector::, - uniform_selector::, - ], - }, - local_to_world: LocalToWorld::identity(), - translation: Translation::new(0.0, 0.0, 0.0), + ..Default::default() }) // cube .add_archetype(NewMeshEntity { mesh: cube_handle.clone(), material: StandardMaterial { albedo: math::vec4(1.0, 0.0, 0.0, 1.0), + everything_is_red: false, }, - shader_uniforms: ShaderUniforms { - uniform_selectors: vec![ - uniform_selector::, - uniform_selector::, - ], - }, - local_to_world: LocalToWorld::identity(), translation: Translation::new(0.0, 0.0, 1.0), + ..Default::default() }) .add_archetype(NewMeshEntity { mesh: cube_handle.clone(), material: StandardMaterial { albedo: math::vec4(0.0, 1.0, 0.0, 1.0), + everything_is_red: false, }, - shader_uniforms: ShaderUniforms { - uniform_selectors: vec![ - uniform_selector::, - uniform_selector::, - ], - }, - local_to_world: LocalToWorld::identity(), translation: Translation::new(-2.0, 0.0, 1.0), + ..Default::default() }) // light .add_archetype(LightEntity { @@ -160,19 +144,14 @@ fn setup(world: &mut World) { rng.gen_range(0.0, 1.0), 1.0, ), + everything_is_red: false, }, - shader_uniforms: ShaderUniforms { - uniform_selectors: vec![ - uniform_selector::, - uniform_selector::, - ], - }, - local_to_world: LocalToWorld::identity(), translation: Translation::new( rng.gen_range(-50.0, 50.0), rng.gen_range(-50.0, 50.0), 0.0, ), + ..Default::default() }) } diff --git a/examples/texture_new.rs b/examples/texture_new.rs index bcb2ad671e..9ad5395b18 100644 --- a/examples/texture_new.rs +++ b/examples/texture_new.rs @@ -27,10 +27,10 @@ fn setup(world: &mut World) { mesh: cube_handle.clone(), material: StandardMaterial { albedo: math::vec4(0.5, 0.3, 0.3, 1.0), + everything_is_red: false, }, - shader_uniforms: ShaderUniforms::new(), - local_to_world: LocalToWorld::identity(), translation: Translation::new(0.0, 0.0, 1.0), + ..Default::default() }) // light .add_archetype(LightEntity { diff --git a/examples/ui_new.rs b/examples/ui_new.rs index 68c2a2ef58..26c5b29b7c 100644 --- a/examples/ui_new.rs +++ b/examples/ui_new.rs @@ -21,10 +21,10 @@ fn setup(world: &mut World) { mesh: cube_handle.clone(), material: StandardMaterial { albedo: math::vec4(0.5, 0.3, 0.3, 1.0), + everything_is_red: false, }, - shader_uniforms: ShaderUniforms::new(), - local_to_world: LocalToWorld::identity(), translation: Translation::new(0.0, 0.0, 1.0), + ..Default::default() }) // light .add_archetype(LightEntity { diff --git a/src/asset/mod.rs b/src/asset/mod.rs index 12118705dc..caf44f6884 100644 --- a/src/asset/mod.rs +++ b/src/asset/mod.rs @@ -13,6 +13,16 @@ pub struct Handle { marker: PhantomData, } +// TODO: somehow handle this gracefully in asset managers. or alternatively remove Default +impl Default for Handle { + fn default() -> Self { + Handle { + id: std::usize::MAX, + marker: PhantomData, + } + } +} + impl Clone for Handle { fn clone(&self) -> Self { Handle { diff --git a/src/ecs/default_archetypes.rs b/src/ecs/default_archetypes.rs index 68128ec5ad..c432fba25d 100644 --- a/src/ecs/default_archetypes.rs +++ b/src/ecs/default_archetypes.rs @@ -1,6 +1,6 @@ use crate::{ prelude::*, - render::render_graph_2::{ShaderUniforms, StandardMaterial}, + render::render_graph_2::{ShaderUniforms, StandardMaterial, Renderable}, }; use bevy_derive::EntityArchetype; @@ -12,10 +12,11 @@ pub struct MeshEntity { pub translation: Translation, } -#[derive(EntityArchetype)] +#[derive(EntityArchetype, Default)] pub struct NewMeshEntity { pub mesh: Handle, pub material: StandardMaterial, + pub renderable: Renderable, pub shader_uniforms: ShaderUniforms, pub local_to_world: LocalToWorld, pub translation: Translation, diff --git a/src/render/render_graph_2/renderable.rs b/src/render/render_graph_2/renderable.rs index 207a918e72..2656bcde63 100644 --- a/src/render/render_graph_2/renderable.rs +++ b/src/render/render_graph_2/renderable.rs @@ -1,6 +1,21 @@ use crate::{asset::Handle, render::Shader}; +use legion::prelude::Entity; +use std::collections::HashSet; pub struct Renderable { - pub render: bool, + pub is_visible: bool, pub shaders: Vec>, } + +impl Default for Renderable { + fn default() -> Self { + Renderable { + is_visible: true, + shaders: Vec::new(), + } + } +} + +pub struct ShaderAssignments { + pub assignments: HashSet>, +} diff --git a/src/render/render_graph_2/uniform.rs b/src/render/render_graph_2/uniform.rs index 80f1dcfc38..0b170f0e8d 100644 --- a/src/render/render_graph_2/uniform.rs +++ b/src/render/render_graph_2/uniform.rs @@ -83,6 +83,7 @@ where pub type ShaderUniformSelector = fn(Entity, &World) -> Option>; +#[derive(Default)] pub struct ShaderUniforms { // used for distinguishing pub uniform_selectors: Vec, diff --git a/src/render/render_graph_2/uniforms/standard_material.rs b/src/render/render_graph_2/uniforms/standard_material.rs index 2685e1fdd2..28319a6be1 100644 --- a/src/render/render_graph_2/uniforms/standard_material.rs +++ b/src/render/render_graph_2/uniforms/standard_material.rs @@ -1,4 +1,5 @@ use crate::{ + math, math::Vec4, render::render_graph_2::{ uniform::{AsUniforms, GetBytes, UniformInfo}, @@ -13,4 +14,13 @@ pub struct StandardMaterial { pub albedo: Vec4, #[uniform(ignore,shader_def)] pub everything_is_red: bool, +} + +impl Default for StandardMaterial { + fn default() -> Self { + StandardMaterial { + albedo: math::vec4(0.3, 0.3, 0.3, 1.0), + everything_is_red: false, + } + } } \ No newline at end of file