use super::Axis;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, Default)]
pub struct BlockTransform {
pub x: i32,
pub y: i32,
pub uvlock: bool,
}
impl BlockTransform {
pub fn new(x: i32, y: i32, uvlock: bool) -> Self {
Self { x, y, uvlock }
}
pub fn is_identity(&self) -> bool {
self.x == 0 && self.y == 0
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ElementRotation {
#[serde(default = "default_origin")]
pub origin: [f32; 3],
pub axis: Axis,
pub angle: f32,
#[serde(default)]
pub rescale: bool,
}
fn default_origin() -> [f32; 3] {
[8.0, 8.0, 8.0]
}
impl ElementRotation {
pub fn normalized_origin(&self) -> [f32; 3] {
[
self.origin[0] / 16.0 - 0.5,
self.origin[1] / 16.0 - 0.5,
self.origin[2] / 16.0 - 0.5,
]
}
pub fn angle_radians(&self) -> f32 {
self.angle.to_radians()
}
pub fn rescale_factor(&self) -> f32 {
if self.rescale {
1.0 / self.angle_radians().cos()
} else {
1.0
}
}
}