Skip to main content

alice_sdf/types/
transforms.rs

1//! Spatial transform methods for SdfNode
2//!
3//! Author: Moroya Sakamoto
4
5use glam::{Quat, Vec3};
6use std::sync::Arc;
7
8use super::SdfNode;
9
10impl SdfNode {
11    // === Transform methods ===
12
13    /// Translate by offset
14    #[must_use]
15    #[inline]
16    pub fn translate(self, x: f32, y: f32, z: f32) -> Self {
17        Self::Translate {
18            child: Arc::new(self),
19            offset: Vec3::new(x, y, z),
20        }
21    }
22
23    /// Translate by vector
24    #[must_use]
25    #[inline]
26    pub fn translate_vec(self, offset: Vec3) -> Self {
27        Self::Translate {
28            child: Arc::new(self),
29            offset,
30        }
31    }
32
33    /// Rotate by quaternion
34    #[must_use]
35    #[inline]
36    pub fn rotate(self, rotation: Quat) -> Self {
37        Self::Rotate {
38            child: Arc::new(self),
39            rotation,
40        }
41    }
42
43    /// Rotate by Euler angles (radians)
44    #[must_use]
45    #[inline]
46    pub fn rotate_euler(self, x: f32, y: f32, z: f32) -> Self {
47        Self::Rotate {
48            child: Arc::new(self),
49            rotation: Quat::from_euler(glam::EulerRot::XYZ, x, y, z),
50        }
51    }
52
53    /// Uniform scale
54    #[must_use]
55    #[inline]
56    pub fn scale(self, factor: f32) -> Self {
57        Self::Scale {
58            child: Arc::new(self),
59            factor,
60        }
61    }
62
63    /// Non-uniform scale
64    #[must_use]
65    #[inline]
66    pub fn scale_xyz(self, x: f32, y: f32, z: f32) -> Self {
67        Self::ScaleNonUniform {
68            child: Arc::new(self),
69            factors: Vec3::new(x, y, z),
70        }
71    }
72
73    /// Projective (perspective) transform
74    #[must_use]
75    #[inline]
76    pub fn projective_transform(self, inv_matrix: [f32; 16], lipschitz_bound: f32) -> Self {
77        Self::ProjectiveTransform {
78            child: Arc::new(self),
79            inv_matrix,
80            lipschitz_bound,
81        }
82    }
83
84    /// Lattice deformation (Free-Form Deformation)
85    #[must_use]
86    #[inline]
87    pub fn lattice_deform(
88        self,
89        control_points: Vec<Vec3>,
90        nx: u32,
91        ny: u32,
92        nz: u32,
93        bbox_min: Vec3,
94        bbox_max: Vec3,
95    ) -> Self {
96        Self::LatticeDeform {
97            child: Arc::new(self),
98            control_points,
99            nx,
100            ny,
101            nz,
102            bbox_min,
103            bbox_max,
104        }
105    }
106
107    /// SDF skinning (bone-weight based deformation)
108    #[must_use]
109    #[inline]
110    pub fn sdf_skinning(self, bones: Vec<crate::transforms::skinning::BoneTransform>) -> Self {
111        Self::SdfSkinning {
112            child: Arc::new(self),
113            bones,
114        }
115    }
116}