VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtSpeedTreeForest.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2025 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvSt/vrvSt.h>
15 #include <vrvCore/DtTreeRecord.h>
16 #include <vrvCore/DtForestObject.h>
17 #include <osg/ref_ptr>
18 #include <osg/PositionAttitudeTransform>
19 #include <osg/Geode>
20 #include <osg/BoundingBox>
21 
22 #include <OsgST_Forest.h>
23 
24 #include <unordered_set>
25 #include <unordered_map>
26 
27 #include <tbb/mutex.h>
28 
29 namespace makOsgSpeedTree
30 {
31  class TreeInstance;
32  struct TreeInstanceDescriptor;
33 }
34 
35 namespace makVrv
36 {
37  class DtAgentUpdateResolverInterface;
38  class DtSpeedTreeModelInstance;
39  class DtSpeedTreeCore;
40  class DtOsgCullVisitor;
41  class DtOsgCullVisitorParameters;
42  class DtGlDebugGroup;
43  class DtCoordinateConverter;
44  class DtOsgRenderer;
45  class DtSkyObjectManager;
46 
51  {
52  friend class DtSpeedTreeForestClassesCreator;
54  friend class DtForestDrawCallback;
55 
56  public:
57  //Destructor
58  virtual ~DtSpeedTreeForest();
59 
61  DtSpeedTreeForest() = delete;
62 
64  DtSpeedTreeForest(const DtSpeedTreeForest& other) = delete;
65 
67  DtSpeedTreeForest& operator=(const DtSpeedTreeForest& other) = delete;
68 
69  public:
73  virtual void setVisible(bool isVisible);
74 
75  virtual void addUniqueTree(DtTreeRecord& record);
76  virtual void removeTree(DtUniqueID record);
77  virtual void removeAllTrees();
78 
79  virtual DtUniqueID addUniqueTreesToUniqueCell(DtVectorTreeRecords& records);
80  virtual void removeAllUniqueTreesAndUniqueCell(DtUniqueID cellID);
81 
82  virtual void setTreeClippingPlane(float fFar);
83  virtual void getTreeClippingPlane(float& fFar);
84 
85  virtual void setTree3DLodDistances(float fNear, float fFar);
86  virtual void getTree3DLodDistances(float& fNear, float& fFar);
87 
88  virtual void setTreeBillboardDistances(float fStart, float fEnd);
89  virtual void getTreeBillboardDistances(float& fStart, float& fEnd);
90 
92  virtual void setBillboardFadeOutRange(float fRange);
94  virtual void getBillboardFadeOutRange(float& fRange);
95 
96  virtual void enableBillboardRendering(bool enable);
97  virtual bool isBillboardRenderingEnabled() const;
98 
99  virtual void enable3DTreeRendering(bool enable);
100  virtual bool is3DTreeRenderingEnabled() const;
101 
102  virtual void enableReceiveShadows(bool enable);
103  virtual bool isReceiveShadowsEnabled() const { return myReceiveShadows; }
104 
105  virtual void setBoundingBox(const osg::BoundingBox& box);
106  virtual const osg::BoundingBox& getBoundingBox(void) const;
107 
110  virtual osg::ref_ptr<osg::Node> getRootNode(void);
111 
114  virtual void programBoundCallback(osg::ref_ptr<makOsgSpeedTree::Forest> pForest,
115  const makOsgSpeedTree::TreeType* pTreeType, uint32 programID);
116 
119  virtual void slot_reloadShaders();
120 
122  virtual void slot_treeProfilingChanged(bool active);
123 
125  virtual void slot_useGlobalAmbientChanged(bool enabled);
126 
128  virtual void slot_useGlobalDiffuseChanged(bool enabled);
129 
132  virtual void slot_perPixelLightingEnabledChanged(bool enabled);
133 
135  virtual void slot_planarReflectionsShowSpeedTreesChanged(bool enabled);
136 
138  virtual void processUninitialized();
139 
141  virtual bool initialized();
142 
144  virtual tbb::mutex& mergeDrawMutex();
145 
147  virtual tbb::mutex& mergeUpdateMutex();
148 
150  virtual osg::ref_ptr<makOsgSpeedTree::Forest>& makSpeedTreeForest();
151  protected:
152  // The tree scale from the .earth file and the terrain patch
153  // are applied in DtStreamedSpeedTreeThread::handleRequest
154  // However, the user could also set the model definition
155  // scale. Store model def scale when we store the ST file name
156  // so we can multiply it into the record.scale().
158  {
159  std::string strSRTFileName;
161  };
162 
163  protected:
167  DtSpeedTreeForest(DtDe& de, DtUniqueID id, const std::string& strVisManagerType);
168 
169  protected:
171  void init(const std::string& strVisManagerType);
172 
173  virtual void connectSignals(void);
174 
175  virtual osg::Vec3f computeWindDirection(float fDirection);
176 
177  virtual void setWindStrength(float fStrength);
178  virtual void setWindDirection(float fDirection);
179 
181  virtual void preCull(DtOsgCullVisitor* cullVisitor);
182 
185  virtual void preCullSetup(osg::Camera* osgCamera);
186 
187  virtual bool preRenderCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
188  osg::RenderInfo& renderInfo);
189  virtual void postRenderCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
190  osg::RenderInfo& renderInfo);
191  virtual void provideTimeCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
192  double& fTime);
193 
194  virtual void forestDeInitCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest);
195 
196  virtual void pushGraphicsState(osg::RenderInfo& renderInfo);
197  virtual void popGraphicsState(osg::RenderInfo& renderInfo);
198 
200  virtual bool createTree(DtTreeRecord& record);
201 
204  virtual void initTreeDesc(makOsgSpeedTree::TreeInstanceDescriptor& desc,
205  DtTreeRecord& record, const DtVector& up, DtCoordinateConverter* converter);
208  virtual void initTreeDesc(makOsgSpeedTree::TreeInstanceDescriptor& desc,
209  DtTreeRecord& record, DtCoordinateConverter* converter, bool setupTopoFrame = true);
210  virtual void applyModelDefParameters(makOsgSpeedTree::TreeInstanceDescriptor& desc,
211  DtTreeRecord& record);
212 
221  virtual const bool bindLightingAttributes(const osg::Node* node,
222  const uint32 programID, DtOsgRenderer* osgRenderer,
223  const std::string& searchNodeName);
224 
226  virtual void enablePlanarReflections(bool enable);
227 
228  protected:
229  static DtOsgCullVisitorParameters* getCullParameters(
230  osg::RenderInfo& renderInfo);
231 
232  static bool isCameraOrthographic(DtOsgCullVisitorParameters* params);
233 
234  static float getZoomFactor(DtOsgCullVisitorParameters* params, DtDe& de);
235 
236  protected:
237 
238  static const float myCellSize;
239 
240  //Static members used by imgui to keep track of the ImGui state.
241  static unsigned int theLastImGuiFrameNumber;
242 
243  // Static member variables for keeping track of whether shaders have already been
244  // reloaded this frame by another forest
245  static unsigned int theLastFrameShadersReloaded;
246 
247  protected:
248  makOsgSpeedTree::TreeInstanceDescriptor myScratchTreeInstanceDesc;
249  makOsgSpeedTree::TreeInstanceDescriptorCollection
251  makOsgSpeedTree::TreeInstanceCollection myScratchInstanceCollection;
252 
253  typedef std::map<std::string, ModelDefParams> MapModelDefToSTFileName;
255 
257 
258  osg::Camera* myCamera;
259 
261 
262  std::unordered_map<int, bool> myShaderBoundMap;
263 
264  float myFarPlane;
265 
270  osg::BoundingBox myBoundingBox;
272 
273  typedef std::unordered_map<DtUniqueID,
274  makOsgSpeedTree::TreeInstanceCollection> MapCellsToTrees;
276 
277  typedef std::unordered_map<DtUniqueID, makOsgSpeedTree::TreeInstance*>
280 
282  unsigned int myLastShaderHash;
283 
286 
289 
291 
293 
294  // REMOVE POST UBO CHANGE:
296 
298 
299  // Couple mutexes to avoid thread safety issues.
300  // The merge draw mutex should be moved down into the vis manager but this
301  // was the safer and lower risk option at the moment.
305 
308 
310 
312 
314 
316 
317  // SpeedTree clears its global scene-dirty flag after every render,
318  // including shadow renders. Preserve a pending regular-view refresh
319  // across the shadow pass when perFrameUpdate dirties the scene.
321  };
322 
327  {
328  public:
331 
332  private:
337 
338  public:
340  virtual DtForestObject* create(DtDe& de, DtUniqueID id);
341 
343  virtual DtForestObject* create(DtDe& de, DtUniqueID id, const std::string& strVisManagerType);
344  };
345 }
DtSpeedTreeForestObjectCreator is the SpeedTree implementation of a DtForestObjectCreator.
Definition: DtSpeedTreeForest.h:326
const std::string mySpeedTreeMultiViewUserFuncsVertexShader
Definition: DtSpeedTreeForest.h:290
MapModelDefToSTFileName myMapModelDefToSTFileName
Definition: DtSpeedTreeForest.h:254
DT_DLL_EXAMPLESCENEROOTPLUGIN void init(DtDe &anIG)
static unsigned int theLastFrameShadersReloaded
Definition: DtSpeedTreeForest.h:245
static unsigned int theLastImGuiFrameNumber
Definition: DtSpeedTreeForest.h:241
The DtOsgRenderer is the component responsible for rendering 3D images onto the screen via OpenSceneG...
Definition: DtOsgRenderer.h:92
float myFarPlane
Definition: DtSpeedTreeForest.h:264
#define DT_DLL_VRVST
Definition: vrvSt.h:20
std::unordered_map< int, bool > myShaderBoundMap
Definition: DtSpeedTreeForest.h:262
std::string strSRTFileName
Definition: DtSpeedTreeForest.h:159
DtCoordinateConverter is the base class for &#39;local (cig) to geocentric&#39; converters.
Definition: DtCoordinateConverter.h:25
bool myReloadShaders
Should we reload the SpeedTree shaders.
Definition: DtSpeedTreeForest.h:285
makOsgSpeedTree::TreeInstanceDescriptor myScratchTreeInstanceDesc
Definition: DtSpeedTreeForest.h:248
const std::string mySpeedTreeDefaultUserFuncsPixelShader
Definition: DtSpeedTreeForest.h:288
Definition: DtSkyObjectManager.h:30
makOsgSpeedTree::TreeInstanceCollection myScratchInstanceCollection
Definition: DtSpeedTreeForest.h:251
Contains DLL export macros.
std::vector< DtTreeRecord * > DtVectorTreeRecords
Definition: DtTreeRecord.h:139
DtSpeedTreeCore & myCore
Definition: DtSpeedTreeForest.h:271
Contains makVrv::DtForestObject class.
DtForestObject provides a way to make lots of trees.
Definition: DtForestObject.h:26
osg::BoundingBox myBoundingBox
Definition: DtSpeedTreeForest.h:270
float modelDefScale
Definition: DtSpeedTreeForest.h:160
MapTreeIDToTree myMapTreeIDtoTree
Definition: DtSpeedTreeForest.h:279
DtSpeedTreeCore wraps and provides the interface to makOsgSpeedTree.
Definition: DtSpeedTreeCore.h:38
DtOsgCullVisitor will inspect the camera to see which visual mode is active. If the visual mode is a ...
Definition: DtOsgCullVisitor.h:27
bool myRegularVisibilityRefreshPending
Definition: DtSpeedTreeForest.h:320
static const float myCellSize
Definition: DtSpeedTreeForest.h:238
const std::string mySpeedTreeDefaultUserFuncsVertexShader
Definition: DtSpeedTreeForest.h:287
virtual bool isReceiveShadowsEnabled() const
Definition: DtSpeedTreeForest.h:103
A DtTreeRecord holds the requisite information needed to create a tree in a forest.
Definition: DtTreeRecord.h:30
DtSpeedTreeForest is the SpeedTree implementation of a distributed DtForestObject.
Definition: DtSpeedTreeForest.h:50
bool myReceiveShadows
Definition: DtSpeedTreeForest.h:297
unsigned int myRestoreVisibilityNodeMask
Definition: DtSpeedTreeForest.h:309
osg::ref_ptr< osg::PositionAttitudeTransform > myPat
Definition: DtSpeedTreeForest.h:268
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
The osg cull vistor parameters class provides additional culling and intersector parameters for choos...
Definition: DtOsgCullVisitorParameters.h:46
DtCoordinateConverter * myMergeBackgroundConverter
Definition: DtSpeedTreeForest.h:307
int myLastPerFrameUpdateFrameNumber
Definition: DtSpeedTreeForest.h:315
std::unordered_map< DtUniqueID, makOsgSpeedTree::TreeInstanceCollection > MapCellsToTrees
Definition: DtSpeedTreeForest.h:274
DtCoordinateConverter * myMainThreadConverter
Definition: DtSpeedTreeForest.h:306
unsigned long long DtUniqueID
Definition: DtUniqueID.h:19
MapCellsToTrees myMapCellsToTrees
Definition: DtSpeedTreeForest.h:275
DtSkyObjectManager & mySkyObjectManager
Definition: DtSpeedTreeForest.h:311
osg::ref_ptr< osg::Uniform > myNormalMatrixUniform
Definition: DtSpeedTreeForest.h:295
Base class to provide boost signal/slot management.
osg::Camera * myCamera
Definition: DtSpeedTreeForest.h:258
osg::ref_ptr< makOsgSpeedTree::Forest > myForest
Definition: DtSpeedTreeForest.h:269
makOsgSpeedTree::TreeInstanceDescriptorCollection myScratchTreeInstanceDescCollection
Definition: DtSpeedTreeForest.h:250
DtSignalConnectionManager myConnections
Definition: DtSpeedTreeForest.h:260
int myPreviousTU
Definition: DtSpeedTreeForest.h:256
unsigned int uint32
Definition: DtCommonTypes.h:28
The DtForestObjectCreator for the DtForestObject class.
Definition: DtForestObject.h:103
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:76
std::unordered_map< DtUniqueID, makOsgSpeedTree::TreeInstance * > MapTreeIDToTree
Definition: DtSpeedTreeForest.h:278
tbb::mutex myForestMergeDrawMutex
Definition: DtSpeedTreeForest.h:302
std::map< std::string, ModelDefParams > MapModelDefToSTFileName
Definition: DtSpeedTreeForest.h:253
Contains the DtCVMarkerSeries and DtCVMarkerSeries class declarations responsible for wrapping up to ...
osg::ref_ptr< osg::Uniform > myProjectionMatrixInverseUniform
Definition: DtSpeedTreeForest.h:292
Contains makVrv::DtTreeRecord class.
unsigned int myLastShaderHash
shader hash for the last shaders passed down to SpeedTree
Definition: DtSpeedTreeForest.h:282
bool myUpdateUserDefinedShaders
Definition: DtSpeedTreeForest.h:313
osg::ref_ptr< osg::Group > myRoot
The forest is a collection of trees under a group node.
Definition: DtSpeedTreeForest.h:267
Definition: DtSpeedTreeForest.h:157
tbb::mutex myForestMergeUpdateMutex
Definition: DtSpeedTreeForest.h:304
tbb::mutex myForestAddRemoveMutex
Definition: DtSpeedTreeForest.h:303

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)