Skip to content

Commit 0296cfe

Browse files
committed
fix(viewnode): add optional ability to maintain node ordering
This change adds an argument to `addMissingNodes` to ensure that the view node ordering is maintained. By default, ordering is not maintained. However, for nodes of type `vtkActor2D`, where layering requires a specific order, the node ordering is enforced.
1 parent bdad677 commit 0296cfe

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

Sources/Rendering/OpenGL/Renderer/index.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,10 @@ function vtkOpenGLRenderer(publicAPI, model) {
2424
publicAPI.updateLights();
2525
publicAPI.prepareNodes();
2626
publicAPI.addMissingNode(model.renderable.getActiveCamera());
27-
// Force all actor2D instances to be sorted and re-pushed as scenegraph nodes.
28-
// This ensures that they are rendered in the correct order.
29-
const actors2D = model.renderable.getActors2D();
30-
actors2D.forEach((ac) => {
31-
const vn = publicAPI.getViewNodeFor(ac);
32-
if (vn !== undefined) {
33-
publicAPI.removeNode(vn);
34-
}
35-
});
36-
publicAPI.addMissingNodes(model.renderable.getViewPropsWithNestedProps());
27+
publicAPI.addMissingNodes(
28+
model.renderable.getViewPropsWithNestedProps(),
29+
true
30+
);
3731
publicAPI.removeUnusedNodes();
3832
}
3933
};

Sources/Rendering/SceneGraph/ViewNode/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,27 @@ function vtkViewNode(publicAPI, model) {
113113

114114
// add missing nodes/children for the passed in renderables. This should
115115
// be called only in between prepareNodes and removeUnusedNodes
116-
publicAPI.addMissingNodes = (dataObjs) => {
116+
publicAPI.addMissingNodes = (dataObjs, enforceOrder = false) => {
117117
if (!dataObjs || !dataObjs.length) {
118118
return;
119119
}
120120

121121
for (let index = 0; index < dataObjs.length; ++index) {
122122
const dobj = dataObjs[index];
123-
publicAPI.addMissingNode(dobj);
123+
const node = publicAPI.addMissingNode(dobj);
124+
if (
125+
enforceOrder &&
126+
node !== undefined &&
127+
model.children[index] !== node
128+
) {
129+
for (let i = index + 1; i < model.children.length; ++i) {
130+
if (model.children[i] === node) {
131+
model.children.splice(i, 1);
132+
model.children.splice(index, 0, node);
133+
break;
134+
}
135+
}
136+
}
124137
}
125138
};
126139

0 commit comments

Comments
 (0)