Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for custom vertex formats #60

Open
wolfiestyle opened this issue Feb 21, 2023 · 1 comment
Open

Better support for custom vertex formats #60

wolfiestyle opened this issue Feb 21, 2023 · 1 comment

Comments

@wolfiestyle
Copy link

As of current version, the loading interface looks like this:

pub fn load_obj<V: FromRawVertex<I>, T: BufRead, I>(input: T) -> ObjResult<Obj<V, I>>

so i'm like "yeah, i can plug my own vertex format too!", but when i look at the FromRawVertex trait, i see this:

pub trait FromRawVertex<I>: Sized {
    /// Build vertex and index buffer from raw object data.
    fn process(
        vertices: Vec<(f32, f32, f32, f32)>,
        normals: Vec<(f32, f32, f32)>,
        tex_coords: Vec<(f32, f32, f32)>,
        polygons: Vec<Polygon>,
    ) -> ObjResult<(Vec<Self>, Vec<I>)>;
}

and the vertex from raw conversion in done in an opaque way inside the library, so if I wanted to implement my own vertex format, I would have to re-write all this conversion code myself or copy-paste it from the source.

A better way support user-defined custom vertex formats would be proving a trait like:

pub trait FromRawVertex {
    type Output;

    fn convert_vertex(position: [f32; 4], normal: [f32; 3], tex_coord: [f32; 3]) -> Self::Output;
}

that can be used convert each vertex individually, then have a standalone conversion function like:

fn process_vertices<T: FromRawVertex, I>(raw: RawObj) -> ObjResult<(Vec<T::Output>, Vec<I>)>

Maybe i'm missing some stuff, but that's what I understood so far.

@simnalamburt
Copy link
Owner

I got the point but it was to avoid performance overhead caused by the interface. Maybe exposing both interfaces can be convenient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants