import '@kitware/vtk.js/favicon';
import '@kitware/vtk.js/Rendering/Profiles/Geometry';
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor'; import vtkConeSource from '@kitware/vtk.js/Filters/Sources/ConeSource'; import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow'; import vtkWebXRRenderWindowHelper from '@kitware/vtk.js/Rendering/WebXR/RenderWindowHelper'; import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper'; import { XrSessionTypes } from '@kitware/vtk.js/Rendering/WebXR/RenderWindowHelper/Constants';
import vtkInteractorStyleHMDXR from '@kitware/vtk.js/Interaction/Style/InteractorStyleHMDXR'; import vtkRenderWindowInteractor from '@kitware/vtk.js/Rendering/Core/RenderWindowInteractor';
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 vtkResourceLoader from '@kitware/vtk.js/IO/Core/ResourceLoader';
import controlPanel from './controller.html';
if (navigator.xr === undefined) { vtkResourceLoader .loadScript( 'https://cdn.jsdelivr.net/npm/webxr-polyfill@latest/build/webxr-polyfill.js' ) .then(() => { new WebXRPolyfill(); }); }
function createRenderingPipeline(filter) { const mapper = vtkMapper.newInstance(); mapper.setInputConnection(filter.getOutputPort());
const actor = vtkActor.newInstance(); actor.setMapper(mapper);
return actor; }
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({ background: [0, 0, 0], });
const interactor = vtkRenderWindowInteractor.newInstance(); interactor.setView(fullScreenRenderer.getApiSpecificRenderWindow()); interactor.initialize();
const interactorStyle = vtkInteractorStyleHMDXR.newInstance(); interactor.setInteractorStyle(interactorStyle);
const renderer = fullScreenRenderer.getRenderer(); const renderWindow = fullScreenRenderer.getRenderWindow(); const XRHelper = vtkWebXRRenderWindowHelper.newInstance({ renderWindow: fullScreenRenderer.getApiSpecificRenderWindow(), drawControllersRay: true, });
const coneSource1 = vtkConeSource.newInstance({ height: 100.0, radius: 50 });
const coneSource2 = vtkConeSource.newInstance({ height: 50.0, radius: 20, });
const coneSource3 = vtkConeSource.newInstance({ height: 50.0, radius: 20, });
const coneActor1 = createRenderingPipeline(coneSource1); const coneActor2 = createRenderingPipeline(coneSource2); const coneActor3 = createRenderingPipeline(coneSource3);
coneActor3.setDragable(false);
renderer.addActor(coneActor1); renderer.addActor(coneActor2); renderer.addActor(coneActor3);
coneActor1.setPosition(0.0, 0.0, -20.0); coneActor2.setPosition(50.0, 0.0, -20.0); coneActor3.setPosition(-50.0, 0.0, -20.0);
renderer.resetCamera(); renderWindow.render();
fullScreenRenderer.addController(controlPanel); const vrbutton = document.querySelector('.vrbutton');
vrbutton.addEventListener('click', (e) => { if (vrbutton.textContent === 'Send To VR') { XRHelper.startXR(XrSessionTypes.HmdVR); vrbutton.textContent = 'Return From VR'; } else { XRHelper.stopXR(); vrbutton.textContent = 'Send To VR'; } });
global.coneSource1 = coneSource1; global.coneSource2 = coneSource2; global.coneSource3 = coneSource3;
global.coneActor1 = coneSource1; global.coneActor2 = coneSource2; global.coneActor3 = coneSource3;
global.renderer = renderer; global.renderWindow = renderWindow;
|