VTK.js - Model don't get interactor / mouse event + OBJReader

Hello,

1/ I’m facing a problem with vtkRenderWindowInteractor and i don’t know what’s going wrong. The model is correctly displayed but no interaction with it is possible, even though i followed the examples for mouse event on vtk.js.

Js code :

var renderWindow = vtk.Rendering.Core.vtkRenderWindow.newInstance();
var renderer = vtk.Rendering.Core.vtkRenderer.newInstance();
var cone = vtk.Filters.Sources.vtkConeSource.newInstance();
//var model = vtk.Rendering.Misc.vtkOBJReader.newInstance();

var openGLRenderWindow = vtk.Rendering.OpenGL.vtkRenderWindow.newInstance();
renderWindow.addView(openGLRenderWindow);

var actor = vtk.Rendering.Core.vtkActor.newInstance();
var mapper = vtk.Rendering.Core.vtkMapper.newInstance();

mapper.setInputConnection(cone.getOutputPort());
actor.setMapper(mapper);
renderer.addActor(actor);
renderer.resetCamera();
renderWindow.addRenderer(renderer);

var container = document.getElementById("model");
openGLRenderWindow.setContainer(container);
var size = container.getBoundingClientRect();
openGLRenderWindow.setSize(size.width, size.height);

var interactor = vtk.Rendering.Core.vtkRenderWindowInteractor.newInstance();
interactor.setView(openGLRenderWindow);
interactor.initialize();
interactor.bindEvents(container);

renderWindow.render();

2/ I take advantage of this topic to ask something else :
“var model = vtk.Rendering.Misc.vtkOBJReader.newInstance();” is an error.
I can’t see good examples on OBJReader with Js. Can someone guide me a little on how it works ?

Thank you, any information will be appreciated.

Hi,

  1. You forgot to set an interactor style after you create your interactor. The TrackballCamera will give you 3D trackball interaction.
interactor.setInteractorStyle(vtk.Interaction.Style.vtkInteractorStyleTrackballCamera.newInstance());
  1. Did you mean vtk.IO.Misc.vtkOBJReader.newInstance()? There are no readers under vtk.Rendering.*. That being said, if the error still persists, feel free to post it here.

Hi Forrest,

1/ Perfect, i thought a default style was on it so it was optionnal.

2/ I was searching for the correct path, is there a library or list where i can see all the differents paths ?

Thank you for the help !

You’re welcome!

You can find API paths here: https://kitware.github.io/vtk-js/api/. Alternatively, you can also search for them in the vtk.js github project, as the folder paths correspond to the object paths.

Ok, it’s all clear for me now, i understand better how this works.
Thank you again.
Best regards.