Skip to content

Better support for custom vertex formats #60

@wolfiestyle

Description

@wolfiestyle

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions