gwihlidal / meshopt-rs

Rust ffi and idiomatic wrapper for zeux/meshoptimizer, a mesh optimization library that makes indexed meshes more GPU-friendly.
Apache License 2.0
163 stars 33 forks source link

Bevy mesh support #35

Open davids91 opened 11 months ago

davids91 commented 11 months ago

Hey! Nice library! Hope to utilize it to its potential! Is there a possibility to support Bevy mesh formats?

In the following format for example:

    // ( inside a struct )
    pub(crate) positions: Vec<[f32; 3]>,
    pub(crate) normals: Vec<[f32; 3]>,
    pub(crate) uvs: Vec<[f32; 2]>,

       // inside the struct implementation
        let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
        mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, std::mem::take(&mut self.uvs));
        mesh.insert_attribute(
            Mesh::ATTRIBUTE_POSITION,
            std::mem::take(&mut self.positions),
        );
        mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, std::mem::take(&mut self.normals));
        mesh.set_indices(Some(mesh::Indices::U32(std::mem::take(
            &mut self.triangle_indices,
        ))));

The difference between this, and Vec<Vertex> is that the data is stored in standalone arrays, not interleaved as in the Vertex Vec.

Uriopass commented 9 months ago

I don't think this would be possible without upstream support