-
Notifications
You must be signed in to change notification settings - Fork 2
Transform System
Myriad includes an optional system for updating hierarchical transforms. This system will automatically calculate the world transform (and store it into a component) from a local transform and a parent reference.
Create a new system derived from BaseUpdateTransformHierarchySystem<TData, TTransform, TLocalTransform, TWorldTransform, TTransformParent>
.
-
TData
: The normal system data parameter. -
TTransform : ITransform
: The types of the transform (e.g. a matrix). -
TLocalTransform : ILocalTransform
: A component which represents the local transform of an entity, relative to it's parent. -
TWorldTransform : IWorldTransform
: A component which represents the world transform of an entity. Automatically calculated by this system. -
TTransformParent : ITransformParent
: A component which specifies the parent of an entity in the transform hierarchy.-
Myriad.ECS.Components.TransformParent
component is provided as a ready made implementation.
-
The local transform of root entities is copied directly to the world transform, with no other changes.
It's possible to create a set of entities which reference each other in a loop (e.g. A parent of B parent of C parent of A). When a loop is detected the LoopDetected(Entity entity)
method will be called with an arbitrary entity in the loop. Override LoopDetected
to handle this error. While there is a loop an arbitrary entity in the loop will be used as the root.
Any entity may be referenced as a parent. However, some entites are invalid as transform parents, for example a dead/phantom entity or one without a world transform. In this case the reference will be ignored, i.e. the "child" entity will act as the root.
Transforms are represented by ITransform
. This interface has a Compose
method, which composes together a parent and child transform:
struct OffsetTransform
: ITransform<OffsetTransform>
{
public Vector3 Offset;
OffsetTransform Compose(OffsetTransform child)
{
return new()
{
Offset = Offset + child.Offset;
};
}
}