Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate meshes and materials to required components #15524

Merged
merged 40 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
bf44df8
Migrate meshes to required components
Jondolf Sep 5, 2024
2423a92
Deprecate mesh bundles
Jondolf Sep 10, 2024
92fe7fe
Merge branch 'main' into mesh-required-components-v2
Jondolf Sep 28, 2024
4fa48d8
Remove redundant requires from `Mesh3d`
Jondolf Sep 28, 2024
65702d8
Improve docs and deprecation notices
Jondolf Sep 28, 2024
27bdfb7
Deprecate `MaterialMesh2dBundle`
Jondolf Sep 28, 2024
36720ef
Finish core migration
Jondolf Sep 28, 2024
9bd73bb
Revert glTF asset label rename
Jondolf Sep 28, 2024
7fca426
Fix B0004
Jondolf Sep 28, 2024
a5dac69
Fix 2D material extraction
Jondolf Sep 28, 2024
b3619e6
Fix 3D material mesh extraction
Jondolf Sep 28, 2024
e2bd5c2
Add `PlaceholderMaterial2d`
Jondolf Sep 29, 2024
dba5206
Fix material extraction and default materials, improve docs
Jondolf Sep 29, 2024
c6db025
Fix docs
Jondolf Sep 29, 2024
cc6c5de
Fix some more extraction issues
Jondolf Sep 29, 2024
0e00aa0
`Reflect` on my life choices
Jondolf Sep 29, 2024
95c5d38
Remove `WithMesh2d` from example
Jondolf Sep 29, 2024
0a18f43
Fix some more
Jondolf Sep 29, 2024
ff4b64b
Fix even more
Jondolf Sep 29, 2024
d9345ab
Merge branch 'main' into mesh-required-components-v2
Jondolf Sep 29, 2024
b1e2a96
Revert some material plugin changes and fix wireframes
Jondolf Sep 29, 2024
0aead94
Fix doc tests
Jondolf Sep 29, 2024
4ccf47a
Merge branch 'main' into mesh-required-components-v2
Jondolf Sep 29, 2024
70d5b6a
Fix B0004 error description
Jondolf Sep 29, 2024
8a51e25
Fix more doc stuff (please CI gods)
Jondolf Sep 29, 2024
a9ae0a0
Fix outdated docs
Jondolf Sep 30, 2024
3a23df8
Merge branch 'main' into mesh-required-components-v2
Jondolf Sep 30, 2024
b121e69
Fix new example
Jondolf Sep 30, 2024
3af1393
Merge branch 'main' into mesh-required-components-v2
Jondolf Oct 1, 2024
8c0a77b
Fix vertex color format
Jondolf Oct 1, 2024
4ca2d55
Move `Mesh2d` to `bevy_render` and fix examples (again)
Jondolf Oct 1, 2024
5367f0b
Improve docs
Jondolf Oct 1, 2024
4e3a0ee
Fix doc test
Jondolf Oct 1, 2024
bc791da
Fix unused asset server and mesh imports
Jondolf Oct 1, 2024
d5947d5
Use `AssetId::default()`
Jondolf Oct 1, 2024
4c6f9ed
Merge branch 'mesh-required-components-v2' of https://github.com/Jond…
Jondolf Oct 1, 2024
76b57c6
Merge branch 'main' into mesh-required-components-v2
Jondolf Oct 1, 2024
f4aa5a7
Fix doc test imports
Jondolf Oct 1, 2024
d82e264
Require `HasMaterial2d` in example
Jondolf Oct 1, 2024
40166a4
Merge branch 'main' into mesh-required-components-v2
cart Oct 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,6 @@ jobs:
echo -e "$errors"
echo " Avoid importing internal Bevy crates, they should not be used directly"
echo " Fix the issue by replacing 'bevy_*' with 'bevy'"
echo " Example: 'use bevy::sprite::MaterialMesh2dBundle;' instead of 'bevy_internal::sprite::MaterialMesh2dBundle;'"
echo " Example: 'use bevy::sprite::Mesh2d;' instead of 'bevy_internal::sprite::Mesh2d;'"
exit 1
fi
17 changes: 9 additions & 8 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ use bevy_ecs::{
use bevy_hierarchy::{BuildChildren, ChildBuild, WorldChildBuilder};
use bevy_math::{Affine2, Mat4, Vec3};
use bevy_pbr::{
DirectionalLight, DirectionalLightBundle, PbrBundle, PointLight, PointLightBundle, SpotLight,
SpotLightBundle, StandardMaterial, UvChannel, MAX_JOINTS,
DirectionalLight, DirectionalLightBundle, MeshMaterial3d, PointLight, PointLightBundle,
SpotLight, SpotLightBundle, StandardMaterial, UvChannel, MAX_JOINTS,
};
use bevy_render::{
alpha::AlphaMode,
camera::{Camera, OrthographicProjection, PerspectiveProjection, Projection, ScalingMode},
mesh::{
morph::{MeshMorphWeights, MorphAttributes, MorphTargetImage, MorphWeights},
skinning::{SkinnedMesh, SkinnedMeshInverseBindposes},
Indices, Mesh, MeshVertexAttribute, VertexAttributeValues,
Indices, Mesh, Mesh3d, MeshVertexAttribute, VertexAttributeValues,
},
prelude::SpatialBundle,
primitives::Aabb,
Expand Down Expand Up @@ -1457,12 +1457,13 @@ fn load_node(
};
let bounds = primitive.bounding_box();

let mut mesh_entity = parent.spawn(PbrBundle {
let mut mesh_entity = parent.spawn((
// TODO: handle missing label handle errors here?
mesh: load_context.get_label_handle(primitive_label.to_string()),
material: load_context.get_label_handle(&material_label),
..Default::default()
});
Mesh3d(load_context.get_label_handle(primitive_label.to_string())),
MeshMaterial3d::<StandardMaterial>(
load_context.get_label_handle(&material_label),
),
));

let target_count = primitive.morph_targets().len();
if target_count != 0 {
Expand Down
25 changes: 17 additions & 8 deletions crates/bevy_pbr/src/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#![expect(deprecated)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to move this to the specific places it was needed in this file but then i stumbled upon #15531, like you probably did q:


use crate::{
CascadeShadowConfig, Cascades, DirectionalLight, Material, PointLight, SpotLight,
StandardMaterial,
CascadeShadowConfig, Cascades, DirectionalLight, Material, MeshMaterial3d, PointLight,
SpotLight, StandardMaterial,
};
use bevy_asset::Handle;
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::{
bundle::Bundle,
Expand All @@ -12,21 +13,29 @@ use bevy_ecs::{
};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
mesh::Mesh,
mesh::Mesh3d,
primitives::{CascadesFrusta, CubemapFrusta, Frustum},
view::{InheritedVisibility, ViewVisibility, Visibility},
world_sync::SyncToRenderWorld,
};
use bevy_transform::components::{GlobalTransform, Transform};

/// A component bundle for PBR entities with a [`Mesh`] and a [`StandardMaterial`].
/// A component bundle for PBR entities with a [`Mesh3d`] and a [`MeshMaterial3d<StandardMaterial>`].
#[deprecated(
since = "0.15.0",
note = "Use the `Mesh3d` and `MeshMaterial3d` components instead. Inserting them will now also insert the other components required by them automatically."
)]
pub type PbrBundle = MaterialMeshBundle<StandardMaterial>;

/// A component bundle for entities with a [`Mesh`] and a [`Material`].
/// A component bundle for entities with a [`Mesh3d`] and a [`MeshMaterial3d`].
#[derive(Bundle, Clone)]
#[deprecated(
since = "0.15.0",
note = "Use the `Mesh3d` and `MeshMaterial3d` components instead. Inserting them will now also insert the other components required by them automatically."
)]
pub struct MaterialMeshBundle<M: Material> {
pub mesh: Handle<Mesh>,
pub material: Handle<M>,
pub mesh: Mesh3d,
pub material: MeshMaterial3d<M>,
pub transform: Transform,
pub global_transform: GlobalTransform,
/// User indication of whether an entity is visible
Expand Down
17 changes: 14 additions & 3 deletions crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mod light;
mod light_probe;
mod lightmap;
mod material;
mod mesh_material;
mod parallax;
mod pbr_material;
mod prepass;
Expand All @@ -53,6 +54,7 @@ pub use light::*;
pub use light_probe::*;
pub use lightmap::*;
pub use material::*;
pub use mesh_material::*;
pub use parallax::*;
pub use pbr_material::*;
pub use prepass::*;
Expand All @@ -68,6 +70,7 @@ pub use volumetric_fog::{
/// The PBR prelude.
///
/// This includes the most common types in this crate, re-exported for your convenience.
#[expect(deprecated)]
pub mod prelude {
#[doc(hidden)]
pub use crate::{
Expand All @@ -82,6 +85,7 @@ pub mod prelude {
LightProbe,
},
material::{Material, MaterialPlugin},
mesh_material::MeshMaterial3d,
parallax::ParallaxMappingMethod,
pbr_material::StandardMaterial,
ssao::ScreenSpaceAmbientOcclusionPlugin,
Expand Down Expand Up @@ -410,13 +414,13 @@ impl Plugin for PbrPlugin {
app.add_plugins(DeferredPbrLightingPlugin);
}

// Initialize the default material.
app.world_mut()
.resource_mut::<Assets<StandardMaterial>>()
.insert(
&Handle::<StandardMaterial>::default(),
StandardMaterial {
base_color: Color::srgb(1.0, 0.0, 0.5),
unlit: true,
base_color: Color::WHITE,
..Default::default()
},
);
Expand All @@ -427,7 +431,14 @@ impl Plugin for PbrPlugin {

// Extract the required data from the main world
render_app
.add_systems(ExtractSchedule, (extract_clusters, extract_lights))
.add_systems(
ExtractSchedule,
(
extract_clusters,
extract_lights,
extract_default_materials.after(clear_material_instances::<StandardMaterial>),
),
)
.add_systems(
Render,
(
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_pbr/src/light/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy_render::{
camera::{Camera, CameraProjection},
extract_component::ExtractComponent,
extract_resource::ExtractResource,
mesh::Mesh,
mesh::Mesh3d,
primitives::{Aabb, CascadesFrusta, CubemapFrusta, Frustum, Sphere},
view::{
InheritedVisibility, NoFrustumCulling, RenderLayers, ViewVisibility, VisibilityRange,
Expand Down Expand Up @@ -440,19 +440,19 @@ fn calculate_cascade(
texel_size: cascade_texel_size,
}
}
/// Add this component to make a [`Mesh`] not cast shadows.
/// Add this component to make a [`Mesh3d`] not cast shadows.
#[derive(Debug, Component, Reflect, Default)]
#[reflect(Component, Default, Debug)]
pub struct NotShadowCaster;
/// Add this component to make a [`Mesh`] not receive shadows.
/// Add this component to make a [`Mesh3d`] not receive shadows.
///
/// **Note:** If you're using diffuse transmission, setting [`NotShadowReceiver`] will
/// cause both “regular” shadows as well as diffusely transmitted shadows to be disabled,
/// even when [`TransmittedShadowReceiver`] is being used.
#[derive(Debug, Component, Reflect, Default)]
#[reflect(Component, Default, Debug)]
pub struct NotShadowReceiver;
/// Add this component to make a [`Mesh`] using a PBR material with [`diffuse_transmission`](crate::pbr_material::StandardMaterial::diffuse_transmission)`> 0.0`
/// Add this component to make a [`Mesh3d`] using a PBR material with [`diffuse_transmission`](crate::pbr_material::StandardMaterial::diffuse_transmission)`> 0.0`
/// receive shadows on its diffuse transmission lobe. (i.e. its “backside”)
///
/// Not enabled by default, as it requires carefully setting up [`thickness`](crate::pbr_material::StandardMaterial::thickness)
Expand Down Expand Up @@ -697,7 +697,7 @@ pub fn check_dir_light_mesh_visibility(
(
Without<NotShadowCaster>,
Without<DirectionalLight>,
With<Handle<Mesh>>,
With<Mesh3d>,
),
>,
visible_entity_ranges: Option<Res<VisibleEntityRanges>>,
Expand Down Expand Up @@ -866,7 +866,7 @@ pub fn check_point_light_mesh_visibility(
(
Without<NotShadowCaster>,
Without<DirectionalLight>,
With<Handle<Mesh>>,
With<Mesh3d>,
),
>,
visible_entity_ranges: Option<Res<VisibleEntityRanges>>,
Expand Down
18 changes: 10 additions & 8 deletions crates/bevy_pbr/src/lightmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//! with an addon like [The Lightmapper]. The tools in the [`bevy-baked-gi`]
//! project support other lightmap baking methods.
//!
//! When a [`Lightmap`] component is added to an entity with a [`Mesh`] and a
//! [`StandardMaterial`](crate::StandardMaterial), Bevy applies the lightmap when rendering. The brightness
//! When a [`Lightmap`] component is added to an entity with a [`Mesh3d`] and a
//! [`MeshMaterial3d<StandardMaterial>`], Bevy applies the lightmap when rendering. The brightness
//! of the lightmap may be controlled with the `lightmap_exposure` field on
//! `StandardMaterial`.
//! [`StandardMaterial`].
//!
//! During the rendering extraction phase, we extract all lightmaps into the
//! [`RenderLightmaps`] table, which lives in the render world. Mesh bindgroup
Expand All @@ -25,7 +25,9 @@
//! appropriately.
//!
//! [The Lightmapper]: https://github.com/Naxela/The_Lightmapper
//!
//! [`Mesh3d`]: bevy_render::mesh::Mesh3d
//! [`MeshMaterial3d<StandardMaterial>`]: crate::StandardMaterial
//! [`StandardMaterial`]: crate::StandardMaterial
//! [`bevy-baked-gi`]: https://github.com/pcwalton/bevy-baked-gi

use bevy_app::{App, Plugin};
Expand Down Expand Up @@ -61,10 +63,10 @@ pub struct LightmapPlugin;
/// A component that applies baked indirect diffuse global illumination from a
/// lightmap.
///
/// When assigned to an entity that contains a [`Mesh`] and a
/// [`StandardMaterial`](crate::StandardMaterial), if the mesh has a second UV
/// layer ([`ATTRIBUTE_UV_1`](bevy_render::mesh::Mesh::ATTRIBUTE_UV_1)), then
/// the lightmap will render using those UVs.
/// When assigned to an entity that contains a [`Mesh3d`](bevy_render::mesh::Mesh3d) and a
/// [`MeshMaterial3d<StandardMaterial>`](crate::StandardMaterial), if the mesh
/// has a second UV layer ([`ATTRIBUTE_UV_1`](bevy_render::mesh::Mesh::ATTRIBUTE_UV_1)),
/// then the lightmap will render using those UVs.
#[derive(Component, Clone, Reflect)]
#[reflect(Component, Default)]
pub struct Lightmap {
Expand Down
Loading