Closed orzel7 closed 2 years ago
I would need some more context to investigate this issue. Ideally a code snippet showing how this glb was created.
Hey great library! I'm unable to create a simple gltf that parses for some reason.
Below example taken from the README.
Looks like the vertices and indices are missing?
doc := gltf.NewDocument()
doc.Meshes = []*gltf.Mesh{{
Name: "Pyramid",
Primitives: []*gltf.Primitive{{
Indices: gltf.Index(modeler.WriteIndices(doc, []uint16{0, 1, 2})),
Attributes: map[string]uint32{
gltf.POSITION: modeler.WritePosition(doc, [][3]float32{{0, 0, 0}, {0, 10, 0}, {0, 0, 10}}),
gltf.COLOR_0: modeler.WriteColor(doc, [][3]uint8{{255, 0, 0}, {0, 255, 0}, {0, 0, 255}}),
},
}},
}}
gltf.Save(doc, "./foo.gltf")
{
"accessors": [
{
"bufferView": 0,
"componentType": 5123,
"count": 3,
"type": "SCALAR"
},
{
"bufferView": 1,
"componentType": 5126,
"count": 3,
"type": "VEC3",
"max": [
0,
10,
10
],
"min": [
0,
0,
0
]
},
{
"bufferView": 2,
"componentType": 5121,
"normalized": true,
"count": 3,
"type": "VEC3"
}
],
"asset": {
"generator": "qmuntal/gltf",
"version": "2.0"
},
"buffers": [
{
"byteLength": 56
}
],
"bufferViews": [
{
"buffer": 0,
"byteLength": 6,
"target": 34963
},
{
"buffer": 0,
"byteOffset": 8,
"byteLength": 36,
"target": 34962
},
{
"buffer": 0,
"byteOffset": 44,
"byteLength": 12,
"byteStride": 4,
"target": 34962
}
],
"meshes": [
{
"name": "Pyramid",
"primitives": [
{
"attributes": {
"COLOR_0": 2,
"POSITION": 1
},
"indices": 0
}
]
}
],
"scene": 0,
"scenes": [
{
"name": "Root Scene"
}
]
}
You forget to wrap Mesh into the Node and add this Node to the Scene.
Something has changed in the meantime, i can't reproduce this problem again.
For anyone else that ends up here, here is an example of adding the node to a scene.
doc := gltf.NewDocument()
doc.Meshes = []*gltf.Mesh{{
Name: "Pyramid",
Primitives: []*gltf.Primitive{{
Indices: gltf.Index(modeler.WriteIndices(doc, []uint16{0, 1, 2})),
Attributes: map[string]uint32{
gltf.POSITION: modeler.WritePosition(doc, [][3]float32{{0, 0, 0}, {0, 10, 0}, {0, 0, 10}}),
gltf.COLOR_0: modeler.WriteColor(doc, [][3]uint8{{255, 0, 0}, {0, 255, 0}, {0, 0, 255}}),
},
}},
}}
doc.Nodes = []*gltf.Node{{Name: "Root", Mesh: gltf.Index(0)}}
doc.Scenes[0].Nodes = append(doc.Scenes[0].Nodes, 0)
gltf.SaveBinary(doc, "output/test.glb")
KhronosGroup/glTF-Validator reports errors on glb file(see attachment test.glb.gz) generated by this package: