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) 2024 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 
55  public:
56  //Destructor
57  virtual ~DtSpeedTreeForest();
58 
60  DtSpeedTreeForest() = delete;
61 
63  DtSpeedTreeForest(const DtSpeedTreeForest& other) = delete;
64 
66  DtSpeedTreeForest& operator=(const DtSpeedTreeForest& other) = delete;
67 
68  public:
72  virtual void setVisible(bool isVisible);
73 
74  virtual void addUniqueTree(DtTreeRecord& record);
75  virtual void removeTree(DtUniqueID record);
76  virtual void removeAllTrees();
77 
78  virtual DtUniqueID addUniqueTreesToUniqueCell(DtVectorTreeRecords& records);
79  virtual void removeAllUniqueTreesAndUniqueCell(DtUniqueID cellID);
80 
81  virtual void setTreeClippingPlane(float fFar);
82  virtual void getTreeClippingPlane(float& fFar);
83 
84  virtual void setTree3DLodDistances(float fNear, float fFar);
85  virtual void getTree3DLodDistances(float& fNear, float& fFar);
86 
87  virtual void setTreeBillboardDistances(float fStart, float fEnd);
88  virtual void getTreeBillboardDistances(float& fStart, float& fEnd);
89 
91  virtual void setBillboardFadeOutRange(float fRange);
93  virtual void getBillboardFadeOutRange(float& fRange);
94 
95  virtual void enableBillboardRendering(bool enable);
96  virtual bool isBillboardRenderingEnabled() const;
97 
98  virtual void enable3DTreeRendering(bool enable);
99  virtual bool is3DTreeRenderingEnabled() const;
100 
101  virtual void enableReceiveShadows(bool enable);
102  virtual bool isReceiveShadowsEnabled() const { return myReceiveShadows; }
103 
104  virtual void setBoundingBox(const osg::BoundingBox& box);
105  virtual const osg::BoundingBox& getBoundingBox(void) const;
106 
109  virtual osg::ref_ptr<osg::Node> getRootNode(void);
110 
113  virtual void programBoundCallback(osg::ref_ptr<makOsgSpeedTree::Forest> pForest,
114  const makOsgSpeedTree::TreeType* pTreeType, uint32 programID);
115 
118  virtual void slot_reloadShaders();
119 
121  virtual void slot_treeProfilingChanged(bool active);
122 
124  virtual void slot_useGlobalAmbientChanged(bool enabled);
125 
127  virtual void slot_useGlobalDiffuseChanged(bool enabled);
128 
131  virtual void slot_perPixelLightingEnabledChanged(bool enabled);
132 
134  virtual void slot_planarReflectionsShowSpeedTreesChanged(bool enabled);
135 
137  virtual void processUninitialized();
138 
140  virtual bool initialized();
141 
143  virtual tbb::mutex& mergeDrawMutex();
144 
146  virtual tbb::mutex& mergeUpdateMutex();
147 
149  virtual osg::ref_ptr<makOsgSpeedTree::Forest>& makSpeedTreeForest();
150  protected:
151  // The tree scale from the .earth file and the terrain patch
152  // are applied in DtStreamedSpeedTreeThread::handleRequest
153  // However, the user could also set the model definition
154  // scale. Store model def scale when we store the ST file name
155  // so we can multiply it into the record.scale().
157  {
158  std::string strSRTFileName;
160  };
161 
162  protected:
166  DtSpeedTreeForest(DtDe& de, DtUniqueID id, const std::string& strVisManagerType);
167 
168  protected:
170  void init(const std::string& strVisManagerType);
171 
172  virtual void connectSignals(void);
173 
174  virtual osg::Vec3f computeWindDirection(float fDirection);
175 
176  virtual void setWindStrength(float fStrength);
177  virtual void setWindDirection(float fDirection);
178 
180  virtual void preCull(DtOsgCullVisitor* cullVisitor);
181 
184  virtual void preCullSetup(osg::Camera* osgCamera);
185 
186  virtual bool preRenderCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
187  osg::RenderInfo& renderInfo);
188  virtual void postRenderCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
189  osg::RenderInfo& renderInfo);
190  virtual void provideTimeCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
191  double& fTime);
192 
193  virtual void forestDeInitCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest);
194 
195  virtual void pushGraphicsState(osg::RenderInfo& renderInfo);
196  virtual void popGraphicsState(osg::RenderInfo& renderInfo);
197 
199  virtual bool createTree(DtTreeRecord& record);
200 
203  virtual void initTreeDesc(makOsgSpeedTree::TreeInstanceDescriptor& desc,
204  DtTreeRecord& record, const DtVector& up, DtCoordinateConverter* converter);
207  virtual void initTreeDesc(makOsgSpeedTree::TreeInstanceDescriptor& desc,
208  DtTreeRecord& record, DtCoordinateConverter* converter, bool setupTopoFrame = true);
209  virtual void applyModelDefParameters(makOsgSpeedTree::TreeInstanceDescriptor& desc,
210  DtTreeRecord& record);
211 
220  virtual const bool bindLightingAttributes(const osg::Node* node,
221  const uint32 programID, DtOsgRenderer* osgRenderer,
222  const std::string& searchNodeName);
223 
225  virtual void enablePlanarReflections(bool enable);
226 
227  protected:
228  static DtOsgCullVisitorParameters* getCullParameters(
229  osg::RenderInfo& renderInfo);
230 
231  static bool isCameraOrthographic(DtOsgCullVisitorParameters* params);
232 
234  static bool isReflectionCamera(osg::Camera* camera);
235 
236  static float getZoomFactor(DtOsgCullVisitorParameters* params, DtDe& de);
237 
238  protected:
239 
240  static const float myCellSize;
241 
242  //Static members used by imgui to keep track of the ImGui state.
243  static unsigned int theLastImGuiFrameNumber;
244 
245  // Static member variables for keeping track of whether shaders have already been
246  // reloaded this frame by another forest
247  static unsigned int theLastFrameShadersReloaded;
248 
249  protected:
250  makOsgSpeedTree::TreeInstanceDescriptor myScratchTreeInstanceDesc;
251  makOsgSpeedTree::TreeInstanceDescriptorCollection
253  makOsgSpeedTree::TreeInstanceCollection myScratchInstanceCollection;
254 
255  typedef std::map<std::string, ModelDefParams> MapModelDefToSTFileName;
257 
259 
260  osg::Camera* myCamera;
261 
263 
264  std::unordered_map<int, bool> myShaderBoundMap;
265 
266  float myFarPlane;
267 
272  osg::BoundingBox myBoundingBox;
274 
275  typedef std::unordered_map<DtUniqueID,
276  makOsgSpeedTree::TreeInstanceCollection> MapCellsToTrees;
278 
279  typedef std::unordered_map<DtUniqueID, makOsgSpeedTree::TreeInstance*>
282 
284  unsigned int myLastShaderHash;
285 
288 
291 
293 
295 
296  // REMOVE POST UBO CHANGE:
298 
300 
301  // Couple mutexes to avoid thread safety issues.
302  // The merge draw mutex should be moved down into the vis manager but this
303  // was the safer and lower risk option at the moment.
307 
310 
312 
314 
316 
318  };
319 
324  {
325  public:
328 
329  private:
334 
335  public:
337  virtual DtForestObject* create(DtDe& de, DtUniqueID id);
338 
340  virtual DtForestObject* create(DtDe& de, DtUniqueID id, const std::string& strVisManagerType);
341  };
342 }
DtSpeedTreeForestObjectCreator is the SpeedTree implementation of a DtForestObjectCreator.
Definition: DtSpeedTreeForest.h:323
const std::string mySpeedTreeMultiViewUserFuncsVertexShader
Definition: DtSpeedTreeForest.h:292
MapModelDefToSTFileName myMapModelDefToSTFileName
Definition: DtSpeedTreeForest.h:256
DT_DLL_EXAMPLESCENEROOTPLUGIN void init(DtDe &anIG)
static unsigned int theLastFrameShadersReloaded
Definition: DtSpeedTreeForest.h:247
static unsigned int theLastImGuiFrameNumber
Definition: DtSpeedTreeForest.h:243
The DtOsgRenderer is the component responsible for rendering 3D images onto the screen via OpenSceneG...
Definition: DtOsgRenderer.h:91
float myFarPlane
Definition: DtSpeedTreeForest.h:266
#define DT_DLL_VRVST
Definition: vrvSt.h:20
std::unordered_map< int, bool > myShaderBoundMap
Definition: DtSpeedTreeForest.h:264
std::string strSRTFileName
Definition: DtSpeedTreeForest.h:158
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:287
makOsgSpeedTree::TreeInstanceDescriptor myScratchTreeInstanceDesc
Definition: DtSpeedTreeForest.h:250
const std::string mySpeedTreeDefaultUserFuncsPixelShader
Definition: DtSpeedTreeForest.h:290
Definition: DtSkyObjectManager.h:30
makOsgSpeedTree::TreeInstanceCollection myScratchInstanceCollection
Definition: DtSpeedTreeForest.h:253
Contains DLL export macros.
std::vector< DtTreeRecord * > DtVectorTreeRecords
Definition: DtTreeRecord.h:139
DtSpeedTreeCore & myCore
Definition: DtSpeedTreeForest.h:273
Contains makVrv::DtForestObject class.
DtForestObject provides a way to make lots of trees.
Definition: DtForestObject.h:26
osg::BoundingBox myBoundingBox
Definition: DtSpeedTreeForest.h:272
float modelDefScale
Definition: DtSpeedTreeForest.h:159
MapTreeIDToTree myMapTreeIDtoTree
Definition: DtSpeedTreeForest.h:281
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
static const float myCellSize
Definition: DtSpeedTreeForest.h:240
const std::string mySpeedTreeDefaultUserFuncsVertexShader
Definition: DtSpeedTreeForest.h:289
virtual bool isReceiveShadowsEnabled() const
Definition: DtSpeedTreeForest.h:102
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:299
unsigned int myRestoreVisibilityNodeMask
Definition: DtSpeedTreeForest.h:311
osg::ref_ptr< osg::PositionAttitudeTransform > myPat
Definition: DtSpeedTreeForest.h:270
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:44
DtCoordinateConverter * myMergeBackgroundConverter
Definition: DtSpeedTreeForest.h:309
int myLastPerFrameUpdateFrameNumber
Definition: DtSpeedTreeForest.h:317
std::unordered_map< DtUniqueID, makOsgSpeedTree::TreeInstanceCollection > MapCellsToTrees
Definition: DtSpeedTreeForest.h:276
DtCoordinateConverter * myMainThreadConverter
Definition: DtSpeedTreeForest.h:308
unsigned long long DtUniqueID
Definition: DtUniqueID.h:19
MapCellsToTrees myMapCellsToTrees
Definition: DtSpeedTreeForest.h:277
DtSkyObjectManager & mySkyObjectManager
Definition: DtSpeedTreeForest.h:313
osg::ref_ptr< osg::Uniform > myNormalMatrixUniform
Definition: DtSpeedTreeForest.h:297
Base class to provide boost signal/slot management.
osg::Camera * myCamera
Definition: DtSpeedTreeForest.h:260
osg::ref_ptr< makOsgSpeedTree::Forest > myForest
Definition: DtSpeedTreeForest.h:271
makOsgSpeedTree::TreeInstanceDescriptorCollection myScratchTreeInstanceDescCollection
Definition: DtSpeedTreeForest.h:252
DtSignalConnectionManager myConnections
Definition: DtSpeedTreeForest.h:262
int myPreviousTU
Definition: DtSpeedTreeForest.h:258
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:280
tbb::mutex myForestMergeDrawMutex
Definition: DtSpeedTreeForest.h:304
std::map< std::string, ModelDefParams > MapModelDefToSTFileName
Definition: DtSpeedTreeForest.h:255
Contains the DtCVMarkerSeries and DtCVMarkerSeries class declarations responsible for wrapping up to ...
osg::ref_ptr< osg::Uniform > myProjectionMatrixInverseUniform
Definition: DtSpeedTreeForest.h:294
Contains makVrv::DtTreeRecord class.
unsigned int myLastShaderHash
shader hash for the last shaders passed down to SpeedTree
Definition: DtSpeedTreeForest.h:284
bool myUpdateUserDefinedShaders
Definition: DtSpeedTreeForest.h:315
osg::ref_ptr< osg::Group > myRoot
The forest is a collection of trees under a group node.
Definition: DtSpeedTreeForest.h:269
Definition: DtSpeedTreeForest.h:156
tbb::mutex myForestMergeUpdateMutex
Definition: DtSpeedTreeForest.h:306
tbb::mutex myForestAddRemoveMutex
Definition: DtSpeedTreeForest.h:305

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)