Class reference

Transform3D

A 3×4 matrix representing a 3D transformation.

Description

The Transform3D built-in Variant type is a 3×4 matrix representing a transformation in 3D space. It contains a Basis, which on its own can represent rotation, scale, and shear. Additionally, combined with its own origin, the transform can also represent a translation. For a general introduction, see the Matrices and transforms tutorial. Note: Redot uses a right-handed coordinate system, which is a common standard. For directions, the convention for built-in types like Camera3D is for -Z to point forward (+X is right, +Y is up, and +Z is back). Other objects may use different direction conventions. For more information, see the 3D asset direction conventions tutorial.

Properties

Basis basis = Basis(1, 0, 0, 0, 1, 0, 0, 0, 1)

The Basis of this transform. It is composed by 3 axes (Basis.x, Basis.y, and Basis.z). Together, these represent the transform's rotation, scale, and shear.

Vector3 origin = Vector3(0, 0, 0)

The translation offset of this transform. In 3D space, this can be seen as the position.

Constructors

Methods

Transform3D affine_inverse() const

Returns the inverted version of this transform. Unlike inverse(), this method works with almost any basis, including non-uniform ones, but is slower. See also Basis.inverse(). Note: For this method to return correctly, the transform's basis needs to have a determinant that is not exactly 0.0 (see Basis.determinant()).

Transform3D interpolate_with(Transform3D xform, float weight) const

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.

Transform3D looking_at(Vector3 target, Vector3 up = Vector3(0, 1, 0), bool use_model_front = false) const

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

Transform3D orthonormalized() const

Returns a copy of this transform with its 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().

Transform3D rotated(Vector3 axis, float angle) const

Returns a copy of this transform rotated around the given axis by the given angle (in radians). The axis must be a normalized vector (see Vector3.normalized()). If angle is positive, the basis is rotated counter-clockwise around the axis. This method is an optimized version of multiplying the given transform X with a corresponding rotation transform R from the left, i.e., R * X. This can be seen as transforming with respect to the global/parent frame.

Transform3D rotated_local(Vector3 axis, float angle) const

Returns a copy of this transform rotated around the given axis by the given angle (in radians). The axis must be a normalized vector in the transform's local coordinate system. For example, to rotate around the local X-axis, use Vector3.RIGHT. This method is an optimized version of multiplying the given transform X with a corresponding rotation transform R from the right, i.e., X * R. This can be seen as transforming with respect to the local frame.

Transform3D scaled(Vector3 scale) const

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.

Transform3D scaled_local(Vector3 scale) const

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.

Transform3D translated(Vector3 offset) const

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.

Transform3D translated_local(Vector3 offset) const

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.

Constants

IDENTITY = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)

The identity Transform3D. This is a transform with no translation, no rotation, and a scale of Vector3.ONE. Its basis is equal to Basis.IDENTITY. This also means that: - Its Basis.x points right (Vector3.RIGHT); - Its Basis.y points up (Vector3.UP); - Its Basis.z points back (Vector3.BACK).

			var transform = Transform3D.IDENTITY
			var basis = transform.basis
			print("| X | Y | Z | Origin")
			print("| %.f | %.f | %.f | %.f" % [basis.x.x, basis.y.x, basis.z.x, transform.origin.x])
			print("| %.f | %.f | %.f | %.f" % [basis.x.y, basis.y.y, basis.z.y, transform.origin.y])
			print("| %.f | %.f | %.f | %.f" % [basis.x.z, basis.y.z, basis.z.z, transform.origin.z])
			# Prints:
			# | X | Y | Z | Origin
			# | 1 | 0 | 0 | 0
			# | 0 | 1 | 0 | 0
			# | 0 | 0 | 1 | 0
			

If a Vector3, an AABB, a Plane, a PackedVector3Array, or another Transform3D is transformed (multiplied) by this constant, no transformation occurs. Note: In GDScript, this constant is equivalent to creating a Transform3D without any arguments. It can be used to make your code clearer, and for consistency with C#.

FLIP_X = Transform3D(-1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)

Transform3D with mirroring applied perpendicular to the YZ plane. Its basis is equal to Basis.FLIP_X.

FLIP_Y = Transform3D(1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0)

Transform3D with mirroring applied perpendicular to the XZ plane. Its basis is equal to Basis.FLIP_Y.

FLIP_Z = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0)

Transform3D with mirroring applied perpendicular to the XY plane. Its basis is equal to Basis.FLIP_Z.

Operators

bool operator !=(Transform3D right)

Returns true if the components of both transforms are not equal. Note: Due to floating-point precision errors, consider using is_equal_approx() instead, which is more reliable.

AABB operator *(AABB right)

Transforms (multiplies) the AABB by this transformation matrix.

Plane operator *(Plane right)

Transforms (multiplies) the Plane by this transformation matrix.

bool operator ==(Transform3D right)

Returns true if the components of both transforms are exactly equal. Note: Due to floating-point precision errors, consider using is_equal_approx() instead, which is more reliable.

Tutorials

Source revision 5592dc3a7a61
Connection interrupted. Reload×

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.