mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
ecs: rename EntityArchetype to ComponentSet
This commit is contained in:
parent
f17cf82a87
commit
92c44320ee
29 changed files with 141 additions and 162 deletions
|
@ -1,11 +1,11 @@
|
|||
use legion::prelude::*;
|
||||
|
||||
// builder macro that makes defaults easy? Object3dBuilder { Option<Material> } impl Builder for Object3dBuilder { }
|
||||
pub trait EntityArchetype {
|
||||
pub trait ComponentSet {
|
||||
fn insert(self, world: &mut World) -> Entity;
|
||||
fn insert_command_buffer(self, command_buffer: &mut CommandBuffer) -> Entity;
|
||||
|
||||
// this would make composing entities from multiple archetypes possible
|
||||
// this would make composing entities from multiple sets possible
|
||||
// add_components appears to be missing from World. it will be less efficient without that
|
||||
// fn add_components(self, world: &mut World);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
mod app;
|
||||
mod app_builder;
|
||||
mod entity_archetype;
|
||||
mod component_set;
|
||||
mod event;
|
||||
mod plugin;
|
||||
mod resources;
|
||||
|
@ -12,8 +12,8 @@ mod system;
|
|||
|
||||
pub use app::*;
|
||||
pub use app_builder::*;
|
||||
pub use bevy_derive::{DynamicAppPlugin, EntityArchetype, FromResources};
|
||||
pub use entity_archetype::*;
|
||||
pub use bevy_derive::{DynamicAppPlugin, ComponentSet, FromResources};
|
||||
pub use component_set::*;
|
||||
pub use event::*;
|
||||
pub use plugin::*;
|
||||
pub use resources::*;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use bevy_app::EntityArchetype;
|
||||
use bevy_app::ComponentSet;
|
||||
use bevy_transform::components::{LocalTransform, Parent};
|
||||
use legion::{
|
||||
filter::{ChunksetFilterData, Filter},
|
||||
|
@ -27,7 +27,7 @@ pub struct WorldBuilder<'a> {
|
|||
}
|
||||
|
||||
impl<'a> WorldBuilder<'a> {
|
||||
pub fn build_entity(&mut self) -> &mut Self {
|
||||
pub fn entity(&mut self) -> &mut Self {
|
||||
let entity = *self.world.insert((), vec![()]).first().unwrap();
|
||||
self.current_entity = Some(entity);
|
||||
self.add_parent_to_current_entity();
|
||||
|
@ -35,7 +35,7 @@ impl<'a> WorldBuilder<'a> {
|
|||
}
|
||||
|
||||
/// note: this is slow and does a full entity copy
|
||||
pub fn add<T>(&mut self, component: T) -> &mut Self
|
||||
pub fn with<T>(&mut self, component: T) -> &mut Self
|
||||
where
|
||||
T: legion::storage::Component,
|
||||
{
|
||||
|
@ -45,33 +45,22 @@ impl<'a> WorldBuilder<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn tag<T>(&mut self, tag: T) -> &mut Self
|
||||
pub fn entities<C>(&mut self, components: C) -> &mut Self
|
||||
where
|
||||
T: legion::storage::Tag,
|
||||
{
|
||||
let _ = self
|
||||
.world
|
||||
.add_tag(*self.current_entity.as_ref().unwrap(), tag);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_entities<T, C>(&mut self, tags: T, components: C) -> &mut Self
|
||||
where
|
||||
T: TagSet + TagLayout + for<'b> Filter<ChunksetFilterData<'b>>,
|
||||
C: IntoComponentSource,
|
||||
{
|
||||
self.world.insert(tags, components);
|
||||
self.world.insert((), components);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_entity(&mut self, entity_archetype: impl EntityArchetype) -> &mut Self {
|
||||
let current_entity = entity_archetype.insert(self.world);
|
||||
pub fn entity_with(&mut self, component_set: impl ComponentSet) -> &mut Self {
|
||||
let current_entity = component_set.insert(self.world);
|
||||
self.current_entity = Some(current_entity);
|
||||
self.add_parent_to_current_entity();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_children(&mut self, mut build_children: impl FnMut(&mut Self) -> &mut Self) -> &mut Self {
|
||||
pub fn with_children(&mut self, mut build_children: impl FnMut(&mut Self) -> &mut Self) -> &mut Self {
|
||||
self.parent_entity = self.current_entity;
|
||||
self.current_entity = None;
|
||||
|
||||
|
@ -116,7 +105,7 @@ pub struct CommandBufferBuilder<'a> {
|
|||
}
|
||||
|
||||
impl<'a> CommandBufferBuilder<'a> {
|
||||
pub fn build_entity(&mut self) -> &mut Self {
|
||||
pub fn entity(&mut self) -> &mut Self {
|
||||
let entity = *self.command_buffer.insert((), vec![()]).first().unwrap();
|
||||
self.current_entity = Some(entity);
|
||||
self.add_parent_to_current_entity();
|
||||
|
@ -124,7 +113,7 @@ impl<'a> CommandBufferBuilder<'a> {
|
|||
}
|
||||
|
||||
// note: this is slow and does a full entity copy
|
||||
pub fn add<T>(&mut self, component: T) -> &mut Self
|
||||
pub fn with<T>(&mut self, component: T) -> &mut Self
|
||||
where
|
||||
T: legion::storage::Component,
|
||||
{
|
||||
|
@ -134,17 +123,7 @@ impl<'a> CommandBufferBuilder<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn tag<T>(&mut self, tag: T) -> &mut Self
|
||||
where
|
||||
T: legion::storage::Tag,
|
||||
{
|
||||
let _ = self
|
||||
.command_buffer
|
||||
.add_tag(*self.current_entity.as_ref().unwrap(), tag);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_entities<T, C>(&mut self, tags: T, components: C) -> &mut Self
|
||||
pub fn entities<T, C>(&mut self, tags: T, components: C) -> &mut Self
|
||||
where
|
||||
T: TagSet + TagLayout + for<'b> Filter<ChunksetFilterData<'b>> + 'static,
|
||||
C: IntoComponentSource + 'static,
|
||||
|
@ -153,14 +132,14 @@ impl<'a> CommandBufferBuilder<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn add_entity(&mut self, entity_archetype: impl EntityArchetype) -> &mut Self {
|
||||
let current_entity = entity_archetype.insert_command_buffer(self.command_buffer);
|
||||
pub fn entity_with(&mut self, component_set: impl ComponentSet) -> &mut Self {
|
||||
let current_entity = component_set.insert_command_buffer(self.command_buffer);
|
||||
self.current_entity = Some(current_entity);
|
||||
self.add_parent_to_current_entity();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_children(&mut self, mut build_children: impl FnMut(&mut Self) -> &mut Self) -> &mut Self {
|
||||
pub fn with_children(&mut self, mut build_children: impl FnMut(&mut Self) -> &mut Self) -> &mut Self {
|
||||
self.parent_entity = self.current_entity;
|
||||
self.current_entity = None;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use proc_macro::TokenStream;
|
|||
use quote::quote;
|
||||
use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Fields, Ident};
|
||||
|
||||
pub fn derive_entity_archetype(input: TokenStream) -> TokenStream {
|
||||
pub fn derive_component_set(input: TokenStream) -> TokenStream {
|
||||
let ast = parse_macro_input!(input as DeriveInput);
|
||||
let fields = match &ast.data {
|
||||
Data::Struct(DataStruct {
|
||||
|
@ -28,7 +28,7 @@ pub fn derive_entity_archetype(input: TokenStream) -> TokenStream {
|
|||
let struct_name = &ast.ident;
|
||||
|
||||
TokenStream::from(quote! {
|
||||
impl #impl_generics #bevy_app_path::EntityArchetype for #struct_name#ty_generics {
|
||||
impl #impl_generics #bevy_app_path::ComponentSet for #struct_name#ty_generics {
|
||||
fn insert(self, world: &mut #legion_path::prelude::World) -> #legion_path::prelude::Entity {
|
||||
*world.insert((),
|
||||
vec![(
|
|
@ -4,7 +4,7 @@ mod app_plugin;
|
|||
mod as_vertex_buffer_descriptor;
|
||||
mod attributes;
|
||||
mod bytes;
|
||||
mod entity_archetype;
|
||||
mod component_set;
|
||||
mod modules;
|
||||
mod render_resource;
|
||||
mod render_resources;
|
||||
|
@ -43,9 +43,9 @@ pub fn derive_as_vertex_buffer_descriptor(input: TokenStream) -> TokenStream {
|
|||
as_vertex_buffer_descriptor::derive_as_vertex_buffer_descriptor(input)
|
||||
}
|
||||
|
||||
#[proc_macro_derive(EntityArchetype, attributes(tag, module))]
|
||||
pub fn derive_entity_archetype(input: TokenStream) -> TokenStream {
|
||||
entity_archetype::derive_entity_archetype(input)
|
||||
#[proc_macro_derive(ComponentSet, attributes(tag, module))]
|
||||
pub fn derive_component_set(input: TokenStream) -> TokenStream {
|
||||
component_set::derive_component_set(input)
|
||||
}
|
||||
|
||||
#[proc_macro_derive(DynamicAppPlugin)]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{light::Light, material::StandardMaterial, pipelines::FORWARD_PIPELINE_HANDLE};
|
||||
use bevy_asset::Handle;
|
||||
use bevy_derive::EntityArchetype;
|
||||
use bevy_derive::ComponentSet;
|
||||
use bevy_render::{
|
||||
draw::Draw,
|
||||
mesh::Mesh,
|
||||
|
@ -8,8 +8,8 @@ use bevy_render::{
|
|||
};
|
||||
use bevy_transform::prelude::{Rotation, Scale, Transform, Translation};
|
||||
|
||||
#[derive(EntityArchetype)]
|
||||
pub struct MeshEntity {
|
||||
#[derive(ComponentSet)]
|
||||
pub struct MeshComponents {
|
||||
pub mesh: Handle<Mesh>,
|
||||
pub material: Handle<StandardMaterial>,
|
||||
pub draw: Draw,
|
||||
|
@ -20,7 +20,7 @@ pub struct MeshEntity {
|
|||
pub scale: Scale,
|
||||
}
|
||||
|
||||
impl Default for MeshEntity {
|
||||
impl Default for MeshComponents {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
||||
|
@ -52,8 +52,8 @@ impl Default for MeshEntity {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(EntityArchetype, Default)]
|
||||
pub struct LightEntity {
|
||||
#[derive(ComponentSet, Default)]
|
||||
pub struct LightComponents {
|
||||
pub light: Light,
|
||||
pub transform: Transform,
|
||||
pub translation: Translation,
|
||||
|
|
|
@ -3,11 +3,11 @@ use crate::{
|
|||
OrthographicProjection, PerspectiveProjection, WindowOrigin, VisibleEntities,
|
||||
};
|
||||
use bevy_asset::Handle;
|
||||
use bevy_derive::EntityArchetype;
|
||||
use bevy_derive::ComponentSet;
|
||||
use bevy_transform::components::{Rotation, Scale, Transform, Translation};
|
||||
|
||||
#[derive(EntityArchetype, Default)]
|
||||
pub struct MeshMaterialEntity<T: Default + Send + Sync + 'static> {
|
||||
#[derive(ComponentSet, Default)]
|
||||
pub struct MeshMaterialComponents<T: Default + Send + Sync + 'static> {
|
||||
pub mesh: Handle<Mesh>,
|
||||
pub material: Handle<T>,
|
||||
pub draw: Draw,
|
||||
|
@ -18,8 +18,8 @@ pub struct MeshMaterialEntity<T: Default + Send + Sync + 'static> {
|
|||
pub scale: Scale,
|
||||
}
|
||||
|
||||
#[derive(EntityArchetype)]
|
||||
pub struct PerspectiveCameraEntity {
|
||||
#[derive(ComponentSet)]
|
||||
pub struct PerspectiveCameraComponents {
|
||||
pub camera: Camera,
|
||||
pub perspective_projection: PerspectiveProjection,
|
||||
pub visible_entities: VisibleEntities,
|
||||
|
@ -29,9 +29,9 @@ pub struct PerspectiveCameraEntity {
|
|||
pub scale: Scale,
|
||||
}
|
||||
|
||||
impl Default for PerspectiveCameraEntity {
|
||||
impl Default for PerspectiveCameraComponents {
|
||||
fn default() -> Self {
|
||||
PerspectiveCameraEntity {
|
||||
PerspectiveCameraComponents {
|
||||
camera: Camera {
|
||||
name: Some(base_render_graph::camera::CAMERA.to_string()),
|
||||
..Default::default()
|
||||
|
@ -46,8 +46,8 @@ impl Default for PerspectiveCameraEntity {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(EntityArchetype)]
|
||||
pub struct OrthographicCameraEntity {
|
||||
#[derive(ComponentSet)]
|
||||
pub struct OrthographicCameraComponents {
|
||||
pub camera: Camera,
|
||||
pub orthographic_projection: OrthographicProjection,
|
||||
pub visible_entities: VisibleEntities,
|
||||
|
@ -57,9 +57,9 @@ pub struct OrthographicCameraEntity {
|
|||
pub scale: Scale,
|
||||
}
|
||||
|
||||
impl OrthographicCameraEntity {
|
||||
impl OrthographicCameraComponents {
|
||||
pub fn ui() -> Self {
|
||||
OrthographicCameraEntity {
|
||||
OrthographicCameraComponents {
|
||||
camera: Camera {
|
||||
name: Some("UiCamera".to_string()),
|
||||
..Default::default()
|
||||
|
@ -77,9 +77,9 @@ impl OrthographicCameraEntity {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for OrthographicCameraEntity {
|
||||
impl Default for OrthographicCameraComponents {
|
||||
fn default() -> Self {
|
||||
OrthographicCameraEntity {
|
||||
OrthographicCameraComponents {
|
||||
camera: Camera {
|
||||
name: Some(base_render_graph::camera::CAMERA2D.to_string()),
|
||||
..Default::default()
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
|||
render::SPRITE_PIPELINE_HANDLE, sprite::Sprite, ColorMaterial, TextureAtlas,
|
||||
TextureAtlasSprite, QUAD_HANDLE, SPRITE_SHEET_PIPELINE_HANDLE,
|
||||
};
|
||||
use bevy_app::EntityArchetype;
|
||||
use bevy_app::ComponentSet;
|
||||
use bevy_asset::Handle;
|
||||
use bevy_render::{
|
||||
draw::Draw,
|
||||
|
@ -11,8 +11,8 @@ use bevy_render::{
|
|||
};
|
||||
use bevy_transform::prelude::{Rotation, Scale, Transform, Translation};
|
||||
|
||||
#[derive(EntityArchetype)]
|
||||
pub struct SpriteEntity {
|
||||
#[derive(ComponentSet)]
|
||||
pub struct SpriteComponents {
|
||||
pub sprite: Sprite,
|
||||
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
|
||||
pub material: Handle<ColorMaterial>,
|
||||
|
@ -24,7 +24,7 @@ pub struct SpriteEntity {
|
|||
pub scale: Scale,
|
||||
}
|
||||
|
||||
impl Default for SpriteEntity {
|
||||
impl Default for SpriteComponents {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
mesh: QUAD_HANDLE,
|
||||
|
@ -60,8 +60,8 @@ impl Default for SpriteEntity {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(EntityArchetype)]
|
||||
pub struct SpriteSheetEntity {
|
||||
#[derive(ComponentSet)]
|
||||
pub struct SpriteSheetComponents {
|
||||
pub sprite: TextureAtlasSprite,
|
||||
pub texture_atlas: Handle<TextureAtlas>,
|
||||
pub draw: Draw,
|
||||
|
@ -73,7 +73,7 @@ pub struct SpriteSheetEntity {
|
|||
pub scale: Scale,
|
||||
}
|
||||
|
||||
impl Default for SpriteSheetEntity {
|
||||
impl Default for SpriteSheetComponents {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
use super::Node;
|
||||
use crate::{render::UI_PIPELINE_HANDLE, widget::Label};
|
||||
use bevy_asset::Handle;
|
||||
use bevy_derive::EntityArchetype;
|
||||
use bevy_derive::ComponentSet;
|
||||
use bevy_render::{draw::Draw, mesh::Mesh, pipeline::{PipelineSpecialization, RenderPipelines, DynamicBinding, RenderPipeline}};
|
||||
use bevy_sprite::{ColorMaterial, QUAD_HANDLE};
|
||||
use bevy_transform::prelude::{Translation, Transform, Rotation, Scale};
|
||||
|
||||
#[derive(EntityArchetype)]
|
||||
pub struct UiEntity {
|
||||
#[derive(ComponentSet)]
|
||||
pub struct UiComponents {
|
||||
pub node: Node,
|
||||
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
|
||||
pub material: Handle<ColorMaterial>,
|
||||
|
@ -19,9 +19,9 @@ pub struct UiEntity {
|
|||
pub scale: Scale,
|
||||
}
|
||||
|
||||
impl Default for UiEntity {
|
||||
impl Default for UiComponents {
|
||||
fn default() -> Self {
|
||||
UiEntity {
|
||||
UiComponents {
|
||||
mesh: QUAD_HANDLE,
|
||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
||||
UI_PIPELINE_HANDLE,
|
||||
|
@ -52,8 +52,8 @@ impl Default for UiEntity {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(EntityArchetype)]
|
||||
pub struct LabelEntity {
|
||||
#[derive(ComponentSet)]
|
||||
pub struct LabelComponents {
|
||||
pub node: Node,
|
||||
pub draw: Draw,
|
||||
pub label: Label,
|
||||
|
@ -63,9 +63,9 @@ pub struct LabelEntity {
|
|||
pub scale: Scale,
|
||||
}
|
||||
|
||||
impl Default for LabelEntity {
|
||||
impl Default for LabelComponents {
|
||||
fn default() -> Self {
|
||||
LabelEntity {
|
||||
LabelComponents {
|
||||
label: Label::default(),
|
||||
node: Default::default(),
|
||||
draw: Draw {
|
||||
|
|
|
@ -15,8 +15,8 @@ fn setup(
|
|||
let texture_handle = asset_server.load("assets/branding/icon.png").unwrap();
|
||||
command_buffer
|
||||
.build()
|
||||
.add_entity(OrthographicCameraEntity::default())
|
||||
.add_entity(SpriteEntity {
|
||||
.entity_with(OrthographicCameraComponents::default())
|
||||
.entity_with(SpriteComponents {
|
||||
material: materials.add(texture_handle.into()),
|
||||
..Default::default()
|
||||
});
|
||||
|
|
|
@ -38,11 +38,11 @@ fn setup(
|
|||
let texture_atlas_handle = texture_atlases.add(texture_atlas);
|
||||
command_buffer
|
||||
.build()
|
||||
.add_entity(OrthographicCameraEntity::default())
|
||||
.add_entity(SpriteSheetEntity {
|
||||
.entity_with(OrthographicCameraComponents::default())
|
||||
.entity_with(SpriteSheetComponents {
|
||||
texture_atlas: texture_atlas_handle,
|
||||
scale: Scale(6.0),
|
||||
..Default::default()
|
||||
})
|
||||
.add(Timer::from_seconds(0.1));
|
||||
.with(Timer::from_seconds(0.1));
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ fn setup(
|
|||
.unwrap();
|
||||
command_buffer
|
||||
.build()
|
||||
.add_entity(OrthographicCameraEntity::default());
|
||||
.entity_with(OrthographicCameraComponents::default());
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -68,7 +68,7 @@ fn load_atlas(
|
|||
command_buffer
|
||||
.build()
|
||||
// draw a sprite from the atlas
|
||||
.add_entity(SpriteSheetEntity {
|
||||
.entity_with(SpriteSheetComponents {
|
||||
scale: Scale(4.0),
|
||||
translation: Translation(Vec3::new(150.0, 0.0, 0.0)),
|
||||
sprite: TextureAtlasSprite::new(vendor_index as u32),
|
||||
|
@ -76,7 +76,7 @@ fn load_atlas(
|
|||
..Default::default()
|
||||
})
|
||||
// draw the atlas itself
|
||||
.add_entity(SpriteEntity {
|
||||
.entity_with(SpriteComponents {
|
||||
material: materials.add(texture_atlas_texture.into()),
|
||||
translation: Vec3::new(-300.0, 0., 0.0).into(),
|
||||
..Default::default()
|
||||
|
|
|
@ -31,25 +31,25 @@ fn setup(
|
|||
command_buffer
|
||||
.build()
|
||||
// plane
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: plane_handle,
|
||||
material: plane_material_handle,
|
||||
..Default::default()
|
||||
})
|
||||
// cube
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: cube_handle,
|
||||
material: cube_material_handle,
|
||||
translation: Translation::new(0.0, 1.0, 0.0),
|
||||
..Default::default()
|
||||
})
|
||||
// light
|
||||
.add_entity(LightEntity {
|
||||
.entity_with(LightComponents {
|
||||
translation: Translation::new(4.0, 5.0, -4.0),
|
||||
..Default::default()
|
||||
})
|
||||
// camera
|
||||
.add_entity(PerspectiveCameraEntity {
|
||||
.entity_with(PerspectiveCameraComponents {
|
||||
transform: Transform::new_sync_disabled(Mat4::face_toward(
|
||||
Vec3::new(3.0, 5.0, 8.0),
|
||||
Vec3::new(0.0, 0.0, 0.0),
|
||||
|
|
|
@ -27,18 +27,18 @@ fn setup(
|
|||
command_buffer
|
||||
.build()
|
||||
// mesh
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: mesh_handle,
|
||||
material: material_handle,
|
||||
..Default::default()
|
||||
})
|
||||
// light
|
||||
.add_entity(LightEntity {
|
||||
.entity_with(LightComponents {
|
||||
translation: Translation::new(4.0, 5.0, 4.0),
|
||||
..Default::default()
|
||||
})
|
||||
// camera
|
||||
.add_entity(PerspectiveCameraEntity {
|
||||
.entity_with(PerspectiveCameraComponents {
|
||||
transform: Transform::new_sync_disabled(Mat4::face_toward(
|
||||
Vec3::new(-2.0, 2.0, 6.0),
|
||||
Vec3::new(0.0, 0.0, 0.0),
|
||||
|
|
|
@ -30,16 +30,16 @@ fn setup(
|
|||
command_buffer
|
||||
.build()
|
||||
// parent cube
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: cube_handle,
|
||||
material: cube_material_handle,
|
||||
translation: Translation::new(0.0, 0.0, 1.0),
|
||||
..Default::default()
|
||||
})
|
||||
.add(Rotator)
|
||||
.add_children(|builder| {
|
||||
.with(Rotator)
|
||||
.with_children(|builder| {
|
||||
// child cube
|
||||
builder.add_entity(MeshEntity {
|
||||
builder.entity_with(MeshComponents {
|
||||
mesh: cube_handle,
|
||||
material: cube_material_handle,
|
||||
translation: Translation::new(0.0, 0.0, 3.0),
|
||||
|
@ -47,12 +47,12 @@ fn setup(
|
|||
})
|
||||
})
|
||||
// light
|
||||
.add_entity(LightEntity {
|
||||
.entity_with(LightComponents {
|
||||
translation: Translation::new(4.0, 5.0, -4.0),
|
||||
..Default::default()
|
||||
})
|
||||
// camera
|
||||
.add_entity(PerspectiveCameraEntity {
|
||||
.entity_with(PerspectiveCameraComponents {
|
||||
transform: Transform::new_sync_disabled(Mat4::face_toward(
|
||||
Vec3::new(5.0, 10.0, 10.0),
|
||||
Vec3::new(0.0, 0.0, 0.0),
|
||||
|
|
|
@ -44,25 +44,25 @@ fn setup(
|
|||
let mut builder = command_buffer.build();
|
||||
builder
|
||||
// plane
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: plane_handle,
|
||||
material: plane_material_handle,
|
||||
..Default::default()
|
||||
})
|
||||
// cube
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: cube_handle,
|
||||
material: cube_material_handle,
|
||||
translation: Translation::new(0.0, 0.0, 1.0),
|
||||
..Default::default()
|
||||
})
|
||||
// light
|
||||
.add_entity(LightEntity {
|
||||
.entity_with(LightComponents {
|
||||
translation: Translation::new(4.0, -4.0, 5.0),
|
||||
..Default::default()
|
||||
})
|
||||
// camera
|
||||
.add_entity(PerspectiveCameraEntity {
|
||||
.entity_with(PerspectiveCameraComponents {
|
||||
transform: Transform::new_sync_disabled(Mat4::face_toward(
|
||||
Vec3::new(3.0, 5.0, -8.0),
|
||||
Vec3::new(0.0, 0.0, 0.0),
|
||||
|
@ -81,7 +81,7 @@ fn setup(
|
|||
),
|
||||
..Default::default()
|
||||
});
|
||||
builder.add_entity(MeshEntity {
|
||||
builder.entity_with(MeshComponents {
|
||||
mesh: cube_handle,
|
||||
material: spawned_material_handle,
|
||||
translation: Translation::new(
|
||||
|
|
|
@ -56,7 +56,7 @@ fn setup(
|
|||
command_buffer
|
||||
.build()
|
||||
// textured quad - normal
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: quad_handle,
|
||||
material: material_handle,
|
||||
translation: Translation::new(0.0, 0.0, -1.5),
|
||||
|
@ -68,7 +68,7 @@ fn setup(
|
|||
..Default::default()
|
||||
})
|
||||
// textured quad - modulated
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: quad_handle,
|
||||
material: red_material_handle,
|
||||
translation: Translation::new(0.0, 0.0, 0.0),
|
||||
|
@ -80,7 +80,7 @@ fn setup(
|
|||
..Default::default()
|
||||
})
|
||||
// textured quad - modulated
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: quad_handle,
|
||||
material: blue_material_handle,
|
||||
translation: Translation::new(0.0, 0.0, 1.5),
|
||||
|
@ -92,7 +92,7 @@ fn setup(
|
|||
..Default::default()
|
||||
})
|
||||
// camera
|
||||
.add_entity(PerspectiveCameraEntity {
|
||||
.entity_with(PerspectiveCameraComponents {
|
||||
transform: Transform::new_sync_disabled(Mat4::face_toward(
|
||||
Vec3::new(3.0, 5.0, -8.0),
|
||||
Vec3::new(0.0, 0.0, 0.0),
|
||||
|
|
|
@ -45,7 +45,7 @@ fn setup(
|
|||
command_buffer
|
||||
.build()
|
||||
// parent cube
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: cube_handle,
|
||||
material: materials.add(StandardMaterial {
|
||||
shaded: false,
|
||||
|
@ -54,11 +54,11 @@ fn setup(
|
|||
translation: Translation::new(0.0, 0.0, 1.0),
|
||||
..Default::default()
|
||||
})
|
||||
.add(Rotator)
|
||||
.add_children(|builder| {
|
||||
.with(Rotator)
|
||||
.with_children(|builder| {
|
||||
// child cubes
|
||||
builder
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: cube_handle,
|
||||
material: materials.add(StandardMaterial {
|
||||
shaded: false,
|
||||
|
@ -67,7 +67,7 @@ fn setup(
|
|||
translation: Translation::new(0.0, 3.0, 0.0),
|
||||
..Default::default()
|
||||
})
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: cube_handle,
|
||||
material: materials.add(StandardMaterial {
|
||||
shaded: false,
|
||||
|
@ -78,7 +78,7 @@ fn setup(
|
|||
})
|
||||
})
|
||||
// camera
|
||||
.add_entity(PerspectiveCameraEntity {
|
||||
.entity_with(PerspectiveCameraComponents {
|
||||
transform: Transform::new_sync_disabled(Mat4::face_toward(
|
||||
Vec3::new(5.0, 10.0, 10.0),
|
||||
Vec3::new(0.0, 0.0, 0.0),
|
||||
|
|
|
@ -23,18 +23,18 @@ fn setup(
|
|||
command_buffer
|
||||
.build()
|
||||
// cube
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: cube_handle,
|
||||
material: cube_material_handle,
|
||||
..Default::default()
|
||||
})
|
||||
// light
|
||||
.add_entity(LightEntity {
|
||||
.entity_with(LightComponents {
|
||||
translation: Translation::new(4.0, 5.0, 4.0),
|
||||
..Default::default()
|
||||
})
|
||||
// camera
|
||||
.add_entity(PerspectiveCameraEntity {
|
||||
.entity_with(PerspectiveCameraComponents {
|
||||
transform: Transform::new_sync_disabled(Mat4::face_toward(
|
||||
Vec3::new(3.0, 5.0, 8.0),
|
||||
Vec3::new(0.0, 0.0, 0.0),
|
||||
|
|
|
@ -45,33 +45,33 @@ fn setup(
|
|||
command_buffer
|
||||
.build()
|
||||
// monkey
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: monkey_handle,
|
||||
material: material_handle,
|
||||
translation: Translation::new(-3.0, 0.0, 0.0),
|
||||
..Default::default()
|
||||
})
|
||||
// cube
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: cube_handle,
|
||||
material: material_handle,
|
||||
translation: Translation::new(0.0, 0.0, 0.0),
|
||||
..Default::default()
|
||||
})
|
||||
// sphere
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: sphere_handle,
|
||||
material: material_handle,
|
||||
translation: Translation::new(3.0, 0.0, 0.0),
|
||||
..Default::default()
|
||||
})
|
||||
// light
|
||||
.add_entity(LightEntity {
|
||||
.entity_with(LightComponents {
|
||||
translation: Translation::new(4.0, 5.0, 4.0),
|
||||
..Default::default()
|
||||
})
|
||||
// camera
|
||||
.add_entity(PerspectiveCameraEntity {
|
||||
.entity_with(PerspectiveCameraComponents {
|
||||
transform: Transform::new_sync_disabled(Mat4::face_toward(
|
||||
Vec3::new(0.0, 3.0, 10.0),
|
||||
Vec3::new(0.0, 0.0, 0.0),
|
||||
|
|
|
@ -35,18 +35,18 @@ fn setup(
|
|||
command_buffer
|
||||
.build()
|
||||
// mesh
|
||||
.add_entity(MeshEntity {
|
||||
.entity_with(MeshComponents {
|
||||
mesh: mesh_handle,
|
||||
material: material_handle,
|
||||
..Default::default()
|
||||
})
|
||||
// light
|
||||
.add_entity(LightEntity {
|
||||
.entity_with(LightComponents {
|
||||
translation: Translation::new(4.0, 5.0, 4.0),
|
||||
..Default::default()
|
||||
})
|
||||
// camera
|
||||
.add_entity(PerspectiveCameraEntity {
|
||||
.entity_with(PerspectiveCameraComponents {
|
||||
transform: Transform::new_sync_disabled(Mat4::face_toward(
|
||||
Vec3::new(2.0, 2.0, 6.0),
|
||||
Vec3::new(0.0, 0.0, 0.0),
|
||||
|
|
|
@ -107,14 +107,14 @@ fn save_scene_system(_world: &mut World, resources: &mut Resources) {
|
|||
let mut world = World::new();
|
||||
world
|
||||
.build()
|
||||
.build_entity()
|
||||
.add(ComponentA { x: 1.0, y: 2.0 })
|
||||
.add(ComponentB {
|
||||
.entity()
|
||||
.with(ComponentA { x: 1.0, y: 2.0 })
|
||||
.with(ComponentB {
|
||||
value: "hello".to_string(),
|
||||
..ComponentB::from_resources(resources)
|
||||
})
|
||||
.build_entity()
|
||||
.add(ComponentA { x: 3.0, y: 4.0 });
|
||||
.entity()
|
||||
.with(ComponentA { x: 3.0, y: 4.0 });
|
||||
|
||||
// The component registry resource contains information about all registered components. This is used to construct scenes.
|
||||
let type_registry = resources.get::<TypeRegistry>().unwrap();
|
||||
|
|
|
@ -76,7 +76,7 @@ fn setup(
|
|||
command_buffer
|
||||
.build()
|
||||
// cube
|
||||
.add_entity(MeshMaterialEntity::<MyMaterial> {
|
||||
.entity_with(MeshMaterialComponents::<MyMaterial> {
|
||||
mesh: cube_handle,
|
||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
||||
pipeline_handle,
|
||||
|
@ -102,7 +102,7 @@ fn setup(
|
|||
..Default::default()
|
||||
})
|
||||
// camera
|
||||
.add_entity(PerspectiveCameraEntity {
|
||||
.entity_with(PerspectiveCameraComponents {
|
||||
transform: Transform::new_sync_disabled(Mat4::face_toward(
|
||||
Vec3::new(3.0, 5.0, -8.0),
|
||||
Vec3::new(0.0, 0.0, 0.0),
|
||||
|
|
|
@ -93,7 +93,7 @@ fn setup(
|
|||
command_buffer
|
||||
.build()
|
||||
// cube
|
||||
.add_entity(MeshMaterialEntity::<MyMaterial> {
|
||||
.entity_with(MeshMaterialComponents::<MyMaterial> {
|
||||
mesh: cube_handle,
|
||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
||||
pipeline_handle,
|
||||
|
@ -119,7 +119,7 @@ fn setup(
|
|||
..Default::default()
|
||||
})
|
||||
// cube
|
||||
.add_entity(MeshMaterialEntity::<MyMaterial> {
|
||||
.entity_with(MeshMaterialComponents::<MyMaterial> {
|
||||
mesh: cube_handle,
|
||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
||||
pipeline_handle,
|
||||
|
@ -145,7 +145,7 @@ fn setup(
|
|||
..Default::default()
|
||||
})
|
||||
// camera
|
||||
.add_entity(PerspectiveCameraEntity {
|
||||
.entity_with(PerspectiveCameraComponents {
|
||||
transform: Transform::new_sync_disabled(Mat4::face_toward(
|
||||
Vec3::new(3.0, 5.0, -8.0),
|
||||
Vec3::new(0.0, 0.0, 0.0),
|
||||
|
|
|
@ -40,7 +40,7 @@ fn atlas_render_system(
|
|||
for (_size, font_atlas) in set.iter() {
|
||||
state.added = true;
|
||||
let texture_atlas = texture_atlases.get(&font_atlas.texture_atlas).unwrap();
|
||||
command_buffer.build().add_entity(SpriteEntity {
|
||||
command_buffer.build().entity_with(SpriteComponents {
|
||||
material: materials.add(texture_atlas.texture.into()),
|
||||
translation: Vec3::new(-300.0, 0., 0.0).into(),
|
||||
..Default::default()
|
||||
|
@ -68,10 +68,10 @@ fn setup(
|
|||
command_buffer
|
||||
.build()
|
||||
// 2d camera
|
||||
.add_entity(OrthographicCameraEntity::default())
|
||||
.add_entity(OrthographicCameraEntity::ui())
|
||||
.entity_with(OrthographicCameraComponents::default())
|
||||
.entity_with(OrthographicCameraComponents::ui())
|
||||
// texture
|
||||
.add_entity(LabelEntity {
|
||||
.entity_with(LabelComponents {
|
||||
node: Node::new(
|
||||
Anchors::TOP_LEFT,
|
||||
Margins::new(0.0, 250.0, 0.0, 60.0),
|
||||
|
|
|
@ -25,9 +25,9 @@ fn setup(command_buffer: &mut CommandBuffer, asset_server: Res<AssetServer>) {
|
|||
command_buffer
|
||||
.build()
|
||||
// 2d camera
|
||||
.add_entity(OrthographicCameraEntity::ui())
|
||||
.entity_with(OrthographicCameraComponents::ui())
|
||||
// texture
|
||||
.add_entity(LabelEntity {
|
||||
.entity_with(LabelComponents {
|
||||
node: Node::new(
|
||||
Anchors::TOP_LEFT,
|
||||
Margins::new(0.0, 250.0, 0.0, 60.0),
|
||||
|
|
|
@ -56,9 +56,9 @@ fn setup(
|
|||
// ..Default::default()
|
||||
// })
|
||||
// ui camera
|
||||
.add_entity(OrthographicCameraEntity::ui())
|
||||
.entity_with(OrthographicCameraComponents::ui())
|
||||
// left vertical fill
|
||||
.add_entity(UiEntity {
|
||||
.entity_with(UiComponents {
|
||||
node: Node::new(
|
||||
Anchors::LEFT_FULL,
|
||||
Margins::new(10.0, 200.0, 10.0, 10.0),
|
||||
|
@ -66,8 +66,8 @@ fn setup(
|
|||
material: materials.add(Color::rgb(0.02, 0.02, 0.02).into()),
|
||||
..Default::default()
|
||||
})
|
||||
.add_children(|builder| {
|
||||
builder.add_entity(LabelEntity {
|
||||
.with_children(|builder| {
|
||||
builder.entity_with(LabelComponents {
|
||||
node: Node::new(
|
||||
Anchors::TOP_LEFT,
|
||||
Margins::new(10.0, 200.0, 40.0, 10.0),
|
||||
|
@ -84,7 +84,7 @@ fn setup(
|
|||
})
|
||||
})
|
||||
// right vertical fill
|
||||
.add_entity(UiEntity {
|
||||
.entity_with(UiComponents {
|
||||
node: Node::new(
|
||||
Anchors::RIGHT_FULL,
|
||||
Margins::new(10.0, 100.0, 100.0, 100.0),
|
||||
|
@ -93,7 +93,7 @@ fn setup(
|
|||
..Default::default()
|
||||
})
|
||||
// render order test: reddest in the back, whitest in the front
|
||||
.add_entity(UiEntity {
|
||||
.entity_with(UiComponents {
|
||||
node: Node::positioned(
|
||||
math::vec2(75.0, 60.0),
|
||||
Anchors::CENTER,
|
||||
|
@ -102,7 +102,7 @@ fn setup(
|
|||
material: materials.add(Color::rgb(1.0, 0.0, 0.0).into()),
|
||||
..Default::default()
|
||||
})
|
||||
.add_entity(UiEntity {
|
||||
.entity_with(UiComponents {
|
||||
node: Node::positioned(
|
||||
math::vec2(50.0, 35.0),
|
||||
Anchors::CENTER,
|
||||
|
@ -111,7 +111,7 @@ fn setup(
|
|||
material: materials.add(Color::rgb(1.0, 0.3, 0.3).into()),
|
||||
..Default::default()
|
||||
})
|
||||
.add_entity(UiEntity {
|
||||
.entity_with(UiComponents {
|
||||
node: Node::positioned(
|
||||
math::vec2(100.0, 85.0),
|
||||
Anchors::CENTER,
|
||||
|
@ -120,7 +120,7 @@ fn setup(
|
|||
material: materials.add(Color::rgb(1.0, 0.5, 0.5).into()),
|
||||
..Default::default()
|
||||
})
|
||||
.add_entity(UiEntity {
|
||||
.entity_with(UiComponents {
|
||||
node: Node::positioned(
|
||||
math::vec2(150.0, 135.0),
|
||||
Anchors::CENTER,
|
||||
|
@ -130,7 +130,7 @@ fn setup(
|
|||
..Default::default()
|
||||
})
|
||||
// parenting
|
||||
.add_entity(UiEntity {
|
||||
.entity_with(UiComponents {
|
||||
node: Node::positioned(
|
||||
math::vec2(210.0, 0.0),
|
||||
Anchors::BOTTOM_LEFT,
|
||||
|
@ -139,8 +139,8 @@ fn setup(
|
|||
material: materials.add(Color::rgb(0.1, 0.1, 1.0).into()),
|
||||
..Default::default()
|
||||
})
|
||||
.add_children(|builder| {
|
||||
builder.add_entity(UiEntity {
|
||||
.with_children(|builder| {
|
||||
builder.entity_with(UiComponents {
|
||||
node: Node::new(
|
||||
Anchors::FULL,
|
||||
Margins::new(20.0, 20.0, 20.0, 20.0),
|
||||
|
@ -150,7 +150,7 @@ fn setup(
|
|||
})
|
||||
})
|
||||
// alpha test
|
||||
.add_entity(UiEntity {
|
||||
.entity_with(UiComponents {
|
||||
node: Node::positioned(
|
||||
math::vec2(200.0, 185.0),
|
||||
Anchors::CENTER,
|
||||
|
@ -160,7 +160,7 @@ fn setup(
|
|||
..Default::default()
|
||||
})
|
||||
// texture
|
||||
.add_entity(UiEntity {
|
||||
.entity_with(UiComponents {
|
||||
node: Node::new(
|
||||
Anchors::CENTER_TOP,
|
||||
Margins::new(-250.0, 250.0, 510.0 * aspect, 10.0),
|
||||
|
|
|
@ -23,14 +23,14 @@ fn placement_system(
|
|||
|
||||
fn setup(command_buffer: &mut CommandBuffer, mut materials: ResMut<Assets<ColorMaterial>>) {
|
||||
let mut builder = command_buffer.build();
|
||||
builder.add_entity(OrthographicCameraEntity::ui());
|
||||
builder.entity_with(OrthographicCameraComponents::ui());
|
||||
|
||||
let mut prev = Vec2::default();
|
||||
let count = 1000;
|
||||
for i in 0..count {
|
||||
// 2d camera
|
||||
let cur = Vec2::new(1.0, 1.0) + prev;
|
||||
builder.add_entity(UiEntity {
|
||||
builder.entity_with(UiComponents {
|
||||
node: Node {
|
||||
position: Vec2::new(75.0, 75.0) + cur,
|
||||
anchors: Anchors::new(0.5, 0.5, 0.5, 0.5),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
pub use crate::{
|
||||
app::{
|
||||
schedule_runner::ScheduleRunnerPlugin, stage, App, AppBuilder, AppPlugin, DynamicAppPlugin,
|
||||
EntityArchetype, EventReader, Events, FromResources, System,
|
||||
ComponentSet, EventReader, Events, FromResources, System,
|
||||
},
|
||||
asset::{AddAsset, AssetEvent, AssetServer, Assets, Handle},
|
||||
core::{
|
||||
|
@ -32,7 +32,7 @@ pub use crate::{
|
|||
},
|
||||
scene::{Scene, SceneSpawner},
|
||||
sprite::{
|
||||
entity::{SpriteEntity, SpriteSheetEntity},
|
||||
entity::{SpriteComponents, SpriteSheetComponents},
|
||||
ColorMaterial, Sprite, TextureAtlas, TextureAtlasSprite,
|
||||
},
|
||||
text::{Font, TextStyle},
|
||||
|
|
Loading…
Reference in a new issue