VTK  9.7.1
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
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 
24 VTK_ABI_NAMESPACE_BEGIN
25 
26 class VTKRENDERINGWEBXR_EXPORT VTK_MARSHALAUTO vtkWebXRRenderWindowInteractor
28 {
29 public:
31  void PrintSelf(ostream& os, vtkIndent indent) override;
33 
34  enum class SessionMode
35  {
39  };
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 
69  void ConvertWebXRPoseToWorldCoordinates(const WebXRRigidTransform& xrPose, double pos[3],
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;
91  void AddAction(
92  const std::string& path, bool isAnalog, const std::function<void(vtkEventData*)>&) override;
94 
98  void UpdateXRControllers();
99 
101 
109  static void StartXR(SessionMode mode = SessionMode::VR, vtkTypeUInt32 requiredFeatures = 1,
110  vtkTypeUInt32 optionalFeatures = 2);
111  static void StopXR();
113 
114 protected:
116  ~vtkWebXRRenderWindowInteractor() override;
117 
119  {
120  public:
123  std::function<void(vtkEventData*)> Function;
124  bool UseFunction = false;
125  bool IsHandPose = false;
126  };
127 
131  bool LoadActions(const std::string& actionFilename);
132  const ActionData* GetActionData(const std::string& actionName);
133  const ActionData* GetActionData(
135 
139  void ApplyAction(const ActionData& actionData, vtkEventDataDevice3D* ed);
140 
141  std::map<std::string, ActionData> ActionMap;
142  struct WebXRInput
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 
166 private:
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 
176 VTK_ABI_NAMESPACE_END
177 #endif
std::map< WebXRInput, ActionData * > ButtonToActionMap
virtual void DoOneEvent(vtkVRRenderWindow *renWin, vtkRenderer *ren)=0
Implements the event loop.
vtkEventDataDeviceInput
Definition: vtkEventData.h:28
Implements VR specific functions required by vtkRenderWindowInteractor.
WebXR rigid transform.
Definition: vtkWebXR.h:82
VR rendering window.
Minimal WebXR Device API wrapper.
abstract specification for renderers
Definition: vtkRenderer.h:63
std::map< std::string, ActionData > ActionMap
WebXRInputPoseMode
WebXR 'XRSessionMode' enum.
Definition: vtkWebXR.h:75
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
implements WebXR specific functions required by vtkVRRenderWindowInteractor.
a simple class to control print indentation
Definition: vtkIndent.h:28
WebXRHandedness
WebXR handedness.
Definition: vtkWebXR.h:44
virtual void AddAction(const std::string &path, const vtkCommand::EventIds &, bool isAnalog)=0
Assign an event or std::function to an event path.
void Initialize() override
Initialize the event handler.
WebXRGamepadButtonMapping
Definition: vtkWebXR.h:114
void StartEventLoop() override
This will start up the event loop and never return.
virtual void TerminateApp()
This function is called on 'q','e' keypress if exitmethod is not specified and should be overridden b...
static vtkRenderWindowInteractor3D * New()
Construct object so that light follows camera motion.
#define VTK_MARSHALAUTO
WebXR Gamepad see https://www.w3.org/TR/2024/WD-webxr-gamepads-module-1-20240409/#xr-standard-heading...
Definition: vtkWebXR.h:143