An interface that enables manipulating the scale, rotation, and translation
of an entity.
All entities automatically adopt this protocol because the ``Entity`` base
class does. This adoption gives all entities a ``Transform`` component, and
a collection of methods for manipulating the component, that you use to
position the entity in space.
Sets the transform of the entity relative to the given reference entity
using a 4x4 matrix representation.
The ``Transform`` component can’t represent all transforms that a
general 4x4 matrix can represent. Setting a ``HasTransform/transform``
using a 4x4 matrix is therefore a lossy event that might result in
certain transformations, like shear, being dropped.
- Parameters:
- transform: A 4x4 transform matrix, given relative to `referenceEntity`.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
Gets the orientation of an entity relative to the given entity.
- Parameters:
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
- Returns: The orientation of the entity relative to `referenceEntity`.
get · iOS 13.0+
orientation
Swift declaration
@MainActor @preconcurrency var orientation: simd_quatf { get set }
The rotation of the entity relative to its parent.
This value is the entity’s rotation relative to its parent. To get the
world-space orientation of the entity, use
``HasTransform/orientation(relativeTo:)``, passing `nil` as the
reference entity.
This is the same as the ``Transform/rotation`` value on the
``HasTransform/transform``.
set · iOS 13.0+
orientation
Swift declaration
@MainActor @preconcurrency var orientation: simd_quatf { get set }
The rotation of the entity relative to its parent.
This value is the entity’s rotation relative to its parent. To get the
world-space orientation of the entity, use
``HasTransform/orientation(relativeTo:)``, passing `nil` as the
reference entity.
This is the same as the ``Transform/rotation`` value on the
``HasTransform/transform``.
Sets the position of the entity relative to the given reference entity.
- Parameters:
- position: A new position, relative to `referenceEntity`.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
Computes a bounding box for the entity in the specified space,
optionally including child entities.
The method has complexity `O(n)`, where `n` is the number of entities in
the hierarchy.
- Parameters:
- recursive: A Boolean that you set to `true` to incorporate the bounds
of all descendants.
- referenceEntity: An entity that defines a frame of reference. Set to
`nil` to indicate world space.
- excludeInactive: A Boolean that you set to `true` to exclude inactive
entities.
- Returns: The bounding box.
Sets the orientation of the entity relative to the given reference
entity.
- Parameters:
- orientation: A new orientation, relative to `referenceEntity`.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
Gets the 4 x 4 transform matrix of an entity relative to the given
entity.
- Parameters:
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
- Returns: The transform of the entity relative to `referenceEntity`.
Positions and orients the entity such that it looks at certain target from a give position.
- Parameters:
- target: The target position to look at.
- position: The new position of the entity.
- upVector: The *up* direction of the entity.
- referenceEntity: The reference entity which defines the frame of reference.
Can be `nil`, which is equivalent to "world space".
- forward: Use default forward (.negativeZ).
Can be set to .positiveZ for non-camera entities
This function moves the entity to the specified `position`. It rotates the entity such that
the forward direction is pointing towards `target`. It further makes sure that entity's *up*
direction aligns with the specified `upVector`.
- Note: This method can be used for non-camera entities.
Positions and orients the entity to look at a target from a given
position.
You can use this method on any entity, but it’s particularly useful for
orienting cameras and lights to aim at a particular point in space.
- Parameters:
- target: The target position to look at.
- position: The new position of the entity.
- upVector: The up direction of the entity after moving.
- referenceEntity: The entity that defines a frame of reference. Set this to
`nil` to indicate world space.
Moves an entity over a period of time to a new location given by a
transform.
Animating the scale of an entity to 0 will cause a subsequent inverse
of the entity's transform to return NaN values. Developers may consider animating
the scale of an entity to a small non-zero value. When the move completes, the
entity can then be hidden or removed if applicable to the use case.
- Parameters:
- target: A ``Transform`` instance that indicates the new location.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
- duration: The time in seconds over which the move should occur.
- timingFunction: A timing function that controls the progress of the
animation.
- Returns: An ``AnimationPlaybackController`` instance that you use to
control the animation playback.
Moves an entity over a period of time to a new location given by a 4x4
matrix.
- Parameters:
- target: A 4x4 matrix that indicates the new location.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
- duration: The time in seconds over which the move should occur.
- timingFunction: A timing function that controls the progress of the
animation.
- Returns: An ``AnimationPlaybackController`` instance that you use to
control the animation playback.
Moves an entity instantly to a new location given by a transform.
- Parameters:
- transform: A ``Transform`` instance that indicates the new location.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
Moves an entity instantly to a new location given by a 4x4 matrix.
- Parameters:
- transform: A 4x4 matrix that indicates the new location.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
Moves and rotates the entity by a transformation from the origin pin to the target pin.
- Parameter originPin: The `GeometricPin` to align. It should be one of the pins on the entity.
- Parameter targetPin: The `GeometricPin` to align to.
- Returns: Transformation matrix that has been applied to the `Entity`,
in the frame or reference of the parent of the `Entity`. If either pin doesn't exist, returns `nil`.
Gets the scale of an entity relative to the given entity.
- Parameters:
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
get · iOS 13.0+
scale
Swift declaration
@MainActor @preconcurrency var scale: SIMD3<Float> { get set }
The scale of the entity relative to its parent.
This value is the entity’s scale relative to its parent. To get the
actual scale of the entity in the scene, use
``HasTransform/scale(relativeTo:)``, passing `nil` as the reference
entity.
This is the same as the ``Transform/scale`` value on the
``HasTransform/transform``.
set · iOS 13.0+
scale
Swift declaration
@MainActor @preconcurrency var scale: SIMD3<Float> { get set }
The scale of the entity relative to its parent.
This value is the entity’s scale relative to its parent. To get the
actual scale of the entity in the scene, use
``HasTransform/scale(relativeTo:)``, passing `nil` as the reference
entity.
This is the same as the ``Transform/scale`` value on the
``HasTransform/transform``.
method · iOS 13.0+
convert
Swift declaration
@MainActor @preconcurrency func convert(normal: SIMD3<Float>, to referenceEntity: Entity?) -> SIMD3<Float>
Converts a normal vector from the local space of the entity on which you
called this method to the local space of a reference entity.
- Parameters:
- normal: A vector perpendicular to a surface at a point, given in the
local space of the entity.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
- Returns: The normal vector specified relative to `referenceEntity`.
method · iOS 13.0+
convert
Swift declaration
@MainActor @preconcurrency func convert(normal: SIMD3<Float>, from referenceEntity: Entity?) -> SIMD3<Float>
Converts a normal vector from the local space of a reference entity to
the local space of the entity on which you called this method.
- Parameters:
- normal: A vector perpendicular to a surface at a point, specified
relative to specified relative to `referenceEntity`.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
- Returns: The normal vector given in the local space of the entity.
method · iOS 13.0+
convert
Swift declaration
@MainActor @preconcurrency func convert(position: SIMD3<Float>, to referenceEntity: Entity?) -> SIMD3<Float>
Converts a position from the local space of the entity on which you
called this method to the local space of a reference entity.
- Parameters:
- position: The position given in the local space of the entity.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
- Returns: The position specified relative to `referenceEntity`.
method · iOS 13.0+
convert
Swift declaration
@MainActor @preconcurrency func convert(position: SIMD3<Float>, from referenceEntity: Entity?) -> SIMD3<Float>
Converts a position from the local space of a reference entity to the
local space of the entity on which you called this method.
- Parameters:
- position: The position specified relative to `referenceEntity`.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
- Returns: The position given in the local space of the entity.
method · iOS 13.0+
convert
Swift declaration
@MainActor @preconcurrency func convert(direction: SIMD3<Float>, to referenceEntity: Entity?) -> SIMD3<Float>
Converts a direction vector from the local space of the entity on which
you called this method to the local space of a reference entity.
- Parameters:
- direction: The direction vector given in the local space of the entity.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
- Returns: The direction vector specified relative to `referenceEntity`.
method · iOS 13.0+
convert
Swift declaration
@MainActor @preconcurrency func convert(direction: SIMD3<Float>, from referenceEntity: Entity?) -> SIMD3<Float>
Converts a direction vector from the local space of a reference entity
to the local space of the entity on which you called this method.
- Parameters:
- direction: The direction vector specified relative to `referenceEntity`.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
- Returns: The direction vector given in the local space of the entity.
method · iOS 13.0+
convert
Swift declaration
@MainActor @preconcurrency func convert(transform: Transform, to referenceEntity: Entity?) -> Transform
Converts the scale, rotation, and position of a transform from the local
space of the entity on which you called this method to the local space
of a reference entity.
- Parameters:
- transform: The transform given in the local space of the entity.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
- Returns: The transform specified relative to `referenceEntity`.
method · iOS 13.0+
convert
Swift declaration
@MainActor @preconcurrency func convert(transform: Transform, from referenceEntity: Entity?) -> Transform
Converts the scale, rotation, and position of a transform from the local
space of a reference entity to the local space of the entity on which
you called this method.
- Parameters:
- transform: The transform specified relative to `referenceEntity`.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
- Returns: The transform given in the local space of the entity.
Gets the position of an entity relative to the given entity.
- Parameters:
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
- Returns: The position of the entity relative to `referenceEntity`.
get · iOS 13.0+
position
Swift declaration
@MainActor @preconcurrency var position: SIMD3<Float> { get set }
The position of the entity relative to its parent.
This value is the entity’s position relative to its parent. To get the
world-space position of the entity in the scene, use
``HasTransform/position(relativeTo:)``, passing `nil` as the reference
entity.
This is the same as the ``Transform/translation`` value on the
``HasTransform/transform``.
set · iOS 13.0+
position
Swift declaration
@MainActor @preconcurrency var position: SIMD3<Float> { get set }
The position of the entity relative to its parent.
This value is the entity’s position relative to its parent. To get the
world-space position of the entity in the scene, use
``HasTransform/position(relativeTo:)``, passing `nil` as the reference
entity.
This is the same as the ``Transform/translation`` value on the
``HasTransform/transform``.
Sets the scale factor of the entity relative to the given reference
entity.
- Parameters:
- scale: A new scale factor, relative to `referenceEntity`.
- referenceEntity: The entity that defines a frame of reference. Set
this to `nil` to indicate world space.
get · iOS 13.0+
transform
Swift declaration
@MainActor @preconcurrency var transform: Transform { get set }
The transform of an entity relative to its parent.
For an ``AnchorEntity`` instance, the transform is relative to the AR
anchor.
set · iOS 13.0+
transform
Swift declaration
@MainActor @preconcurrency var transform: Transform { get set }
The transform of an entity relative to its parent.
For an ``AnchorEntity`` instance, the transform is relative to the AR
anchor.