Transform3D
Basis and translation for local/world conversion.
transform × point includes Basis and Origin; Basis × direction adds no translation. parent × child applies child first. For an Entity3D with an Entity3D parent and TopLevel = false, the world transform normally equals parent.GlobalTransform × Transform. TopLevel disables inheritance. Recalculation with SetDisableScale(true) orthonormalizes the world Basis; the flag alone does not update an already cached transform.
Inverse and point × transform require an orthonormal basis; scale needs AffineInverse with nonzero determinant. Rotated also rotates Origin around the external origin; RotatedLocal preserves Origin. Transform interpolation is not collision-aware physics movement.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors4
Transform3D4 overloads
public Transform3D(Basis basis, Vector3 origin);Constructs a Transform3D from four Vector3 values (also called matrix columns).
The first three arguments are the Transform3D.Basis's axes (Basis.X, Basis.Y, and Basis.Z).
| Name | Type | Default |
|---|---|---|
basis | Basis | — |
origin | Vector3 | — |
basisThe Basis to create the basis from.
originThe origin vector, or column index 3.
public Transform3D(Projection projection);Constructs a Transform3D from four Vector3 values (also called matrix columns).
The first three arguments are the Transform3D.Basis's axes (Basis.X, Basis.Y, and Basis.Z).
| Name | Type | Default |
|---|---|---|
projection | Projection | — |
projectionThe Projection to create the transform from.
public Transform3D(Vector3 column0, Vector3 column1, Vector3 column2, Vector3 origin);Constructs a Transform3D from four Vector3 values (also called matrix columns).
The first three arguments are the Transform3D.Basis's axes (Basis.X, Basis.Y, and Basis.Z).
| Name | Type | Default |
|---|---|---|
column0 | Vector3 | — |
column1 | Vector3 | — |
column2 | Vector3 | — |
origin | Vector3 | — |
column0The X vector, or column index 0.
column1The Y vector, or column index 1.
column2The Z vector, or column index 2.
originThe origin vector, or column index 3.
public Transform3D(float xx, float yx, float zx, float xy, float yy, float zy, float xz, float yz, float zz, float ox, float oy, float oz);Constructs a Transform3D from four Vector3 values (also called matrix columns).
The first three arguments are the Transform3D.Basis's axes (Basis.X, Basis.Y, and Basis.Z).
| Name | Type | Default |
|---|---|---|
xx | float | — |
yx | float | — |
zx | float | — |
xy | float | — |
yy | float | — |
zy | float | — |
xz | float | — |
yz | float | — |
zz | float | — |
ox | float | — |
oy | float | — |
oz | float | — |
xxThe X component of the X column vector, accessed via t.Basis.X.X or [0][0].
yxThe X component of the Y column vector, accessed via t.Basis.Y.X or [1][0].
zxThe X component of the Z column vector, accessed via t.Basis.Z.X or [2][0].
xyThe Y component of the X column vector, accessed via t.Basis.X.Y or [0][1].
yyThe Y component of the Y column vector, accessed via t.Basis.Y.Y or [1][1].
zyThe Y component of the Z column vector, accessed via t.Basis.Y.Y or [2][1].
xzThe Z component of the X column vector, accessed via t.Basis.X.Y or [0][2].
yzThe Z component of the Y column vector, accessed via t.Basis.Y.Y or [1][2].
zzThe Z component of the Z column vector, accessed via t.Basis.Y.Y or [2][2].
oxThe X component of the origin vector, accessed via t.Origin.X or [2][0].
oyThe Y component of the origin vector, accessed via t.Origin.Y or [2][1].
ozThe Z component of the origin vector, accessed via t.Origin.Z or [2][2].
Properties6
FlipXProperty
public static Transform3D FlipX { get; }Transform3D with mirroring applied perpendicular to the YZ plane. Its Transform3D.Basis is equal to Basis.FlipX.
FlipYProperty
public static Transform3D FlipY { get; }Transform3D with mirroring applied perpendicular to the XZ plane. Its Transform3D.Basis is equal to Basis.FlipY.
FlipZProperty
public static Transform3D FlipZ { get; }Transform3D with mirroring applied perpendicular to the XY plane. Its Transform3D.Basis is equal to Basis.FlipZ.
IdentityProperty
public static Transform3D Identity { get; }The identity Transform3D. This is a transform with no translation, no rotation, and a scale of Vector3.One. Its Transform3D.Basis is equal to Basis.Identity. This also means that:
- Its
Basis.Xpoints right (Vector3.Right); - Its
Basis.Ypoints up (Vector3.Up); - Its
Basis.Zpoints back (Vector3.Back).
If a Vector3, an Aabb, a Plane, a Vector3[], or another Transform3D is transformed (multiplied) by this constant, no transformation occurs.
Note: In C#, this constant is equivalent to creating a [constructor Transform3D] without any arguments. It can be used to make your code clearer, and for consistency with C#.
Item2 overloads
public Vector3 this[int column] { get; set; }Access whole columns in the form of Vector3.
The fourth column is the Transform3D.Origin vector.
public float this[int column, int row] { get; set; }Access matrix elements in column-major order.
The fourth column is the Transform3D.Origin vector.
Methods30
AffineInverseTransform3D
public Transform3D AffineInverse();Inverts Basis and translation, including scale. An exactly zero Basis determinant throws InvalidOperationException. Transform a surface normal with inverse-transposed Basis, without translation.
Transform3DThe inverse value. An exactly zero determinant throws InvalidOperationException instead of returning a result.
Equals2 overloads
public bool Equals(Transform3D other);Returns true if the transforms are exactly equal.
Note: Due to floating-point precision errors, consider using
Transform3D.IsEqualApprox instead, which is more reliable.
| Name | Type | Default |
|---|---|---|
other | Transform3D | — |
otherThe other transform to compare.
boolWhether or not the matrices are exactly equal.
public override bool Equals(object? obj);Returns true if the transform is exactly equal
to the given object (obj).
Note: Due to floating-point precision errors, consider using
Transform3D.IsEqualApprox instead, which is more reliable.
| Name | Type | Default |
|---|---|---|
obj | object | — |
objThe object to compare with.
boolWhether or not the transform and the object are exactly equal.
GetHashCodeint
public override int GetHashCode();Serves as the hash function for Transform3D.
intA hash code for this transform.
InterpolateWithTransform3D
public Transform3D InterpolateWith(Transform3D transform, float weight);Returns the result of the linear interpolation between this transform and xform by the given weight.
The weight should be between 0.0 and 1.0 (inclusive). Values outside this range are allowed and can be used to perform extrapolation instead.
| Name | Type | Default |
|---|---|---|
transform | Transform3D | — |
weight | float | — |
transformThe other transform.
weightA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Transform3DThe interpolated transform.
InverseTransform3D
public Transform3D Inverse();Uses a transposed Basis and assumes orthonormality. Does not replace AffineInverse under nonuniform scale.
Transform3DThe inverse matrix.
IsEqualApproxbool
public bool IsEqualApprox(Transform3D other);Returns true if this transform and xform are approximately equal, by running @GlobalScope.is_equal_approx on each component.
| Name | Type | Default |
|---|---|---|
other | Transform3D | — |
otherThe other transform to compare.
boolWhether or not the matrices are approximately equal.
IsFinitebool
public bool IsFinite();Returns true if this transform is finite, by calling @GlobalScope.is_finite on each component.
boolWhether this vector is finite or not.
LookingAt2 overloads
public Transform3D LookingAt(Vector3 target, Vector3 up);Returns a copy of this transform rotated so that the forward axis (-Z) points towards the target position.
The up axis (+Y) points as close to the up vector as possible while staying perpendicular to the forward axis. The resulting transform is orthonormalized. The existing rotation, scale, and skew information from the original transform is discarded. The target and up vectors cannot be zero, cannot be parallel to each other, and are defined in global/parent space.
If use_model_front is true, the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the target position. By default, the -Z axis (camera forward) is treated as forward (implies +X is right).
| Name | Type | Default |
|---|---|---|
target | Vector3 | — |
up | Vector3 | — |
Transform3Dpublic Transform3D LookingAt(Vector3 target, Vector3? up = default, bool useModelFront = false);Returns a copy of this transform rotated so that the forward axis (-Z) points towards the target position.
The up axis (+Y) points as close to the up vector as possible while staying perpendicular to the forward axis. The resulting transform is orthonormalized. The existing rotation, scale, and skew information from the original transform is discarded. The target and up vectors cannot be zero, cannot be parallel to each other, and are defined in global/parent space.
If use_model_front is true, the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the target position. By default, the -Z axis (camera forward) is treated as forward (implies +X is right).
| Name | Type | Default |
|---|---|---|
target | Vector3 | — |
up | Vector3? | default |
useModelFront | bool | false |
targetThe object to look at.
upThe relative up direction.
useModelFrontIf true, then the model is oriented in reverse, towards the model front axis (+Z, Vector3.ModelFront), which is more useful for orienting 3D models.
Transform3DThe resulting transform.
OrthonormalizedTransform3D
public Transform3D Orthonormalized();Returns a copy of this transform with its Transform3D.Basis orthonormalized. An orthonormal basis is both orthogonal (the axes are perpendicular to each other) and normalized (the axes have a length of 1.0), which also means it can only represent a rotation. See also Basis.Orthonormalized.
Transform3DThe orthonormalized transform.
RotatedTransform3D
public Transform3D Rotated(Vector3 axis, float angle);Rotates in external space, including Origin around the external origin. axis must have unit length; angle is in radians. Returns a copy without modifying the original value.
| Name | Type | Default |
|---|---|---|
axis | Vector3 | — |
angle | float | — |
axisUnit axis in external space.
angleAngle in radians; convert degrees with Mathf.DegToRad.
Transform3DA copy with a new Basis and rotated Origin.
RotatedLocalTransform3D
public Transform3D RotatedLocal(Vector3 axis, float angle);Rotates in the local basis and preserves Origin. axis must have unit length; angle is in radians. Returns a copy without modifying the original value.
| Name | Type | Default |
|---|---|---|
axis | Vector3 | — |
angle | float | — |
axisUnit axis in local space.
angleAngle in radians; convert degrees with Mathf.DegToRad.
Transform3DA copy with a new Basis and unchanged Origin.
ScaledTransform3D
public Transform3D Scaled(Vector3 scale);Returns a copy of this transform scaled by the given scale factor.
This method is an optimized version of multiplying the given transform X with a corresponding scaling transform S from the left, i.e., S * X.
This can be seen as transforming with respect to the global/parent frame.
| Name | Type | Default |
|---|---|---|
scale | Vector3 | — |
scaleThe scale to introduce.
Transform3DThe scaled transformation matrix.
ScaledLocalTransform3D
public Transform3D ScaledLocal(Vector3 scale);Returns a copy of this transform scaled by the given scale factor.
This method is an optimized version of multiplying the given transform X with a corresponding scaling transform S from the right, i.e., X * S.
This can be seen as transforming with respect to the local frame.
| Name | Type | Default |
|---|---|---|
scale | Vector3 | — |
scaleThe scale to introduce.
Transform3DThe scaled transformation matrix.
ToString2 overloads
public override string ToString();Converts this Transform3D to a string.
stringA string representation of this transform.
public string ToString(string? format);Converts this Transform3D to a string with the given format.
| Name | Type | Default |
|---|---|---|
format | string | — |
stringA string representation of this transform.
TranslatedTransform3D
public Transform3D Translated(Vector3 offset);Returns a copy of this transform translated by the given offset.
This method is an optimized version of multiplying the given transform X with a corresponding translation transform T from the left, i.e., T * X.
This can be seen as transforming with respect to the global/parent frame.
| Name | Type | Default |
|---|---|---|
offset | Vector3 | — |
offsetThe offset to translate by.
Transform3DThe translated matrix.
TranslatedLocalTransform3D
public Transform3D TranslatedLocal(Vector3 offset);Returns a copy of this transform translated by the given offset.
This method is an optimized version of multiplying the given transform X with a corresponding translation transform T from the right, i.e., X * T.
This can be seen as transforming with respect to the local frame.
| Name | Type | Default |
|---|---|---|
offset | Vector3 | — |
offsetThe offset to translate by.
Transform3DThe translated matrix.
op_Equalitybool
public static bool operator ==(Transform3D left, Transform3D right);Returns true if the transforms are exactly equal.
Note: Due to floating-point precision errors, consider using
Transform3D.IsEqualApprox instead, which is more reliable.
| Name | Type | Default |
|---|---|---|
left | Transform3D | — |
right | Transform3D | — |
leftThe left transform.
rightThe right transform.
boolWhether or not the transforms are exactly equal.
op_Inequalitybool
public static bool operator !=(Transform3D left, Transform3D right);Returns true if the transforms are not equal.
Note: Due to floating-point precision errors, consider using
Transform3D.IsEqualApprox instead, which is more reliable.
| Name | Type | Default |
|---|---|---|
left | Transform3D | — |
right | Transform3D | — |
leftThe left transform.
rightThe right transform.
boolWhether or not the transforms are not equal.
op_Multiply9 overloads
public static Aabb operator *(Aabb aabb, Transform3D transform);Returns an AABB transformed (multiplied) by the inverse transformation matrix,
under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection
is fine, scaling/skew is not).
aabb * transform is equivalent to transform.Inverse() * aabb. See Transform3D.Inverse.
For transforming by inverse of an affine transformation (e.g. with scaling) transform.AffineInverse() * aabb can be used instead. See Transform3D.AffineInverse.
| Name | Type | Default |
|---|---|---|
aabb | Aabb | — |
transform | Transform3D | — |
aabbAn AABB to inversely transform.
transformThe transformation to apply.
AabbThe inversely transformed AABB.
public static Plane operator *(Plane plane, Transform3D transform);Returns a Plane transformed (multiplied) by the inverse transformation matrix.
plane * transform is equivalent to transform.AffineInverse() * plane. See Transform3D.AffineInverse.
| Name | Type | Default |
|---|---|---|
plane | Plane | — |
transform | Transform3D | — |
planeA Plane to inversely transform.
transformThe transformation to apply.
PlaneThe inversely transformed Plane.
public static Aabb operator *(Transform3D transform, Aabb aabb);Returns an AABB transformed (multiplied) by the transformation matrix.
| Name | Type | Default |
|---|---|---|
transform | Transform3D | — |
aabb | Aabb | — |
transformThe transformation to apply.
aabbAn AABB to transform.
AabbThe transformed AABB.
public static Plane operator *(Transform3D transform, Plane plane);Returns a Plane transformed (multiplied) by the transformation matrix.
| Name | Type | Default |
|---|---|---|
transform | Transform3D | — |
plane | Plane | — |
transformThe transformation to apply.
planeA Plane to transform.
PlaneThe transformed Plane.
public static Transform3D operator *(Transform3D left, Transform3D right);Composes these two transformation matrices by multiplying them together. This has the effect of transforming the second transform (the child) by the first transform (the parent).
| Name | Type | Default |
|---|---|---|
left | Transform3D | — |
right | Transform3D | — |
leftThe parent transform.
rightThe child transform.
Transform3DThe composed transform.
public static Vector3 operator *(Transform3D transform, Vector3 vector);Returns a Vector3 transformed (multiplied) by the transformation matrix.
| Name | Type | Default |
|---|---|---|
transform | Transform3D | — |
vector | Vector3 | — |
transformThe transformation to apply.
vectorA Vector3 to transform.
Vector3The transformed Vector3.
public static Vector3[] operator *(Transform3D transform, Vector3[] array);Returns a copy of the given Vector3[] transformed (multiplied) by the transformation matrix.
| Name | Type | Default |
|---|---|---|
transform | Transform3D | — |
array | Vector3[] | — |
transformThe transformation to apply.
arrayA Vector3[] to transform.
Vector3[]The transformed copy of the Vector3[].
public static Vector3 operator *(Vector3 vector, Transform3D transform);Returns a Vector3 transformed (multiplied) by the inverse transformation matrix,
under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection
is fine, scaling/skew is not).
vector * transform is equivalent to transform.Inverse() * vector. See Transform3D.Inverse.
For transforming by inverse of an affine transformation (e.g. with scaling) transform.AffineInverse() * vector can be used instead. See Transform3D.AffineInverse.
| Name | Type | Default |
|---|---|---|
vector | Vector3 | — |
transform | Transform3D | — |
vectorA Vector3 to inversely transform.
transformThe transformation to apply.
Vector3The inversely transformed Vector3.
public static Vector3[] operator *(Vector3[] array, Transform3D transform);Returns a copy of the given Vector3[] transformed (multiplied) by the inverse transformation matrix,
under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection
is fine, scaling/skew is not).
array * transform is equivalent to transform.Inverse() * array. See Transform3D.Inverse.
For transforming by inverse of an affine transformation (e.g. with scaling) transform.AffineInverse() * array can be used instead. See Transform3D.AffineInverse.
| Name | Type | Default |
|---|---|---|
array | Vector3[] | — |
transform | Transform3D | — |
arrayA Vector3[] to inversely transform.
transformThe transformation to apply.
Vector3[]The inversely transformed copy of the Vector3[].
Fields and constants2
BasisField
OriginField
public Vector3 Origin;The translation offset of this transform. In 3D space, this can be seen as the position.