import '@kitware/vtk.js/favicon';
import '@kitware/vtk.js/Rendering/Profiles/Geometry';
import '@kitware/vtk.js/IO/Core/DataAccessHelper/HtmlDataAccessHelper'; import '@kitware/vtk.js/IO/Core/DataAccessHelper/HttpDataAccessHelper'; import '@kitware/vtk.js/IO/Core/DataAccessHelper/JSZipDataAccessHelper';
import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow'; import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor'; import vtkHttpDataSetSeriesReader from '@kitware/vtk.js/IO/Core/HttpDataSetSeriesReader'; import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
import controlPanel from './controller.html';
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance(); const renderer = fullScreenRenderer.getRenderer(); const renderWindow = fullScreenRenderer.getRenderWindow();
renderer.getActiveCamera().setPosition(6, 3, 7); renderer.getActiveCamera().setFocalPoint(0, 2, 0);
const reader = vtkHttpDataSetSeriesReader.newInstance({ fetchGzip: true }); reader .setUrl('https://kitware.github.io/vtk-js-datasets/data/temporal') .then(() => { fullScreenRenderer.addController(controlPanel);
const timeSteps = reader.getTimeSteps(); const timeStepLabel = document.querySelector('#timeStep');
const updateTimeStep = (index) => { const newTimeStep = timeSteps[index]; timeStepLabel.textContent = `Current time step: ${newTimeStep}`; reader.setUpdateTimeStep(newTimeStep); renderer.resetCameraClippingRange(); renderWindow.render(); };
let index = 0; updateTimeStep(index);
document.querySelector('#previous').onclick = () => { index = (index - 1 + timeSteps.length) % timeSteps.length; updateTimeStep(index); };
document.querySelector('#next').onclick = () => { index = (index + 1) % timeSteps.length; updateTimeStep(index); }; });
const mapper = vtkMapper.newInstance(); mapper.setInputConnection(reader.getOutputPort());
const actor = vtkActor.newInstance(); actor.setMapper(mapper);
renderer.addActor(actor);
global.source = reader; global.mapper = mapper; global.actor = actor; global.renderer = renderer; global.renderWindow = renderWindow;
|