use bevy::{
math::Vec3,
prelude::{Entity, GlobalTransform},
reflect::Reflect,
};
#[derive(Debug, Copy, Clone, Default, Reflect)]
#[must_use]
pub struct VertexAnchor {
pub custom_target: Option<Entity>,
pub custom_offset: Option<Vec3>,
pub ignore_vertex_position: bool,
}
impl VertexAnchor {
#[must_use]
pub fn get_position<'a>(
&self,
original_pos: Vec3,
self_transform: &GlobalTransform,
query: &impl Fn(Entity) -> Option<&'a GlobalTransform>,
) -> Vec3 {
let transform = self.custom_target.and_then(query).unwrap_or(self_transform);
let local_pos = if self.ignore_vertex_position {
Vec3::ZERO
} else {
original_pos
} + self.custom_offset.unwrap_or(Vec3::ZERO);
transform.transform_point(local_pos)
}
}