Struct Transform

Source
pub struct Transform { /* private fields */ }
Expand description

An affine 4×4 transform in USD’s row-vector layout.

Values are f64 so that georeferenced translations keep millimetre precision. The last column is always (0, 0, 0, 1).

Implementations§

Source§

impl Transform

Source

pub const IDENTITY: Self

The transform that leaves every point where it is.

Source

pub fn from_rows(rows: [[f64; 4]; 4]) -> Result<Self, DecodeError>

Builds a transform from rows in the file’s layout (translation in the last row). Fails if the last column is not (0, 0, 0, 1) or a value is not finite.

Source

pub fn from_translation(t: Vec3) -> Self

A pure translation.

Source

pub fn from_attribute(value: &Value) -> Result<Self, DecodeError>

Decodes the value of a ATTRIBUTE (usd::xformop) attribute, an object whose transform field holds the matrix.

use openbim_ifcx_geometry::transform::Transform;

let value = serde_json::json!({"transform": [
    [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [5, 0, 2, 1]
]});
let t = Transform::from_attribute(&value)?;
assert_eq!(t.translation(), [5.0, 0.0, 2.0]);
assert_eq!(t.transform_point([1.0, 1.0, 1.0]), [6.0, 1.0, 3.0]);
Source

pub fn from_matrix_json(value: &Value) -> Result<Self, DecodeError>

Decodes the matrix itself: four arrays of four numbers, rows first.

Source

pub fn rows(&self) -> &[[f64; 4]; 4]

The rows in the file’s layout; the translation is rows()[3].

Source

pub fn translation(&self) -> Vec3

The translation part.

Source

pub fn to_column_major(&self) -> [f64; 16]

The 16 values in column-major order of the equivalent column-vector matrix: the layout of glTF node.matrix and three.js Matrix4.elements. This equals the file’s rows flattened in order.

Source

pub fn then(&self, outer: &Transform) -> Transform

The transform that applies self first and then outer; in the row-vector layout this is the product self · outer.

For a node with local transform local under a parent with world transform parent, the node’s world transform is local.then(&parent).

Source

pub fn transform_point(&self, p: Vec3) -> Vec3

Maps a point, including the translation.

Source

pub fn transform_vector(&self, v: Vec3) -> Vec3

Maps a direction, ignoring the translation. Normals need the inverse transpose instead when the transform scales unevenly.

Source

pub fn determinant(&self) -> f64

Determinant of the 3×3 linear part. A negative value means the transform mirrors, which reverses triangle winding.

Trait Implementations§

Source§

impl Clone for Transform

Source§

fn clone(&self) -> Transform

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Transform

Source§

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

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

impl Default for Transform

Source§

fn default() -> Self

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

impl PartialEq for Transform

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Transform

Source§

impl StructuralPartialEq for Transform

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> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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.