cargo fmt
This commit is contained in:
parent
68676bf6fa
commit
7037c8c494
@ -205,7 +205,9 @@ fn create_person(world: &mut World, mesh_handle: Handle<Mesh>, translation: Tran
|
|||||||
value: math::vec3(0.0, 0.0, 0.0),
|
value: math::vec3(0.0, 0.0, 0.0),
|
||||||
},
|
},
|
||||||
Instanced,
|
Instanced,
|
||||||
Material::new(Albedo::Color(math::vec4(0.5, 0.3, 0.3, 1.0) * random::<f32>())),
|
Material::new(Albedo::Color(
|
||||||
|
math::vec4(0.5, 0.3, 0.3, 1.0) * random::<f32>(),
|
||||||
|
)),
|
||||||
mesh_handle,
|
mesh_handle,
|
||||||
LocalToWorld::identity(),
|
LocalToWorld::identity(),
|
||||||
translation,
|
translation,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use bevy::{prelude::*, asset};
|
use bevy::{asset, prelude::*};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
asset::load_gltf("examples/assets/Box.gltf").unwrap();
|
asset::load_gltf("examples/assets/Box.gltf").unwrap();
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
use bevy::{prelude::*, serialization::*};
|
use bevy::{prelude::*, serialization::*};
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use type_uuid::TypeUuid;
|
use type_uuid::TypeUuid;
|
||||||
fn main() {
|
fn main() {
|
||||||
let app = AppBuilder::new().add_defaults().setup_world(setup).build();
|
let app = AppBuilder::new().add_defaults().setup_world(setup).build();
|
||||||
|
|
||||||
let comp_registrations = [
|
let comp_registrations = [ComponentRegistration::of::<Test>()];
|
||||||
ComponentRegistration::of::<Test>(),
|
|
||||||
];
|
|
||||||
|
|
||||||
let tag_registrations = [];
|
let tag_registrations = [];
|
||||||
|
|
||||||
@ -14,12 +12,20 @@ fn main() {
|
|||||||
let serializable = legion::ser::serializable_world(&app.world, &ser_helper);
|
let serializable = legion::ser::serializable_world(&app.world, &ser_helper);
|
||||||
let serialized_data = serde_json::to_string(&serializable).unwrap();
|
let serialized_data = serde_json::to_string(&serializable).unwrap();
|
||||||
println!("{}", serialized_data);
|
println!("{}", serialized_data);
|
||||||
let de_helper = DeserializeImpl::new(ser_helper.comp_types, ser_helper.tag_types, ser_helper.entity_map);
|
let de_helper = DeserializeImpl::new(
|
||||||
|
ser_helper.comp_types,
|
||||||
|
ser_helper.tag_types,
|
||||||
|
ser_helper.entity_map,
|
||||||
|
);
|
||||||
|
|
||||||
let mut new_world = app.universe.create_world();
|
let mut new_world = app.universe.create_world();
|
||||||
let mut deserializer = serde_json::Deserializer::from_str(&serialized_data);
|
let mut deserializer = serde_json::Deserializer::from_str(&serialized_data);
|
||||||
legion::de::deserialize(&mut new_world, &de_helper, &mut deserializer).unwrap();
|
legion::de::deserialize(&mut new_world, &de_helper, &mut deserializer).unwrap();
|
||||||
let ser_helper = SerializeImpl::new_with_map(&comp_registrations, &tag_registrations, de_helper.entity_map.into_inner());
|
let ser_helper = SerializeImpl::new_with_map(
|
||||||
|
&comp_registrations,
|
||||||
|
&tag_registrations,
|
||||||
|
de_helper.entity_map.into_inner(),
|
||||||
|
);
|
||||||
let serializable = legion::ser::serializable_world(&new_world, &ser_helper);
|
let serializable = legion::ser::serializable_world(&new_world, &ser_helper);
|
||||||
let roundtrip_data = serde_json::to_string(&serializable).unwrap();
|
let roundtrip_data = serde_json::to_string(&serializable).unwrap();
|
||||||
println!("{}", roundtrip_data);
|
println!("{}", roundtrip_data);
|
||||||
@ -35,10 +41,5 @@ pub struct Test {
|
|||||||
|
|
||||||
fn setup(world: &mut World) {
|
fn setup(world: &mut World) {
|
||||||
// plane
|
// plane
|
||||||
world.insert(
|
world.insert((), vec![(Test { x: 3.0, y: 4.0 },)]);
|
||||||
(),
|
|
||||||
vec![(
|
|
||||||
Test {x: 3.0, y: 4.0},
|
|
||||||
)],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ use winit::{
|
|||||||
|
|
||||||
use legion::prelude::*;
|
use legion::prelude::*;
|
||||||
|
|
||||||
use crate::{render::*, core::Time};
|
use crate::{core::Time, render::*};
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
pub universe: Universe,
|
pub universe: Universe,
|
||||||
@ -16,7 +16,12 @@ pub struct App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub fn new(universe: Universe, world: World, schedule: Schedule, render_graph: RenderGraph) -> App {
|
pub fn new(
|
||||||
|
universe: Universe,
|
||||||
|
world: World,
|
||||||
|
schedule: Schedule,
|
||||||
|
render_graph: RenderGraph,
|
||||||
|
) -> App {
|
||||||
App {
|
App {
|
||||||
universe,
|
universe,
|
||||||
world,
|
world,
|
||||||
@ -50,9 +55,7 @@ impl App {
|
|||||||
self.world.resources.insert(window);
|
self.world.resources.insert(window);
|
||||||
|
|
||||||
log::info!("Initializing the example...");
|
log::info!("Initializing the example...");
|
||||||
self.render_graph.initialize(
|
self.render_graph.initialize(&mut self.world);
|
||||||
&mut self.world,
|
|
||||||
);
|
|
||||||
|
|
||||||
log::info!("Entering render loop...");
|
log::info!("Entering render loop...");
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
@ -66,7 +69,8 @@ impl App {
|
|||||||
event: WindowEvent::Resized(size),
|
event: WindowEvent::Resized(size),
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
self.render_graph.resize(size.width, size.height, &mut self.world);
|
self.render_graph
|
||||||
|
.resize(size.width, size.height, &mut self.world);
|
||||||
}
|
}
|
||||||
event::Event::WindowEvent { event, .. } => match event {
|
event::Event::WindowEvent { event, .. } => match event {
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
|
app::App,
|
||||||
asset::*,
|
asset::*,
|
||||||
legion::{
|
core::Time,
|
||||||
prelude::{Schedule, Schedulable, World, Universe, Runnable},
|
legion::prelude::{Runnable, Schedulable, Schedule, Universe, World},
|
||||||
},
|
legion_transform::transform_system_bundle,
|
||||||
render::{passes::*, *},
|
render::{passes::*, *},
|
||||||
legion_transform::transform_system_bundle, ui, app::App, core::Time,
|
ui,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@ -54,7 +55,12 @@ impl AppBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
App::new(self.universe, self.world, schedule_builder.build(), self.render_graph)
|
App::new(
|
||||||
|
self.universe,
|
||||||
|
self.world,
|
||||||
|
schedule_builder.build(),
|
||||||
|
self.render_graph,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(self) {
|
pub fn run(self) {
|
||||||
@ -77,7 +83,8 @@ impl AppBuilder {
|
|||||||
|
|
||||||
pub fn add_system_to_stage(mut self, stage_name: &str, system: Box<dyn Schedulable>) -> Self {
|
pub fn add_system_to_stage(mut self, stage_name: &str, system: Box<dyn Schedulable>) -> Self {
|
||||||
if let None = self.system_stages.get(stage_name) {
|
if let None = self.system_stages.get(stage_name) {
|
||||||
self.system_stages.insert(stage_name.to_string(), Vec::new());
|
self.system_stages
|
||||||
|
.insert(stage_name.to_string(), Vec::new());
|
||||||
self.stage_order.push(stage_name.to_string());
|
self.stage_order.push(stage_name.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +96,8 @@ impl AppBuilder {
|
|||||||
|
|
||||||
pub fn add_runnable_to_stage(mut self, stage_name: &str, system: Box<dyn Runnable>) -> Self {
|
pub fn add_runnable_to_stage(mut self, stage_name: &str, system: Box<dyn Runnable>) -> Self {
|
||||||
if let None = self.runnable_stages.get(stage_name) {
|
if let None = self.runnable_stages.get(stage_name) {
|
||||||
self.runnable_stages.insert(stage_name.to_string(), Vec::new());
|
self.runnable_stages
|
||||||
|
.insert(stage_name.to_string(), Vec::new());
|
||||||
self.stage_order.push(stage_name.to_string());
|
self.stage_order.push(stage_name.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,8 +119,15 @@ impl AppBuilder {
|
|||||||
.add_render_resource_manager(Box::new(render_resources::Global2dResourceManager));
|
.add_render_resource_manager(Box::new(render_resources::Global2dResourceManager));
|
||||||
|
|
||||||
let depth_format = wgpu::TextureFormat::Depth32Float;
|
let depth_format = wgpu::TextureFormat::Depth32Float;
|
||||||
render_graph.set_pass("forward", Box::new(ForwardPass::new(depth_format, msaa_samples)));
|
render_graph.set_pass(
|
||||||
render_graph.set_pipeline("forward", "forward", Box::new(ForwardPipeline::new(msaa_samples)));
|
"forward",
|
||||||
|
Box::new(ForwardPass::new(depth_format, msaa_samples)),
|
||||||
|
);
|
||||||
|
render_graph.set_pipeline(
|
||||||
|
"forward",
|
||||||
|
"forward",
|
||||||
|
Box::new(ForwardPipeline::new(msaa_samples)),
|
||||||
|
);
|
||||||
render_graph.set_pipeline(
|
render_graph.set_pipeline(
|
||||||
"forward",
|
"forward",
|
||||||
"forward_instanced",
|
"forward_instanced",
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
mod app_builder;
|
|
||||||
mod app;
|
mod app;
|
||||||
|
mod app_builder;
|
||||||
|
|
||||||
pub use app_builder::AppBuilder;
|
|
||||||
pub use app::App;
|
pub use app::App;
|
||||||
|
pub use app_builder::AppBuilder;
|
||||||
|
|||||||
@ -67,10 +67,26 @@ pub fn create_quad(
|
|||||||
south_east: Vec2,
|
south_east: Vec2,
|
||||||
) -> (Vec<Vertex>, Vec<u16>) {
|
) -> (Vec<Vertex>, Vec<u16>) {
|
||||||
let vertex_data = [
|
let vertex_data = [
|
||||||
Vertex::from(([south_west.x(), south_west.y(), 0.0], [0.0, 0.0, 1.0], [0.0, 0.0])),
|
Vertex::from((
|
||||||
Vertex::from(([north_west.x(), north_west.y(), 0.0], [0.0, 0.0, 1.0], [0.0, 1.0])),
|
[south_west.x(), south_west.y(), 0.0],
|
||||||
Vertex::from(([north_east.x(), north_east.y(), 0.0], [0.0, 0.0, 1.0], [1.0, 1.0])),
|
[0.0, 0.0, 1.0],
|
||||||
Vertex::from(([south_east.x(), south_east.y(), 0.0], [0.0, 0.0, 1.0], [1.0, 0.0])),
|
[0.0, 0.0],
|
||||||
|
)),
|
||||||
|
Vertex::from((
|
||||||
|
[north_west.x(), north_west.y(), 0.0],
|
||||||
|
[0.0, 0.0, 1.0],
|
||||||
|
[0.0, 1.0],
|
||||||
|
)),
|
||||||
|
Vertex::from((
|
||||||
|
[north_east.x(), north_east.y(), 0.0],
|
||||||
|
[0.0, 0.0, 1.0],
|
||||||
|
[1.0, 1.0],
|
||||||
|
)),
|
||||||
|
Vertex::from((
|
||||||
|
[south_east.x(), south_east.y(), 0.0],
|
||||||
|
[0.0, 0.0, 1.0],
|
||||||
|
[1.0, 0.0],
|
||||||
|
)),
|
||||||
];
|
];
|
||||||
|
|
||||||
let index_data: &[u16] = &[0, 2, 1, 0, 3, 2];
|
let index_data: &[u16] = &[0, 2, 1, 0, 3, 2];
|
||||||
|
|||||||
@ -14,16 +14,14 @@ impl Asset<TextureType> for Texture {
|
|||||||
TextureType::Data(data) => data.clone(),
|
TextureType::Data(data) => data.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Texture {
|
Texture { data: data }
|
||||||
data: data,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_texels(size: usize) -> Vec<u8> {
|
pub fn create_texels(size: usize) -> Vec<u8> {
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
(0 .. size * size)
|
(0..size * size)
|
||||||
.flat_map(|id| {
|
.flat_map(|id| {
|
||||||
// get high five for recognizing this ;)
|
// get high five for recognizing this ;)
|
||||||
let cx = 3.0 * (id % size) as f32 / (size - 1) as f32 - 2.0;
|
let cx = 3.0 * (id % size) as f32 / (size - 1) as f32 - 2.0;
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
use crate::prelude::{Children, Entity, World, SubWorld};
|
use crate::prelude::{Children, Entity, SubWorld, World};
|
||||||
|
|
||||||
pub fn run_on_hierarchy<T>(
|
pub fn run_on_hierarchy<T>(
|
||||||
world: &mut World,
|
world: &mut World,
|
||||||
entity: Entity,
|
entity: Entity,
|
||||||
|
|||||||
@ -2,12 +2,12 @@ pub mod app;
|
|||||||
pub mod asset;
|
pub mod asset;
|
||||||
pub mod core;
|
pub mod core;
|
||||||
pub mod ecs;
|
pub mod ecs;
|
||||||
pub mod render;
|
|
||||||
pub mod ui;
|
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
|
pub mod render;
|
||||||
pub mod serialization;
|
pub mod serialization;
|
||||||
|
pub mod ui;
|
||||||
|
|
||||||
pub use wgpu;
|
|
||||||
pub use glam as math;
|
pub use glam as math;
|
||||||
pub use legion;
|
pub use legion;
|
||||||
pub use legion_transform;
|
pub use legion_transform;
|
||||||
|
pub use wgpu;
|
||||||
|
|||||||
@ -3,8 +3,10 @@ pub use crate::{
|
|||||||
asset::{Asset, AssetStorage, Handle, Mesh, MeshType, Texture, TextureType},
|
asset::{Asset, AssetStorage, Handle, Mesh, MeshType, Texture, TextureType},
|
||||||
core::Time,
|
core::Time,
|
||||||
ecs,
|
ecs,
|
||||||
render::{Albedo, Camera, CameraType, ActiveCamera, ActiveCamera2d, Instanced, Light, Material},
|
render::{
|
||||||
ui::{Node, Anchors, Margins},
|
ActiveCamera, ActiveCamera2d, Albedo, Camera, CameraType, Instanced, Light, Material,
|
||||||
|
},
|
||||||
|
ui::{Anchors, Margins, Node},
|
||||||
};
|
};
|
||||||
pub use glam as math;
|
pub use glam as math;
|
||||||
pub use legion::{
|
pub use legion::{
|
||||||
@ -14,4 +16,4 @@ pub use legion::{
|
|||||||
system::SystemBuilder,
|
system::SystemBuilder,
|
||||||
};
|
};
|
||||||
pub use legion_transform::prelude::*;
|
pub use legion_transform::prelude::*;
|
||||||
pub use math::{Mat3, Mat4, Vec2, Vec3, Vec4, Quat};
|
pub use math::{Mat3, Mat4, Quat, Vec2, Vec3, Vec4};
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
use crate::{asset::{Handle, Texture}, math};
|
use crate::{
|
||||||
|
asset::{Handle, Texture},
|
||||||
|
math,
|
||||||
|
};
|
||||||
use zerocopy::{AsBytes, FromBytes};
|
use zerocopy::{AsBytes, FromBytes};
|
||||||
|
|
||||||
pub enum Albedo {
|
pub enum Albedo {
|
||||||
|
|||||||
@ -86,7 +86,10 @@ impl Pass for ForwardPass {
|
|||||||
&render_graph.swap_chain_descriptor,
|
&render_graph.swap_chain_descriptor,
|
||||||
self.msaa_samples,
|
self.msaa_samples,
|
||||||
);
|
);
|
||||||
render_graph.set_texture(MULTISAMPLED_FRAMEBUFFER_TEXTURE_NAME, multisampled_framebuffer);
|
render_graph.set_texture(
|
||||||
|
MULTISAMPLED_FRAMEBUFFER_TEXTURE_NAME,
|
||||||
|
multisampled_framebuffer,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +115,9 @@ impl Pass for ForwardPass {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let multisampled_framebuffer = render_graph.get_texture(MULTISAMPLED_FRAMEBUFFER_TEXTURE_NAME).unwrap();
|
let multisampled_framebuffer = render_graph
|
||||||
|
.get_texture(MULTISAMPLED_FRAMEBUFFER_TEXTURE_NAME)
|
||||||
|
.unwrap();
|
||||||
wgpu::RenderPassColorAttachmentDescriptor {
|
wgpu::RenderPassColorAttachmentDescriptor {
|
||||||
attachment: multisampled_framebuffer,
|
attachment: multisampled_framebuffer,
|
||||||
resolve_target: Some(&frame.view),
|
resolve_target: Some(&frame.view),
|
||||||
@ -151,7 +156,10 @@ impl Pass for ForwardPass {
|
|||||||
&render_graph.swap_chain_descriptor,
|
&render_graph.swap_chain_descriptor,
|
||||||
self.msaa_samples,
|
self.msaa_samples,
|
||||||
);
|
);
|
||||||
render_graph.set_texture(MULTISAMPLED_FRAMEBUFFER_TEXTURE_NAME, multisampled_framebuffer);
|
render_graph.set_texture(
|
||||||
|
MULTISAMPLED_FRAMEBUFFER_TEXTURE_NAME,
|
||||||
|
multisampled_framebuffer,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
asset::*,
|
asset::*,
|
||||||
render::{instancing::InstanceBufferInfo, *},
|
|
||||||
prelude::LocalToWorld,
|
prelude::LocalToWorld,
|
||||||
|
render::{instancing::InstanceBufferInfo, *},
|
||||||
};
|
};
|
||||||
use legion::prelude::*;
|
use legion::prelude::*;
|
||||||
use std::{collections::HashMap, mem};
|
use std::{collections::HashMap, mem};
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
asset::*,
|
asset::*,
|
||||||
ecs, math,
|
ecs, math,
|
||||||
|
prelude::Parent,
|
||||||
render::{instancing::InstanceBufferInfo, *},
|
render::{instancing::InstanceBufferInfo, *},
|
||||||
ui::Node,
|
ui::Node,
|
||||||
prelude::Parent,
|
|
||||||
};
|
};
|
||||||
use legion::prelude::*;
|
use legion::prelude::*;
|
||||||
use wgpu::SwapChainOutput;
|
use wgpu::SwapChainOutput;
|
||||||
|
|||||||
@ -29,6 +29,7 @@ pub struct RenderGraphData {
|
|||||||
uniform_buffers: HashMap<String, UniformBuffer>,
|
uniform_buffers: HashMap<String, UniformBuffer>,
|
||||||
bind_group_layouts: HashMap<String, wgpu::BindGroupLayout>,
|
bind_group_layouts: HashMap<String, wgpu::BindGroupLayout>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderGraphData {
|
impl RenderGraphData {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
device: wgpu::Device,
|
device: wgpu::Device,
|
||||||
@ -152,7 +153,8 @@ impl RenderGraph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&mut self, world: &mut World) {
|
pub fn render(&mut self, world: &mut World) {
|
||||||
let frame = self.swap_chain
|
let frame = self
|
||||||
|
.swap_chain
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.get_next_texture()
|
.get_next_texture()
|
||||||
|
|||||||
@ -22,14 +22,9 @@ impl From<([f32; 4], [f32; 4], [f32; 2])> for Vertex {
|
|||||||
impl From<([f32; 3], [f32; 3], [f32; 2])> for Vertex {
|
impl From<([f32; 3], [f32; 3], [f32; 2])> for Vertex {
|
||||||
fn from((position, normal, uv): ([f32; 3], [f32; 3], [f32; 2])) -> Self {
|
fn from((position, normal, uv): ([f32; 3], [f32; 3], [f32; 2])) -> Self {
|
||||||
Vertex {
|
Vertex {
|
||||||
position: [
|
position: [position[0], position[1], position[2], 1.0],
|
||||||
position[0],
|
|
||||||
position[1],
|
|
||||||
position[2],
|
|
||||||
1.0,
|
|
||||||
],
|
|
||||||
normal: [normal[0], normal[1], normal[2], 0.0],
|
normal: [normal[0], normal[1], normal[2], 0.0],
|
||||||
uv: uv
|
uv: uv,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,10 +44,7 @@ impl From<([i8; 4], [i8; 4], [i8; 2])> for Vertex {
|
|||||||
normal[2] as f32,
|
normal[2] as f32,
|
||||||
normal[3] as f32,
|
normal[3] as f32,
|
||||||
],
|
],
|
||||||
uv: [
|
uv: [uv[0] as f32, uv[1] as f32],
|
||||||
uv[0] as f32,
|
|
||||||
uv[1] as f32,
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user