add model.rs

This commit is contained in:
Quaternions 2023-09-22 15:21:13 -07:00
parent 2e786b090f
commit eafcbae677
2 changed files with 27 additions and 25 deletions

View File

@ -1,16 +1,9 @@
use bytemuck::{Pod, Zeroable};
use std::{borrow::Cow, time::Instant}; use std::{borrow::Cow, time::Instant};
use wgpu::{util::DeviceExt, AstcBlock, AstcChannel}; use wgpu::{util::DeviceExt, AstcBlock, AstcChannel};
use model::{Vertex,ModelData,ModelInstance};
#[derive(Clone, Copy, Pod, Zeroable)]
#[repr(C)]
struct Vertex {
pos: [f32; 3],
texture: [f32; 2],
normal: [f32; 3],
color: [f32; 4],
}
mod body; mod body;
mod model;
mod zeroes; mod zeroes;
mod framework; mod framework;
mod instruction; mod instruction;
@ -21,22 +14,6 @@ struct Entity {
index_buf: wgpu::Buffer, index_buf: wgpu::Buffer,
} }
struct ModelInstance {
transform: glam::Mat4,
color: glam::Vec4,
}
struct ModelData {
instances: Vec<ModelInstance>,
vertices: Vec<Vertex>,
entities: Vec<Vec<u16>>,
}
impl ModelData {
const COLOR_FLOATS_WHITE: [f32;4] = [1.0,1.0,1.0,1.0];
const COLOR_VEC4_WHITE: glam::Vec4 = glam::vec4(1.0,1.0,1.0,1.0);
}
struct ModelGraphics { struct ModelGraphics {
instances: Vec<ModelInstance>, instances: Vec<ModelInstance>,
vertex_buf: wgpu::Buffer, vertex_buf: wgpu::Buffer,

25
src/model.rs Normal file
View File

@ -0,0 +1,25 @@
use bytemuck::{Pod, Zeroable};
#[derive(Clone, Copy, Pod, Zeroable)]
#[repr(C)]
pub struct Vertex {
pub pos: [f32; 3],
pub texture: [f32; 2],
pub normal: [f32; 3],
pub color: [f32; 4],
}
pub struct ModelInstance {
pub transform: glam::Mat4,
pub color: glam::Vec4,
}
pub struct ModelData {
pub instances: Vec<ModelInstance>,
pub vertices: Vec<Vertex>,
pub entities: Vec<Vec<u16>>,
}
impl ModelData {
pub const COLOR_FLOATS_WHITE: [f32;4] = [1.0,1.0,1.0,1.0];
pub const COLOR_VEC4_WHITE: glam::Vec4 = glam::vec4(1.0,1.0,1.0,1.0);
}