Ocean
VRNativeApplicationAdvanced.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_META_QUEST_OPENXR_APPLICATION_VR_NATIVE_APPLICATION_ADVANCED_H
9 #define META_OCEAN_PLATFORM_META_QUEST_OPENXR_APPLICATION_VR_NATIVE_APPLICATION_ADVANCED_H
10 
15 
18 
19 #include "ocean/rendering/Scene.h"
20 
22 
23 #include <queue>
24 
25 namespace Ocean
26 {
27 
28 namespace Platform
29 {
30 
31 namespace Meta
32 {
33 
34 namespace Quest
35 {
36 
37 namespace OpenXR
38 {
39 
40 namespace Application
41 {
42 
43 /**
44  * This class implements an advanced Oculus (VR) application using Ocean's scene graph rendering pipline (Rendering::GLESceneGraph).
45  * In addition to `VRNativeApplication`, this provides the following features
46  * - Controller rendering
47  * - Hand rendering
48  * - Importers for 3D file formats
49  * - Passthrough
50  * @ingroup platformmetaquestopenxrapplication
51  */
52 class OCEAN_PLATFORM_META_QUEST_OPENXR_APPLICATION_EXPORT VRNativeApplicationAdvanced : public VRNativeApplication
53 {
54  private:
55 
56  /**
57  * Definition of a pair holding a 3D model filename and an optional 6-DOF transformation.
58  */
59  typedef std::pair<std::string, HomogenousMatrix4> ModelFilenamePair;
60 
61  /**
62  * Definition of a queue holding model filename pairs.
63  */
64  typedef std::queue<ModelFilenamePair> ModelFilenamePairQueue;
65 
66  /**
67  * Definition of a queue holdingfilename.
68  */
69  typedef std::queue<std::string> ModelFilenameQueue;
70 
71  /**
72  * Definition of a pair combining scene description and rendering scene ids.
73  */
74  typedef std::pair<SceneDescription::SceneId, Rendering::ObjectId> SceneIdPair;
75 
76  /**
77  * Definition of a map mapping filenames to scene ids.
78  */
79  typedef std::unordered_map<std::string, SceneIdPair> SceneFilenameMap;
80 
81  public:
82 
83  /**
84  * Creates a new application object.
85  * @param androidApp The android app object as provided in the main function of the native activity, must be valid
86  */
87  explicit VRNativeApplicationAdvanced(struct android_app* androidApp);
88 
89  /**
90  * Destructs this object.
91  */
93 
94  /**
95  * Loads a new 3D model file to the scene.
96  * Once the scene is loaded, the onModelLoaded() event function will be called.
97  * @param modelFilename The filename of the 3D model to be loaded, must be valid
98  * @param world_T_model The transformation between model and world to be set after the model is loded, must be valid
99  * @see removeModel(), onModelLoaded().
100  */
101  void loadModel(std::string modelFilename, const HomogenousMatrix4& world_T_model = HomogenousMatrix4(true));
102 
103  /**
104  * Removes a 3D model file from the scene.
105  * Once the scene is removed, the onModelRemoved() event function will be called.
106  * @param modelFilename The filename of the 3D model to be removed, must be valid
107  * @see loadModel(), onModelRemoved().
108  */
109  void removeModel(std::string modelFilename);
110 
111  protected:
112 
113  /**
114  * Disabled copy constructor.
115  * @param nativeApplication Application object which would have been copied
116  */
117  VRNativeApplicationAdvanced(const VRNativeApplicationAdvanced& nativeApplication) = delete;
118 
119  /**
120  * Returns the names of the necessary OpenXR extensions the application needs.
121  * @see NativeApplication::necessaryOpenXRExtensionNames().
122  */
124 
125  /**
126  * Removes all 3D scene models from the scenegraph which are queued to be removed.
127  */
128  virtual void handleModelRemoveQueue();
129 
130  /**
131  * Removes a loaded 3D scene model from the scenegraph.
132  * @param sceneIdPair The pair combining the scene id and rendering object id of a model to be removed, must be valid
133  * @param filename The filename of the 3D model to be removed, must be valid
134  */
135  virtual void invokeRemoveModel(const SceneIdPair& sceneIdPair, const std::string& filename);
136 
137  /**
138  * Loads all 3D scene models into the scenegraph which are queued to be loaded.
139  * @param predictedDisplayTime The timestamp which will be used for rendering, must be valid
140  */
141  virtual void handleModelLoadQueue(const Timestamp& predictedDisplayTime);
142 
143  /**
144  * Event function called whenever the session is ready, when the session state changed to XR_SESSION_STATE_READY.
145  * @see VRNativeApplication::onOpenXRSessionReady().
146  */
147  void onOpenXRSessionReady() override;
148 
149  /**
150  * Event function called whenever the session is stopping, when the session state changed to XR_SESSION_STATE_STOPPING.
151  * @see RNativeApplication::onOpenXRSessionStopping().
152  */
153  void onOpenXRSessionStopping() override;
154 
155  /**
156  * The event function which is called when all resources should finally be released.
157  * @see NativeApplication::onReleaseResources().
158  */
159  void onReleaseResources() override;
160 
161  /**
162  * Event function called after the framebuffer has been initialized.
163  * @see VRNativeApplication::onFramebufferInitialized().
164  */
165  void onFramebufferInitialized() override;
166 
167  /**
168  * Event function called before the framebuffer will be released.
169  * @see VRNativeApplication::onFramebufferReleasing().
170  */
171  void onFramebufferReleasing() override;
172 
173  /**
174  * Event function allows to add custom compositor layers at the very back.
175  * @see VRNativeApplication::onAddCompositorBackLayers().
176  */
177  void onAddCompositorBackLayers(XrCompositorLayerUnions& xrCompositorLayerUnions) override;
178 
179  /**
180  * Events function called before the scene is rendered.
181  * @see VRNativeApplication::onPreRender().
182  */
183  void onPreRender(const XrTime& xrPredictedDisplayTime, const Timestamp& predictedDisplayTime) override;
184 
185  /**
186  * Event function called after a new 3D model has been loaded or has failed to load.
187  * @param modelFilename The filename of the model which has been loaded, will be valid
188  * @param scene The scene object of the new model, will be invalid if the model could not be loaded
189  */
190  virtual void onModelLoaded(const std::string& modelFilename, const Rendering::SceneRef& scene);
191 
192  /**
193  * Event function called after a 3D model has been removed.
194  * @param modelFilename The filename of the model which has been removed, will be valid
195  */
196  virtual void onModelRemoved(const std::string& modelFilename);
197 
198  /**
199  * Disabled copy operator.
200  * @param nativeApplication Application object which would have been copied
201  * @return Reference to this object
202  */
204 
205  protected:
206 
207  /// The visualizer for controllers.
209 
210  /// The visualizer for hands.
212 
213  /// The accessor for most recent hand poses.
215 
216  /// The passhrough object.
218 
219  private:
220 
221  /// The pending 3D model files which will be loaded once the access to the disk is granted.
223 
224  /// The pending 3D model files to be removed.
226 
227  /// The map combining filenames with scene ids.
229 
230  /// The lock for the 3D model filename queue.
232 
233  /// The timestamp when the scene description was updated the last time.
235 };
236 
237 #ifdef OCEAN_PLATFORM_QUEST_OPENXR_APPLICATION_USE_EXTERNAL_RESOURCES
238 
239 /**
240  * Registers external resources.
241  * @ingroup platformmetaquestopenxrapplication
242  */
244 
245 /**
246  * Un-registers external resources.
247  * @ingroup platformmetaquestopenxrapplication
248  */
250 
251 #endif
252 
253 }
254 
255 }
256 
257 }
258 
259 }
260 
261 }
262 
263 }
264 
265 #endif // META_OCEAN_PLATFORM_META_QUEST_OPENXR_APPLICATION_VR_NATIVE_APPLICATION_ADVANCED_H
This class implements a recursive lock object.
Definition: Lock.h:31
std::unordered_set< std::string > StringSet
Definition of an unordered set holding strings.
Definition: NativeApplication.h:69
This class implements helper functions allowing to visualize the controllers of Quest headsets in an ...
Definition: openxr/application/VRControllerVisualizer.h:41
This class implements helper functions allowing to visualize the hand mesh used by hand tracking (Nim...
Definition: VRHandVisualizer.h:46
This class implements an advanced Oculus (VR) application using Ocean's scene graph rendering pipline...
Definition: VRNativeApplicationAdvanced.h:53
void onOpenXRSessionReady() override
Event function called whenever the session is ready, when the session state changed to XR_SESSION_STA...
VRControllerVisualizer vrControllerVisualizer_
The visualizer for controllers.
Definition: VRNativeApplicationAdvanced.h:208
virtual void onModelLoaded(const std::string &modelFilename, const Rendering::SceneRef &scene)
Event function called after a new 3D model has been loaded or has failed to load.
std::pair< std::string, HomogenousMatrix4 > ModelFilenamePair
Definition of a pair holding a 3D model filename and an optional 6-DOF transformation.
Definition: VRNativeApplicationAdvanced.h:59
void onFramebufferInitialized() override
Event function called after the framebuffer has been initialized.
HandPoses handPoses_
The accessor for most recent hand poses.
Definition: VRNativeApplicationAdvanced.h:214
void onAddCompositorBackLayers(XrCompositorLayerUnions &xrCompositorLayerUnions) override
Event function allows to add custom compositor layers at the very back.
Lock modelFilenameQueueLock_
The lock for the 3D model filename queue.
Definition: VRNativeApplicationAdvanced.h:231
void onFramebufferReleasing() override
Event function called before the framebuffer will be released.
Passthrough passthrough_
The passhrough object.
Definition: VRNativeApplicationAdvanced.h:217
ModelFilenameQueue modelFilenameRemoveQueue_
The pending 3D model files to be removed.
Definition: VRNativeApplicationAdvanced.h:225
VRNativeApplicationAdvanced(const VRNativeApplicationAdvanced &nativeApplication)=delete
Disabled copy constructor.
std::pair< SceneDescription::SceneId, Rendering::ObjectId > SceneIdPair
Definition of a pair combining scene description and rendering scene ids.
Definition: VRNativeApplicationAdvanced.h:74
virtual void handleModelRemoveQueue()
Removes all 3D scene models from the scenegraph which are queued to be removed.
void removeModel(std::string modelFilename)
Removes a 3D model file from the scene.
void onReleaseResources() override
The event function which is called when all resources should finally be released.
Timestamp sceneDescriptionUpdateTimestamp_
The timestamp when the scene description was updated the last time.
Definition: VRNativeApplicationAdvanced.h:234
std::queue< std::string > ModelFilenameQueue
Definition of a queue holdingfilename.
Definition: VRNativeApplicationAdvanced.h:69
VRHandVisualizer vrHandVisualizer_
The visualizer for hands.
Definition: VRNativeApplicationAdvanced.h:211
virtual void invokeRemoveModel(const SceneIdPair &sceneIdPair, const std::string &filename)
Removes a loaded 3D scene model from the scenegraph.
virtual void onModelRemoved(const std::string &modelFilename)
Event function called after a 3D model has been removed.
ModelFilenamePairQueue modelFilenameLoadQueue_
The pending 3D model files which will be loaded once the access to the disk is granted.
Definition: VRNativeApplicationAdvanced.h:222
StringSet necessaryOpenXRExtensionNames() const override
Returns the names of the necessary OpenXR extensions the application needs.
void onOpenXRSessionStopping() override
Event function called whenever the session is stopping, when the session state changed to XR_SESSION_...
std::unordered_map< std::string, SceneIdPair > SceneFilenameMap
Definition of a map mapping filenames to scene ids.
Definition: VRNativeApplicationAdvanced.h:79
SceneFilenameMap sceneFilenameMap_
The map combining filenames with scene ids.
Definition: VRNativeApplicationAdvanced.h:228
std::queue< ModelFilenamePair > ModelFilenamePairQueue
Definition of a queue holding model filename pairs.
Definition: VRNativeApplicationAdvanced.h:64
void loadModel(std::string modelFilename, const HomogenousMatrix4 &world_T_model=HomogenousMatrix4(true))
Loads a new 3D model file to the scene.
VRNativeApplicationAdvanced & operator=(const VRNativeApplicationAdvanced &nativeApplication)=delete
Disabled copy operator.
virtual void handleModelLoadQueue(const Timestamp &predictedDisplayTime)
Loads all 3D scene models into the scenegraph which are queued to be loaded.
void onPreRender(const XrTime &xrPredictedDisplayTime, const Timestamp &predictedDisplayTime) override
Events function called before the scene is rendered.
VRNativeApplicationAdvanced(struct android_app *androidApp)
Creates a new application object.
This class implements a basic OpenXR (VR) application using Ocean's scene graph rendering pipline (Re...
Definition: VRNativeApplication.h:53
std::vector< XrCompositorLayerUnion > XrCompositorLayerUnions
Definition of a vector holding xrCompositorLayerUnion objects.
Definition: VRNativeApplication.h:86
This class implements a wrapper for OpenXR-based hand tracking.
Definition: HandPoses.h:41
This class implements a wrapper for passthrough.
Definition: Passthrough.h:36
This class implements a timestamp.
Definition: Timestamp.h:36
HomogenousMatrixT4< Scalar > HomogenousMatrix4
Definition of the HomogenousMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag eit...
Definition: HomogenousMatrix4.h:37
void VRNativeApplicationAdvanced_registerExternalResources()
Registers external resources.
void VRNativeApplicationAdvanced_unregisterExternalResources()
Un-registers external resources.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15