Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_mesh/src/lib.rs
9349 views
1
#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
2
3
extern crate alloc;
4
extern crate core;
5
6
mod components;
7
mod conversions;
8
mod index;
9
mod mesh;
10
#[cfg(feature = "bevy_mikktspace")]
11
mod mikktspace;
12
#[cfg(feature = "morph")]
13
pub mod morph;
14
pub mod primitives;
15
pub mod skinning;
16
mod vertex;
17
use bevy_app::{App, Plugin, PostUpdate};
18
use bevy_asset::{AssetApp, AssetEventSystems};
19
use bevy_ecs::schedule::{IntoScheduleConfigs, SystemSet};
20
use bitflags::bitflags;
21
pub use components::*;
22
pub use index::*;
23
pub use mesh::*;
24
#[cfg(feature = "bevy_mikktspace")]
25
pub use mikktspace::*;
26
pub use primitives::*;
27
pub use vertex::*;
28
pub use wgpu_types::VertexFormat;
29
30
/// The mesh prelude.
31
///
32
/// This includes the most common types in this crate, re-exported for your convenience.
33
pub 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
40
bitflags! {
41
/// Our base mesh pipeline key bits start from the highest bit and go
42
/// downward. The PBR mesh pipeline key bits start from the lowest bit and
43
/// go upward. This allows the PBR bits in the downstream crate `bevy_pbr`
44
/// to coexist in the same field without any shifts.
45
#[derive(Clone, Debug)]
46
pub struct BaseMeshPipelineKey: u64 {
47
const MORPH_TARGETS = 1 << (u64::BITS - 1);
48
}
49
}
50
51
/// Adds [`Mesh`] as an asset.
52
#[derive(Default)]
53
pub struct MeshPlugin;
54
55
impl 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
67
impl 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
/// `bevy_render::mesh::inherit_weights` runs in this `SystemSet`
94
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
95
pub struct InheritWeightSystems;
96
97