schematic_mesher/types/
transform.rs1use super::Axis;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Copy, Default)]
8pub struct BlockTransform {
9 pub x: i32,
11 pub y: i32,
13 pub uvlock: bool,
15}
16
17impl BlockTransform {
18 pub fn new(x: i32, y: i32, uvlock: bool) -> Self {
19 Self { x, y, uvlock }
20 }
21
22 pub fn is_identity(&self) -> bool {
24 self.x == 0 && self.y == 0
25 }
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct ElementRotation {
31 #[serde(default = "default_origin")]
33 pub origin: [f32; 3],
34 pub axis: Axis,
36 pub angle: f32,
38 #[serde(default)]
40 pub rescale: bool,
41}
42
43fn default_origin() -> [f32; 3] {
44 [8.0, 8.0, 8.0]
45}
46
47impl ElementRotation {
48 pub fn normalized_origin(&self) -> [f32; 3] {
50 [
51 self.origin[0] / 16.0 - 0.5,
52 self.origin[1] / 16.0 - 0.5,
53 self.origin[2] / 16.0 - 0.5,
54 ]
55 }
56
57 pub fn angle_radians(&self) -> f32 {
59 self.angle.to_radians()
60 }
61
62 pub fn rescale_factor(&self) -> f32 {
65 if self.rescale {
66 1.0 / self.angle_radians().cos()
67 } else {
68 1.0
69 }
70 }
71}