Twinklebear / tobj

Tiny OBJ Loader in Rust
MIT License
238 stars 46 forks source link

Invalid groups when loading object #48

Open agorgl opened 3 years ago

agorgl commented 3 years ago

Using CornellBox-Original.obj from https://casual-effects.com/data/ the following snippet:

        let meshes = models
            .iter()
            .map(|m| {
                let mesh = &m.mesh;
                println!("{}: {}", m.name, mesh.indices.len());
                ...
            })
            .collect();

shows:

floor: 6
ceiling: 6
backWall: 6
rightWall: 6
leftWall: 6
leftWall: 36
shortBox: 36
light: 6
Twinklebear commented 2 years ago

Hi @agorgl , I think you're seeing this because tobj triangulates obj files by default. So the quads in the OBJ file are turned into 2 triangles. This is why the floor ends up with 6 indices (two triangles) instead of 4 (a quad).

You can now pass the LoadOptions struct to tobj to tell it to not triangulate the mesh. Then I think the indices should match what you expect, since you'll get the quads back.