1#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
2
3extern crate alloc;
4extern crate core;
5
6mod components;
7mod conversions;
8mod index;
9mod mesh;
10#[cfg(feature = "bevy_mikktspace")]
11mod mikktspace;
12#[cfg(feature = "morph")]
13pub mod morph;
14pub mod primitives;
15pub mod skinning;
16mod vertex;
17use bevy_app::{App, Plugin, PostUpdate};
18use bevy_asset::{AssetApp, AssetEventSystems};
19use bevy_ecs::schedule::{IntoScheduleConfigs, SystemSet};
20use bitflags::bitflags;
21pub use components::*;
22pub use index::*;
23pub use mesh::*;
24#[cfg(feature = "bevy_mikktspace")]
25pub use mikktspace::*;
26pub use primitives::*;
27pub use vertex::*;
28pub use wgpu_types::VertexFormat;
29
30pub mod prelude {
34 #[cfg(feature = "morph")]
35 pub use crate::morph::MorphWeights;
36 #[doc(hidden)]
37 pub use crate::{primitives::MeshBuilder, primitives::Meshable, Mesh, Mesh2d, Mesh3d};
38}
39
40bitflags! {
41 #[derive(Clone, Debug)]
46 pub struct BaseMeshPipelineKey: u64 {
47 const MORPH_TARGETS = 1 << (u64::BITS - 1);
48 }
49}
50
51#[derive(Default)]
53pub struct MeshPlugin;
54
55impl Plugin for MeshPlugin {
56 fn build(&self, app: &mut App) {
57 app.init_asset::<Mesh>()
58 .init_asset::<skinning::SkinnedMeshInverseBindposes>()
59 .register_asset_reflect::<Mesh>()
60 .add_systems(
61 PostUpdate,
62 mark_3d_meshes_as_changed_if_their_assets_changed.after(AssetEventSystems),
63 );
64 }
65}
66
67impl BaseMeshPipelineKey {
68 pub const PRIMITIVE_TOPOLOGY_MASK_BITS: u64 = 0b111;
69 pub const PRIMITIVE_TOPOLOGY_SHIFT_BITS: u64 =
70 (u64::BITS - 1 - Self::PRIMITIVE_TOPOLOGY_MASK_BITS.count_ones()) as u64;
71
72 pub fn from_primitive_topology(primitive_topology: PrimitiveTopology) -> Self {
73 let primitive_topology_bits = ((primitive_topology as u64)
74 & Self::PRIMITIVE_TOPOLOGY_MASK_BITS)
75 << Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS;
76 Self::from_bits_retain(primitive_topology_bits)
77 }
78
79 pub fn primitive_topology(&self) -> PrimitiveTopology {
80 let primitive_topology_bits = (self.bits() >> Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS)
81 & Self::PRIMITIVE_TOPOLOGY_MASK_BITS;
82 match primitive_topology_bits {
83 x if x == PrimitiveTopology::PointList as u64 => PrimitiveTopology::PointList,
84 x if x == PrimitiveTopology::LineList as u64 => PrimitiveTopology::LineList,
85 x if x == PrimitiveTopology::LineStrip as u64 => PrimitiveTopology::LineStrip,
86 x if x == PrimitiveTopology::TriangleList as u64 => PrimitiveTopology::TriangleList,
87 x if x == PrimitiveTopology::TriangleStrip as u64 => PrimitiveTopology::TriangleStrip,
88 _ => PrimitiveTopology::default(),
89 }
90 }
91}
92
93#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
95pub struct InheritWeightSystems;