Giter VIP home page Giter VIP logo

Comments (3)

gwihlidal avatar gwihlidal commented on July 29, 2024

Performance has been improved, will do some timings in the near future and see what's remaining.

from meshopt-rs.

gwihlidal avatar gwihlidal commented on July 29, 2024

The remaining work is around improving the DecodePosition -> collect pattern. I'm thinking that implementing a nice referencing data reader that can step by a configurable stride, and is zero-copy would do the trick (needs to work like the C++ API which works similar to glVertexPointer)

An example:

pub struct VertexDataReader<'a> {
    reader: Cursor<&'a [u8]>
}

impl<'a> VertexDataReader<'a> {
    pub fn new (data: &'a [u8]) -> VertexDataReader<'a> {
        VertexDataReader{ reader: Cursor::new(data) }
    }
}

impl<'a> Read for VertexDataReader<'a> {
    fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> {
        self.reader.read(buf)
    }
}

from meshopt-rs.

repi avatar repi commented on July 29, 2024

I'm using nalgebra_glm types for my vertex streams as well as some custom types and ran into some issues with that related to DecodePosition and with requiring that vertex data implement Default (which none of my types did).

My first workaround was to implement some new function wrappers locally for this use case, one that allowed me to remap without having the structure implement the Default trait by providing a fn that could do that instead:

fn remap_vertex_buffer<T>(
    vertex_remap: &[u32],
    source_vertices: &[T],
    default_fn: fn() -> T,
) -> Vec<T>
where
    T: Clone,
{
    let mut dest_vertices: Vec<T> = vec![default_fn(); vertex_remap.len()];
    unsafe {
        meshopt::ffi::meshopt_remapVertexBuffer(
            dest_vertices.as_mut_ptr() as *mut ::std::os::raw::c_void,
            source_vertices.as_ptr() as *const ::std::os::raw::c_void,
            vertex_remap.len(),
            std::mem::size_of::<T>(),
            vertex_remap.as_ptr() as *const ::std::os::raw::c_uint,
        );
    }
    dest_vertices
}

Which I called like this, which felt like an ok workaround:

mesh.positions = remap_vertex_buffer(&vertex_remap, &mesh.positions, || glm::vec3(0.0, 0.0, 0.0));

To avoid DecodePosition I simply did a local explicit version with the glm::Vec3 type which is definitely not as nice but works:

fn optimize_overdraw_in_place(indices: &mut [u32], vertices: &[glm::Vec3], threshold: f32) {
    let positions = vertices
        .iter()
        .map(|vertex| [vertex.x, vertex.y, vertex.z])
        .collect::<Vec<[f32; 3]>>();
    unsafe {
        meshopt::ffi::meshopt_optimizeOverdraw(
            indices.as_mut_ptr() as *mut ::std::os::raw::c_uint,
            indices.as_ptr() as *const ::std::os::raw::c_uint,
            indices.len(),
            positions.as_ptr() as *const f32,
            positions.len(),
            std::mem::size_of::<f32>() * 3,
            threshold,
        );
    }
}

So having your proposed VertexDataReader and being able to pass that in to read and convert any data stream would be a much better approach I think.

from meshopt-rs.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.