pub struct TextureTransform {
pub offset: [f32; 2],
pub rotation: f32,
pub scale: [f32; 2],
pub uv_set: Option<u32>,
}Expand description
Typed per-texture-reference UV transform, aligned with the
ratified KHR_texture_transform extension.
The transform maps a primitive’s stored UV coordinates into the
coordinates actually sampled — the standard mechanism for texture
atlasing (offset + scale select an atlas region) and for axis
flips (scale: [1.0, -1.0] with offset: [0.0, 1.0] inverts the
T axis for a bottom-left-origin source). The applied mapping is
the affine composition translation · rotation · scale on
homogeneous UV coordinates:
uv' = T(offset) · R(rotation) · S(scale) · [u, v, 1]ᵀi.e. scale first, then rotate counter-clockwise about the UV
origin, then offset. Per the extension, the result is generally
only meaningful when the sampler wraps with
WrapMode::Repeat or when the
transformed coordinates stay inside [0, 1]. Remember the UV
origin (0, 0) is the top-left corner of the image, so a
counter-clockwise UV rotation reads as a clockwise image rotation.
All fields default to the extension’s normative defaults (zero
offset, zero rotation, unit scale, no texCoord override), so
TextureTransform::default() is the identity mapping.
Fields§
§offset: [f32; 2]Offset of the UV origin as a factor of the texture dimensions
(offset). Default [0.0, 0.0].
rotation: f32Rotation applied to the UVs, in radians counter-clockwise
around the origin (rotation). Default 0.0.
scale: [f32; 2]Scale factor applied to the UV components (scale). Default
[1.0, 1.0]. Negative components are legal and mirror the
respective axis.
uv_set: Option<u32>UV-set override (texCoord): when Some, replaces the
TextureRef::uv_set of the reference carrying this
transform. None (the default) keeps the reference’s own set.
Implementations§
Source§impl TextureTransform
impl TextureTransform
Sourcepub fn with_offset(self, offset: [f32; 2]) -> Self
pub fn with_offset(self, offset: [f32; 2]) -> Self
Builder-style offset setter.
Sourcepub fn with_rotation(self, rotation: f32) -> Self
pub fn with_rotation(self, rotation: f32) -> Self
Builder-style rotation setter (radians counter-clockwise).
Sourcepub fn with_scale(self, scale: [f32; 2]) -> Self
pub fn with_scale(self, scale: [f32; 2]) -> Self
Builder-style scale setter.
Sourcepub fn with_uv_set(self, uv_set: u32) -> Self
pub fn with_uv_set(self, uv_set: u32) -> Self
Builder-style UV-set (texCoord) override setter.
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
true when this transform is a complete no-op: the affine
part is the identity and there is no UV-set override
(a transform that only re-targets texCoord still changes
sampling, so it is not an identity).
Sourcepub fn is_finite(&self) -> bool
pub fn is_finite(&self) -> bool
true when every affine component (offset, rotation, scale)
is finite. A non-finite component would poison every
transformed coordinate;
Scene3D::validate reports it.
Sourcepub fn to_matrix(&self) -> [[f32; 3]; 3]
pub fn to_matrix(&self) -> [[f32; 3]; 3]
The transform as a row-major 3×3 homogeneous matrix acting on
column vectors [u, v, 1]ᵀ — the product
T(offset) · R(rotation) · S(scale):
⎡ cos·sx −sin·sy ox ⎤
⎢ sin·sx cos·sy oy ⎥
⎣ 0 0 1 ⎦Same row-major column-vector convention as the crate’s 4×4 node matrices.
Sourcepub fn apply(&self, uv: [f32; 2]) -> [f32; 2]
pub fn apply(&self, uv: [f32; 2]) -> [f32; 2]
Apply the transform to one UV coordinate: scale, then rotate
counter-clockwise about the origin, then offset — exactly
to_matrix times [u, v, 1]ᵀ.
Sourcepub fn apply_channel(&self, uvs: &[[f32; 2]]) -> Vec<[f32; 2]>
pub fn apply_channel(&self, uvs: &[[f32; 2]]) -> Vec<[f32; 2]>
Apply the transform to a whole UV channel — the baking helper
for exporters targeting a format without per-reference UV
transforms: replace the primitive’s channel with the baked
coordinates (and drop the transform, e.g. via
Material::map_texture_refs). Pure; the input is untouched.
Trait Implementations§
Source§impl Clone for TextureTransform
impl Clone for TextureTransform
Source§fn clone(&self) -> TextureTransform
fn clone(&self) -> TextureTransform
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more