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
impl Transform
Sourcepub fn from_rows(rows: [[f64; 4]; 4]) -> Result<Self, DecodeError>
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.
Sourcepub fn from_translation(t: Vec3) -> Self
pub fn from_translation(t: Vec3) -> Self
A pure translation.
Sourcepub fn from_attribute(value: &Value) -> Result<Self, DecodeError>
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]);Sourcepub fn from_matrix_json(value: &Value) -> Result<Self, DecodeError>
pub fn from_matrix_json(value: &Value) -> Result<Self, DecodeError>
Decodes the matrix itself: four arrays of four numbers, rows first.
Sourcepub fn rows(&self) -> &[[f64; 4]; 4]
pub fn rows(&self) -> &[[f64; 4]; 4]
The rows in the file’s layout; the translation is rows()[3].
Sourcepub fn translation(&self) -> Vec3
pub fn translation(&self) -> Vec3
The translation part.
Sourcepub fn to_column_major(&self) -> [f64; 16]
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.
Sourcepub fn then(&self, outer: &Transform) -> Transform
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).
Sourcepub fn transform_point(&self, p: Vec3) -> Vec3
pub fn transform_point(&self, p: Vec3) -> Vec3
Maps a point, including the translation.
Sourcepub fn transform_vector(&self, v: Vec3) -> Vec3
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.
Sourcepub fn determinant(&self) -> f64
pub fn determinant(&self) -> f64
Determinant of the 3×3 linear part. A negative value means the transform mirrors, which reverses triangle winding.