From 3756181e23e6fd7420e8fe908ecd8d64c25eed49 Mon Sep 17 00:00:00 2001 From: Kirillov Kirill Date: Fri, 8 Apr 2022 17:28:32 +0000 Subject: [PATCH] Change scaling mode to FixedHorizontal (#4055) # Objective - Fixes the issue with orthographic camera imported from glTF not displaying anything (mentioned in #4005). ## Solution - This was due to wrong scaling mode being used. This PR simply changes WindowSize scaling mode to FixedHorizontal. ## Important Note Currently, othographic scale in Blender, three.js, and possibly other software does not translate to Bevy (via glTF) because their developers have [misinterpreted the spec](https://github.com/KhronosGroup/glTF/issues/1663#issuecomment-618194015). The camera parameters have been clarified in glTF 2.0, which was released on October of 2021. In Blender 3.0.1 this issue has **not** been fixed yet. If you are importing orthographic cameras from Blender, you have to divide the scale by 2. --- crates/bevy_gltf/src/loader.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 8b98b713a1e64..2b95f3e5541b4 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -15,7 +15,8 @@ use bevy_pbr::{ }; use bevy_render::{ camera::{ - Camera, Camera2d, Camera3d, CameraProjection, OrthographicProjection, PerspectiveProjection, + Camera, Camera3d, CameraProjection, OrthographicProjection, PerspectiveProjection, + ScalingMode, }, color::Color, mesh::{ @@ -721,22 +722,22 @@ fn load_node( match camera.projection() { gltf::camera::Projection::Orthographic(orthographic) => { let xmag = orthographic.xmag(); - let ymag = orthographic.ymag(); let orthographic_projection: OrthographicProjection = OrthographicProjection { - left: -xmag, - right: xmag, - top: ymag, - bottom: -ymag, far: orthographic.zfar(), near: orthographic.znear(), + scaling_mode: ScalingMode::FixedHorizontal, + scale: xmag / 2.0, ..Default::default() }; node.insert(Camera { projection_matrix: orthographic_projection.get_projection_matrix(), + near: orthographic_projection.near, + far: orthographic_projection.far, ..Default::default() }); - node.insert(orthographic_projection).insert(Camera2d); + node.insert(orthographic_projection); + node.insert(Camera3d); } gltf::camera::Projection::Perspective(perspective) => { let mut perspective_projection: PerspectiveProjection = PerspectiveProjection {