import '@kitware/vtk.js/favicon';
import '@kitware/vtk.js/Rendering/Profiles/Geometry';
import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow'; import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor'; import vtkConeSource from '@kitware/vtk.js/Filters/Sources/ConeSource'; import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper'; import vtkInteractorStyleManipulator from '@kitware/vtk.js/Interaction/Style/InteractorStyleManipulator'; import vtkMouseCameraTrackballRotateManipulator from '@kitware/vtk.js/Interaction/Manipulators/MouseCameraTrackballRotateManipulator'; import vtkMouseCameraTrackballPanManipulatorAutoCenter from '@kitware/vtk.js/Interaction/Manipulators/MouseCameraTrackballPanManipulatorAutoCenter'; import vtkMouseCameraTrackballZoomManipulator from '@kitware/vtk.js/Interaction/Manipulators/MouseCameraTrackballZoomManipulator';
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance(); const renderer = fullScreenRenderer.getRenderer(); const renderWindow = fullScreenRenderer.getRenderWindow();
const interactorStyle = vtkInteractorStyleManipulator.newInstance(); fullScreenRenderer.getInteractor().setInteractorStyle(interactorStyle);
const coneSource = vtkConeSource.newInstance({ height: 1.0 }); const coneMapper = vtkMapper.newInstance(); coneMapper.setInputConnection(coneSource.getOutputPort());
const coneActor = vtkActor.newInstance(); coneActor.setMapper(coneMapper); coneActor.getProperty().setColor(0.5, 0.5, 1.0);
renderer.addActor(coneActor); renderer.resetCamera();
const rotateManipulator = vtkMouseCameraTrackballRotateManipulator.newInstance(); rotateManipulator.setButton(1); interactorStyle.addMouseManipulator(rotateManipulator);
const middleZoomManipulator = vtkMouseCameraTrackballZoomManipulator.newInstance(); middleZoomManipulator.setButton(2); interactorStyle.addMouseManipulator(middleZoomManipulator);
const shiftPanManipulator = vtkMouseCameraTrackballPanManipulatorAutoCenter.newInstance(); shiftPanManipulator.setButton(1); shiftPanManipulator.setShift(true); interactorStyle.addMouseManipulator(shiftPanManipulator);
const rightPanManipulator = vtkMouseCameraTrackballPanManipulatorAutoCenter.newInstance(); rightPanManipulator.setButton(3); interactorStyle.addMouseManipulator(rightPanManipulator);
const wheelZoomManipulator = vtkMouseCameraTrackballZoomManipulator.newInstance(); wheelZoomManipulator.setScrollEnabled(true); wheelZoomManipulator.setDragEnabled(false); interactorStyle.addMouseManipulator(wheelZoomManipulator);
renderWindow.render();
const infoDiv = document.createElement('div'); infoDiv.style.position = 'absolute'; infoDiv.style.top = '10px'; infoDiv.style.left = '10px'; infoDiv.style.padding = '10px'; infoDiv.style.background = 'rgba(255, 255, 255, 0.9)'; infoDiv.style.borderRadius = '5px'; infoDiv.style.fontFamily = 'monospace'; infoDiv.style.maxWidth = '400px';
infoDiv.innerHTML = ` <h3>Auto-Adjusting Center of Rotation Demo</h3> <p>The center of rotation automatically moves with the camera during panning, maintaining consistent rotation behavior relative to the camera position.</p> <p><strong>Controls:</strong></p> <ul> <li>Left Mouse: Rotate around center</li> <li>Middle Mouse: Zoom</li> <li>Right Mouse or Shift+Left: Pan (center adjusts automatically)</li> <li>Mouse Wheel: Zoom</li> </ul> <p><strong>Try this:</strong> Try to rotate around the tip of the cone.</p> `; document.body.appendChild(infoDiv);
global.coneSource = coneSource; global.coneActor = coneActor; global.renderer = renderer; global.renderWindow = renderWindow; global.interactorStyle = interactorStyle;
|