Hello everyone,
I am using vtk.js (imported as an external file) to add a mesh visualization section on my personal GitHub page. I’m working directly on my Github page so debugging is not very convenient.
The following example is working just fine:
<html>
<body>
<script type="text/javascript" src="https://unpkg.com/@babel/polyfill@7.0.0/dist/polyfill.js"></script>
<script type="text/javascript" src="https://unpkg.com/vtk.js"></script>
<script type="text/javascript">
var fullScreenRenderer = vtk.Rendering.Misc.vtkFullScreenRenderWindow.newInstance({
background: [0, 0, 0],
containerStyle: { width: '400px', height: "600px" } });
var actor = vtk.Rendering.Core.vtkActor.newInstance();
var mapper = vtk.Rendering.Core.vtkMapper.newInstance();
var cone = vtk.Filters.Sources.vtkConeSource.newInstance();
var camera = vtk.Rendering.Core.vtkCamera.newInstance();
actor.setMapper(mapper);
mapper.setInputConnection(cone.getOutputPort());
var renderer = fullScreenRenderer.getRenderer();
renderer.addActor(actor);
renderer.resetCamera();
var renderWindow = fullScreenRenderer.getRenderWindow();
renderWindow.render();
</script>
</body>
</html>
However, when I try to visualize a mesh of my own, only a blank screen appears on my website.
<body>
<script type="text/javascript" src="https://unpkg.com/vtk.js"></script>
<script type="text/javascript">
var fullScreenRenderer = vtk.Rendering.Misc.vtkFullScreenRenderWindow.newInstance({
background: [0, 0, 0],
containerStyle: { width: '400px', height: "600px" } });
var actor = vtk.Rendering.Core.vtkActor.newInstance();
var mapper = vtk.Sources.Rendering.OpenGL.PolyDataMapper.newInstance();
var reader = vtk.IO.Legacy.vtkPolyDataReader.newInstance();
var camera = vtk.Rendering.Core.vtkCamera.newInstance();
const url = '/assets/img/my_mesh.vtk';
reader.setUrl(url);
reader.update();
mapper.setInputData(reader.getOutputData());
actor.setMapper(mapper);
var renderer = fullScreenRenderer.getRenderer();
renderer.addActor(actor);
renderer.resetCamera();
var renderWindow = fullScreenRenderer.getRenderWindow();
renderWindow.render();
</script>
</body>
</html>
Any help would be great!
Thanks in advance,
Fleur