1use crate::{Indices, Mesh, MeshBuilder, Meshable, PrimitiveTopology};
2use bevy_asset::RenderAssetUsages;
3use bevy_math::{ops, primitives::Capsule3d, Vec2, Vec3};
4use bevy_reflect::prelude::*;
5
6#[derive(#[automatically_derived]
impl ::core::clone::Clone for CapsuleUvProfile {
#[inline]
fn clone(&self) -> CapsuleUvProfile { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for CapsuleUvProfile { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for CapsuleUvProfile {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
CapsuleUvProfile::Aspect => "Aspect",
CapsuleUvProfile::Uniform => "Uniform",
CapsuleUvProfile::Fixed => "Fixed",
})
}
}Debug, #[automatically_derived]
impl ::core::default::Default for CapsuleUvProfile {
#[inline]
fn default() -> CapsuleUvProfile { Self::Aspect }
}Default, const _: () =
{
impl bevy_reflect::GetTypeRegistration for CapsuleUvProfile where {
fn get_type_registration() -> bevy_reflect::TypeRegistration {
let mut registration =
bevy_reflect::TypeRegistration::of::<Self>();
registration.insert::<bevy_reflect::ReflectFromPtr>(bevy_reflect::FromType::<Self>::from_type());
registration.insert::<bevy_reflect::ReflectFromReflect>(bevy_reflect::FromType::<Self>::from_type());
registration.register_type_data::<ReflectDefault, Self>();
registration
}
#[inline(never)]
fn register_type_dependencies(registry:
&mut bevy_reflect::TypeRegistry) {}
}
impl bevy_reflect::Typed for CapsuleUvProfile where {
#[inline]
fn type_info() -> &'static bevy_reflect::TypeInfo {
static CELL: bevy_reflect::utility::NonGenericTypeInfoCell =
bevy_reflect::utility::NonGenericTypeInfoCell::new();
CELL.get_or_set(||
{
bevy_reflect::TypeInfo::Enum(bevy_reflect::enums::EnumInfo::new::<Self>(&[bevy_reflect::enums::VariantInfo::Unit(bevy_reflect::enums::UnitVariantInfo::new("Aspect")),
bevy_reflect::enums::VariantInfo::Unit(bevy_reflect::enums::UnitVariantInfo::new("Uniform")),
bevy_reflect::enums::VariantInfo::Unit(bevy_reflect::enums::UnitVariantInfo::new("Fixed"))]))
})
}
}
#[allow(deprecated, reason =
"derives on a deprecated type shouldn't be considered a usage")]
impl bevy_reflect::TypePath for CapsuleUvProfile where {
fn type_path() -> &'static str {
"bevy_mesh::primitives::dim3::capsule::CapsuleUvProfile"
}
fn short_type_path() -> &'static str { "CapsuleUvProfile" }
fn type_ident() -> ::core::option::Option<&'static str> {
::core::option::Option::Some("CapsuleUvProfile")
}
fn crate_name() -> ::core::option::Option<&'static str> {
::core::option::Option::Some("bevy_mesh::primitives::dim3::capsule".split(':').next().unwrap())
}
fn module_path() -> ::core::option::Option<&'static str> {
::core::option::Option::Some("bevy_mesh::primitives::dim3::capsule")
}
}
impl bevy_reflect::Reflect for CapsuleUvProfile where {
#[inline]
fn into_any(self:
bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
->
bevy_reflect::__macro_exports::alloc_utils::Box<dyn ::core::any::Any> {
self
}
#[inline]
fn as_any(&self) -> &dyn ::core::any::Any { self }
#[inline]
fn as_any_mut(&mut self) -> &mut dyn ::core::any::Any { self }
#[inline]
fn into_reflect(self:
bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
->
bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect> {
self
}
#[inline]
fn as_reflect(&self) -> &dyn bevy_reflect::Reflect { self }
#[inline]
fn as_reflect_mut(&mut self) -> &mut dyn bevy_reflect::Reflect {
self
}
#[inline]
fn set(&mut self,
value:
bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect>)
->
::core::result::Result<(),
bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect>> {
*self = <dyn bevy_reflect::Reflect>::take(value)?;
::core::result::Result::Ok(())
}
}
#[allow(non_upper_case_globals)]
const _: () =
{
static __INVENTORY: ::inventory::Node =
::inventory::Node {
value: &{
bevy_reflect::__macro_exports::auto_register::AutomaticReflectRegistrations(<CapsuleUvProfile
as
bevy_reflect::__macro_exports::auto_register::RegisterForReflection>::__register)
},
next: ::inventory::__private::UnsafeCell::new(::inventory::__private::Option::None),
};
#[link_section = ".text.startup"]
unsafe extern "C" fn __ctor() {
unsafe {
::inventory::ErasedNode::submit(__INVENTORY.value,
&__INVENTORY)
}
}
#[used]
#[link_section = ".init_array"]
static __CTOR: unsafe extern "C" fn() = __ctor;
};
impl bevy_reflect::enums::Enum for CapsuleUvProfile where {
fn field(&self, __name_param: &str)
-> ::core::option::Option<&dyn bevy_reflect::PartialReflect> {
match self { _ => ::core::option::Option::None, }
}
fn field_at(&self, __index_param: usize)
-> ::core::option::Option<&dyn bevy_reflect::PartialReflect> {
match self { _ => ::core::option::Option::None, }
}
fn field_mut(&mut self, __name_param: &str)
->
::core::option::Option<&mut dyn bevy_reflect::PartialReflect> {
match self { _ => ::core::option::Option::None, }
}
fn field_at_mut(&mut self, __index_param: usize)
->
::core::option::Option<&mut dyn bevy_reflect::PartialReflect> {
match self { _ => ::core::option::Option::None, }
}
fn index_of(&self, __name_param: &str)
-> ::core::option::Option<usize> {
match self { _ => ::core::option::Option::None, }
}
fn name_at(&self, __index_param: usize)
-> ::core::option::Option<&str> {
match self { _ => ::core::option::Option::None, }
}
fn iter_fields(&self) -> bevy_reflect::enums::VariantFieldIter {
bevy_reflect::enums::VariantFieldIter::new(self)
}
#[inline]
fn field_len(&self) -> usize {
match self {
CapsuleUvProfile::Aspect { .. } => 0usize,
CapsuleUvProfile::Uniform { .. } => 0usize,
CapsuleUvProfile::Fixed { .. } => 0usize,
_ => 0,
}
}
#[inline]
fn variant_name(&self) -> &str {
match self {
CapsuleUvProfile::Aspect { .. } => "Aspect",
CapsuleUvProfile::Uniform { .. } => "Uniform",
CapsuleUvProfile::Fixed { .. } => "Fixed",
_ =>
::core::panicking::panic("internal error: entered unreachable code"),
}
}
#[inline]
fn variant_index(&self) -> usize {
match self {
CapsuleUvProfile::Aspect { .. } => 0usize,
CapsuleUvProfile::Uniform { .. } => 1usize,
CapsuleUvProfile::Fixed { .. } => 2usize,
_ =>
::core::panicking::panic("internal error: entered unreachable code"),
}
}
#[inline]
fn variant_type(&self) -> bevy_reflect::enums::VariantType {
match self {
CapsuleUvProfile::Aspect { .. } =>
bevy_reflect::enums::VariantType::Unit,
CapsuleUvProfile::Uniform { .. } =>
bevy_reflect::enums::VariantType::Unit,
CapsuleUvProfile::Fixed { .. } =>
bevy_reflect::enums::VariantType::Unit,
_ =>
::core::panicking::panic("internal error: entered unreachable code"),
}
}
fn to_dynamic_enum(&self) -> bevy_reflect::enums::DynamicEnum {
bevy_reflect::enums::DynamicEnum::from_ref::<Self>(self)
}
}
impl bevy_reflect::PartialReflect for CapsuleUvProfile where {
#[inline]
fn get_represented_type_info(&self)
-> ::core::option::Option<&'static bevy_reflect::TypeInfo> {
::core::option::Option::Some(<Self as
bevy_reflect::Typed>::type_info())
}
#[inline]
fn try_apply(&mut self,
__value_param: &dyn bevy_reflect::PartialReflect)
-> ::core::result::Result<(), bevy_reflect::ApplyError> {
if let bevy_reflect::ReflectRef::Enum(__value_param) =
bevy_reflect::PartialReflect::reflect_ref(__value_param) {
if bevy_reflect::enums::Enum::variant_name(self) ==
bevy_reflect::enums::Enum::variant_name(__value_param) {
match bevy_reflect::enums::Enum::variant_type(__value_param)
{
bevy_reflect::enums::VariantType::Struct => {
for field in
bevy_reflect::enums::Enum::iter_fields(__value_param) {
let name = field.name().unwrap();
if let ::core::option::Option::Some(v) =
bevy_reflect::enums::Enum::field_mut(self, name) {
bevy_reflect::PartialReflect::try_apply(v, field.value())?;
}
}
}
bevy_reflect::enums::VariantType::Tuple => {
for (index, field) in
::core::iter::Iterator::enumerate(bevy_reflect::enums::Enum::iter_fields(__value_param))
{
if let ::core::option::Option::Some(v) =
bevy_reflect::enums::Enum::field_at_mut(self, index) {
bevy_reflect::PartialReflect::try_apply(v, field.value())?;
}
}
}
_ => {}
}
} else {
match bevy_reflect::enums::Enum::variant_name(__value_param)
{
"Aspect" => { *self = CapsuleUvProfile::Aspect {} }
"Uniform" => { *self = CapsuleUvProfile::Uniform {} }
"Fixed" => { *self = CapsuleUvProfile::Fixed {} }
name => {
return ::core::result::Result::Err(bevy_reflect::ApplyError::UnknownVariant {
enum_name: ::core::convert::Into::into(bevy_reflect::DynamicTypePath::reflect_type_path(self)),
variant_name: ::core::convert::Into::into(name),
});
}
}
}
} else {
return ::core::result::Result::Err(bevy_reflect::ApplyError::MismatchedKinds {
from_kind: bevy_reflect::PartialReflect::reflect_kind(__value_param),
to_kind: bevy_reflect::ReflectKind::Enum,
});
}
::core::result::Result::Ok(())
}
fn reflect_kind(&self) -> bevy_reflect::ReflectKind {
bevy_reflect::ReflectKind::Enum
}
fn reflect_ref(&self) -> bevy_reflect::ReflectRef {
bevy_reflect::ReflectRef::Enum(self)
}
fn reflect_mut(&mut self) -> bevy_reflect::ReflectMut {
bevy_reflect::ReflectMut::Enum(self)
}
fn reflect_owned(self:
bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
-> bevy_reflect::ReflectOwned {
bevy_reflect::ReflectOwned::Enum(self)
}
#[inline]
fn try_into_reflect(self:
bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
->
::core::result::Result<bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect>,
bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::PartialReflect>> {
::core::result::Result::Ok(self)
}
#[inline]
fn try_as_reflect(&self)
-> ::core::option::Option<&dyn bevy_reflect::Reflect> {
::core::option::Option::Some(self)
}
#[inline]
fn try_as_reflect_mut(&mut self)
-> ::core::option::Option<&mut dyn bevy_reflect::Reflect> {
::core::option::Option::Some(self)
}
#[inline]
fn into_partial_reflect(self:
bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
->
bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::PartialReflect> {
self
}
#[inline]
fn as_partial_reflect(&self)
-> &dyn bevy_reflect::PartialReflect {
self
}
#[inline]
fn as_partial_reflect_mut(&mut self)
-> &mut dyn bevy_reflect::PartialReflect {
self
}
fn reflect_hash(&self) -> ::core::option::Option<u64> {
(bevy_reflect::enums::enum_hash)(self)
}
fn reflect_partial_eq(&self,
value: &dyn bevy_reflect::PartialReflect)
-> ::core::option::Option<bool> {
(bevy_reflect::enums::enum_partial_eq)(self, value)
}
fn reflect_partial_cmp(&self,
value: &dyn bevy_reflect::PartialReflect)
-> ::core::option::Option<::core::cmp::Ordering> {
(bevy_reflect::enums::enum_partial_cmp)(self, value)
}
fn debug(&self, f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
::core::fmt::Debug::fmt(self, f)
}
#[inline]
fn reflect_clone(&self)
->
::core::result::Result<bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect>,
bevy_reflect::ReflectCloneError> {
::core::result::Result::Ok(bevy_reflect::__macro_exports::alloc_utils::Box::new(::core::clone::Clone::clone(self)))
}
}
impl bevy_reflect::FromReflect for CapsuleUvProfile where {
fn from_reflect(__param0: &dyn bevy_reflect::PartialReflect)
-> ::core::option::Option<Self> {
if let bevy_reflect::ReflectRef::Enum(__param0) =
bevy_reflect::PartialReflect::reflect_ref(__param0) {
match bevy_reflect::enums::Enum::variant_name(__param0) {
"Aspect" =>
::core::option::Option::Some(CapsuleUvProfile::Aspect {}),
"Uniform" =>
::core::option::Option::Some(CapsuleUvProfile::Uniform {}),
"Fixed" =>
::core::option::Option::Some(CapsuleUvProfile::Fixed {}),
name => ::core::option::Option::None,
}
} else { ::core::option::Option::None }
}
}
};Reflect)]
8#[reflect(Default, Debug, Clone)]
9pub enum CapsuleUvProfile {
10 #[default]
12 Aspect,
13 Uniform,
15 Fixed,
18}
19
20#[derive(#[automatically_derived]
impl ::core::clone::Clone for Capsule3dMeshBuilder {
#[inline]
fn clone(&self) -> Capsule3dMeshBuilder {
let _: ::core::clone::AssertParamIsClone<Capsule3d>;
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<CapsuleUvProfile>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Capsule3dMeshBuilder { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for Capsule3dMeshBuilder {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field5_finish(f,
"Capsule3dMeshBuilder", "capsule", &self.capsule, "rings",
&self.rings, "longitudes", &self.longitudes, "latitudes",
&self.latitudes, "uv_profile", &&self.uv_profile)
}
}Debug, const _: () =
{
impl bevy_reflect::GetTypeRegistration for Capsule3dMeshBuilder where
{
fn get_type_registration() -> bevy_reflect::TypeRegistration {
let mut registration =
bevy_reflect::TypeRegistration::of::<Self>();
registration.insert::<bevy_reflect::ReflectFromPtr>(bevy_reflect::FromType::<Self>::from_type());
registration.insert::<bevy_reflect::ReflectFromReflect>(bevy_reflect::FromType::<Self>::from_type());
registration.register_type_data::<ReflectDefault, Self>();
registration
}
#[inline(never)]
fn register_type_dependencies(registry:
&mut bevy_reflect::TypeRegistry) {
<Capsule3d as
bevy_reflect::__macro_exports::RegisterForReflection>::__register(registry);
<u32 as
bevy_reflect::__macro_exports::RegisterForReflection>::__register(registry);
<CapsuleUvProfile as
bevy_reflect::__macro_exports::RegisterForReflection>::__register(registry);
}
}
impl bevy_reflect::Typed for Capsule3dMeshBuilder where {
#[inline]
fn type_info() -> &'static bevy_reflect::TypeInfo {
static CELL: bevy_reflect::utility::NonGenericTypeInfoCell =
bevy_reflect::utility::NonGenericTypeInfoCell::new();
CELL.get_or_set(||
{
bevy_reflect::TypeInfo::Struct(bevy_reflect::structs::StructInfo::new::<Self>(&[bevy_reflect::NamedField::new::<Capsule3d>("capsule"),
bevy_reflect::NamedField::new::<u32>("rings"),
bevy_reflect::NamedField::new::<u32>("longitudes"),
bevy_reflect::NamedField::new::<u32>("latitudes"),
bevy_reflect::NamedField::new::<CapsuleUvProfile>("uv_profile")]))
})
}
}
#[allow(deprecated, reason =
"derives on a deprecated type shouldn't be considered a usage")]
impl bevy_reflect::TypePath for Capsule3dMeshBuilder where {
fn type_path() -> &'static str {
"bevy_mesh::primitives::dim3::capsule::Capsule3dMeshBuilder"
}
fn short_type_path() -> &'static str { "Capsule3dMeshBuilder" }
fn type_ident() -> ::core::option::Option<&'static str> {
::core::option::Option::Some("Capsule3dMeshBuilder")
}
fn crate_name() -> ::core::option::Option<&'static str> {
::core::option::Option::Some("bevy_mesh::primitives::dim3::capsule".split(':').next().unwrap())
}
fn module_path() -> ::core::option::Option<&'static str> {
::core::option::Option::Some("bevy_mesh::primitives::dim3::capsule")
}
}
impl bevy_reflect::Reflect for Capsule3dMeshBuilder where {
#[inline]
fn into_any(self:
bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
->
bevy_reflect::__macro_exports::alloc_utils::Box<dyn ::core::any::Any> {
self
}
#[inline]
fn as_any(&self) -> &dyn ::core::any::Any { self }
#[inline]
fn as_any_mut(&mut self) -> &mut dyn ::core::any::Any { self }
#[inline]
fn into_reflect(self:
bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
->
bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect> {
self
}
#[inline]
fn as_reflect(&self) -> &dyn bevy_reflect::Reflect { self }
#[inline]
fn as_reflect_mut(&mut self) -> &mut dyn bevy_reflect::Reflect {
self
}
#[inline]
fn set(&mut self,
value:
bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect>)
->
::core::result::Result<(),
bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect>> {
*self = <dyn bevy_reflect::Reflect>::take(value)?;
::core::result::Result::Ok(())
}
}
#[allow(non_upper_case_globals)]
const _: () =
{
static __INVENTORY: ::inventory::Node =
::inventory::Node {
value: &{
bevy_reflect::__macro_exports::auto_register::AutomaticReflectRegistrations(<Capsule3dMeshBuilder
as
bevy_reflect::__macro_exports::auto_register::RegisterForReflection>::__register)
},
next: ::inventory::__private::UnsafeCell::new(::inventory::__private::Option::None),
};
#[link_section = ".text.startup"]
unsafe extern "C" fn __ctor() {
unsafe {
::inventory::ErasedNode::submit(__INVENTORY.value,
&__INVENTORY)
}
}
#[used]
#[link_section = ".init_array"]
static __CTOR: unsafe extern "C" fn() = __ctor;
};
impl bevy_reflect::structs::Struct for Capsule3dMeshBuilder where {
fn field(&self, name: &str)
-> ::core::option::Option<&dyn bevy_reflect::PartialReflect> {
match name {
"capsule" => ::core::option::Option::Some(&self.capsule),
"rings" => ::core::option::Option::Some(&self.rings),
"longitudes" =>
::core::option::Option::Some(&self.longitudes),
"latitudes" =>
::core::option::Option::Some(&self.latitudes),
"uv_profile" =>
::core::option::Option::Some(&self.uv_profile),
_ => ::core::option::Option::None,
}
}
fn field_mut(&mut self, name: &str)
->
::core::option::Option<&mut dyn bevy_reflect::PartialReflect> {
match name {
"capsule" =>
::core::option::Option::Some(&mut self.capsule),
"rings" => ::core::option::Option::Some(&mut self.rings),
"longitudes" =>
::core::option::Option::Some(&mut self.longitudes),
"latitudes" =>
::core::option::Option::Some(&mut self.latitudes),
"uv_profile" =>
::core::option::Option::Some(&mut self.uv_profile),
_ => ::core::option::Option::None,
}
}
fn field_at(&self, index: usize)
-> ::core::option::Option<&dyn bevy_reflect::PartialReflect> {
match index {
0usize => ::core::option::Option::Some(&self.capsule),
1usize => ::core::option::Option::Some(&self.rings),
2usize => ::core::option::Option::Some(&self.longitudes),
3usize => ::core::option::Option::Some(&self.latitudes),
4usize => ::core::option::Option::Some(&self.uv_profile),
_ => ::core::option::Option::None,
}
}
fn field_at_mut(&mut self, index: usize)
->
::core::option::Option<&mut dyn bevy_reflect::PartialReflect> {
match index {
0usize => ::core::option::Option::Some(&mut self.capsule),
1usize => ::core::option::Option::Some(&mut self.rings),
2usize =>
::core::option::Option::Some(&mut self.longitudes),
3usize => ::core::option::Option::Some(&mut self.latitudes),
4usize =>
::core::option::Option::Some(&mut self.uv_profile),
_ => ::core::option::Option::None,
}
}
fn name_at(&self, index: usize) -> ::core::option::Option<&str> {
match index {
0usize => ::core::option::Option::Some("capsule"),
1usize => ::core::option::Option::Some("rings"),
2usize => ::core::option::Option::Some("longitudes"),
3usize => ::core::option::Option::Some("latitudes"),
4usize => ::core::option::Option::Some("uv_profile"),
_ => ::core::option::Option::None,
}
}
fn index_of_name(&self, name: &str)
-> ::core::option::Option<usize> {
match name {
"capsule" => ::core::option::Option::Some(0usize),
"rings" => ::core::option::Option::Some(1usize),
"longitudes" => ::core::option::Option::Some(2usize),
"latitudes" => ::core::option::Option::Some(3usize),
"uv_profile" => ::core::option::Option::Some(4usize),
_ => ::core::option::Option::None,
}
}
fn field_len(&self) -> usize { 5usize }
fn iter_fields(&self) -> bevy_reflect::structs::FieldIter {
bevy_reflect::structs::FieldIter::new(self)
}
fn to_dynamic_struct(&self)
-> bevy_reflect::structs::DynamicStruct {
let mut dynamic: bevy_reflect::structs::DynamicStruct =
::core::default::Default::default();
dynamic.set_represented_type(bevy_reflect::PartialReflect::get_represented_type_info(self));
dynamic.insert_boxed("capsule",
bevy_reflect::PartialReflect::to_dynamic(&self.capsule));
dynamic.insert_boxed("rings",
bevy_reflect::PartialReflect::to_dynamic(&self.rings));
dynamic.insert_boxed("longitudes",
bevy_reflect::PartialReflect::to_dynamic(&self.longitudes));
dynamic.insert_boxed("latitudes",
bevy_reflect::PartialReflect::to_dynamic(&self.latitudes));
dynamic.insert_boxed("uv_profile",
bevy_reflect::PartialReflect::to_dynamic(&self.uv_profile));
dynamic
}
}
impl bevy_reflect::PartialReflect for Capsule3dMeshBuilder where {
#[inline]
fn get_represented_type_info(&self)
-> ::core::option::Option<&'static bevy_reflect::TypeInfo> {
::core::option::Option::Some(<Self as
bevy_reflect::Typed>::type_info())
}
#[inline]
fn try_apply(&mut self, value: &dyn bevy_reflect::PartialReflect)
-> ::core::result::Result<(), bevy_reflect::ApplyError> {
if let bevy_reflect::ReflectRef::Struct(struct_value) =
bevy_reflect::PartialReflect::reflect_ref(value) {
for (name, value) in
bevy_reflect::structs::Struct::iter_fields(struct_value) {
if let ::core::option::Option::Some(v) =
bevy_reflect::structs::Struct::field_mut(self, name) {
bevy_reflect::PartialReflect::try_apply(v, value)?;
}
}
} else {
return ::core::result::Result::Err(bevy_reflect::ApplyError::MismatchedKinds {
from_kind: bevy_reflect::PartialReflect::reflect_kind(value),
to_kind: bevy_reflect::ReflectKind::Struct,
});
}
::core::result::Result::Ok(())
}
#[inline]
fn reflect_kind(&self) -> bevy_reflect::ReflectKind {
bevy_reflect::ReflectKind::Struct
}
#[inline]
fn reflect_ref(&self) -> bevy_reflect::ReflectRef {
bevy_reflect::ReflectRef::Struct(self)
}
#[inline]
fn reflect_mut(&mut self) -> bevy_reflect::ReflectMut {
bevy_reflect::ReflectMut::Struct(self)
}
#[inline]
fn reflect_owned(self:
bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
-> bevy_reflect::ReflectOwned {
bevy_reflect::ReflectOwned::Struct(self)
}
#[inline]
fn try_into_reflect(self:
bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
->
::core::result::Result<bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect>,
bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::PartialReflect>> {
::core::result::Result::Ok(self)
}
#[inline]
fn try_as_reflect(&self)
-> ::core::option::Option<&dyn bevy_reflect::Reflect> {
::core::option::Option::Some(self)
}
#[inline]
fn try_as_reflect_mut(&mut self)
-> ::core::option::Option<&mut dyn bevy_reflect::Reflect> {
::core::option::Option::Some(self)
}
#[inline]
fn into_partial_reflect(self:
bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
->
bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::PartialReflect> {
self
}
#[inline]
fn as_partial_reflect(&self)
-> &dyn bevy_reflect::PartialReflect {
self
}
#[inline]
fn as_partial_reflect_mut(&mut self)
-> &mut dyn bevy_reflect::PartialReflect {
self
}
fn reflect_partial_eq(&self,
value: &dyn bevy_reflect::PartialReflect)
-> ::core::option::Option<bool> {
(bevy_reflect::structs::struct_partial_eq)(self, value)
}
fn reflect_partial_cmp(&self,
value: &dyn bevy_reflect::PartialReflect)
-> ::core::option::Option<::core::cmp::Ordering> {
(bevy_reflect::structs::struct_partial_cmp)(self, value)
}
fn debug(&self, f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
::core::fmt::Debug::fmt(self, f)
}
#[inline]
fn reflect_clone(&self)
->
::core::result::Result<bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect>,
bevy_reflect::ReflectCloneError> {
::core::result::Result::Ok(bevy_reflect::__macro_exports::alloc_utils::Box::new(::core::clone::Clone::clone(self)))
}
}
impl bevy_reflect::FromReflect for Capsule3dMeshBuilder where {
fn from_reflect(reflect: &dyn bevy_reflect::PartialReflect)
-> ::core::option::Option<Self> {
if let bevy_reflect::ReflectRef::Struct(__ref_struct) =
bevy_reflect::PartialReflect::reflect_ref(reflect) {
let mut __this =
<Self as ::core::default::Default>::default();
if let ::core::option::Option::Some(__field) =
(||
<Capsule3d as
bevy_reflect::FromReflect>::from_reflect(bevy_reflect::structs::Struct::field(__ref_struct,
"capsule")?))() {
__this.capsule = __field;
}
if let ::core::option::Option::Some(__field) =
(||
<u32 as
bevy_reflect::FromReflect>::from_reflect(bevy_reflect::structs::Struct::field(__ref_struct,
"rings")?))() {
__this.rings = __field;
}
if let ::core::option::Option::Some(__field) =
(||
<u32 as
bevy_reflect::FromReflect>::from_reflect(bevy_reflect::structs::Struct::field(__ref_struct,
"longitudes")?))() {
__this.longitudes = __field;
}
if let ::core::option::Option::Some(__field) =
(||
<u32 as
bevy_reflect::FromReflect>::from_reflect(bevy_reflect::structs::Struct::field(__ref_struct,
"latitudes")?))() {
__this.latitudes = __field;
}
if let ::core::option::Option::Some(__field) =
(||
<CapsuleUvProfile as
bevy_reflect::FromReflect>::from_reflect(bevy_reflect::structs::Struct::field(__ref_struct,
"uv_profile")?))() {
__this.uv_profile = __field;
}
::core::option::Option::Some(__this)
} else { ::core::option::Option::None }
}
}
};Reflect)]
22#[reflect(Default, Debug, Clone)]
23pub struct Capsule3dMeshBuilder {
24 pub capsule: Capsule3d,
26 pub rings: u32,
29 pub longitudes: u32,
32 pub latitudes: u32,
35 pub uv_profile: CapsuleUvProfile,
38}
39
40impl Default for Capsule3dMeshBuilder {
41 fn default() -> Self {
42 Self {
43 capsule: Capsule3d::default(),
44 rings: 0,
45 longitudes: 32,
46 latitudes: 16,
47 uv_profile: CapsuleUvProfile::default(),
48 }
49 }
50}
51
52impl Capsule3dMeshBuilder {
53 #[inline]
58 pub fn new(radius: f32, height: f32, longitudes: u32, latitudes: u32) -> Self {
59 Self {
60 capsule: Capsule3d::new(radius, height),
61 longitudes,
62 latitudes,
63 ..Default::default()
64 }
65 }
66
67 #[inline]
69 pub const fn rings(mut self, rings: u32) -> Self {
70 self.rings = rings;
71 self
72 }
73
74 #[inline]
76 pub const fn longitudes(mut self, longitudes: u32) -> Self {
77 self.longitudes = longitudes;
78 self
79 }
80
81 #[inline]
83 pub const fn latitudes(mut self, latitudes: u32) -> Self {
84 self.latitudes = latitudes;
85 self
86 }
87
88 #[inline]
90 pub const fn uv_profile(mut self, uv_profile: CapsuleUvProfile) -> Self {
91 self.uv_profile = uv_profile;
92 self
93 }
94}
95
96impl MeshBuilder for Capsule3dMeshBuilder {
97 fn build(&self) -> Mesh {
98 let Capsule3dMeshBuilder {
100 capsule,
101 rings,
102 longitudes,
103 latitudes,
104 uv_profile,
105 } = *self;
106 let Capsule3d {
107 radius,
108 half_length,
109 } = capsule;
110
111 let calc_middle = rings > 0;
112 let half_lats = latitudes / 2;
113 let half_latsn1 = half_lats - 1;
114 let half_latsn2 = half_lats - 2;
115 let ringsp1 = rings + 1;
116 let lonsp1 = longitudes + 1;
117 let summit = half_length + radius;
118
119 let vert_offset_north_hemi = longitudes;
121 let vert_offset_north_equator = vert_offset_north_hemi + lonsp1 * half_latsn1;
122 let vert_offset_cylinder = vert_offset_north_equator + lonsp1;
123 let vert_offset_south_equator = if calc_middle {
124 vert_offset_cylinder + lonsp1 * rings
125 } else {
126 vert_offset_cylinder
127 };
128 let vert_offset_south_hemi = vert_offset_south_equator + lonsp1;
129 let vert_offset_south_polar = vert_offset_south_hemi + lonsp1 * half_latsn2;
130 let vert_offset_south_cap = vert_offset_south_polar + lonsp1;
131
132 let vert_len = (vert_offset_south_cap + longitudes) as usize;
134
135 let mut vs: Vec<Vec3> = ::alloc::vec::from_elem(Vec3::ZERO, vert_len)vec![Vec3::ZERO; vert_len];
136 let mut vts: Vec<Vec2> = ::alloc::vec::from_elem(Vec2::ZERO, vert_len)vec![Vec2::ZERO; vert_len];
137 let mut vns: Vec<Vec3> = ::alloc::vec::from_elem(Vec3::ZERO, vert_len)vec![Vec3::ZERO; vert_len];
138
139 let to_theta = 2.0 * core::f32::consts::PI / longitudes as f32;
140 let to_phi = core::f32::consts::PI / latitudes as f32;
141 let to_tex_horizontal = 1.0 / longitudes as f32;
142 let to_tex_vertical = 1.0 / half_lats as f32;
143
144 let vt_aspect_ratio = match uv_profile {
145 CapsuleUvProfile::Aspect => radius / (2.0 * half_length + radius + radius),
146 CapsuleUvProfile::Uniform => half_lats as f32 / (ringsp1 + latitudes) as f32,
147 CapsuleUvProfile::Fixed => 1.0 / 3.0,
148 };
149 let vt_aspect_north = 1.0 - vt_aspect_ratio;
150 let vt_aspect_south = vt_aspect_ratio;
151
152 let mut theta_cartesian: Vec<Vec2> = ::alloc::vec::from_elem(Vec2::ZERO, longitudes as usize)vec![Vec2::ZERO; longitudes as usize];
153 let mut rho_theta_cartesian: Vec<Vec2> = ::alloc::vec::from_elem(Vec2::ZERO, longitudes as usize)vec![Vec2::ZERO; longitudes as usize];
154 let mut s_texture_cache: Vec<f32> = ::alloc::vec::from_elem(0.0, lonsp1 as usize)vec![0.0; lonsp1 as usize];
155
156 for j in 0..longitudes as usize {
157 let jf = j as f32;
158 let s_texture_polar = 1.0 - ((jf + 0.5) * to_tex_horizontal);
159 let theta = jf * to_theta;
160
161 theta_cartesian[j] = Vec2::from_angle(theta);
162 rho_theta_cartesian[j] = radius * theta_cartesian[j];
163
164 vs[j] = Vec3::new(0.0, summit, 0.0);
166 vts[j] = Vec2::new(s_texture_polar, 1.0);
167 vns[j] = Vec3::Y;
168
169 let idx = vert_offset_south_cap as usize + j;
171 vs[idx] = Vec3::new(0.0, -summit, 0.0);
172 vts[idx] = Vec2::new(s_texture_polar, 0.0);
173 vns[idx] = Vec3::new(0.0, -1.0, 0.0);
174 }
175
176 for (j, s_texture_cache_j) in s_texture_cache.iter_mut().enumerate().take(lonsp1 as usize) {
178 let s_texture = 1.0 - j as f32 * to_tex_horizontal;
179 *s_texture_cache_j = s_texture;
180
181 let j_mod = j % longitudes as usize;
183 let tc = theta_cartesian[j_mod];
184 let rtc = rho_theta_cartesian[j_mod];
185
186 let idxn = vert_offset_north_equator as usize + j;
188 vs[idxn] = Vec3::new(rtc.x, half_length, -rtc.y);
189 vts[idxn] = Vec2::new(s_texture, vt_aspect_north);
190 vns[idxn] = Vec3::new(tc.x, 0.0, -tc.y);
191
192 let idxs = vert_offset_south_equator as usize + j;
194 vs[idxs] = Vec3::new(rtc.x, -half_length, -rtc.y);
195 vts[idxs] = Vec2::new(s_texture, vt_aspect_south);
196 vns[idxs] = Vec3::new(tc.x, 0.0, -tc.y);
197 }
198
199 for i in 0..half_latsn1 {
201 let ip1f = i as f32 + 1.0;
202 let phi = ip1f * to_phi;
203
204 let (sin_phi_south, cos_phi_south) = ops::sin_cos(phi);
206
207 let cos_phi_north = sin_phi_south;
210 let sin_phi_north = -cos_phi_south;
211
212 let rho_cos_phi_north = radius * cos_phi_north;
213 let rho_sin_phi_north = radius * sin_phi_north;
214 let z_offset_north = half_length - rho_sin_phi_north;
215
216 let rho_cos_phi_south = radius * cos_phi_south;
217 let rho_sin_phi_south = radius * sin_phi_south;
218 let z_offset_sout = -half_length - rho_sin_phi_south;
219
220 let t_tex_fac = ip1f * to_tex_vertical;
222 let cmpl_tex_fac = 1.0 - t_tex_fac;
223 let t_tex_north = cmpl_tex_fac + vt_aspect_north * t_tex_fac;
224 let t_tex_south = cmpl_tex_fac * vt_aspect_south;
225
226 let i_lonsp1 = i * lonsp1;
227 let vert_curr_lat_north = vert_offset_north_hemi + i_lonsp1;
228 let vert_curr_lat_south = vert_offset_south_hemi + i_lonsp1;
229
230 for (j, s_texture) in s_texture_cache.iter().enumerate().take(lonsp1 as usize) {
231 let j_mod = j % longitudes as usize;
232
233 let tc = theta_cartesian[j_mod];
234
235 let idxn = vert_curr_lat_north as usize + j;
237 vs[idxn] = Vec3::new(
238 rho_cos_phi_north * tc.x,
239 z_offset_north,
240 -rho_cos_phi_north * tc.y,
241 );
242 vts[idxn] = Vec2::new(*s_texture, t_tex_north);
243 vns[idxn] = Vec3::new(cos_phi_north * tc.x, -sin_phi_north, -cos_phi_north * tc.y);
244
245 let idxs = vert_curr_lat_south as usize + j;
247 vs[idxs] = Vec3::new(
248 rho_cos_phi_south * tc.x,
249 z_offset_sout,
250 -rho_cos_phi_south * tc.y,
251 );
252 vts[idxs] = Vec2::new(*s_texture, t_tex_south);
253 vns[idxs] = Vec3::new(cos_phi_south * tc.x, -sin_phi_south, -cos_phi_south * tc.y);
254 }
255 }
256
257 if calc_middle {
259 let to_fac = 1.0 / ringsp1 as f32;
262 let mut idx_cyl_lat = vert_offset_cylinder as usize;
263
264 for h in 1..ringsp1 {
265 let fac = h as f32 * to_fac;
266 let cmpl_fac = 1.0 - fac;
267 let t_texture = cmpl_fac * vt_aspect_north + fac * vt_aspect_south;
268 let z = half_length - 2.0 * half_length * fac;
269
270 for (j, s_texture) in s_texture_cache.iter().enumerate().take(lonsp1 as usize) {
271 let j_mod = j % longitudes as usize;
272 let tc = theta_cartesian[j_mod];
273 let rtc = rho_theta_cartesian[j_mod];
274
275 vs[idx_cyl_lat] = Vec3::new(rtc.x, z, -rtc.y);
276 vts[idx_cyl_lat] = Vec2::new(*s_texture, t_texture);
277 vns[idx_cyl_lat] = Vec3::new(tc.x, 0.0, -tc.y);
278
279 idx_cyl_lat += 1;
280 }
281 }
282 }
283
284 let lons3 = longitudes * 3;
289 let lons6 = longitudes * 6;
290 let hemi_lons = half_latsn1 * lons6;
291
292 let tri_offset_north_hemi = lons3;
293 let tri_offset_cylinder = tri_offset_north_hemi + hemi_lons;
294 let tri_offset_south_hemi = tri_offset_cylinder + ringsp1 * lons6;
295 let tri_offset_south_cap = tri_offset_south_hemi + hemi_lons;
296
297 let fs_len = tri_offset_south_cap + lons3;
298 let mut tris: Vec<u32> = ::alloc::vec::from_elem(0, fs_len as usize)vec![0; fs_len as usize];
299
300 let mut i = 0;
302 let mut k = 0;
303 let mut m = tri_offset_south_cap as usize;
304 while i < longitudes {
305 tris[k] = i;
307 tris[k + 1] = vert_offset_north_hemi + i;
308 tris[k + 2] = vert_offset_north_hemi + i + 1;
309
310 tris[m] = vert_offset_south_cap + i;
312 tris[m + 1] = vert_offset_south_polar + i + 1;
313 tris[m + 2] = vert_offset_south_polar + i;
314
315 i += 1;
316 k += 3;
317 m += 3;
318 }
319
320 let mut i = 0;
323 let mut k = tri_offset_north_hemi as usize;
324 let mut m = tri_offset_south_hemi as usize;
325
326 while i < half_latsn1 {
327 let i_lonsp1 = i * lonsp1;
328
329 let vert_curr_lat_north = vert_offset_north_hemi + i_lonsp1;
330 let vert_next_lat_north = vert_curr_lat_north + lonsp1;
331
332 let vert_curr_lat_south = vert_offset_south_equator + i_lonsp1;
333 let vert_next_lat_south = vert_curr_lat_south + lonsp1;
334
335 let mut j = 0;
336 while j < longitudes {
337 let north00 = vert_curr_lat_north + j;
339 let north01 = vert_next_lat_north + j;
340 let north11 = vert_next_lat_north + j + 1;
341 let north10 = vert_curr_lat_north + j + 1;
342
343 tris[k] = north00;
344 tris[k + 1] = north11;
345 tris[k + 2] = north10;
346
347 tris[k + 3] = north00;
348 tris[k + 4] = north01;
349 tris[k + 5] = north11;
350
351 let south00 = vert_curr_lat_south + j;
353 let south01 = vert_next_lat_south + j;
354 let south11 = vert_next_lat_south + j + 1;
355 let south10 = vert_curr_lat_south + j + 1;
356
357 tris[m] = south00;
358 tris[m + 1] = south11;
359 tris[m + 2] = south10;
360
361 tris[m + 3] = south00;
362 tris[m + 4] = south01;
363 tris[m + 5] = south11;
364
365 j += 1;
366 k += 6;
367 m += 6;
368 }
369
370 i += 1;
371 }
372
373 let mut i = 0;
375 let mut k = tri_offset_cylinder as usize;
376
377 while i < ringsp1 {
378 let vert_curr_lat = vert_offset_north_equator + i * lonsp1;
379 let vert_next_lat = vert_curr_lat + lonsp1;
380
381 let mut j = 0;
382 while j < longitudes {
383 let cy00 = vert_curr_lat + j;
384 let cy01 = vert_next_lat + j;
385 let cy11 = vert_next_lat + j + 1;
386 let cy10 = vert_curr_lat + j + 1;
387
388 tris[k] = cy00;
389 tris[k + 1] = cy11;
390 tris[k + 2] = cy10;
391
392 tris[k + 3] = cy00;
393 tris[k + 4] = cy01;
394 tris[k + 5] = cy11;
395
396 j += 1;
397 k += 6;
398 }
399
400 i += 1;
401 }
402
403 let vs: Vec<[f32; 3]> = vs.into_iter().map(Into::into).collect();
404 let vns: Vec<[f32; 3]> = vns.into_iter().map(Into::into).collect();
405 let vts: Vec<[f32; 2]> = vts.into_iter().map(Into::into).collect();
406
407 match (&vs.len(), &vert_len) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(vs.len(), vert_len);
408 match (&tris.len(), &(fs_len as usize)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(tris.len(), fs_len as usize);
409
410 Mesh::new(
411 PrimitiveTopology::TriangleList,
412 RenderAssetUsages::default(),
413 )
414 .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, vs)
415 .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, vns)
416 .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, vts)
417 .with_inserted_indices(Indices::U32(tris))
418 }
419}
420
421impl Meshable for Capsule3d {
422 type Output = Capsule3dMeshBuilder;
423
424 fn mesh(&self) -> Self::Output {
425 Capsule3dMeshBuilder {
426 capsule: *self,
427 ..Default::default()
428 }
429 }
430}
431
432impl From<Capsule3d> for Mesh {
433 fn from(capsule: Capsule3d) -> Self {
434 capsule.mesh().build()
435 }
436}