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
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
Potential Approaches
1. Depth-based Sorting (Pattern-based)
Add
hierarchyDepthto 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 asobjecs-hierarchypackage.3. Matrix-based Transforms (Full Scene Graph)
For proper rotation/scale inheritance using matrix math. Requires a small math library.
Challenges
Open Questions
localTransformandworldTransformalways?world.archetype("parent"))References