VTK  9.6.20260329
vtkWebXRRenderWindowInteractor.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
15
16#ifndef vtkWebXRRenderWindowInteractor_h
17#define vtkWebXRRenderWindowInteractor_h
18
19#include "vtkRenderingWebXRModule.h" // For export macro
21#include "vtkWebXR.h"
22#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
23
24VTK_ABI_NAMESPACE_BEGIN
25
26class VTKRENDERINGWEBXR_EXPORT VTK_MARSHALAUTO vtkWebXRRenderWindowInteractor
28{
29public:
31 void PrintSelf(ostream& os, vtkIndent indent) override;
33
40
44 void Initialize() override;
45
49 void StartEventLoop() override;
50
54 void DoOneEvent(vtkVRRenderWindow* renWin, vtkRenderer* ren) override;
55
59 void TerminateApp() override;
60
70 double wxyz[4], double ppos[3], double wdir[3]);
71
73
77 void AddAction(const std::string& path, const vtkCommand::EventIds&);
78 void AddAction(const std::string& path, const std::function<void(vtkEventData*)>&);
80
82
90 void AddAction(const std::string& path, const vtkCommand::EventIds&, bool isAnalog) override;
92 const std::string& path, bool isAnalog, const std::function<void(vtkEventData*)>&) override;
94
99
101
109 static void StartXR(SessionMode mode = SessionMode::VR, vtkTypeUInt32 requiredFeatures = 1,
110 vtkTypeUInt32 optionalFeatures = 2);
111 static void StopXR();
113
114protected:
117
127
131 bool LoadActions(const std::string& actionFilename);
132 const ActionData* GetActionData(const std::string& actionName);
135
139 void ApplyAction(const ActionData& actionData, vtkEventDataDevice3D* ed);
140
141 std::map<std::string, ActionData> ActionMap;
143 {
147
148 bool operator<(const WebXRInput& other) const
149 {
150 if (this->hand != other.hand)
151 {
152 return this->hand < other.hand;
153 }
154 else if (this->button != other.button)
155 {
156 return this->button < other.button;
157 }
158 else
159 {
160 return this->mode < other.mode;
161 }
162 }
163 };
164 std::map<WebXRInput, ActionData*> ButtonToActionMap;
165
166private:
168 void operator=(const vtkWebXRRenderWindowInteractor&) = delete;
169
170 vtkNew<vtkMatrix4x4> PoseToWorldMatrix; // used in calculations
171#ifdef __EMSCRIPTEN__
172 WebXRGamepad LastGamepadState[2]; // support 2 controllers (left and right)
173#endif
174};
175
176VTK_ABI_NAMESPACE_END
177#endif
a simple class to control print indentation
Definition vtkIndent.h:108
Allocate and hold a VTK object.
Definition vtkNew.h:167
abstract specification for renderers
VR rendering window.
static vtkWebXRRenderWindowInteractor * New()
void AddAction(const std::string &path, const std::function< void(vtkEventData *)> &)
Assign an event or std::function to an event path.
bool LoadActions(const std::string &actionFilename)
Load JSON actions file from given path for interactions.
const ActionData * GetActionData(const std::string &actionName)
static void StartXR(SessionMode mode=SessionMode::VR, vtkTypeUInt32 requiredFeatures=1, vtkTypeUInt32 optionalFeatures=2)
Starts and Stops a WebXR Session.
std::map< WebXRInput, ActionData * > ButtonToActionMap
void DoOneEvent(vtkVRRenderWindow *renWin, vtkRenderer *ren) override
Implement the event loop.
void UpdateXRControllers()
Updates WebXR controllers state and invoke corresponding events.
void TerminateApp() override
Stop the XR session and stop the emscripten main loop.
void Initialize() override
Initialize the event handler.
const ActionData * GetActionData(WebXRHandedness hand, WebXRGamepadButtonMapping button, WebXRInputPoseMode mode)
void AddAction(const std::string &path, const vtkCommand::EventIds &)
Assign an event or std::function to an event path.
std::map< std::string, ActionData > ActionMap
void StartEventLoop() override
Start emscripten main loop with an empty function.
~vtkWebXRRenderWindowInteractor() override
void AddAction(const std::string &path, bool isAnalog, const std::function< void(vtkEventData *)> &) override
Assign an event or std::function to an event path.
static void StopXR()
Starts and Stops a WebXR Session.
void ConvertWebXRPoseToWorldCoordinates(const WebXRRigidTransform &xrPose, double pos[3], double wxyz[4], double ppos[3], double wdir[3])
Retrieve camera's world coordinates from WebXR API's pose.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void AddAction(const std::string &path, const vtkCommand::EventIds &, bool isAnalog) override
Assign an event or std::function to an event path.
void ApplyAction(const ActionData &actionData, vtkEventDataDevice3D *ed)
Invoke event or callback of an action.
WebXR Gamepad see https://www.w3.org/TR/2024/WD-webxr-gamepads-module-1-20240409/#xr-standard-heading...
Definition vtkWebXR.h:144
WebXR rigid transform.
Definition vtkWebXR.h:83
vtkEventDataDeviceInput
Minimal WebXR Device API wrapper.
WebXRInputPoseMode
WebXR 'XRSessionMode' enum.
Definition vtkWebXR.h:76
WebXRGamepadButtonMapping
Definition vtkWebXR.h:115
WebXRHandedness
WebXR handedness.
Definition vtkWebXR.h:45
@ WEBXR_SESSION_MODE_INLINE
Definition vtkWebXR.h:62
@ WEBXR_SESSION_MODE_IMMERSIVE_AR
Definition vtkWebXR.h:64
@ WEBXR_SESSION_MODE_IMMERSIVE_VR
Definition vtkWebXR.h:63
#define VTK_MARSHALAUTO