Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_mesh/src/lib.rs
6595 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
mod mikktspace;
11
pub mod morph;
12
pub mod primitives;
13
pub mod skinning;
14
mod vertex;
15
use bevy_app::{App, Plugin, PostUpdate};
16
use bevy_asset::{AssetApp, AssetEventSystems};
17
use bevy_ecs::schedule::{IntoScheduleConfigs, SystemSet};
18
use bitflags::bitflags;
19
pub use components::*;
20
pub use index::*;
21
pub use mesh::*;
22
pub use mikktspace::*;
23
pub use primitives::*;
24
pub use vertex::*;
25
pub use wgpu_types::VertexFormat;
26
27
/// The mesh prelude.
28
///
29
/// This includes the most common types in this crate, re-exported for your convenience.
30
pub mod prelude {
31
#[doc(hidden)]
32
pub use crate::{
33
morph::MorphWeights, primitives::MeshBuilder, primitives::Meshable, Mesh, Mesh2d, Mesh3d,
34
};
35
}
36
37
bitflags! {
38
/// Our base mesh pipeline key bits start from the highest bit and go
39
/// downward. The PBR mesh pipeline key bits start from the lowest bit and
40
/// go upward. This allows the PBR bits in the downstream crate `bevy_pbr`
41
/// to coexist in the same field without any shifts.
42
#[derive(Clone, Debug)]
43
pub struct BaseMeshPipelineKey: u64 {
44
const MORPH_TARGETS = 1 << (u64::BITS - 1);
45
}
46
}
47
48
#[derive(Default)]
49
pub struct MeshPlugin;
50
51
impl Plugin for MeshPlugin {
52
fn build(&self, app: &mut App) {
53
app.init_asset::<Mesh>()
54
.register_asset_reflect::<Mesh>()
55
.add_systems(
56
PostUpdate,
57
mark_3d_meshes_as_changed_if_their_assets_changed.before(AssetEventSystems),
58
);
59
}
60
}
61
62
impl BaseMeshPipelineKey {
63
pub const PRIMITIVE_TOPOLOGY_MASK_BITS: u64 = 0b111;
64
pub const PRIMITIVE_TOPOLOGY_SHIFT_BITS: u64 =
65
(u64::BITS - 1 - Self::PRIMITIVE_TOPOLOGY_MASK_BITS.count_ones()) as u64;
66
67
pub fn from_primitive_topology(primitive_topology: PrimitiveTopology) -> Self {
68
let primitive_topology_bits = ((primitive_topology as u64)
69
& Self::PRIMITIVE_TOPOLOGY_MASK_BITS)
70
<< Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS;
71
Self::from_bits_retain(primitive_topology_bits)
72
}
73
74
pub fn primitive_topology(&self) -> PrimitiveTopology {
75
let primitive_topology_bits = (self.bits() >> Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS)
76
& Self::PRIMITIVE_TOPOLOGY_MASK_BITS;
77
match primitive_topology_bits {
78
x if x == PrimitiveTopology::PointList as u64 => PrimitiveTopology::PointList,
79
x if x == PrimitiveTopology::LineList as u64 => PrimitiveTopology::LineList,
80
x if x == PrimitiveTopology::LineStrip as u64 => PrimitiveTopology::LineStrip,
81
x if x == PrimitiveTopology::TriangleList as u64 => PrimitiveTopology::TriangleList,
82
x if x == PrimitiveTopology::TriangleStrip as u64 => PrimitiveTopology::TriangleStrip,
83
_ => PrimitiveTopology::default(),
84
}
85
}
86
}
87
88
/// `bevy_render::mesh::inherit_weights` runs in this `SystemSet`
89
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
90
pub struct InheritWeightSystems;
91
92