Skip to content

Commit

Permalink
Change scaling mode to FixedHorizontal (bevyengine#4055)
Browse files Browse the repository at this point in the history
# Objective

- Fixes the issue with orthographic camera imported from glTF not displaying anything (mentioned in bevyengine#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](KhronosGroup/glTF#1663 (comment)). 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.
  • Loading branch information
kirusfg authored and ItsDoot committed Feb 1, 2023
1 parent d05817f commit fdecd0c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit fdecd0c

Please sign in to comment.