VR-Engage  2.2
Loading...
Searching...
No Matches
pilotRenderUpdater.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file pilotRenderUpdater.h
7//! \brief Defines render components for the pilot role including instrument displays
8//! \ingroup vrePilotFrontend
9
10#pragma once
11
13#include "vreUtil/attribute.h"
14
17
18#include <vrvOsg/DtChannelSpecificGroup.h>
19#include <vrvUtil/DtChannelConfiguration.h>
20
21#include <osg/Node>
22#include <osg/NodeVisitor>
23#include <osg/Texture2D>
24#include <osg/BoundingBox>
25
27
28namespace makVre
29{
30
32{
33//! \ingroup RoleConfigParams
34//! \defgroup PilotRenderUpdaterRoleParams Pilot Render Updater Role Parameters
35//! \roleInherits{PlayerComponentRoleParams}
36//! Configuration Options for pilot render updater component.
37//! @{
38
39//! \vreRoleParam{liveTextures,table,{},pilotRenderUpdater,Configuration table for live texture definitions used in cockpit displays and instruments.}
40constexpr const char* liveTextures = "liveTextures";
41
42//! \vreRoleParam{renderCockpitGeometryOnly,bool,false,pilotRenderUpdater,Whether to render only the cockpit geometry without other scene elements.}
43constexpr const char* renderCockpitGeometryOnly = "renderCockpitGeometryOnly";
44
45//! @}
46} // namespace PilotRenderUpdaterConfig
47
48} // namespace makVre
49
50namespace makVrv
51{
52//! \brief Forward declaration of the display element class
53class DtDe;
54
55//! \brief Forward declaration of the model definition class
56class DtModelDefinition;
57
58//! \brief Forward declaration of the model instance class
59class DtModelInstance;
60
61//! \brief Forward declaration of the scene object class
62class DtSceneObject;
63
64//! \brief Forward declaration of the scene object agent class
65class DtSceneObjectAgent;
66
67//! \brief Forward declaration of the articulated model agent class
68class DtArticulatedModelAgent;
69
70//! \brief Forward declaration of the OSG observer object class
71class DtOsgObserverObject;
72
73//! \brief Forward declaration of the observer class
74class DtObserver;
75
76//! \brief Forward declaration of the channel-specific group class
77class DtChannelSpecificGroup;
78
79//! \brief Forward declaration of the channel class
80class DtChannel;
81}; // namespace makVrv
82
83namespace makVre
84{
85//! \brief Forward declaration of the entity resolver class
87
88//! \brief Forward declaration of the instrument panel manager class
90
91//! \brief Forward declaration of the scene object mimic updater agent class
93
94//! \brief Forward declaration of the camera structure
95struct DtCameraStruct;
96
97//! \brief Node visitor for replacing instrument textures in cockpit models
98//!
99//! DtInstrumentTextureReplacer traverses a scene graph to find and replace
100//! specific textures with render-to-texture (RTT) displays for aircraft instruments.
101//! It can also collect geometry information about the textures for proper positioning.
102class PILOT_DLL DtInstrumentTextureReplacer : public osg::NodeVisitor
103{
104public:
105 //! \brief Constructor
106 //! \param targetTextureName Name of the texture to replace
107 //! \param replacementTexture Reference to the replacement texture
108 //! \param isHud Flag indicating if this is a HUD texture
109 //! \param findPosition Flag indicating whether to collect geometry information
110 //! \param overrideNormal Optional normal vector to override the calculated normal
111 DtInstrumentTextureReplacer(const std::string& targetTextureName, osg::ref_ptr<osg::Texture2D> replacementTexture,
112 bool isHud = false, bool findPosition = false, const osg::Vec3* overrideNormal = NULL);
113
114 //! \brief Virtual destructor
116
117 //! \brief The visitor apply method used to traverse the scene-graph
118 //! \param node The osg::Node being visited
119 //!
120 //! Called during scene-graph traversal. Do not directly call this function.
121 virtual void apply(osg::Node& node) override;
122
123 //! \brief The visitor apply method for geodes
124 //! \param geode The osg::Geode being visited
125 //!
126 //! Called during scene-graph traversal. Do not directly call this function.
127 //! Currently commented out and not used.
128 // virtual void apply(osg::Geode& geode);
129
130 //! \brief Checks if the target texture was found
131 //! \return True if the target texture was found, false otherwise
132 bool foundTarget() const;
133
134 //! \brief Gets the normal vector of the target geometry
135 //! \return Normal vector of the target geometry
136 osg::Vec3 targetNormal() const;
137
138 //! \brief Gets the minimum bounds of the target geometry
139 //! \return Minimum bounds vector
140 osg::Vec3 targetBoundsMin() const;
141
142 //! \brief Gets the maximum bounds of the target geometry
143 //! \return Maximum bounds vector
144 osg::Vec3 targetBoundsMax() const;
145
146protected:
147 //! \brief Replaces a texture in the given state set
148 //! \param ss State set containing the texture to replace
149 //! \param node Node associated with the state set
150 //! \return True if the texture was replaced, false otherwise
151 virtual bool replaceTexture(osg::StateSet& ss, osg::Node& node);
152
153 //! \brief Collects geometry information for the target texture
154 //! \param node Node containing the geometry
155 //! \param nodePath Path to the node in the scene graph
156 //! \return True if geometry was collected, false otherwise
157 virtual bool collectGeometry(const osg::Node& node, const osg::NodePath& nodePath);
158
159 //! \brief Name of the texture to replace
161
162 //! \brief Reference to the replacement texture
163 osg::ref_ptr<osg::Texture2D> myReplacementTexture;
164
165 //! \brief Flag indicating if this is a HUD texture
167
168 //! \brief Flag indicating if the target texture was found
170
171 //! \brief Flag indicating if geometry information should be collected
173
174 //! \brief Flag indicating whether to continue traversal after finding the target
176
177 //! \brief Structure containing geometry information for the target texture
178 struct Geometry
179 {
180 osg::Vec3 normal; //!< Average normal of RTT geometry
181 osg::Plane plane; //!< Plane on farthest point along average normal
182 osg::BoundingBox box; //!< Box holding geometry bounds in model space
183 osg::Vec3 min; //!< Minimum RTT geometry bounds projected on plane
184 osg::Vec3 max; //!< Maximum RTT geometry bounds projected on plane
185 };
186
187 //! \brief Collected geometry information for the target texture
189
190 //! \brief Flag indicating whether to use the provided override normal
192};
193
194//! \brief Type identifier constant for DtPilotRenderUpdater components
195//!
196//! This constant defines the string identifier used to identify DtPilotRenderUpdater
197//! component types within the VR-Engage framework. It is used for component
198//! registration, type checking, and serialization operations.
199constexpr const char* DtPilotRenderUpdaterType = "DtPilotRenderUpdater";
200
201//! \brief Render updater component for the pilot role
202//!
203//! DtPilotRenderUpdater handles render-to-texture (RTT) channels and channel
204//! configurations for aircraft cockpit displays and instruments. It manages
205//! cockpit model initialization, instrument panel updates, and HUD elements.
207{
208public:
209 //! \brief Default constructor
211
212 //! \brief Virtual destructor
213 virtual ~DtPilotRenderUpdater() override;
214
215 //! \brief Initializes the render updater component
216 //! \param player Pointer to the player station
217 //! \param config Configuration settings for initialization
218 //! \return True if initialization was successful, false otherwise
219 virtual bool initialize(DtPlayerStation* player, DtInitTable& config) override;
220
221 //! \brief Performs post-initialization setup
222 //! \return True if post-initialization was successful, false otherwise
223 virtual bool postInitialize() override;
224
225 //! \brief Updates rendering elements for the current frame
226 //! \param dt Delta time since the last frame in seconds
227 virtual void tick(double dt) override;
228
229 //! \brief Cleans up resources when the component is being shut down
230 virtual void shutdown() override;
231
232 //! \brief Returns the component type identifier
233 //! \return String identifier for this component type
234 //!
235 //! Returns the type identifier string for this component, which is used
236 //! by the VR-Engage framework for component identification and management.
237 //! The returned value matches DtPilotRenderUpdaterType.
238 virtual const char* type() const override;
239
240 //! \brief Handles render texture initialized messages
241 //! \param msg Pointer to the message being processed
242 //! \return Message processing result
244
245 //! \brief Handles sensor data messages
246 //! \param msg Pointer to the message being processed
247 //! \return Message processing result
248 //!
249 //! Caches sensor contacts, so tick can convert to screen coordinates for the HUD.
251
252 //! \brief Overrides the camera mask for a channel
253 //! \param channel Pointer to the channel to override
254 //! \param mask New camera mask to apply
255 //! \return The original camera mask
256 static unsigned int overrideChannelCameraMask(makVrv::DtChannel* channel, unsigned int mask);
257
258protected:
259 //! \brief Initializes render textures for a model instance
260 //! \param modelInstance Pointer to the model instance
261 //! \return Number of render textures initialized
262 virtual int initRenderTexturesFor(makVrv::DtModelInstance* modelInstance);
263
264 //! \brief Replaces RTT textures on a scene object
265 //! \param so Pointer to the scene object
266 //! \param cameraStruct Pointer to the camera structure
267 //! \return True if textures were replaced successfully, false otherwise
268 virtual bool replaceRttTexturesOn(makVrv::DtSceneObject* so, DtCameraStruct* cameraStruct);
269
270 //! \brief Enables RTT effect texture for texture swapping
271 //! \param cameraStruct Pointer to the camera structure
272 //! \param addToList Flag indicating whether to add the texture to the effect textures list
273 //! \return True if the texture was enabled successfully, false otherwise
274 virtual bool enableRttEffectTexture(DtCameraStruct* cameraStruct, bool addToList = true);
275
276 //! \brief Turns off the RTT effect textures and restores the original textures
278
279 //! \brief Initializes cockpit objects
280 //! \return True if initialization was successful, false otherwise
281 //!
282 //! Called during tick. Maps RTT texture indices to elements in the 3D model.
283 virtual bool initCockpitObjects();
284
285 //! \brief Destroys cockpit objects and releases resources
286 virtual void destroyCockpitObjects();
287
288 //! \brief Initializes ownship-only rendering mode
289 //! \return True if initialization was successful, false otherwise
290 virtual bool initOwnshipOnlyRender();
291
292 //! \brief Reverts the ownship-only rendering mode
293 virtual void undoOwnshipOnlyRender();
294
295 //! \brief Updates vision block observers for cockpit views
297
298 //! \brief Handles changes in VR state
299 //! \param enabled True if VR is enabled, false otherwise
300 virtual void onVrStateChanged(bool enabled);
301
302 //! \brief Handles channel modification events
303 //! \param deName Name of the display element
304 //! \param winName Name of the window
305 //! \param channelName Name of the modified channel
306 //! \param config New channel configuration
307 virtual void slot_channelModified(const std::string& deName, const std::string& winName,
308 const std::string& channelName, const makVrv::DtChannelConfiguration& config);
309
310 //! \brief Initializes a 3D cockpit model with instruments
311 //!
312 //! Initialization to be done when using a "real" 3D cockpit model.
313 //! Sets up render-to-texture elements for instruments.
314 virtual void initRealCockpit();
315
316 //! \brief Updates HUD contact positions
317 //!
318 //! Updates HUD contact positions based on contact locations and
319 //! current position and orientation of ownship.
320 virtual void updateHudContacts();
321
322 //! \brief Pointer to the instrument panel manager
324
325 //! \brief Aircraft marking text
326 std::string myMarkingText;
327
328 //! \brief Pointer to the cockpit model definition
329 const makVrv::DtModelDefinition* myCockpitModelDef;
330
331 //! \brief Agent for the cockpit articulated model
332 makVrv::DtArticulatedModelAgent* myCockpitModelAgent;
333
334 //! \brief Agent for the cockpit scene object
335 makVrv::DtSceneObjectAgent* myCockpitSceneObjectAgent;
336
337 //! \brief Agent for the cockpit updater
339
340 //! \brief Flag indicating if cockpit objects are initialized
342
343 //! \brief Flag indicating if cockpit models are initialized
345
346 //! \brief Map of RTT definitions indexed by name
347 std::map<std::string, DtInitTable> myRttDefs;
348
349 //! \brief Pointer to the ownship scene object
350 makVrv::DtSceneObject* myOwnshipSceneObject;
351
352 //! \brief Flag indicating if only the model should be rendered
354
355 //! \brief Flag indicating if ownship-only rendering is desired
357
358 //! \brief Flag indicating if ownship-only rendering is active
360
361 //! \brief Flag indicating if ownship was set up in VR mode
363
364 //! \brief Reference to the ownship node group
365 osg::ref_ptr<makVrv::DtChannelSpecificGroup> myOwnshipNode;
366
367 //! \brief Saved sky mask for ownship-only rendering
368 unsigned int mySavedSkyMask;
369
370 //! \brief Saved cloud mask for ownship-only rendering
371 unsigned int mySavedCloudMask;
372
373 //! \brief Saved camera mask for ownship-only rendering
374 unsigned int mySavedCameraMask;
375
376 //! \brief Mask bit for the ownship
377 unsigned int myOwnshipMaskBit;
378
379 //! \brief Pointer to the OSG observer object
380 makVrv::DtOsgObserverObject* myOsgObserver;
381
382 //! \brief Structure containing vision block geometry information
384 {
385 osg::Quat modelSpaceCamRot; //!< Camera rotation in model space
386 osg::Vec3 modelSpaceRttMin; //!< Minimum extent of RTT in model space
387 osg::Vec3 modelSpaceRttMax; //!< Maximum extent of RTT in model space
388 osg::Vec3 viewOffset; //!< Offset for the view
389 osg::Quat viewRotation; //!< Rotation for the view
390 float viewZoom; //!< Zoom factor for the view
391 };
392
393 //! \brief List of vision blocks with their associated camera structures
394 std::list<std::pair<VisionBlockGeometry, DtCameraStruct*>> myVisionBlocks;
395
396 //! \brief Vector of effect texture camera structures
397 std::vector<DtCameraStruct*> myEffectTextures;
398
399 //! \brief Vector of sensor contacts for HUD display
400 std::vector<SensorDataMessage::SensorContact> mySensorContacts;
401};
402}; // namespace makVre
Provides attribute handling system for hierarchical data storage and manipulation.
Entity resolution and mapping system.
Definition entityResolver.h:52
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Manager for instrument panels, gimbal sensors, and specialized views.
Definition instrumentPanelManager.h:44
virtual void apply(osg::Node &node) override
The visitor apply method used to traverse the scene-graph.
virtual bool replaceTexture(osg::StateSet &ss, osg::Node &node)
Replaces a texture in the given state set.
osg::ref_ptr< osg::Texture2D > myReplacementTexture
Reference to the replacement texture.
Definition pilotRenderUpdater.h:163
bool myTraverseOnTarget
Flag indicating whether to continue traversal after finding the target.
Definition pilotRenderUpdater.h:175
osg::Vec3 targetBoundsMin() const
Gets the minimum bounds of the target geometry.
virtual bool collectGeometry(const osg::Node &node, const osg::NodePath &nodePath)
Collects geometry information for the target texture.
osg::Vec3 targetNormal() const
Gets the normal vector of the target geometry.
bool myIsHud
Flag indicating if this is a HUD texture.
Definition pilotRenderUpdater.h:166
Geometry myGeometry
Collected geometry information for the target texture.
Definition pilotRenderUpdater.h:188
bool myUseOverrideNormal
Flag indicating whether to use the provided override normal.
Definition pilotRenderUpdater.h:191
osg::Vec3 targetBoundsMax() const
Gets the maximum bounds of the target geometry.
std::string myTargetTextureName
Name of the texture to replace.
Definition pilotRenderUpdater.h:160
bool myWantsGeometry
Flag indicating if geometry information should be collected.
Definition pilotRenderUpdater.h:172
bool myFoundTarget
Flag indicating if the target texture was found.
Definition pilotRenderUpdater.h:169
bool foundTarget() const
The visitor apply method for geodes.
virtual ~DtInstrumentTextureReplacer() override
Virtual destructor.
DtInstrumentTextureReplacer(const std::string &targetTextureName, osg::ref_ptr< osg::Texture2D > replacementTexture, bool isHud=false, bool findPosition=false, const osg::Vec3 *overrideNormal=NULL)
Constructor.
virtual void undoOwnshipOnlyRender()
Reverts the ownship-only rendering mode.
virtual void destroyCockpitObjects()
Destroys cockpit objects and releases resources.
bool myRenderModelOnly
Flag indicating if only the model should be rendered.
Definition pilotRenderUpdater.h:353
osg::ref_ptr< makVrv::DtChannelSpecificGroup > myOwnshipNode
Reference to the ownship node group.
Definition pilotRenderUpdater.h:365
bool myMadeOwnshipOnly
Flag indicating if ownship-only rendering is active.
Definition pilotRenderUpdater.h:359
std::vector< DtCameraStruct * > myEffectTextures
Vector of effect texture camera structures.
Definition pilotRenderUpdater.h:397
virtual void onVrStateChanged(bool enabled)
Handles changes in VR state.
makVrv::DtSceneObjectAgent * myCockpitSceneObjectAgent
Agent for the cockpit scene object.
Definition pilotRenderUpdater.h:335
DtSceneObjectMimicUpdaterAgent * myCockpitUpdaterAgent
Agent for the cockpit updater.
Definition pilotRenderUpdater.h:338
DtPilotRenderUpdater()
Default constructor.
std::list< std::pair< VisionBlockGeometry, DtCameraStruct * > > myVisionBlocks
List of vision blocks with their associated camera structures.
Definition pilotRenderUpdater.h:394
bool myWantOwnshipOnly
Flag indicating if ownship-only rendering is desired.
Definition pilotRenderUpdater.h:356
virtual void tick(double dt) override
Updates rendering elements for the current frame.
bool myCockpitModelsInitialized
Flag indicating if cockpit models are initialized.
Definition pilotRenderUpdater.h:344
virtual bool enableRttEffectTexture(DtCameraStruct *cameraStruct, bool addToList=true)
Enables RTT effect texture for texture swapping.
virtual bool postInitialize() override
Performs post-initialization setup.
virtual void slot_channelModified(const std::string &deName, const std::string &winName, const std::string &channelName, const makVrv::DtChannelConfiguration &config)
Handles channel modification events.
unsigned int mySavedCameraMask
Saved camera mask for ownship-only rendering.
Definition pilotRenderUpdater.h:374
virtual void disableRttEffectTextures()
Turns off the RTT effect textures and restores the original textures.
makVrv::DtSceneObject * myOwnshipSceneObject
Pointer to the ownship scene object.
Definition pilotRenderUpdater.h:350
makVrv::DtOsgObserverObject * myOsgObserver
Pointer to the OSG observer object.
Definition pilotRenderUpdater.h:380
virtual int initRenderTexturesFor(makVrv::DtModelInstance *modelInstance)
Initializes render textures for a model instance.
const makVrv::DtModelDefinition * myCockpitModelDef
Pointer to the cockpit model definition.
Definition pilotRenderUpdater.h:329
bool myDidOwnshipInVR
Flag indicating if ownship was set up in VR mode.
Definition pilotRenderUpdater.h:362
DtInstrumentPanelManager * myInstrumentPanelManager
Pointer to the instrument panel manager.
Definition pilotRenderUpdater.h:323
virtual void updateHudContacts()
Updates HUD contact positions.
virtual bool initialize(DtPlayerStation *player, DtInitTable &config) override
Initializes the render updater component.
virtual bool replaceRttTexturesOn(makVrv::DtSceneObject *so, DtCameraStruct *cameraStruct)
Replaces RTT textures on a scene object.
std::vector< SensorDataMessage::SensorContact > mySensorContacts
Vector of sensor contacts for HUD display.
Definition pilotRenderUpdater.h:400
makVrv::DtArticulatedModelAgent * myCockpitModelAgent
Agent for the cockpit articulated model.
Definition pilotRenderUpdater.h:332
std::string myMarkingText
Aircraft marking text.
Definition pilotRenderUpdater.h:326
unsigned int myOwnshipMaskBit
Mask bit for the ownship.
Definition pilotRenderUpdater.h:377
virtual bool initCockpitObjects()
Initializes cockpit objects.
bool myCockpitObjectsInitialized
Flag indicating if cockpit objects are initialized.
Definition pilotRenderUpdater.h:341
std::map< std::string, DtInitTable > myRttDefs
Map of RTT definitions indexed by name.
Definition pilotRenderUpdater.h:347
virtual ~DtPilotRenderUpdater() override
Virtual destructor.
virtual void updateVisionBlockObservers()
Updates vision block observers for cockpit views.
unsigned int mySavedCloudMask
Saved cloud mask for ownship-only rendering.
Definition pilotRenderUpdater.h:371
virtual bool initOwnshipOnlyRender()
Initializes ownship-only rendering mode.
static unsigned int overrideChannelCameraMask(makVrv::DtChannel *channel, unsigned int mask)
Overrides the camera mask for a channel.
virtual void shutdown() override
Cleans up resources when the component is being shut down.
virtual DtVreMessageResult handleSensorData(DtVreMessage *msg)
Handles sensor data messages.
virtual DtVreMessageResult handleRenderTextureInitialized(DtVreMessage *msg)
Handles render texture initialized messages.
virtual const char * type() const override
Returns the component type identifier.
virtual void initRealCockpit()
Initializes a 3D cockpit model with instruments.
unsigned int mySavedSkyMask
Saved sky mask for ownship-only rendering.
Definition pilotRenderUpdater.h:368
virtual DtPlayerStation & player()
Gets the player station.
DtPlayerComponent()
Constructor.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
Agent class for the scene object class: DtSceneObjectMimicUpdater.
Definition DtSceneObjectMimicUpdaterAgent.hpp:32
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
constexpr const char * liveTextures
Definition pilotRenderUpdater.h:40
constexpr const char * renderCockpitGeometryOnly
Definition pilotRenderUpdater.h:43
Defines export/import macros for the Pilot Frontend library.
#define PILOT_DLL
Definition export.h:19
Definition pilotRenderUpdater.h:32
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtPilotRenderUpdaterType
Type identifier constant for DtPilotRenderUpdater components.
Definition pilotRenderUpdater.h:199
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Definition appLauncherComponent.h:28
Defines the DtPlayerComponent base class for VR-Engage role components.
Structure that manages camera and render-to-texture for instrument panels.
Definition instrumentPanelManagerStructs.h:93
Structure containing geometry information for the target texture.
Definition pilotRenderUpdater.h:179
osg::Plane plane
Plane on farthest point along average normal.
Definition pilotRenderUpdater.h:181
osg::Vec3 min
Minimum RTT geometry bounds projected on plane.
Definition pilotRenderUpdater.h:183
osg::Vec3 max
Maximum RTT geometry bounds projected on plane.
Definition pilotRenderUpdater.h:184
osg::BoundingBox box
Box holding geometry bounds in model space.
Definition pilotRenderUpdater.h:182
osg::Vec3 normal
Average normal of RTT geometry.
Definition pilotRenderUpdater.h:180
Structure containing vision block geometry information.
Definition pilotRenderUpdater.h:384
osg::Quat viewRotation
Rotation for the view.
Definition pilotRenderUpdater.h:389
float viewZoom
Zoom factor for the view.
Definition pilotRenderUpdater.h:390
osg::Vec3 modelSpaceRttMax
Maximum extent of RTT in model space.
Definition pilotRenderUpdater.h:387
osg::Vec3 viewOffset
Offset for the view.
Definition pilotRenderUpdater.h:388
osg::Vec3 modelSpaceRttMin
Minimum extent of RTT in model space.
Definition pilotRenderUpdater.h:386
osg::Quat modelSpaceCamRot
Camera rotation in model space.
Definition pilotRenderUpdater.h:385
Defines the base class for all VREngage messages.