Add load all materials function
This commit is contained in:
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user