API reference
API reference
Select your platform
No SDKs available
No versions available

TransformerUtils Class

Contains a variety of static methods for specialized utility purposes, along with related child structures and classes.
The static methods constrain a 3D data in a variety of ways, or encapsulate highly specific arithmetic operations.
These functions are not general; they are used by various ITransformer implementations, and the degree to which each function is tightly coupled to the conventions and assumptions of its usage varies. For that reason, you should avoid leveraging these directly; only add new usage if copy-pasting from existing usages, and use the existing implementation as a guide to understand how to use each of these correctly.

Static Member Functions

Generates a new set of PositionConstraints based on an initialPosition .
Parameters
constraints
The PositionConstraints upon which the new constraints should be based.
initialPosition
The initial position from which relative constraints should be relative.
Returns
New constraints which take initialPosition into account.
Generates a new set of ScaleConstraints based on an initialScale .
Parameters
constraints
The ScaleConstraints upon which the new constraints should be based.
initialScale
The initial scale from which relative constraints should be relative.
Returns
New constraints which take initialScale into account.
Applies a set of PositionConstraints to a vector representing the position of a Transform.
Parameters
unconstrainedPosition
The position of the Transform before constraining.
positionConstraints
The constraints to be applied to positionConstraints .
relativeTransform
The transform to which constraint should be considered relative; if omitted, constraining will be applied relative to world space.
Returns
A position which is as similar as possible to unconstrainedPosition but allowed by positionConstraints .
Applies a set of RotationConstraints to a Quaternion representing the rotation of a Transform.
Parameters
unconstrainedRotation
The rotation of the Transform before constraining.
rotationConstraints
The constraints to be applied to unconstrainedRotation .
relativeTransform
The transform to which constraint should be considered relative; if omitted, constraining will be applied relative to world space.
Returns
A rotation which is as similar as possible to unconstrainedRotation but allowed by rotationConstraints .
Applies a set of ScaleConstraints to a vector representing the scale of a Transform.
Parameters
unconstrainedScale
The scale of the Transform before constraining.
scaleConstraints
The constraints to be applied to unconstrainedScale .
Returns
A scale which is as similar as possible to unconstrainedScale but allowed by scaleConstraints .
Convenience method for taking a Pose in world space (or whatever space is the domain of the transform represented by worldToLocal ) and returning its representation in local space (or whatever space is the range of worldToLocal ).
Parameters
worldPose
The Pose to be transformed.
worldToLocal
The transformation to be applied.
Returns
The image of worldPose in worldToLocal 's range.
This is an old utility method, new uses of which should be avoided.
For homogeneous transform arithmetic, just use Unity's built-in Transform and matrix math support. The naming and use of Pose representation in this implementation can be confusing, so this explanation will avoid them and map back at the end. Conceptually, there are three things: a scaled transform T in world space, an unscaled transform A in T space, and an unscaled transform B in world space. The goal is to find a scaled transform T' (sharing the scale of T) such that an unmodified A in T' equals B when mapped to world space; colloquially, "find where we need to move T to so that A and B are on top of one another." Mathematically, this means the relationship between T' and B is the same as the relationship between T and A; thus, if we find T in the space of A (or, more precisely, A as a scaled transform in world space), we can use that same relationship with B to find T'. This gives us the following arithmetic (treating each transform as a "local to world" matrix):
given T, A, and B
A_inWorldSpace := T * A
T_inASpace := inverse(A_inWorldSpace) * T
T' := b * T_inASpace
Mapping this back to the variables and assumptions of this implementation, localToWorld is T, local is A, and world is B. The fact that the result T' is a scaled transform is not reflected in the return value of this extension and is instead implicit in its usage. The position and rotation of the returned Pose must be assigned directly to the corresponding fields of the Transform which provided localToWorld, without modifying the scale of that Transform; any other usage may not yield the desired alignment.
Parameters
localToWorld
T (see remarks for details).
local
A (see remarks for details).
world
B (see remarks for details).
Returns
T', excluding scale (see remarks for details).
Calculates how large a certain magnitude in world space is in local space.
This method specifically works by approximating the scale change from the world-space Z axis. If the transform hierarchy involves skew (rotated nonuniform scales), the result may not fully describe the scale relationship between local and world space. For more information, refer to Unity's documentation for Transform.lossyScale.
Parameters
magnitude
The magnitude to be converted to local space.
localToWorld
The homogeneous transform from world to local space.
Returns
The magnitude in local space.
Calculates how large a certain magnitude in local space is in world space.
This method specifically works by approximating the scale change from the local-space Z axis. If the transform hierarchy involves skew (rotated nonuniform scales), the result may not fully describe the scale relationship between local and world space. For more information, refer to Unity's documentation for Transform.lossyScale.
Parameters
magnitude
The magnitude to be converted to world space.
localToWorld
The homogeneous transform from local to world space.
Returns
The magnitude in world space.
Constrains a position to a certain range of positions along a line defined by position and direction minimally distant from a range of points from origin plus direction scaled by min to origin plus direction scaled by max .
This is an extremely specialized utility used only by TwoGrabPlaneTransformer.
Parameters
position
The position to be constrained.
origin
The origin of the line to which position should be projected for constraint.
direction
The direction along which position should be constrained.
min
The minimum signed distance along the line defined by origin and direction to which the closest projection of position should be constrained.
max
The maximum signed distance along the line defined by origin and direction to which the closest projection of position should be constrained.
Returns
The constrained position.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon