gltf-rs / gltf

A crate for loading glTF 2.0
Apache License 2.0
535 stars 124 forks source link

Accessor failing to correctly identify type. #311

Closed StarArawn closed 3 years ago

StarArawn commented 3 years ago

I'm pulling positions out of a gltf using:

let reader = primitive.reader(|buffer| Some(&buffer_data[buffer.index()]));
if let Some(positions) = reader
    .read_positions()
{
    ...
}

This works fine for most of my meshes however one mesh fails when reading the positions with the following error:

accessor.index() = 0
accessor.dimensions().multiplicity() = 3
accessor.data_type().size() = 2
accessor.data_type() = U16
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `12`,
 right: `6`', \github.com-1ecc6299db9ec823\gltf-0.16.0\src\accessor\util.rs:338:13

This mesh works in common C++/javascript gltf viewers.

I'm 100% sure that the data_type should not be U16 for the positions. In fact looking at the gltf data I see that accessor index 0 is:

 {
    "bufferView": 0,
    "componentType": 5126,
    "count": 10,
    "max": [
        6.312699794769287,
        0.0348999984562397,
        -0.2665998637676239
    ],
    "min": [
        -6.312699794769287,
        0.0348999984562397,
        -4.096299171447754
    ],
    "type": "VEC3"
},
StarArawn commented 3 years ago

Nevermind, the issue was on my side.