Class MatrixScaleHelper
Extraction and application of the per-axis scale stored in a Unity.Transforms.PostTransformMatrix or in a Unity.Transforms.LocalToWorld's float4x4
TransformHelpers.Scale can't be used for this: it returns unsigned lengths, losing mirrored axes.
Inherited Members
Namespace: Unity.Netcode
Assembly: Unity.NetCode.dll
Syntax
public static class MatrixScaleHelper
Remarks
A matrix does not uniquely encode which axes are mirrored, so SignedScaleFromScaleOnlyMatrix(in float4x4) takes the per-axis signs from the diagonal. That is faithful for scale-only matrices, and pairs with a rotation coming from elsewhere (e.g. the replicated Unity.Transforms.LocalTransform.Rotation) rather than one orthonormalized out of the same matrix - a quaternion cannot carry a mirror, so that would invent a rotation instead. If the matrix does carry its own rotation, diagonal signs it turns negative (rotations past 90°) are read - and on SetScale(in float4x4, float3), overwritten - as scale signs. Adapt to the convention: read/write scale through this helper and author mirroring as negative scale, not as 180° rotations.
Methods
SetScale(in float4x4, float3)
Replaces the matrix's per-axis signed scale (per SignedScaleFromScaleOnlyMatrix(in float4x4)'s convention), preserving its rotation and translation.
Declaration
public static float4x4 SetScale(in float4x4 matrix, float3 newScale)
Parameters
| Type | Name | Description |
|---|---|---|
| float4x4 | matrix | The matrix to re-scale. |
| float3 | newScale | The new per-axis scale. Negative values mirror the axis. |
Returns
| Type | Description |
|---|---|
| float4x4 | A matrix with the requested scale and the original rotation/translation. |
SignedScaleFromScaleOnlyMatrix(in float4x4)
The signed per-axis scale: column lengths, signs from the matrix diagonal. Only faithful for scale-only matrices (see class remarks).
Declaration
public static float3 SignedScaleFromScaleOnlyMatrix(in float4x4 matrix)
Parameters
| Type | Name | Description |
|---|---|---|
| float4x4 | matrix | The matrix to extract the scale from. |
Returns
| Type | Description |
|---|---|
| float3 | The signed per-axis scale. |