Renderer.removeAllActors() doesn't work when actors are added a mixin

Hi all,

I wanted to add a custom property ‘path’ to vtkActor instances. To do so I created a mixin and added it to my vtkActor instances:

const pathMixin = o => {
    let path = "";

    return Object.assign({}, o, {
        getPath() {
            return path;
        },

        setPath(p) {
            path = p;
        }
    });
}

// Later
const actor = pathMixin(vtkActor.newInstance());
actor.setPath(path);
actor.setMapper(mapper);
this.renderer.addActor(actor);

So far so good. I can see the actors are correctly displayed in the scene. But, in a use case, I must remove all the actors from the scene. I do:

this.renderer.removeAllActors();

And this doesn’t work. If instead of a mixin, I add bare metal vtkActors to the scene, removeAllActors work as expected.

Is that expected ?

Does calling removeAllViewProps() works?

Looking at the code, it actually make sense (unfortunately) as we do a reference comparison and getActors() get called on the vtkActor instance which return its actual instance rather than the mixin. But if you use add/remove(All)ViewProp instead, then, you should be good.

Yes it does. Thank you Sébastien.

1 Like