Skip to content

Commit c45a809

Browse files
committed
feat(actor2d): overlay 2D actors in the order of their layer number
This change adds support for sorting 2D actor overlays based on their `layerNumber` property.
1 parent a78800e commit c45a809

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Sources/Rendering/Core/Viewport/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,20 @@ function vtkViewport(publicAPI, model) {
4747
}
4848

4949
publicAPI.getViewPropsWithNestedProps = () => {
50-
const allPropsArray = [];
51-
for (let i = 0; i < model.props.length; i++) {
52-
gatherProps(model.props[i], allPropsArray);
50+
let allPropsArray = [];
51+
// Handle actor2D instances separately so that they can be overlayed and layered
52+
const actors2D = publicAPI.getActors2D();
53+
// Sort the actor2D list using its layer number
54+
actors2D.sort((a, b) => a.getLayerNumber() - b.getLayerNumber());
55+
// Filter out all the actor2D instances
56+
const newPropList = model.props.filter((item) => !actors2D.includes(item));
57+
for (let i = 0; i < newPropList.length; i++) {
58+
gatherProps(newPropList[i], allPropsArray);
5359
}
60+
// Finally, add the actor2D props at the end of the list
61+
// This works because, when traversing the render pass in vtkOpenGLRenderer, the children are
62+
// traversed in the order that they are added to the list
63+
allPropsArray = allPropsArray.concat(actors2D);
5464
return allPropsArray;
5565
};
5666

0 commit comments

Comments
 (0)