Inherit group render order
See original GitHub issueIs your feature request related to a problem? Please describe.
We frequently work with deep scene graphs featuring lots of 2D objects in the same Z-plane. Render order is our go-to feature to ensure things are drawn on top of each other in the correct order.
I began to notice that our code was getting littered with haphazardly organized render order assignments, and after some digging I found out that render lists sort objects by groupOrder
first and renderOrder
second. So far, so good. However, an object’s groupOrder
is apparently determined by its closest ancestor Group, and not by any Groups higher up in the scene graph. That’s very surprising behavior!
For example, consider the following tree:
- Scene
- Group A (renderOrder: 4)
- Group (renderOrder: 0)
- Mesh A
- Group (renderOrder: 0)
- Group B (renderOrder: 3)
- Group (renderOrder: 1)
- Mesh B
- Group (renderOrder: 1)
- Group A (renderOrder: 4)
I would expect mesh A to be drawn on top of Mesh B. However, the opposite happens, and Mesh B is drawn on top of mesh A.
This is because currently, only the renderOrder attribute of the closest ancestor Group is actually taken into account when sorting.
Describe the solution you’d like
For renderOrder of all parent nodes (and not just Group objects either, since any Object3D can have children and a renderOrder) to be considered when sorting the render list.
I wouldn’t know off the top of my head what would be the shortest route to an implementation though.
Describe alternatives you’ve considered
Well, currently we are sprinkling our code with (many) additional renderOrder assignments to inherit renderOrder from parent groups manually.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:6 (3 by maintainers)
Top GitHub Comments
I have a series of PRs that would make controlling group render order a lot easier and more intuitive the first of which is #19526. In short it adds a flag to
Group
that enables all children to be sorted and rendered together recursively. I would really like to get feedback on that change because I agree – the current behavior can be very confusing.It isn’t my decision to organize these things or dictate behavior the classes but either way I don’t see a strong case for changing the behavior from operating on Group. I also think whether renderOrder applies to Object3D is an orthogonal problem to addressing the issue of hierarchical render order so it should probably be adjusted in a separate effort if it’s going to be changed.