1#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
23extern crate alloc;
4extern crate core;
56mod 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;
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;
2930/// The mesh prelude.
31///
32/// This includes the most common types in this crate, re-exported for your convenience.
33pub mod prelude {
34#[cfg(feature = "morph")]
35pub use crate::morph::MorphWeights;
36#[doc(hidden)]
37pub use crate::{primitives::MeshBuilder, primitives::Meshable, Mesh, Mesh2d, Mesh3d};
38}
3940#[doc = r" Our base mesh pipeline key bits start from the highest bit and go"]
#[doc =
r" downward. The PBR mesh pipeline key bits start from the lowest bit and"]
#[doc =
r" go upward. This allows the PBR bits in the downstream crate `bevy_pbr`"]
#[doc = r" to coexist in the same field without any shifts."]
pub struct BaseMeshPipelineKey(<BaseMeshPipelineKey as
::bitflags::__private::PublicFlags>::Internal);
#[automatically_derived]
impl ::core::clone::Clone for BaseMeshPipelineKey {
#[inline]
fn clone(&self) -> BaseMeshPipelineKey {
BaseMeshPipelineKey(::core::clone::Clone::clone(&self.0))
}
}
#[automatically_derived]
impl ::core::fmt::Debug for BaseMeshPipelineKey {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"BaseMeshPipelineKey", &&self.0)
}
}
#[allow(dead_code, deprecated, unused_doc_comments, unused_attributes,
unused_mut, unused_imports, non_upper_case_globals, clippy :: min_ident_chars,
clippy :: assign_op_pattern, clippy :: indexing_slicing, clippy ::
same_name_method, clippy :: iter_without_into_iter,)]
const _: () =
{
#[repr(transparent)]
pub struct InternalBitFlags(u64);
#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for InternalBitFlags { }
#[automatically_derived]
impl ::core::clone::Clone for InternalBitFlags {
#[inline]
fn clone(&self) -> InternalBitFlags {
let _: ::core::clone::AssertParamIsClone<u64>;
*self
}
}
#[automatically_derived]
impl ::core::marker::Copy for InternalBitFlags { }
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for InternalBitFlags { }
#[automatically_derived]
impl ::core::cmp::PartialEq for InternalBitFlags {
#[inline]
fn eq(&self, other: &InternalBitFlags) -> bool {
self.0 == other.0
}
}
#[automatically_derived]
impl ::core::cmp::Eq for InternalBitFlags {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u64>;
}
}
#[automatically_derived]
impl ::core::cmp::PartialOrd for InternalBitFlags {
#[inline]
fn partial_cmp(&self, other: &InternalBitFlags)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self,
other))
}
}
#[automatically_derived]
impl ::core::cmp::Ord for InternalBitFlags {
#[inline]
fn cmp(&self, other: &InternalBitFlags) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}
#[automatically_derived]
impl ::core::hash::Hash for InternalBitFlags {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}
impl BaseMeshPipelineKey {
pub const MORPH_TARGETS: Self =
Self::from_bits_retain(1 << Self::MORPH_TARGETS_SHIFT_BITS);
pub const PRIMITIVE_TOPOLOGY_RESERVED_BITS: Self =
Self::from_bits_retain(Self::PRIMITIVE_TOPOLOGY_MASK_BITS <<
Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS);
pub const STRIP_INDEX_FORMAT_RESERVED_BITS: Self =
Self::from_bits_retain(Self::STRIP_INDEX_FORMAT_MASK_BITS <<
Self::STRIP_INDEX_FORMAT_SHIFT_BITS);
pub const STRIP_INDEX_FORMAT_NONE: Self =
Self::from_bits_retain(0 <<
Self::STRIP_INDEX_FORMAT_SHIFT_BITS);
pub const STRIP_INDEX_FORMAT_U32: Self =
Self::from_bits_retain(1 <<
Self::STRIP_INDEX_FORMAT_SHIFT_BITS);
pub const STRIP_INDEX_FORMAT_U16: Self =
Self::from_bits_retain(2 <<
Self::STRIP_INDEX_FORMAT_SHIFT_BITS);
}
impl ::bitflags::Flags for BaseMeshPipelineKey {
const FLAGS: &'static [::bitflags::Flag<BaseMeshPipelineKey>] =
{
mod __bitflags_flag_names {
use super::*;
pub(super) const MORPH_TARGETS: &'static str =
"MORPH_TARGETS";
pub(super) const PRIMITIVE_TOPOLOGY_RESERVED_BITS:
&'static str =
"PRIMITIVE_TOPOLOGY_RESERVED_BITS";
pub(super) const STRIP_INDEX_FORMAT_RESERVED_BITS:
&'static str =
"STRIP_INDEX_FORMAT_RESERVED_BITS";
pub(super) const STRIP_INDEX_FORMAT_NONE: &'static str =
"STRIP_INDEX_FORMAT_NONE";
pub(super) const STRIP_INDEX_FORMAT_U32: &'static str =
"STRIP_INDEX_FORMAT_U32";
pub(super) const STRIP_INDEX_FORMAT_U16: &'static str =
"STRIP_INDEX_FORMAT_U16";
}
&[{
::bitflags::Flag::new(__bitflags_flag_names::MORPH_TARGETS,
BaseMeshPipelineKey::MORPH_TARGETS)
},
{
::bitflags::Flag::new(__bitflags_flag_names::PRIMITIVE_TOPOLOGY_RESERVED_BITS,
BaseMeshPipelineKey::PRIMITIVE_TOPOLOGY_RESERVED_BITS)
},
{
::bitflags::Flag::new(__bitflags_flag_names::STRIP_INDEX_FORMAT_RESERVED_BITS,
BaseMeshPipelineKey::STRIP_INDEX_FORMAT_RESERVED_BITS)
},
{
::bitflags::Flag::new(__bitflags_flag_names::STRIP_INDEX_FORMAT_NONE,
BaseMeshPipelineKey::STRIP_INDEX_FORMAT_NONE)
},
{
::bitflags::Flag::new(__bitflags_flag_names::STRIP_INDEX_FORMAT_U32,
BaseMeshPipelineKey::STRIP_INDEX_FORMAT_U32)
},
{
::bitflags::Flag::new(__bitflags_flag_names::STRIP_INDEX_FORMAT_U16,
BaseMeshPipelineKey::STRIP_INDEX_FORMAT_U16)
}]
};
type Bits = u64;
fn bits(&self) -> u64 { BaseMeshPipelineKey::bits(self) }
fn from_bits_retain(bits: u64) -> BaseMeshPipelineKey {
BaseMeshPipelineKey::from_bits_retain(bits)
}
fn all_named() -> BaseMeshPipelineKey {
const ALL_NAMED: u64 =
{
let mut truncated = <u64 as ::bitflags::Bits>::EMPTY;
let mut i = 0;
{
{
let flag =
&<BaseMeshPipelineKey as ::bitflags::Flags>::FLAGS[i];
if flag.is_named() {
truncated = truncated | flag.value().bits();
}
i += 1;
}
};
{
{
let flag =
&<BaseMeshPipelineKey as ::bitflags::Flags>::FLAGS[i];
if flag.is_named() {
truncated = truncated | flag.value().bits();
}
i += 1;
}
};
{
{
let flag =
&<BaseMeshPipelineKey as ::bitflags::Flags>::FLAGS[i];
if flag.is_named() {
truncated = truncated | flag.value().bits();
}
i += 1;
}
};
{
{
let flag =
&<BaseMeshPipelineKey as ::bitflags::Flags>::FLAGS[i];
if flag.is_named() {
truncated = truncated | flag.value().bits();
}
i += 1;
}
};
{
{
let flag =
&<BaseMeshPipelineKey as ::bitflags::Flags>::FLAGS[i];
if flag.is_named() {
truncated = truncated | flag.value().bits();
}
i += 1;
}
};
{
{
let flag =
&<BaseMeshPipelineKey as ::bitflags::Flags>::FLAGS[i];
if flag.is_named() {
truncated = truncated | flag.value().bits();
}
i += 1;
}
};
let _ = i;
truncated
};
BaseMeshPipelineKey::from_bits_retain(ALL_NAMED)
}
}
impl ::bitflags::__private::PublicFlags for BaseMeshPipelineKey {
type Primitive = u64;
type Internal = InternalBitFlags;
}
impl ::bitflags::__private::core::default::Default for
InternalBitFlags {
#[inline]
fn default() -> Self { InternalBitFlags::empty() }
}
impl ::bitflags::__private::core::fmt::Debug for InternalBitFlags {
fn fmt(&self,
f: &mut ::bitflags::__private::core::fmt::Formatter<'_>)
-> ::bitflags::__private::core::fmt::Result {
if self.is_empty() {
f.write_fmt(format_args!("{0:#x}",
<u64 as ::bitflags::Bits>::EMPTY))
} else {
::bitflags::__private::core::fmt::Display::fmt(self, f)
}
}
}
impl ::bitflags::__private::core::fmt::Display for InternalBitFlags {
fn fmt(&self,
f: &mut ::bitflags::__private::core::fmt::Formatter<'_>)
-> ::bitflags::__private::core::fmt::Result {
::bitflags::parser::to_writer(&BaseMeshPipelineKey(*self), f)
}
}
impl ::bitflags::__private::core::str::FromStr for InternalBitFlags {
type Err = ::bitflags::parser::ParseError;
fn from_str(s: &str)
->
::bitflags::__private::core::result::Result<Self,
Self::Err> {
::bitflags::parser::from_str::<BaseMeshPipelineKey>(s).map(|flags|
flags.0)
}
}
impl ::bitflags::__private::core::convert::AsRef<u64> for
InternalBitFlags {
fn as_ref(&self) -> &u64 { &self.0 }
}
impl ::bitflags::__private::core::convert::From<u64> for
InternalBitFlags {
fn from(bits: u64) -> Self { Self::from_bits_retain(bits) }
}
impl InternalBitFlags {
/// Get a flags value with all bits unset.
#[inline]
pub const fn empty() -> Self {
Self(<u64 as ::bitflags::Bits>::EMPTY)
}
/// Get a flags value with all known bits set.
#[inline]
pub const fn all() -> Self {
let mut truncated = <u64 as ::bitflags::Bits>::EMPTY;
let mut i = 0;
{
{
let flag =
<BaseMeshPipelineKey as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<BaseMeshPipelineKey as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<BaseMeshPipelineKey as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<BaseMeshPipelineKey as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<BaseMeshPipelineKey as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<BaseMeshPipelineKey as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
let _ = i;
Self(truncated)
}
/// Get the underlying bits value.
///
/// The returned value is exactly the bits set in this flags value.
#[inline]
pub const fn bits(&self) -> u64 { self.0 }
/// Convert from a bits value.
///
/// This method will return `None` if any unknown bits are set.
#[inline]
pub const fn from_bits(bits: u64)
-> ::bitflags::__private::core::option::Option<Self> {
let truncated = Self::from_bits_truncate(bits).0;
if truncated == bits {
::bitflags::__private::core::option::Option::Some(Self(bits))
} else { ::bitflags::__private::core::option::Option::None }
}
/// Convert from a bits value, unsetting any unknown bits.
#[inline]
pub const fn from_bits_truncate(bits: u64) -> Self {
Self(bits & Self::all().0)
}
/// Convert from a bits value exactly.
#[inline]
pub const fn from_bits_retain(bits: u64) -> Self { Self(bits) }
/// Get a flags value with the bits of a flag with the given name set.
///
/// This method will return `None` if `name` is empty or doesn't
/// correspond to any named flag.
#[inline]
pub fn from_name(name: &str)
-> ::bitflags::__private::core::option::Option<Self> {
mod __bitflags_flag_names {
use super::*;
pub(super) const MORPH_TARGETS: &'static str =
"MORPH_TARGETS";
pub(super) const PRIMITIVE_TOPOLOGY_RESERVED_BITS:
&'static str =
"PRIMITIVE_TOPOLOGY_RESERVED_BITS";
pub(super) const STRIP_INDEX_FORMAT_RESERVED_BITS:
&'static str =
"STRIP_INDEX_FORMAT_RESERVED_BITS";
pub(super) const STRIP_INDEX_FORMAT_NONE: &'static str =
"STRIP_INDEX_FORMAT_NONE";
pub(super) const STRIP_INDEX_FORMAT_U32: &'static str =
"STRIP_INDEX_FORMAT_U32";
pub(super) const STRIP_INDEX_FORMAT_U16: &'static str =
"STRIP_INDEX_FORMAT_U16";
}
{
{
if name == __bitflags_flag_names::MORPH_TARGETS {
return ::bitflags::__private::core::option::Option::Some(Self(BaseMeshPipelineKey::MORPH_TARGETS.bits()));
}
};
};
{
{
if name ==
__bitflags_flag_names::PRIMITIVE_TOPOLOGY_RESERVED_BITS {
return ::bitflags::__private::core::option::Option::Some(Self(BaseMeshPipelineKey::PRIMITIVE_TOPOLOGY_RESERVED_BITS.bits()));
}
};
};
{
{
if name ==
__bitflags_flag_names::STRIP_INDEX_FORMAT_RESERVED_BITS {
return ::bitflags::__private::core::option::Option::Some(Self(BaseMeshPipelineKey::STRIP_INDEX_FORMAT_RESERVED_BITS.bits()));
}
};
};
{
{
if name == __bitflags_flag_names::STRIP_INDEX_FORMAT_NONE {
return ::bitflags::__private::core::option::Option::Some(Self(BaseMeshPipelineKey::STRIP_INDEX_FORMAT_NONE.bits()));
}
};
};
{
{
if name == __bitflags_flag_names::STRIP_INDEX_FORMAT_U32 {
return ::bitflags::__private::core::option::Option::Some(Self(BaseMeshPipelineKey::STRIP_INDEX_FORMAT_U32.bits()));
}
};
};
{
{
if name == __bitflags_flag_names::STRIP_INDEX_FORMAT_U16 {
return ::bitflags::__private::core::option::Option::Some(Self(BaseMeshPipelineKey::STRIP_INDEX_FORMAT_U16.bits()));
}
};
};
let _ = name;
::bitflags::__private::core::option::Option::None
}
/// Whether all bits in `self` are unset.
#[inline]
pub const fn is_empty(&self) -> bool {
self.0 == <u64 as ::bitflags::Bits>::EMPTY
}
/// Whether all known bits in this flags value are set.
#[inline]
pub const fn is_all(&self) -> bool {
Self::all().0 | self.0 == self.0
}
/// Whether any set bits in `other` are also set in `self`.
#[inline]
pub const fn intersects(&self, other: Self) -> bool {
self.0 & other.0 != <u64 as ::bitflags::Bits>::EMPTY
}
/// Whether all set bits in `other` are also set in `self`.
#[inline]
pub const fn contains(&self, other: Self) -> bool {
self.0 & other.0 == other.0
}
/// The bitwise or (`|`) of the bits in `self` and `other`.
#[inline]
pub fn insert(&mut self, other: Self) {
*self = Self(self.0).union(other);
}
/// The intersection of `self` with the complement of `other` (`&!`).
///
/// This method is not equivalent to `self & !other` when `other` has unknown bits set.
/// `remove` won't truncate `other`, but the `!` operator will.
#[inline]
pub fn remove(&mut self, other: Self) {
*self = Self(self.0).difference(other);
}
/// The bitwise exclusive-or (`^`) of the bits in `self` and `other`.
#[inline]
pub fn toggle(&mut self, other: Self) {
*self = Self(self.0).symmetric_difference(other);
}
/// Call `insert` when `value` is `true` or `remove` when `value` is `false`.
#[inline]
pub fn set(&mut self, other: Self, value: bool) {
if value { self.insert(other); } else { self.remove(other); }
}
/// The bitwise and (`&`) of the bits in `self` and `other`.
#[inline]
#[must_use]
pub const fn intersection(self, other: Self) -> Self {
Self(self.0 & other.0)
}
/// The bitwise or (`|`) of the bits in `self` and `other`.
#[inline]
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
/// The intersection of `self` with the complement of `other` (`&!`).
///
/// This method is not equivalent to `self & !other` when `other` has unknown bits set.
/// `difference` won't truncate `other`, but the `!` operator will.
#[inline]
#[must_use]
pub const fn difference(self, other: Self) -> Self {
Self(self.0 & !other.0)
}
/// The bitwise exclusive-or (`^`) of the bits in `self` and `other`.
#[inline]
#[must_use]
pub const fn symmetric_difference(self, other: Self) -> Self {
Self(self.0 ^ other.0)
}
/// The bitwise negation (`!`) of the bits in `self`, truncating the result.
#[inline]
#[must_use]
pub const fn complement(self) -> Self {
Self::from_bits_truncate(!self.0)
}
}
impl ::bitflags::__private::core::fmt::Binary for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::Octal for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::LowerHex for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::UpperHex for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::ops::BitOr for InternalBitFlags {
type Output = Self;
/// The bitwise or (`|`) of the bits in `self` and `other`.
#[inline]
fn bitor(self, other: InternalBitFlags) -> Self {
self.union(other)
}
}
impl ::bitflags::__private::core::ops::BitOrAssign for
InternalBitFlags {
/// The bitwise or (`|`) of the bits in `self` and `other`.
#[inline]
fn bitor_assign(&mut self, other: Self) { self.insert(other); }
}
impl ::bitflags::__private::core::ops::BitXor for InternalBitFlags {
type Output = Self;
/// The bitwise exclusive-or (`^`) of the bits in `self` and `other`.
#[inline]
fn bitxor(self, other: Self) -> Self {
self.symmetric_difference(other)
}
}
impl ::bitflags::__private::core::ops::BitXorAssign for
InternalBitFlags {
/// The bitwise exclusive-or (`^`) of the bits in `self` and `other`.
#[inline]
fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
}
impl ::bitflags::__private::core::ops::BitAnd for InternalBitFlags {
type Output = Self;
/// The bitwise and (`&`) of the bits in `self` and `other`.
#[inline]
fn bitand(self, other: Self) -> Self { self.intersection(other) }
}
impl ::bitflags::__private::core::ops::BitAndAssign for
InternalBitFlags {
/// The bitwise and (`&`) of the bits in `self` and `other`.
#[inline]
fn bitand_assign(&mut self, other: Self) {
*self =
Self::from_bits_retain(self.bits()).intersection(other);
}
}
impl ::bitflags::__private::core::ops::Sub for InternalBitFlags {
type Output = Self;
/// The intersection of `self` with the complement of `other` (`&!`).
///
/// This method is not equivalent to `self & !other` when `other` has unknown bits set.
/// `difference` won't truncate `other`, but the `!` operator will.
#[inline]
fn sub(self, other: Self) -> Self { self.difference(other) }
}
impl ::bitflags::__private::core::ops::SubAssign for InternalBitFlags
{
/// The intersection of `self` with the complement of `other` (`&!`).
///
/// This method is not equivalent to `self & !other` when `other` has unknown bits set.
/// `difference` won't truncate `other`, but the `!` operator will.
#[inline]
fn sub_assign(&mut self, other: Self) { self.remove(other); }
}
impl ::bitflags::__private::core::ops::Not for InternalBitFlags {
type Output = Self;
/// The bitwise negation (`!`) of the bits in `self`, truncating the result.
#[inline]
fn not(self) -> Self { self.complement() }
}
impl ::bitflags::__private::core::iter::Extend<InternalBitFlags> for
InternalBitFlags {
/// The bitwise or (`|`) of the bits in each flags value.
fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(&mut self, iterator: T) {
for item in iterator { self.insert(item) }
}
}
impl ::bitflags::__private::core::iter::FromIterator<InternalBitFlags>
for InternalBitFlags {
/// The bitwise or (`|`) of the bits in each flags value.
fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(iterator: T) -> Self {
use ::bitflags::__private::core::iter::Extend;
let mut result = Self::empty();
result.extend(iterator);
result
}
}
impl InternalBitFlags {
/// Yield a set of contained flags values.
///
/// Each yielded flags value will correspond to a defined named flag. Any unknown bits
/// will be yielded together as a final flags value.
#[inline]
pub const fn iter(&self)
-> ::bitflags::iter::Iter<BaseMeshPipelineKey> {
::bitflags::iter::Iter::__private_const_new(<BaseMeshPipelineKey
as ::bitflags::Flags>::FLAGS,
BaseMeshPipelineKey::from_bits_retain(self.bits()),
BaseMeshPipelineKey::from_bits_retain(self.bits()))
}
/// Yield a set of contained named flags values.
///
/// This method is like [`iter`](#method.iter), except only yields bits in contained named flags.
/// Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
#[inline]
pub const fn iter_names(&self)
-> ::bitflags::iter::IterNames<BaseMeshPipelineKey> {
::bitflags::iter::IterNames::__private_const_new(<BaseMeshPipelineKey
as ::bitflags::Flags>::FLAGS,
BaseMeshPipelineKey::from_bits_retain(self.bits()),
BaseMeshPipelineKey::from_bits_retain(self.bits()))
}
}
impl ::bitflags::__private::core::iter::IntoIterator for
InternalBitFlags {
type Item = BaseMeshPipelineKey;
type IntoIter = ::bitflags::iter::Iter<BaseMeshPipelineKey>;
fn into_iter(self) -> Self::IntoIter { self.iter() }
}
impl InternalBitFlags {
/// Returns a mutable reference to the raw value of the flags currently stored.
#[inline]
pub fn bits_mut(&mut self) -> &mut u64 { &mut self.0 }
}
impl ::bitflags::__private::serde::Serialize for InternalBitFlags {
fn serialize<S: ::bitflags::__private::serde::Serializer>(&self,
serializer: S)
->
::bitflags::__private::core::result::Result<S::Ok,
S::Error> {
::bitflags::serde::serialize(&BaseMeshPipelineKey::from_bits_retain(self.bits()),
serializer)
}
}
impl<'de> ::bitflags::__private::serde::Deserialize<'de> for
InternalBitFlags {
fn deserialize<D: ::bitflags::__private::serde::Deserializer<'de>>(deserializer:
D)
->
::bitflags::__private::core::result::Result<Self,
D::Error> {
let flags: BaseMeshPipelineKey =
::bitflags::serde::deserialize(deserializer)?;
::bitflags::__private::core::result::Result::Ok(flags.0)
}
}
impl BaseMeshPipelineKey {
/// Get a flags value with all bits unset.
#[inline]
pub const fn empty() -> Self { Self(InternalBitFlags::empty()) }
/// Get a flags value with all known bits set.
#[inline]
pub const fn all() -> Self { Self(InternalBitFlags::all()) }
/// Get the underlying bits value.
///
/// The returned value is exactly the bits set in this flags value.
#[inline]
pub const fn bits(&self) -> u64 { self.0.bits() }
/// Convert from a bits value.
///
/// This method will return `None` if any unknown bits are set.
#[inline]
pub const fn from_bits(bits: u64)
-> ::bitflags::__private::core::option::Option<Self> {
match InternalBitFlags::from_bits(bits) {
::bitflags::__private::core::option::Option::Some(bits) =>
::bitflags::__private::core::option::Option::Some(Self(bits)),
::bitflags::__private::core::option::Option::None =>
::bitflags::__private::core::option::Option::None,
}
}
/// Convert from a bits value, unsetting any unknown bits.
#[inline]
pub const fn from_bits_truncate(bits: u64) -> Self {
Self(InternalBitFlags::from_bits_truncate(bits))
}
/// Convert from a bits value exactly.
#[inline]
pub const fn from_bits_retain(bits: u64) -> Self {
Self(InternalBitFlags::from_bits_retain(bits))
}
/// Get a flags value with the bits of a flag with the given name set.
///
/// This method will return `None` if `name` is empty or doesn't
/// correspond to any named flag.
#[inline]
pub fn from_name(name: &str)
-> ::bitflags::__private::core::option::Option<Self> {
match InternalBitFlags::from_name(name) {
::bitflags::__private::core::option::Option::Some(bits) =>
::bitflags::__private::core::option::Option::Some(Self(bits)),
::bitflags::__private::core::option::Option::None =>
::bitflags::__private::core::option::Option::None,
}
}
/// Whether all bits in `self` are unset.
#[inline]
pub const fn is_empty(&self) -> bool { self.0.is_empty() }
/// Whether all known bits in this flags value are set.
#[inline]
pub const fn is_all(&self) -> bool { self.0.is_all() }
/// Whether any set bits in `other` are also set in `self`.
#[inline]
pub const fn intersects(&self, other: Self) -> bool {
self.0.intersects(other.0)
}
/// Whether all set bits in `other` are also set in `self`.
#[inline]
pub const fn contains(&self, other: Self) -> bool {
self.0.contains(other.0)
}
/// The bitwise or (`|`) of the bits in `self` and `other`.
#[inline]
pub fn insert(&mut self, other: Self) { self.0.insert(other.0) }
/// The intersection of `self` with the complement of `other` (`&!`).
///
/// This method is not equivalent to `self & !other` when `other` has unknown bits set.
/// `remove` won't truncate `other`, but the `!` operator will.
#[inline]
pub fn remove(&mut self, other: Self) { self.0.remove(other.0) }
/// The bitwise exclusive-or (`^`) of the bits in `self` and `other`.
#[inline]
pub fn toggle(&mut self, other: Self) { self.0.toggle(other.0) }
/// Call `insert` when `value` is `true` or `remove` when `value` is `false`.
#[inline]
pub fn set(&mut self, other: Self, value: bool) {
self.0.set(other.0, value)
}
/// The bitwise and (`&`) of the bits in `self` and `other`.
#[inline]
#[must_use]
pub const fn intersection(self, other: Self) -> Self {
Self(self.0.intersection(other.0))
}
/// The bitwise or (`|`) of the bits in `self` and `other`.
#[inline]
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0.union(other.0))
}
/// The intersection of `self` with the complement of `other` (`&!`).
///
/// This method is not equivalent to `self & !other` when `other` has unknown bits set.
/// `difference` won't truncate `other`, but the `!` operator will.
#[inline]
#[must_use]
pub const fn difference(self, other: Self) -> Self {
Self(self.0.difference(other.0))
}
/// The bitwise exclusive-or (`^`) of the bits in `self` and `other`.
#[inline]
#[must_use]
pub const fn symmetric_difference(self, other: Self) -> Self {
Self(self.0.symmetric_difference(other.0))
}
/// The bitwise negation (`!`) of the bits in `self`, truncating the result.
#[inline]
#[must_use]
pub const fn complement(self) -> Self {
Self(self.0.complement())
}
}
impl ::bitflags::__private::core::fmt::Binary for BaseMeshPipelineKey
{
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::Octal for BaseMeshPipelineKey {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::LowerHex for
BaseMeshPipelineKey {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::UpperHex for
BaseMeshPipelineKey {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::ops::BitOr for BaseMeshPipelineKey {
type Output = Self;
/// The bitwise or (`|`) of the bits in `self` and `other`.
#[inline]
fn bitor(self, other: BaseMeshPipelineKey) -> Self {
self.union(other)
}
}
impl ::bitflags::__private::core::ops::BitOrAssign for
BaseMeshPipelineKey {
/// The bitwise or (`|`) of the bits in `self` and `other`.
#[inline]
fn bitor_assign(&mut self, other: Self) { self.insert(other); }
}
impl ::bitflags::__private::core::ops::BitXor for BaseMeshPipelineKey
{
type Output = Self;
/// The bitwise exclusive-or (`^`) of the bits in `self` and `other`.
#[inline]
fn bitxor(self, other: Self) -> Self {
self.symmetric_difference(other)
}
}
impl ::bitflags::__private::core::ops::BitXorAssign for
BaseMeshPipelineKey {
/// The bitwise exclusive-or (`^`) of the bits in `self` and `other`.
#[inline]
fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
}
impl ::bitflags::__private::core::ops::BitAnd for BaseMeshPipelineKey
{
type Output = Self;
/// The bitwise and (`&`) of the bits in `self` and `other`.
#[inline]
fn bitand(self, other: Self) -> Self { self.intersection(other) }
}
impl ::bitflags::__private::core::ops::BitAndAssign for
BaseMeshPipelineKey {
/// The bitwise and (`&`) of the bits in `self` and `other`.
#[inline]
fn bitand_assign(&mut self, other: Self) {
*self =
Self::from_bits_retain(self.bits()).intersection(other);
}
}
impl ::bitflags::__private::core::ops::Sub for BaseMeshPipelineKey {
type Output = Self;
/// The intersection of `self` with the complement of `other` (`&!`).
///
/// This method is not equivalent to `self & !other` when `other` has unknown bits set.
/// `difference` won't truncate `other`, but the `!` operator will.
#[inline]
fn sub(self, other: Self) -> Self { self.difference(other) }
}
impl ::bitflags::__private::core::ops::SubAssign for
BaseMeshPipelineKey {
/// The intersection of `self` with the complement of `other` (`&!`).
///
/// This method is not equivalent to `self & !other` when `other` has unknown bits set.
/// `difference` won't truncate `other`, but the `!` operator will.
#[inline]
fn sub_assign(&mut self, other: Self) { self.remove(other); }
}
impl ::bitflags::__private::core::ops::Not for BaseMeshPipelineKey {
type Output = Self;
/// The bitwise negation (`!`) of the bits in `self`, truncating the result.
#[inline]
fn not(self) -> Self { self.complement() }
}
impl ::bitflags::__private::core::iter::Extend<BaseMeshPipelineKey>
for BaseMeshPipelineKey {
/// The bitwise or (`|`) of the bits in each flags value.
fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(&mut self, iterator: T) {
for item in iterator { self.insert(item) }
}
}
impl ::bitflags::__private::core::iter::FromIterator<BaseMeshPipelineKey>
for BaseMeshPipelineKey {
/// The bitwise or (`|`) of the bits in each flags value.
fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(iterator: T) -> Self {
use ::bitflags::__private::core::iter::Extend;
let mut result = Self::empty();
result.extend(iterator);
result
}
}
impl BaseMeshPipelineKey {
/// Yield a set of contained flags values.
///
/// Each yielded flags value will correspond to a defined named flag. Any unknown bits
/// will be yielded together as a final flags value.
#[inline]
pub const fn iter(&self)
-> ::bitflags::iter::Iter<BaseMeshPipelineKey> {
::bitflags::iter::Iter::__private_const_new(<BaseMeshPipelineKey
as ::bitflags::Flags>::FLAGS,
BaseMeshPipelineKey::from_bits_retain(self.bits()),
BaseMeshPipelineKey::from_bits_retain(self.bits()))
}
/// Yield a set of contained named flags values.
///
/// This method is like [`iter`](#method.iter), except only yields bits in contained named flags.
/// Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
#[inline]
pub const fn iter_names(&self)
-> ::bitflags::iter::IterNames<BaseMeshPipelineKey> {
::bitflags::iter::IterNames::__private_const_new(<BaseMeshPipelineKey
as ::bitflags::Flags>::FLAGS,
BaseMeshPipelineKey::from_bits_retain(self.bits()),
BaseMeshPipelineKey::from_bits_retain(self.bits()))
}
}
impl ::bitflags::__private::core::iter::IntoIterator for
BaseMeshPipelineKey {
type Item = BaseMeshPipelineKey;
type IntoIter = ::bitflags::iter::Iter<BaseMeshPipelineKey>;
fn into_iter(self) -> Self::IntoIter { self.iter() }
}
};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)]
46pub struct BaseMeshPipelineKey: u64 {
47const MORPH_TARGETS = 1 << Self::MORPH_TARGETS_SHIFT_BITS;
4849const PRIMITIVE_TOPOLOGY_RESERVED_BITS = Self::PRIMITIVE_TOPOLOGY_MASK_BITS << Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS;
5051const STRIP_INDEX_FORMAT_RESERVED_BITS = Self::STRIP_INDEX_FORMAT_MASK_BITS << Self::STRIP_INDEX_FORMAT_SHIFT_BITS;
52const STRIP_INDEX_FORMAT_NONE = 0 << Self::STRIP_INDEX_FORMAT_SHIFT_BITS;
53const STRIP_INDEX_FORMAT_U32 = 1 << Self::STRIP_INDEX_FORMAT_SHIFT_BITS;
54const STRIP_INDEX_FORMAT_U16 = 2 << Self::STRIP_INDEX_FORMAT_SHIFT_BITS;
55 }
56}5758/// Adds [`Mesh`] as an asset.
59#[derive(#[automatically_derived]
impl ::core::default::Default for MeshPlugin {
#[inline]
fn default() -> MeshPlugin { MeshPlugin {} }
}Default)]
60pub struct MeshPlugin;
6162impl Pluginfor MeshPlugin {
63fn build(&self, app: &mut App) {
64app.init_asset::<Mesh>()
65 .init_asset::<skinning::SkinnedMeshInverseBindposes>()
66 .register_asset_reflect::<Mesh>()
67 .add_systems(
68PostUpdate,
69mark_3d_meshes_as_changed_if_their_assets_changed.after(AssetEventSystems),
70 );
71 }
72}
7374impl BaseMeshPipelineKey {
75pub const MORPH_TARGETS_SHIFT_BITS: u64 = (u64::BITS - 1) as u64;
7677pub const PRIMITIVE_TOPOLOGY_MASK_BITS: u64 = 0b111;
78pub const PRIMITIVE_TOPOLOGY_SHIFT_BITS: u64 =
79Self::MORPH_TARGETS_SHIFT_BITS - Self::PRIMITIVE_TOPOLOGY_MASK_BITS.count_ones() as u64;
8081pub const STRIP_INDEX_FORMAT_MASK_BITS: u64 = 0b11;
82pub const STRIP_INDEX_FORMAT_SHIFT_BITS: u64 = Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS83 - Self::STRIP_INDEX_FORMAT_MASK_BITS.count_ones() as u64;
8485/// Create a [`BaseMeshPipelineKey`] from mesh primitive topology and index format.
86 ///
87 /// For non-strip topologies, [`Self::STRIP_INDEX_FORMAT_NONE`] is set regardless of the `strip_index_format` argument.
88pub fn from_primitive_topology_and_strip_index(
89 primitive_topology: PrimitiveTopology,
90 strip_index_format: Option<wgpu_types::IndexFormat>,
91 ) -> Self {
92let index_bits = if primitive_topology.is_strip() {
93match strip_index_format {
94None => BaseMeshPipelineKey::STRIP_INDEX_FORMAT_NONE,
95Some(index_format) => match index_format {
96 wgpu_types::IndexFormat::Uint16 => BaseMeshPipelineKey::STRIP_INDEX_FORMAT_U16,
97 wgpu_types::IndexFormat::Uint32 => BaseMeshPipelineKey::STRIP_INDEX_FORMAT_U32,
98 },
99 }
100 } else {
101BaseMeshPipelineKey::STRIP_INDEX_FORMAT_NONE102 }
103 .bits();
104let primitive_topology_bits = ((primitive_topologyas u64)
105 & Self::PRIMITIVE_TOPOLOGY_MASK_BITS)
106 << Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS;
107Self::from_bits_retain(primitive_topology_bits | index_bits)
108 }
109110pub fn primitive_topology(&self) -> PrimitiveTopology {
111let primitive_topology_bits = (self.bits() >> Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS)
112 & Self::PRIMITIVE_TOPOLOGY_MASK_BITS;
113match primitive_topology_bits {
114 x if x == PrimitiveTopology::PointListas u64 => PrimitiveTopology::PointList,
115 x if x == PrimitiveTopology::LineListas u64 => PrimitiveTopology::LineList,
116 x if x == PrimitiveTopology::LineStripas u64 => PrimitiveTopology::LineStrip,
117 x if x == PrimitiveTopology::TriangleListas u64 => PrimitiveTopology::TriangleList,
118 x if x == PrimitiveTopology::TriangleStripas u64 => PrimitiveTopology::TriangleStrip,
119_ => PrimitiveTopology::default(),
120 }
121 }
122}