diff --git a/crates/bevy_mesh/Cargo.toml b/crates/bevy_mesh/Cargo.toml index 7807acbb9d..a34b0e7436 100644 --- a/crates/bevy_mesh/Cargo.toml +++ b/crates/bevy_mesh/Cargo.toml @@ -34,6 +34,7 @@ serde = { version = "1", default-features = false, features = [ hexasphere = "15.0" thiserror = { version = "2", default-features = false } tracing = { version = "0.1", default-features = false, features = ["std"] } +derive_more = { version = "2", default-features = false, features = ["from"] } [dev-dependencies] serde_json = "1.0.140" diff --git a/crates/bevy_render/src/mesh/components.rs b/crates/bevy_mesh/src/components.rs similarity index 94% rename from crates/bevy_render/src/mesh/components.rs rename to crates/bevy_mesh/src/components.rs index 000de324e3..cff5eab7e4 100644 --- a/crates/bevy_render/src/mesh/components.rs +++ b/crates/bevy_mesh/src/components.rs @@ -1,7 +1,4 @@ -use crate::{ - mesh::Mesh, - view::{self, Visibility, VisibilityClass}, -}; +use crate::mesh::Mesh; use bevy_asset::{AsAssetId, AssetEvent, AssetId, Handle}; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ @@ -42,8 +39,7 @@ use derive_more::derive::From; /// ``` #[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)] #[reflect(Component, Default, Clone, PartialEq)] -#[require(Transform, Visibility, VisibilityClass)] -#[component(on_add = view::add_visibility_class::)] +#[require(Transform)] pub struct Mesh2d(pub Handle); impl From for AssetId { @@ -98,8 +94,7 @@ impl AsAssetId for Mesh2d { /// ``` #[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)] #[reflect(Component, Default, Clone, PartialEq)] -#[require(Transform, Visibility, VisibilityClass)] -#[component(on_add = view::add_visibility_class::)] +#[require(Transform)] pub struct Mesh3d(pub Handle); impl From for AssetId { diff --git a/crates/bevy_mesh/src/lib.rs b/crates/bevy_mesh/src/lib.rs index 58702d7d8b..635e36ead4 100644 --- a/crates/bevy_mesh/src/lib.rs +++ b/crates/bevy_mesh/src/lib.rs @@ -3,6 +3,7 @@ extern crate alloc; extern crate core; +mod components; mod conversions; mod index; mod mesh; @@ -12,6 +13,7 @@ pub mod primitives; pub mod skinning; mod vertex; use bitflags::bitflags; +pub use components::*; pub use index::*; pub use mesh::*; pub use mikktspace::*; diff --git a/crates/bevy_render/src/mesh/mod.rs b/crates/bevy_render/src/mesh/mod.rs index c981e75cee..28e106c8f8 100644 --- a/crates/bevy_render/src/mesh/mod.rs +++ b/crates/bevy_render/src/mesh/mod.rs @@ -2,7 +2,6 @@ use bevy_math::Vec3; pub use bevy_mesh::*; use morph::{MeshMorphWeights, MorphWeights}; pub mod allocator; -mod components; use crate::{ primitives::Aabb, render_asset::{PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets}, @@ -21,7 +20,7 @@ use bevy_ecs::{ SystemParamItem, }, }; -pub use components::{mark_3d_meshes_as_changed_if_their_assets_changed, Mesh2d, Mesh3d, MeshTag}; +pub use bevy_mesh::{mark_3d_meshes_as_changed_if_their_assets_changed, Mesh2d, Mesh3d, MeshTag}; use wgpu::IndexFormat; /// Registers all [`MeshBuilder`] types. diff --git a/crates/bevy_render/src/view/mod.rs b/crates/bevy_render/src/view/mod.rs index a348b361c7..0ca492c82d 100644 --- a/crates/bevy_render/src/view/mod.rs +++ b/crates/bevy_render/src/view/mod.rs @@ -2,6 +2,7 @@ pub mod visibility; pub mod window; use bevy_diagnostic::FrameCount; +use bevy_mesh::{Mesh2d, Mesh3d}; pub use visibility::*; pub use window::*; @@ -109,6 +110,10 @@ impl Plugin for ViewPlugin { .register_type::() .register_type::() .register_type::() + .register_required_components::() + .register_required_components::() + .register_required_components::() + .register_required_components::() // NOTE: windows.is_changed() handles cases where a window was resized .add_plugins(( ExtractComponentPlugin::::default(), @@ -117,6 +122,12 @@ impl Plugin for ViewPlugin { VisibilityPlugin, VisibilityRangePlugin, )); + app.world_mut() + .register_component_hooks::() + .on_add(add_visibility_class::); + app.world_mut() + .register_component_hooks::() + .on_add(add_visibility_class::); if let Some(render_app) = app.get_sub_app_mut(RenderApp) { render_app.add_systems(