import '@kitware/vtk.js/favicon';
import '@kitware/vtk.js/Rendering/Profiles/Geometry'; import '@kitware/vtk.js/Rendering/Profiles/Glyph';
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor'; import vtkCubeSource from '@kitware/vtk.js/Filters/Sources/CubeSource'; import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow'; import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper'; import vtkSphereWidget from '@kitware/vtk.js/Widgets/Widgets3D/SphereWidget'; import vtkWidgetManager from '@kitware/vtk.js/Widgets/Core/WidgetManager';
import controlPanel from './controlPanel.html';
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({ background: [0, 0, 0], }); const renderer = fullScreenRenderer.getRenderer(); const renderWindow = fullScreenRenderer.getRenderWindow();
const cube = vtkCubeSource.newInstance(); const mapper = vtkMapper.newInstance(); const actor = vtkActor.newInstance();
actor.setMapper(mapper); mapper.setInputConnection(cube.getOutputPort()); actor.getProperty().setOpacity(0.5);
renderer.addActor(actor);
const widgetManager = vtkWidgetManager.newInstance(); widgetManager.setRenderer(renderer);
let widget = null; let widgetHandle = null;
renderer.resetCamera();
fullScreenRenderer.addController(controlPanel);
document.querySelector('#addWidget').addEventListener('click', () => { widgetManager.releaseFocus(widget); widget = vtkSphereWidget.newInstance(); widget.placeWidget(cube.getOutputData().getBounds()); widgetHandle = widgetManager.addWidget(widget); widgetManager.grabFocus(widget); });
document.querySelector('#removeWidget').addEventListener('click', () => { const widgets = widgetManager.getWidgets(); if (!widgets.length) return; widgetManager.removeWidget(widgets[widgets.length - 1]); });
global.widget = widget; global.renderer = renderer; global.fullScreenRenderer = fullScreenRenderer; global.renderWindow = renderWindow; global.widgetManager = widgetManager; global.widgetHandle = widgetHandle;
|