mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 20:23:28 +00:00
add default to MeshEntity
This commit is contained in:
parent
7a1036fa0b
commit
7cdc2351ba
9 changed files with 56 additions and 43 deletions
|
@ -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 {
|
||||
|
|
|
@ -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::<StandardMaterial>,
|
||||
uniform_selector::<LocalToWorld>,
|
||||
],
|
||||
},
|
||||
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::<StandardMaterial>,
|
||||
uniform_selector::<LocalToWorld>,
|
||||
],
|
||||
},
|
||||
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::<StandardMaterial>,
|
||||
uniform_selector::<LocalToWorld>,
|
||||
],
|
||||
},
|
||||
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::<StandardMaterial>,
|
||||
uniform_selector::<LocalToWorld>,
|
||||
],
|
||||
},
|
||||
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()
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -13,6 +13,16 @@ pub struct Handle<T> {
|
|||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
// TODO: somehow handle this gracefully in asset managers. or alternatively remove Default
|
||||
impl<T> Default for Handle<T> {
|
||||
fn default() -> Self {
|
||||
Handle {
|
||||
id: std::usize::MAX,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for Handle<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Handle {
|
||||
|
|
|
@ -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<Mesh>,
|
||||
pub material: StandardMaterial,
|
||||
pub renderable: Renderable,
|
||||
pub shader_uniforms: ShaderUniforms,
|
||||
pub local_to_world: LocalToWorld,
|
||||
pub translation: Translation,
|
||||
|
|
|
@ -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<Handle<Shader>>,
|
||||
}
|
||||
|
||||
impl Default for Renderable {
|
||||
fn default() -> Self {
|
||||
Renderable {
|
||||
is_visible: true,
|
||||
shaders: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ShaderAssignments {
|
||||
pub assignments: HashSet<usize, Vec<Entity>>,
|
||||
}
|
||||
|
|
|
@ -83,6 +83,7 @@ where
|
|||
|
||||
pub type ShaderUniformSelector = fn(Entity, &World) -> Option<RefMap<&dyn AsUniforms>>;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ShaderUniforms {
|
||||
// used for distinguishing
|
||||
pub uniform_selectors: Vec<ShaderUniformSelector>,
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue