loading camera transform from gltf
parent
c420eada1f
commit
893e01895f
|
@ -165,6 +165,7 @@ impl Graphics {
|
||||||
state: &GameState,
|
state: &GameState,
|
||||||
gl_state: &mut GlState,
|
gl_state: &mut GlState,
|
||||||
level: &crate::LoadedLevel,
|
level: &crate::LoadedLevel,
|
||||||
|
camera: &crate::Camera,
|
||||||
) {
|
) {
|
||||||
use uniforms as u;
|
use uniforms as u;
|
||||||
|
|
||||||
|
@ -178,9 +179,7 @@ impl Graphics {
|
||||||
|
|
||||||
let proj_mat = Mat4::perspective_rh_gl (fov.to_radians (), screen_size.0 / screen_size.1, 0.125, 200.0);
|
let proj_mat = Mat4::perspective_rh_gl (fov.to_radians (), screen_size.0 / screen_size.1, 0.125, 200.0);
|
||||||
|
|
||||||
let view_mat = proj_mat *
|
let view_mat = proj_mat * camera.mat;
|
||||||
Mat4::from_rotation_x (-63.6f32.to_radians ()) *
|
|
||||||
Mat4::from_translation ((0.0, 23.3, -12.2).into ());
|
|
||||||
let world_model_mat = Mat4::IDENTITY;
|
let world_model_mat = Mat4::IDENTITY;
|
||||||
|
|
||||||
self.passes [0].with (gl_state, || {
|
self.passes [0].with (gl_state, || {
|
||||||
|
|
|
@ -69,15 +69,22 @@ async fn main () -> Result <()> {
|
||||||
let level = LoadedLevel::from_path ("gltf/level-00.glb")?;
|
let level = LoadedLevel::from_path ("gltf/level-00.glb")?;
|
||||||
let scene = level.level.scenes ().next ().unwrap ();
|
let scene = level.level.scenes ().next ().unwrap ();
|
||||||
|
|
||||||
|
let mut camera = None;
|
||||||
let mut phys_tris: Vec <opengl_rust::physics::Triangle> = Vec::new ();
|
let mut phys_tris: Vec <opengl_rust::physics::Triangle> = Vec::new ();
|
||||||
|
|
||||||
for node in scene.nodes () {
|
for node in scene.nodes () {
|
||||||
|
if let Some (c) = node.camera () {
|
||||||
|
camera = Some (Camera {
|
||||||
|
mat: gltf_node_get_mat4 (&node).inverse (),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let mesh = match node.mesh () {
|
let mesh = match node.mesh () {
|
||||||
None => continue,
|
None => continue,
|
||||||
Some (x) => x,
|
Some (x) => x,
|
||||||
};
|
};
|
||||||
|
|
||||||
let m = Mat4::from_cols_array_2d (&node.transform ().matrix ());
|
let m = gltf_node_get_mat4 (&node);
|
||||||
|
|
||||||
for prim in mesh.primitives () {
|
for prim in mesh.primitives () {
|
||||||
use gltf::Semantic;
|
use gltf::Semantic;
|
||||||
|
@ -144,6 +151,11 @@ async fn main () -> Result <()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let camera = match camera {
|
||||||
|
None => bail! ("Couldn't find camera node in glTF file"),
|
||||||
|
Some (x) => x,
|
||||||
|
};
|
||||||
|
|
||||||
let mut graphics = Graphics::new ();
|
let mut graphics = Graphics::new ();
|
||||||
|
|
||||||
let mut gl_state = Default::default ();
|
let mut gl_state = Default::default ();
|
||||||
|
@ -284,7 +296,7 @@ async fn main () -> Result <()> {
|
||||||
|
|
||||||
window.gl_make_current (&gl_ctx).unwrap ();
|
window.gl_make_current (&gl_ctx).unwrap ();
|
||||||
|
|
||||||
graphics.draw (&game_state, &mut gl_state, &level);
|
graphics.draw (&game_state, &mut gl_state, &level, &camera);
|
||||||
graphics.frames += 1;
|
graphics.frames += 1;
|
||||||
|
|
||||||
window.gl_swap_window ();
|
window.gl_swap_window ();
|
||||||
|
@ -398,3 +410,11 @@ struct TriangleStream {
|
||||||
pub verts: gpu_buffers::VertexBuffer,
|
pub verts: gpu_buffers::VertexBuffer,
|
||||||
pub indices: gpu_buffers::IndexBuffer,
|
pub indices: gpu_buffers::IndexBuffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Camera {
|
||||||
|
mat: Mat4,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gltf_node_get_mat4 (node: &gltf::Node) -> Mat4 {
|
||||||
|
Mat4::from_cols_array_2d (&node.transform ().matrix ())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue