From 7cf43ccb8b8b1726c2697188b9138847780cd08e Mon Sep 17 00:00:00 2001 From: Lorenzo Torres Date: Mon, 24 Mar 2025 19:49:49 +0100 Subject: glTF models now take buffer lengths at runtime --- assets/models/block.glb | Bin 1944 -> 69684 bytes src/rendering/gltf.zig | 6 ++---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/assets/models/block.glb b/assets/models/block.glb index 879f0ac..74ea15f 100644 Binary files a/assets/models/block.glb and b/assets/models/block.glb differ diff --git a/src/rendering/gltf.zig b/src/rendering/gltf.zig index 888191d..32a632a 100644 --- a/src/rendering/gltf.zig +++ b/src/rendering/gltf.zig @@ -157,10 +157,8 @@ pub fn parseFile(allocator: Allocator, name: []const u8) !struct { vertices: [][ const data = (try std.json.parseFromSlice(Model.JsonChunk, allocator, @constCast(all[Model.Chunk.offset .. Model.Chunk.offset + json_chunk.length]), .{ .ignore_unknown_fields = true })).value; const binary = Model.Binary{ .data = all[Model.Chunk.offset + json_chunk.length + 8 ..] }; - const vertices = try binary.readVec3(allocator, data.bufferViews.?[data.meshes.?[0].primitives.?[0].attributes.?.POSITION.?], 24); - const indices = try binary.readU16(allocator, data.bufferViews.?[data.meshes.?[0].primitives.?[0].indices.?], 36); - std.debug.print("vertices: {any}\n", .{vertices}); - std.debug.print("indices: {any}\n", .{indices}); + const vertices = try binary.readVec3(allocator, data.bufferViews.?[data.meshes.?[0].primitives.?[0].attributes.?.POSITION.?], data.accessors.?[data.meshes.?[0].primitives.?[0].attributes.?.POSITION.?].count); + const indices = try binary.readU16(allocator, data.bufferViews.?[data.meshes.?[0].primitives.?[0].indices.?], data.accessors.?[data.meshes.?[0].primitives.?[0].indices.?].count); return .{ .vertices = vertices, .indices = indices }; } -- cgit v1.2.3