//! 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; #[derive(Clone, Debug)] pub struct Transform { pub transform: glam::Mat4, } #[derive(Clone, Debug)] pub struct Mesh { pub mesh: MeshHandle, } #[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::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, attributes: DEBUG_VERTEX_ATTRS, } } } pub type DebugIndex = u32; #[derive(Clone, Default)] pub struct DebugDrawList { pub vertices: Vec, pub indices: Vec, } impl DebugDrawList { pub fn clear(&mut self) { self.vertices.clear(); self.indices.clear(); } pub fn merge(&mut self, other: &Self) { self.vertices.extend_from_slice(&other.vertices); let is_offset = self.indices.len(); self.indices.reserve(is_offset + other.indices.len()); for index in other.indices.iter() { if *index < (other.vertices.len() as DebugIndex) { self.indices.push(index + is_offset as DebugIndex); } } } }