qmuntal / gltf

Go library for encoding glTF 2.0 files
https://www.khronos.org/gltf/
BSD 2-Clause "Simplified" License
242 stars 32 forks source link

Cannot open .glb file after conversion from .gltf #63

Closed quipo closed 2 years ago

quipo commented 2 years ago

Getting EOF error when opening a .glb file converted from .gltf using gltf.SaveBinary().

Sample input .gltf file: https://github.com/qmuntal/gltf/files/9627951/simple.gltf.txt

Sample script:


import (
    "log"

    "github.com/qmuntal/gltf"
)

func main() {
    const simpleGltf = "simple.gltf"
    const outputGlb = "simple.glb"

    srcDoc, err := gltf.Open(simpleGltf)
    if nil != err {
        log.Fatal(err)
    }
    err = gltf.SaveBinary(srcDoc, outputGlb)
    if nil != err {
        log.Fatal(err)
    }

    tgtDoc, err2 := gltf.Open(outputGlb)
    if nil != err2 {
        log.Fatal(err2)
    }
    log.Println("SUCCESS!")
    log.Printf("DEBUG: %#v", tgtDoc)
}

NB: error seen using latest version of gltf package (v.0.22.1), but not using an older version (v.0.18.3). The output files slightly differ, it looks like the old version of the package was adding some nil "padding" at the end.

qmuntal commented 2 years ago

Thanks for the reproducer @quipo. #64 will fix this issue :)

quipo commented 2 years ago

amazing, thanks!