-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
200 additions
and
100 deletions.
There are no files selected for viewing
This file contains 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 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 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
File renamed without changes.
This file contains 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,136 @@ | ||
const std = @import("std"); | ||
const sokol = @import("sokol"); | ||
const sg = sokol.gfx; | ||
|
||
const zigltf = @import("zigltf"); | ||
const rowmath = @import("rowmath"); | ||
const framework = @import("framework"); | ||
const Scene = framework.Scene; | ||
const gltf_fetcher = framework.gltf_fetcher; | ||
|
||
const state = struct { | ||
var pass_action = sg.PassAction{}; | ||
var input = rowmath.InputState{}; | ||
var orbit = rowmath.OrbitCamera{}; | ||
var gltf: ?std.json.Parsed(zigltf.Gltf) = null; | ||
var scene = Scene{}; | ||
}; | ||
|
||
const load_file = "glTF-Sample-Assets/Models/CesiumMilkTruck/glTF/CesiumMilkTruck.gltf"; | ||
|
||
export fn init() void { | ||
sg.setup(.{ | ||
.environment = sokol.glue.environment(), | ||
.logger = .{ .func = sokol.log.func }, | ||
}); | ||
sokol.gl.setup(.{ | ||
.logger = .{ .func = sokol.log.func }, | ||
}); | ||
|
||
var debugtext_desc = sokol.debugtext.Desc{ | ||
.logger = .{ .func = sokol.log.func }, | ||
}; | ||
debugtext_desc.fonts[0] = sokol.debugtext.fontOric(); | ||
sokol.debugtext.setup(debugtext_desc); | ||
|
||
state.pass_action.colors[0] = .{ | ||
.load_action = .CLEAR, | ||
.clear_value = .{ .r = 0.1, .g = 0.1, .b = 0.1, .a = 1.0 }, | ||
}; | ||
|
||
state.scene.init(std.heap.c_allocator); | ||
|
||
gltf_fetcher.init(std.heap.c_allocator); | ||
gltf_fetcher.fetch_gltf(load_file, &on_gltf) catch @panic("fetch_gltf"); | ||
} | ||
|
||
fn on_gltf(gltf: std.json.Parsed(zigltf.Gltf), bin:?[]const u8) void { | ||
state.gltf = gltf; | ||
std.debug.print("{s}\n", .{gltf.value}); | ||
state.scene.load(gltf, bin) catch |e| { | ||
std.debug.print("{s}\n", .{@errorName(e)}); | ||
@panic("Scene.load"); | ||
}; | ||
gltf_fetcher.state.status = "loaded"; | ||
} | ||
|
||
export fn frame() void { | ||
sokol.fetch.dowork(); | ||
|
||
state.input.screen_width = sokol.app.widthf(); | ||
state.input.screen_height = sokol.app.heightf(); | ||
state.orbit.frame(state.input); | ||
state.input.mouse_wheel = 0; | ||
|
||
sokol.debugtext.canvas(sokol.app.widthf() * 0.5, sokol.app.heightf() * 0.5); | ||
sokol.debugtext.pos(0.5, 0.5); | ||
sokol.debugtext.puts(gltf_fetcher.state.status); | ||
|
||
sg.beginPass(.{ | ||
.action = state.pass_action, | ||
.swapchain = sokol.glue.swapchain(), | ||
}); | ||
state.scene.draw(state.orbit.camera); | ||
sokol.debugtext.draw(); | ||
sg.endPass(); | ||
sg.commit(); | ||
} | ||
|
||
export fn event(e: [*c]const sokol.app.Event) void { | ||
switch (e.*.type) { | ||
.MOUSE_DOWN => { | ||
switch (e.*.mouse_button) { | ||
.LEFT => { | ||
state.input.mouse_left = true; | ||
}, | ||
.RIGHT => { | ||
state.input.mouse_right = true; | ||
}, | ||
.MIDDLE => { | ||
state.input.mouse_middle = true; | ||
}, | ||
.INVALID => {}, | ||
} | ||
}, | ||
.MOUSE_UP => { | ||
switch (e.*.mouse_button) { | ||
.LEFT => { | ||
state.input.mouse_left = false; | ||
}, | ||
.RIGHT => { | ||
state.input.mouse_right = false; | ||
}, | ||
.MIDDLE => { | ||
state.input.mouse_middle = false; | ||
}, | ||
.INVALID => {}, | ||
} | ||
}, | ||
.MOUSE_MOVE => { | ||
state.input.mouse_x = e.*.mouse_x; | ||
state.input.mouse_y = e.*.mouse_y; | ||
}, | ||
.MOUSE_SCROLL => { | ||
state.input.mouse_wheel = e.*.scroll_y; | ||
}, | ||
else => {}, | ||
} | ||
} | ||
|
||
export fn cleanup() void { | ||
sg.shutdown(); | ||
} | ||
|
||
pub fn main() void { | ||
sokol.app.run(.{ | ||
.init_cb = init, | ||
.frame_cb = frame, | ||
.cleanup_cb = cleanup, | ||
.event_cb = event, | ||
.width = 800, | ||
.height = 600, | ||
.window_title = "rowmath: examples/sokol/camera_simple", | ||
.icon = .{ .sokol_default = true }, | ||
.logger = .{ .func = sokol.log.func }, | ||
}); | ||
} |
This file contains 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 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,16 +1,48 @@ | ||
export type SampleType = { | ||
export type LinkType = { | ||
name: string, | ||
url: string, | ||
}; | ||
export type SampleType = { | ||
name: string, | ||
links: LinkType[], | ||
}; | ||
|
||
export const SAMPLES: SampleType[] = [ | ||
{ | ||
name: "minimal", | ||
url: "https://github.khronos.org/glTF-Tutorials/gltfTutorial/gltfTutorial_003_MinimalGltfFile.html", | ||
links: [ | ||
{ | ||
name: 'A Minimal glTF File - glTF-Tutorials', | ||
url: "https://github.khronos.org/glTF-Tutorials/gltfTutorial/gltfTutorial_003_MinimalGltfFile.html", | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "glb", | ||
links: [ | ||
{ | ||
name: 'glb', | ||
url: "https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#glb-file-format-specification", | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "gltf", | ||
links: [ | ||
{ | ||
name: 'gltf', | ||
url: "https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html", | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "CesiumMilkTruck", | ||
url: "https://github.com/KhronosGroup/glTF-Sample-Assets/tree/main/Models/CesiumMilkTruck/glTF-Binary", | ||
name: "draco", | ||
links: [ | ||
{ | ||
name: 'draco - github', | ||
url: "https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md", | ||
}, | ||
], | ||
}, | ||
]; | ||
|