Skip to content

Implement 2d and 3d transform propagation#247

Merged
waynemwashuma merged 7 commits into
wimaengine:devfrom
waynemwashuma:transform-propagation
Sep 10, 2025
Merged

Implement 2d and 3d transform propagation#247
waynemwashuma merged 7 commits into
wimaengine:devfrom
waynemwashuma:transform-propagation

Conversation

@waynemwashuma
Copy link
Copy Markdown
Collaborator

@waynemwashuma waynemwashuma commented Sep 10, 2025

Objective

Introduces transform propagation for 2D and 3D entities, allowing hierarchical transformations to be automatically computed and applied. This eliminates the need for manual calculation of world transforms for child entities and simplifies the process of building complex nested transformations.

Solution

The solution leverages the existing hierarchy system (using Parent and Children components) and introduces new systems that traverse the entity tree in a breadth-first manner. For each child entity, the global transform is computed by multiplying the parent's global transform with the child's local transform. This ensures that all children inherit their parent's position, rotation, and scale.

Modified Children and Parent components to implement VisitEntities for use in relationship queries.

Showcase

To use transform propagation, simply attach Parent and Children components to your entities. The global transform will automatically be updated to reflect the parent's transform.

Example (2D):

const parent = commands.spawn()
  .insertPrefab([
    ...createTransform2D(),
    new Children()
 ])
  .build()

const child = commands.spawn()
  .insertPrefab([
    ...createTransform2D(200, 0, 0, 0.5, 0.5),
    new Parent(parent)
 ])
  .build()

The child will now automatically rotate and scale relative to the parent.

Migration Guide

The introduced changes bring no breaking changes, however:

  • Remove any manual transform propagation code (e.g., manual multiplication of affine transforms).
  • Use GlobalTransform2D or GlobalTransform3D to access the world-space transform of an entity.

Checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@waynemwashuma waynemwashuma self-assigned this Sep 10, 2025
@waynemwashuma waynemwashuma marked this pull request as ready for review September 10, 2025 20:03
@waynemwashuma waynemwashuma merged commit c5b8562 into wimaengine:dev Sep 10, 2025
5 checks passed
@waynemwashuma waynemwashuma deleted the transform-propagation branch September 10, 2025 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant