this repo has no description
at main 1.6 kB view raw
1const std = @import("std"); 2 3const zigimg = @import("zigimg"); 4 5const Camera = @import("Camera.zig"); 6const hittable = @import("hittable.zig"); 7const Material = @import("material.zig").Material; 8const Texture = @import("texture.zig").Texture; 9 10allocator: std.mem.Allocator, 11 12camera: Camera = undefined, 13world: hittable.HittableList, 14 15materials: std.ArrayList(*Material), 16textures: std.ArrayList(*Texture), 17 18const Self = @This(); 19 20pub fn init(alloc: std.mem.Allocator) Self { 21 return Self{ 22 .allocator = alloc, 23 .world = hittable.HittableList.init(alloc), 24 .materials = std.ArrayList(*Material).init(alloc), 25 .textures = std.ArrayList(*Texture).init(alloc), 26 }; 27} 28 29pub fn deinit(self: *Self) void { 30 self.camera.deinit(); 31 self.world.deinit(); 32 33 for (self.materials.items) |mat| { 34 self.allocator.destroy(mat); 35 } 36 37 for (self.textures.items) |tex| { 38 self.allocator.destroy(tex); 39 } 40 41 self.materials.deinit(); 42 self.textures.deinit(); 43} 44 45pub fn createMaterial(self: *Self, mat: anytype) !*Material { 46 const ptr = try Material.init(self.allocator, mat); 47 try self.materials.append(ptr); 48 return ptr; 49} 50 51pub fn createTexture(self: *Self, tex: anytype) !*Texture { 52 const ptr = try Texture.init(self.allocator, tex); 53 try self.textures.append(ptr); 54 return ptr; 55} 56 57pub fn setCamera(self: *Self, cam: Camera.Options) !void { 58 self.camera = try Camera.init(self.allocator, cam); 59} 60 61pub fn writeToFilePath(self: *Self, path: []const u8, opts: zigimg.Image.EncoderOptions) !void { 62 try self.camera.image.writeToFilePath(path, opts); 63}