new architecture

This commit is contained in:
zack 2025-03-26 20:02:58 -04:00
parent 9f7e72b784
commit 9cfd9d8b17
No known key found for this signature in database
GPG key ID: EE8A2B709E2401D1
28 changed files with 2625 additions and 5351 deletions

18
crates/engine/Cargo.toml Normal file
View file

@ -0,0 +1,18 @@
[package]
name = "engine"
version = "0.1.0"
edition = "2021"
[dependencies]
ash.workspace = true
winit.workspace = true
raw-window-handle.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
glam.workspace = true
bytemuck.workspace = true
thiserror.workspace = true
gpu-allocator.workspace = true
gfx_hal = { path = "../gfx_hal" }
resource_manager = { path = "../resource_manager" }

View file

@ -0,0 +1,5 @@
mod scene_data;
fn main() {
println!("Hello, world!");
}

View file

@ -0,0 +1,67 @@
use core::f32;
use bytemuck::{Pod, Zeroable};
use glam::{Mat4, Vec3};
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct Vertex {
pub pos: [f32; 3],
pub normal: [f32; 3],
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct UniformBufferObject {
pub model: Mat4,
pub view: Mat4,
pub proj: Mat4,
pub light_dir: Vec3,
pub _padding: f32,
pub light_color: Vec3,
pub _padding2: f32,
}
pub fn create_sphere(radius: f32, sectors: u32, stacks: u32) -> (Vec<Vertex>, Vec<u32>) {
let mut vertices = Vec::new();
let mut indices = Vec::new();
let sector_step = 2.0 * f32::consts::PI / sectors as f32;
let stack_step = f32::consts::PI / stacks as f32;
for i in 0..stacks {
let stack_angle = std::f32::consts::PI / 2.0 - (i as f32 * stack_step);
let xy = radius * stack_angle.cos();
let z = radius * stack_angle.sin();
for j in 0..=sectors {
let sector_angle = j as f32 * sector_step;
let x = xy * sector_angle.cos();
let y = xy * sector_angle.sin();
let pos = [x, y, z];
let normal = Vec3::from(pos).normalize().to_array();
vertices.push(Vertex { pos, normal });
}
}
for i in 0..stacks {
let k1 = i * (sectors + 1);
let k2 = k1 + sectors + 1;
for j in 0..sectors {
if i != 0 {
indices.push(k1 + j);
indices.push(k2 + j);
indices.push(k1 + j + 1);
}
if i != (stacks - 1) {
indices.push(k1 + j + 1);
indices.push(k2 + j);
indices.push(k2 + j + 1);
}
}
}
(vertices, indices)
}