VTK NPM Mouse/Touch interactor is not working

Hi, I am using vtk in my NPM VUE project.
After I create a simple example, I can’t interact the window with my mouse click.
I have tried to follow the documentation but it still seems doesn’t work.
Anyone who have idea if I am missing anything?

export default class Scene{
    constructor() {
        this.canvas = document.createElement('div');
        this.renderer = vtkRenderer.newInstance();
        this.window = vtkRenderWindow.newInstance();
        this.control = InteractorStyle.newInstance();
        this.interactor = vtkRenderWindowInteractor.newInstance();
        this.openGL = vtkOpenGLRenderWindow.newInstance();
        this.settings();
        this.testMesh();
        this.render();
    }
    settings(){
        document.querySelector('body').appendChild(this.canvas);
        this.window.addRenderer(this.renderer);
        this.window.addView(this.openGL);
        this.openGL.setContainer(this.canvas);

        const { width, height } = this.canvas.getBoundingClientRect();
        this.openGL.setSize(width, height);

        this.interactor.setInteractorStyle(this.control);
        this.interactor.setInteractorStyle(InteractorStyle.newInstance());
        this.interactor.setView(this.openGL);
        this.renderer.setBackground2(102, 51, 0)
        this.renderer.setBackground(0, 102, 104)
    }
    render(){
        this.interactor.initialize();
        this.interactor.bindEvents(this.canvas);
    }
    testMesh(){
        const coneSource = vtkConeSource.newInstance({ height: 1.0 });

        const mapper = vtkMapper.newInstance();
        mapper.setInputConnection(coneSource.getOutputPort());

        const actor = vtkActor.newInstance();
        actor.setMapper(mapper);

        this.renderer.addActor(actor);
        this.renderer.resetCamera();
    }
}

Look at that example. You will see that you’ve instantiated the abstract class for the style rather than a concrete one that will actually process the events.

1 Like

I have got the solution.
I replaced import vtkInteractorStyleTrackballCamera from "@kitware/vtk.js/Rendering/Core/InteractorStyle"
line with
import vtkInteractorStyleTrackballCamera from '@kitware/vtk.js/Interaction/Style/InteractorStyleTrackballCamera';
and it’s working