use bevy::{
asset::RenderAssetUsages,
mesh::{Indices, PrimitiveTopology},
prelude::*,
};
use crate::MeshGraph;
use super::VertexIndexBuffers;
impl From<MeshGraph> for Mesh {
fn from(mesh_graph: MeshGraph) -> Self {
let buffers: VertexIndexBuffers = mesh_graph.into();
Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetUsages::default(),
)
.with_inserted_attribute(
Mesh::ATTRIBUTE_POSITION,
buffers
.positions
.into_iter()
.map(|v| v.to_array())
.collect::<Vec<_>>(),
)
.with_inserted_attribute(
Mesh::ATTRIBUTE_NORMAL,
buffers
.normals
.into_iter()
.map(|v| v.to_array())
.collect::<Vec<_>>(),
)
.with_inserted_indices(Indices::U32(buffers.indices))
}
}