Declaration
Gltf_Primitive :: struct @json(rename_all=camelCase) {
attributes: Table(string, u32); indices: Json_Maybe(u32); material: Json_Maybe(u32); mode: Gltf_Mode = .TRIANGLES; @json(default,as_number) targets: [] Table(string, u32); @json(default,skip_serializing_if=empty) name: string; @json(default,skip_serializing_if=empty) extensions: Json_Value; @json(default,skip_serializing_if=null) extras: Json_Value; @json(default,skip_serializing_if=null)}One draw call of a mesh: vertex attributes by name (such as POSITION) to accessor index,
optional indices and material, the assembly mode, and morph targets.
#import "Hash_Table";
asset, error := gltf_load("{\"asset\":{\"version\":\"2.0\"},\"scene\":0,\"scenes\":[{\"nodes\":[0]}],\"nodes\":[{\"mesh\":0}],\"meshes\":[{\"primitives\":[{\"attributes\":{\"POSITION\":0},\"indices\":1}]}],\"buffers\":[{\"byteLength\":42,\"uri\":\"data:application/octet-stream;base64,AAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAAAAABAAIA\"}],\"bufferViews\":[{\"buffer\":0,\"byteLength\":36,\"target\":34962},{\"buffer\":0,\"byteOffset\":36,\"byteLength\":6,\"target\":34963}],\"accessors\":[{\"bufferView\":0,\"componentType\":5126,\"count\":3,\"type\":\"VEC3\",\"min\":[0,0,0],\"max\":[1,1,0]},{\"bufferView\":1,\"componentType\":5123,\"count\":3,\"type\":\"SCALAR\"}]}");
assert(error.kind == .NONE);
defer gltf_free(*asset);
primitive := asset.document.meshes[0].primitives[0];
found, position := table_find(*primitive.attributes, "POSITION");
assert(found && position == 0);
assert(primitive.indices.state == .SET && primitive.indices.value == 1);