Skip to content

Commit

Permalink
Change the glTF loader to use Camera3dBundle (bevyengine#7890)
Browse files Browse the repository at this point in the history
# Objective

- Fixes bevyengine#7889.

## Solution

- Change the glTF loader to insert a `Camera3dBundle` instead of a manually constructed bundle. This might prevent future issues when new components are required for a 3D Camera to work correctly.
- Register the `ColorGrading` type because `bevy_scene` was complaining about it.
  • Loading branch information
geieredgar authored and Shfty committed Mar 19, 2023
1 parent beb8f1d commit 41f56d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
28 changes: 10 additions & 18 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bevy_asset::{
AssetIoError, AssetLoader, AssetPath, BoxedFuture, Handle, LoadContext, LoadedAsset,
};
use bevy_core::Name;
use bevy_core_pipeline::prelude::Camera3d;
use bevy_core_pipeline::prelude::Camera3dBundle;
use bevy_ecs::{entity::Entity, prelude::FromWorld, world::World};
use bevy_hierarchy::{BuildWorldChildren, WorldChildBuilder};
use bevy_log::warn;
Expand All @@ -13,21 +13,17 @@ use bevy_pbr::{
SpotLight, SpotLightBundle, StandardMaterial,
};
use bevy_render::{
camera::{
Camera, CameraRenderGraph, OrthographicProjection, PerspectiveProjection, Projection,
ScalingMode,
},
camera::{Camera, OrthographicProjection, PerspectiveProjection, Projection, ScalingMode},
color::Color,
mesh::{
skinning::{SkinnedMesh, SkinnedMeshInverseBindposes},
Indices, Mesh, VertexAttributeValues,
},
prelude::SpatialBundle,
primitives::{Aabb, Frustum},
primitives::Aabb,
render_resource::{AddressMode, Face, FilterMode, PrimitiveTopology, SamplerDescriptor},
renderer::RenderDevice,
texture::{CompressedImageFormats, Image, ImageSampler, ImageType, TextureError},
view::VisibleEntities,
};
use bevy_scene::Scene;
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -714,9 +710,8 @@ fn load_node(
) -> Result<(), GltfError> {
let transform = gltf_node.transform();
let mut gltf_error = None;
let mut node = world_builder.spawn(SpatialBundle::from(Transform::from_matrix(
Mat4::from_cols_array_2d(&transform.matrix()),
)));
let transform = Transform::from_matrix(Mat4::from_cols_array_2d(&transform.matrix()));
let mut node = world_builder.spawn(SpatialBundle::from(transform));

node.insert(node_name(gltf_node));

Expand Down Expand Up @@ -756,18 +751,15 @@ fn load_node(
Projection::Perspective(perspective_projection)
}
};

node.insert((
node.insert(Camera3dBundle {
projection,
Camera {
transform,
camera: Camera {
is_active: !*active_camera_found,
..Default::default()
},
VisibleEntities::default(),
Frustum::default(),
Camera3d::default(),
CameraRenderGraph::new(bevy_core_pipeline::core_3d::graph::NAME),
));
..Default::default()
});

*active_camera_found = true;
}
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_render/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl Plugin for ViewPlugin {
.register_type::<RenderLayers>()
.register_type::<Visibility>()
.register_type::<VisibleEntities>()
.register_type::<ColorGrading>()
.init_resource::<Msaa>()
// NOTE: windows.is_changed() handles cases where a window was resized
.add_plugin(ExtractResourcePlugin::<Msaa>::default())
Expand Down

0 comments on commit 41f56d3

Please sign in to comment.