cyborg/src/scene.rs

56 lines
1.3 KiB
Rust

//! Traits for describing Cyborg's scene representation.
//!
//! TODO this will all need to be replaced in favor of a way to represent
//! querying component and resource data framework-agnostically
use crate::storage::mesh::MeshHandle;
use parking_lot::RwLock;
use std::sync::Arc;
#[derive(Clone, Debug)]
pub struct TransformedMesh {
pub transform: glam::Mat4,
pub mesh: MeshHandle,
}
#[derive(Default)]
pub struct Meshes {
pub transformed: Vec<TransformedMesh>,
}
pub type MeshesHandle = Arc<RwLock<Meshes>>;
#[repr(C)]
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
pub struct DebugVertex {
pub position: [f32; 3],
pub color: [f32; 3],
}
pub const DEBUG_VERTEX_ATTRS: &[wgpu::VertexAttribute] =
&wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3];
impl DebugVertex {
pub fn desc() -> wgpu::VertexBufferLayout<'static> {
wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<Self>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: DEBUG_VERTEX_ATTRS,
}
}
}
pub type DebugIndex = u32;
pub struct DebugDraw {
pub vertices: Vec<DebugVertex>,
pub indices: Vec<DebugIndex>,
}
#[derive(Default)]
pub struct DebugDraws {
pub draws: Vec<DebugDraw>,
}
pub type DebugDrawsHandle = Arc<RwLock<DebugDraws>>;