bevy_mesh/
lib.rs

1#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
2
3extern crate alloc;
4extern crate core;
5
6mod conversions;
7mod index;
8mod mesh;
9mod mikktspace;
10pub mod morph;
11pub mod primitives;
12pub mod skinning;
13mod vertex;
14use bitflags::bitflags;
15pub use index::*;
16pub use mesh::*;
17pub use mikktspace::*;
18pub use primitives::*;
19pub use vertex::*;
20pub use wgpu_types::VertexFormat;
21
22bitflags! {
23    /// Our base mesh pipeline key bits start from the highest bit and go
24    /// downward. The PBR mesh pipeline key bits start from the lowest bit and
25    /// go upward. This allows the PBR bits in the downstream crate `bevy_pbr`
26    /// to coexist in the same field without any shifts.
27    #[derive(Clone, Debug)]
28    pub struct BaseMeshPipelineKey: u64 {
29        const MORPH_TARGETS = 1 << (u64::BITS - 1);
30    }
31}
32
33impl BaseMeshPipelineKey {
34    pub const PRIMITIVE_TOPOLOGY_MASK_BITS: u64 = 0b111;
35    pub const PRIMITIVE_TOPOLOGY_SHIFT_BITS: u64 =
36        (u64::BITS - 1 - Self::PRIMITIVE_TOPOLOGY_MASK_BITS.count_ones()) as u64;
37
38    pub fn from_primitive_topology(primitive_topology: PrimitiveTopology) -> Self {
39        let primitive_topology_bits = ((primitive_topology as u64)
40            & Self::PRIMITIVE_TOPOLOGY_MASK_BITS)
41            << Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS;
42        Self::from_bits_retain(primitive_topology_bits)
43    }
44
45    pub fn primitive_topology(&self) -> PrimitiveTopology {
46        let primitive_topology_bits = (self.bits() >> Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS)
47            & Self::PRIMITIVE_TOPOLOGY_MASK_BITS;
48        match primitive_topology_bits {
49            x if x == PrimitiveTopology::PointList as u64 => PrimitiveTopology::PointList,
50            x if x == PrimitiveTopology::LineList as u64 => PrimitiveTopology::LineList,
51            x if x == PrimitiveTopology::LineStrip as u64 => PrimitiveTopology::LineStrip,
52            x if x == PrimitiveTopology::TriangleList as u64 => PrimitiveTopology::TriangleList,
53            x if x == PrimitiveTopology::TriangleStrip as u64 => PrimitiveTopology::TriangleStrip,
54            _ => PrimitiveTopology::default(),
55        }
56    }
57}