-
Notifications
You must be signed in to change notification settings - Fork 0
Chapter 6 from CGPOC #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6bdc98a
Fix sphere
btipling b4df1f4
Earth sphere
btipling fd6d4cd
bindless textures
btipling 7e5a5f3
it builds I guess
btipling 5ddd328
Added a torus
btipling 8913abf
Add a textured torus
btipling 2ef5011
stubbed out a shuttle scene
btipling be5962e
add obj loader to app
btipling 3f7499d
got shuttle
btipling 8f6e42c
Torus normals fixes?
btipling a6ece9e
starting on obj parsing
btipling 3a5ed57
Add an allocator to assets init
btipling 80afe11
Add obj object and reorg
btipling b308912
Object object mesh creator
btipling c9024a9
works
btipling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| data: []u8 = undefined, | ||
| file_name: []const u8 = undefined, | ||
| vertices: [max_vertices][3]f32 = undefined, | ||
| texture_coordinates: [max_vertices][2]f32 = undefined, | ||
| normals: [max_vertices][3]f32 = undefined, | ||
| num_vertices: usize = 0, | ||
| indicies: [max_indicies][3][3]usize = undefined, | ||
| num_indicies: usize = 0, | ||
| num_texture_coords: usize = 0, | ||
| num_normals: usize = 0, | ||
|
|
||
| const max_vertices: usize = 50_000; | ||
| const max_indicies: usize = max_vertices * 2; | ||
|
|
||
| const Obj = @This(); | ||
| const rgba_channels: u8 = 4; | ||
|
|
||
| pub fn init(self: *Obj, _: std.mem.Allocator, data: []u8, file_name: []const u8) void { | ||
| self.data = data; | ||
| self.file_name = file_name; | ||
| var lit = std.mem.tokenizeScalar(u8, data, '\n'); | ||
| var t_index: usize = 0; | ||
| var v_index: usize = 0; | ||
| var n_index: usize = 0; | ||
| var i_index: usize = 0; | ||
| while (lit.next()) |line| { | ||
| switch (line[0]) { | ||
| 'v' => { | ||
| switch (line[1]) { | ||
| 't' => { | ||
| var tcit = std.mem.tokenizeScalar(u8, line[2..], ' '); | ||
| const s: f32 = std.fmt.parseFloat(f32, tcit.next() orelse "") catch @panic("invalid float"); | ||
| const t: f32 = std.fmt.parseFloat(f32, tcit.next() orelse "") catch @panic("invalid float"); | ||
| self.texture_coordinates[t_index] = .{ s, 1 - t }; | ||
| t_index += 1; | ||
| }, | ||
| 'n' => { | ||
| var nit = std.mem.tokenizeScalar(u8, line[2..], ' '); | ||
| const x: f32 = std.fmt.parseFloat(f32, nit.next() orelse "") catch @panic("invalid float"); | ||
| const y: f32 = std.fmt.parseFloat(f32, nit.next() orelse "") catch @panic("invalid float"); | ||
| const z: f32 = std.fmt.parseFloat(f32, nit.next() orelse "") catch @panic("invalid float"); | ||
| self.normals[n_index] = .{ x, y, z }; | ||
| n_index += 1; | ||
| }, | ||
| else => { | ||
| var vit = std.mem.tokenizeScalar(u8, line[1..], ' '); | ||
| const x: f32 = std.fmt.parseFloat(f32, vit.next() orelse "") catch @panic("invalid float"); | ||
| const y: f32 = std.fmt.parseFloat(f32, vit.next() orelse "") catch @panic("invalid float"); | ||
| const z: f32 = std.fmt.parseFloat(f32, vit.next() orelse "") catch @panic("invalid float"); | ||
| self.vertices[v_index] = .{ x, y, z }; | ||
| v_index += 1; | ||
| }, | ||
| } | ||
| }, | ||
| 'f' => { | ||
| var i_it = std.mem.tokenizeScalar(u8, line[1..], ' '); | ||
| const v3: [3]usize = parseFace(i_it.next() orelse "") catch @panic("invalid index"); | ||
| const v2: [3]usize = parseFace(i_it.next() orelse "") catch @panic("invalid index"); | ||
| const v1: [3]usize = parseFace(i_it.next() orelse "") catch @panic("invalid index"); | ||
| self.indicies[i_index] = .{ v1, v2, v3 }; | ||
| i_index += 1; | ||
| }, | ||
| else => {}, | ||
| } | ||
| } | ||
| self.num_vertices = v_index; | ||
| self.num_indicies = i_index; | ||
| self.num_texture_coords = t_index; | ||
| self.num_normals = n_index; | ||
| } | ||
|
|
||
| pub fn toObject(self: *Obj, prog: u32, i_datas: []rhi.instanceData) object.object { | ||
| var attribute_data: [max_vertices]rhi.attributeData = undefined; | ||
| var indices: [max_indicies]u32 = undefined; | ||
|
|
||
| var current_index: usize = 0; | ||
| for (0..self.num_indicies) |i| { | ||
| const index_data = self.indicies[i]; | ||
| for (0..3) |j| { | ||
| const p = self.vertices[index_data[j][0]]; | ||
| attribute_data[current_index] = .{ | ||
| .position = p, | ||
| .normals = self.normals[index_data[j][2]], | ||
| .texture_coords = self.texture_coordinates[index_data[j][1]], | ||
| }; | ||
| indices[current_index] = @intCast(current_index); | ||
| current_index += 1; | ||
| } | ||
| } | ||
|
|
||
| const model: object.object = .{ | ||
| .obj = object.Obj.init( | ||
| prog, | ||
| i_datas, | ||
| attribute_data[0..current_index], | ||
| indices[0..current_index], | ||
| ), | ||
| }; | ||
| return model; | ||
| } | ||
|
|
||
| fn parseFace(face: []const u8) ![3]usize { | ||
| var it = std.mem.tokenizeScalar(u8, face[0..], '/'); | ||
| const v: usize = std.fmt.parseInt(u32, it.next() orelse "", 10) catch @panic("invalid index"); | ||
| const t: usize = std.fmt.parseInt(u32, it.next() orelse "", 10) catch @panic("invalid index"); | ||
| const n: usize = std.fmt.parseInt(u32, it.next() orelse "", 10) catch @panic("invalid index"); | ||
| return .{ v - 1, t - 1, n - 1 }; | ||
| } | ||
|
|
||
| pub fn deinit(self: *Obj, allocator: std.mem.Allocator) void { | ||
| allocator.free(self.data); | ||
| self.data = undefined; | ||
| allocator.destroy(self); | ||
| } | ||
|
|
||
| const std = @import("std"); | ||
| const c = @import("../c.zig").c; | ||
| const rhi = @import("../rhi/rhi.zig"); | ||
| const object = @import("../object/object.zig"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| pub const loader = @import("loader.zig"); | ||
| pub const Image = @import("Image.zig"); | ||
| pub const Obj = @import("Obj.zig"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,4 +138,4 @@ pub fn init( | |
| }; | ||
| } | ||
|
|
||
| const rhi = @import("../../rhi/rhi.zig"); | ||
| const rhi = @import("../rhi/rhi.zig"); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...bject/object_no_render/ObjectNoRender.zig → src/foundations/object/ObjectNoRender.zig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| mesh: rhi.Mesh = .{ .instance_type = .{ .norender = {} } }, | ||
|
|
||
| const rhi = @import("../../rhi/rhi.zig"); | ||
| const rhi = @import("../rhi/rhi.zig"); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarify the purpose of the unused
std.mem.Allocatorparameter.The new
std.mem.Allocatorparameter is not used in the function. Is this an incomplete refactoring or a placeholder for future use?Please provide more context on the purpose of this parameter and consider removing it if it's not needed.