STL Reader using VTK.js on a html page

372 Views Asked by At

I'm just trying to run this code I got from Vtk.js documentation examples:

<!DOCTYPE html>
<html>
<head>
    <title>vtk</title>
</head>
<body>
     
    <script type="text/javascript" src="https://unpkg.com/@babel/[email protected]/dist/polyfill.js"></script>
  <script type="text/javascript" src="https://unpkg.com/vtk.js"></script>
  <script type="text/javascript">

import 'vtk.js/Sources/favicon';

import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
import vtkFullScreenRenderWindow from 'vtk.js/Sources/Rendering/Misc/FullScreenRenderWindow';
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper';
import vtkSTLReader from 'vtk.js/Sources/IO/Geometry/STLReader';

  </script>     
</body>
</html>

But I got a blank page and the console shows me the error:

SyntaxError: Unexpected string literal 'vtk.js/Sources/favicon.'

import call expects exactly one argument. I think my error comes from the my first import.

Thanks in advance

1

There are 1 best solutions below

0
YSFKBDY On

You can run vtk.js on a html page like this:

<!DOCTYPE html>
<html>
    <body>
        <script type="text/javascript" src="https://unpkg.com/@babel/[email protected]/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();
            var actor = vtk.Rendering.Core.vtkActor.newInstance();
            var mapper = vtk.Rendering.Core.vtkMapper.newInstance();
            var stlReader = vtk.IO.Geometry.vtkSTLReader.newInstance();
        </script>
    </body>
</html>