druidengine / druidengine/druid
Explore flecs as a solution for managing a scene graph.
- Dominant language
- C++
- Stars
- 3
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
We need an ECS solution for scene graph transformation hierarchy to handle node-based transforms and render order.
**Describe the solution you'd like**
- [ ] Add a solution to the `druid-scene` app that explores using flecs to manage node transformations.
- [ ] There should be clear steps for the render pipeline for determining transforms and render order.
- [ ] Rendering geometry shall use `DrawMesh` API.
- [ ] Global transforms should only be calculated when a parent's local transform changes.
Pseudo Code:
```cpp
#include
struct Transform
{
Matrix global;
Matrix local;
};
struct Mesh
{
};
class Node
{
public:
auto add_child(std::unique_ptr x)
{
x->e.child_of(this->e);
}
std::vector children() {
e.world().each([](e) {
v.push_back(Node&);
});
return v;
}
private:
flecs::entity e;
};
class SceneTree
{
};
int main()
{
flecs::world world;
auto root = world.entity();
auto entity = world.entity();
entity.set();
entity.set();
entity.set();
entity.child_of(root);
// Calculate "dirty" transforms.
std::vector dirtied;
// "flag" an entity has been dirtied
dirtied.push_back(entity);
// Render Loop {
for(parent : dirtied)
{
// calculate child global transforms
// child.get().global = parent.get().local * child.get().local;
}
dirtied.clear();
world.each([](Mesh& m, Transform& t) {
DrawMesh(m, t.global);
});
// Start with root, iterate over it and its children and its children's children, etc...
auto iterate = [](entity) {
for(child : root.children)
{
iterate(child);
}
};
}
```
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.
Contributor guide
Assessment
This issue has not been assessed yet.