Skip to content

Hierarchy and scene graph support #7

@jakeklassen

Description

@jakeklassen

Context

The shmup demo uses a simple parent-child pattern for hierarchy, but it doesn't handle deep hierarchies, processing order, rotation/scale inheritance, or attach/detach operations. Inspired by Wicked Engine's ECS article.

Current State

// Simple parent reference + manual position update
parent?: SetRequired<Entity, "transform">;
localTransform?: Transform;

entity.transform.position.x =
  entity.parent.transform.position.x + entity.localTransform.position.x;

Potential Approaches

1. Depth-based Sorting (Pattern-based)

Add hierarchyDepth to entities and sort before processing. Simple, fits objECS philosophy, but O(n log n) sorting per frame.

2. SceneGraph Class (Structured)

Dedicated hierarchy manager alongside the ECS with attach/detach/traverse (topological order). Could be published as objecs-hierarchy package.

3. Matrix-based Transforms (Full Scene Graph)

For proper rotation/scale inheritance using matrix math. Requires a small math library.

Challenges

Wicked Engine objECS
Integer entity IDs Object references
Ordered arrays per component Unordered collections
Component managers with sorting Simple archetypes

Open Questions

  • Should SceneGraph automatically sync with World entity deletions?
  • Should transforms be split into localTransform and worldTransform always?
  • How to handle dirty flags / caching for performance?
  • Should hierarchy be query-able via archetypes? (e.g., world.archetype("parent"))
  • Archetypes may need to support sorting for this to work well

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions