1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
use crate::core::{Indices, Color, Vertex, PackedAnimation, AnimationKind}; use bevy::render::mesh::Mesh; use bevy::render::pipeline::PrimitiveTopology; #[derive(Debug, Clone)] pub struct Tessellation { pub vertices: Vec<Vertex>, pub indices: Indices, pub colors: Vec<Color>, } impl Default for Tessellation { fn default() -> Self { Self { vertices: vec![], indices: Indices::U16(vec![]), colors: vec![] } } } pub trait Drawing: Sync + Send + 'static { fn get_tessellation(&self) -> Tessellation; fn get_mesh(&self) -> Mesh { let tessellation = self.get_tessellation(); let mut mesh = Mesh::new(PrimitiveTopology::TriangleList); mesh.set_attribute(Mesh::ATTRIBUTE_POSITION, tessellation.vertices); mesh.set_attribute(Mesh::ATTRIBUTE_COLOR, tessellation.colors); mesh.set_indices(Some(tessellation.indices)); mesh } fn animate<A: AnimationKind>(&self, animation: A) -> PackedAnimation { animation.generate(self.get_tessellation()) } }