Skip to main content

TextureTransform

Struct TextureTransform 

Source
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: f32

Rotation 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

Source

pub const IDENTITY: Self

The identity transform — every field at its normative default.

Source

pub fn new() -> Self

Construct the identity transform (same as default()).

Source

pub fn with_offset(self, offset: [f32; 2]) -> Self

Builder-style offset setter.

Source

pub fn with_rotation(self, rotation: f32) -> Self

Builder-style rotation setter (radians counter-clockwise).

Source

pub fn with_scale(self, scale: [f32; 2]) -> Self

Builder-style scale setter.

Source

pub fn with_uv_set(self, uv_set: u32) -> Self

Builder-style UV-set (texCoord) override setter.

Source

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).

Source

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.

Source

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.

Source

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]ᵀ.

Source

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

Source§

fn clone(&self) -> TextureTransform

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for TextureTransform

Source§

impl Debug for TextureTransform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TextureTransform

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for TextureTransform

Source§

fn eq(&self, other: &TextureTransform) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TextureTransform

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.