diff --git a/src/assets/Materials.zig b/src/assets/Materials.zig index 0b7c346..5a80263 100644 --- a/src/assets/Materials.zig +++ b/src/assets/Materials.zig @@ -110,6 +110,31 @@ pub fn getOrLoadFilename(self: *Materials, engine: *Engine, textures: *Textures, } } +pub fn loadAll(self: *Materials, engine: *Engine, textures: *Textures, temp_allocator: std.mem.Allocator) void { + const cwd = std.fs.cwd(); + + var dir = cwd.openDir("assets/materials", .{ .iterate = true }) catch |err| { + std.log.err("Error while opening metarials directory: {s}", .{@errorName(err)}); + return; + }; + defer dir.close(); + + var it = dir.iterate(); + while (it.next() catch |err| { + std.log.err("Error while iterating over materials directory: {s}", .{@errorName(err)}); + return; + }) |entry| { + if (entry.kind != .file) { + std.log.warn("Skipping material entry {s}, which is not a file", .{entry.name}); + continue; + } + + _ = self.loadMaterial(engine, textures, entry.name, temp_allocator) catch |err| { + std.log.err("Error while loading material entry {s}: {s}", .{ entry.name, @errorName(err) }); + }; + } +} + fn loadMaterial(self: *Materials, engine: *Engine, textures: *Textures, filename: []const u8, temp_allocator: std.mem.Allocator) !Id { const MaterialJson = struct { baseColor: [3]f32 = .{ 1, 1, 1 },