-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgltf_load.rs
More file actions
75 lines (59 loc) · 1.96 KB
/
gltf_load.rs
File metadata and controls
75 lines (59 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
mod glfw;
use glfw::GlfwContext;
use processing::prelude::*;
use processing_render::material::MaterialValue;
use processing_render::render::command::DrawCommand;
fn main() {
match sketch() {
Ok(_) => {
eprintln!("Sketch completed successfully");
exit(0).unwrap();
}
Err(e) => {
eprintln!("Sketch error: {:?}", e);
exit(1).unwrap();
}
};
}
fn sketch() -> error::Result<()> {
let width = 800;
let height = 600;
let mut glfw_ctx = GlfwContext::new(width, height)?;
init(Config::default())?;
let surface = glfw_ctx.create_surface(width, height)?;
let graphics = graphics_create(surface, width, height)?;
let gltf = gltf_load(graphics, "gltf/Duck.glb")?;
let duck = gltf_geometry(gltf, "LOD3spShape")?;
let duck_mat = gltf_material(gltf, "blinn3-fx")?;
graphics_mode_3d(graphics)?;
gltf_camera(gltf, 0)?;
let light = gltf_light(gltf, 0)?;
let mut frame: u64 = 0;
while glfw_ctx.poll_events() {
let t = frame as f32 * 0.02;
let radius = 1.5;
let lx = t.cos() * radius;
let ly = 1.5;
let lz = t.sin() * radius;
transform_set_position(light, lx, ly, lz)?;
transform_look_at(light, 0.0, 0.8, 0.0)?;
let r = (t * 8.0).sin() * 0.5 + 0.5;
let g = (t * 8.0 + 2.0).sin() * 0.5 + 0.5;
let b = (t * 8.0 + 4.0).sin() * 0.5 + 0.5;
material_set(
duck_mat,
"base_color",
MaterialValue::Float4([r, g, b, 1.0]),
)?;
graphics_begin_draw(graphics)?;
graphics_record_command(
graphics,
DrawCommand::BackgroundColor(bevy::color::Color::srgb(0.1, 0.1, 0.12)),
)?;
graphics_record_command(graphics, DrawCommand::Material(duck_mat))?;
graphics_record_command(graphics, DrawCommand::Geometry(duck))?;
graphics_end_draw(graphics)?;
frame += 1;
}
Ok(())
}