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 processUnitialized();
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 
188  virtual bool preUpdateCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
189  osg::ref_ptr<osg::Camera> osgCamera);
190 
191  virtual bool preRenderCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
192  osg::RenderInfo& renderInfo);
193  virtual void postRenderCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
194  osg::RenderInfo& renderInfo);
195  virtual void provideTimeCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
196  double& fTime);
197 
198  virtual void pushGraphicsState(osg::RenderInfo& renderInfo);
199  virtual void popGraphicsState(osg::RenderInfo& renderInfo);
200 
202  virtual bool createTree(DtTreeRecord& record);
203 
206  virtual void initTreeDesc(makOsgSpeedTree::TreeInstanceDescriptor& desc,
207  DtTreeRecord& record, const DtVector& up, DtCoordinateConverter* converter);
210  virtual void initTreeDesc(makOsgSpeedTree::TreeInstanceDescriptor& desc,
211  DtTreeRecord& record, DtCoordinateConverter* converter, bool setupTopoFrame = true);
212  virtual void applyModelDefParameters(makOsgSpeedTree::TreeInstanceDescriptor& desc,
213  DtTreeRecord& record);
214 
223  virtual const bool bindLightingAttributes(const osg::Node* node,
224  const uint32 programID, DtOsgRenderer* osgRenderer,
225  const std::string& searchNodeName);
226 
228  virtual void enablePlanarReflections(bool enable);
229 
230  protected:
231  static DtOsgCullVisitorParameters* getCullParameters(
232  osg::RenderInfo& renderInfo);
233 
234  static bool isCameraOrthographic(DtOsgCullVisitorParameters* params);
235 
237  static bool isReflectionCamera(osg::Camera* camera);
238 
239  static float getZoomFactor(DtOsgCullVisitorParameters* params, DtDe& de);
240 
241  protected:
242 
243  static const float myCellSize;
244 
245  //Static members used by imgui to keep track of the ImGui state.
246  static unsigned int theLastImGuiFrameNumber;
247 
248  // Static member variables for keeping track of whether shaders have already been
249  // reloaded this frame by another forest
250  static unsigned int DtSpeedTreeForest::theLastFrameShadersReloaded;
251 
252  protected:
253  makOsgSpeedTree::TreeInstanceDescriptor myScratchTreeInstanceDesc;
254  makOsgSpeedTree::TreeInstanceDescriptorCollection
256  makOsgSpeedTree::TreeInstanceCollection myScratchInstanceCollection;
257 
258  typedef std::map<std::string, ModelDefParams> MapModelDefToSTFileName;
260 
262 
263  osg::Camera* myCamera;
264 
266 
267  std::unordered_map<int, bool> myShaderBoundMap;
268 
269  float myFarPlane;
270 
275  osg::BoundingBox myBoundingBox;
277 
278  typedef std::unordered_map<DtUniqueID,
279  makOsgSpeedTree::TreeInstanceCollection> MapCellsToTrees;
281 
282  typedef std::unordered_map<DtUniqueID, makOsgSpeedTree::TreeInstance*>
285 
287  unsigned int myLastShaderHash;
288 
291 
294 
296 
298 
299  // REMOVE POST UBO CHANGE:
301 
303 
305 
306  // Couple mutexes to avoid thread safety issues.
307  // The merge draw mutex should be moved down into the vis manager but this
308  // was the safer and lower risk option at the moment.
312 
315 
317 
319  };
320 
325  {
326  public:
329 
330  private:
335 
336  public:
338  virtual DtForestObject* create(DtDe& de, DtUniqueID id);
339 
341  virtual DtForestObject* create(DtDe& de, DtUniqueID id, const std::string& strVisManagerType);
342  };
343 }
DtSpeedTreeForestObjectCreator is the SpeedTree implementation of a DtForestObjectCreator.
Definition: DtSpeedTreeForest.h:324
const std::string mySpeedTreeMultiViewUserFuncsVertexShader
Definition: DtSpeedTreeForest.h:295
MapModelDefToSTFileName myMapModelDefToSTFileName
Definition: DtSpeedTreeForest.h:259
DT_DLL_EXAMPLESCENEROOTPLUGIN void init(DtDe &anIG)
static unsigned int theLastImGuiFrameNumber
Definition: DtSpeedTreeForest.h:246
The DtOsgRenderer is the component responsible for rendering 3D images onto the screen via OpenSceneG...
Definition: DtOsgRenderer.h:90
float myFarPlane
Definition: DtSpeedTreeForest.h:269
#define DT_DLL_VRVST
Definition: vrvSt.h:20
std::unordered_map< int, bool > myShaderBoundMap
Definition: DtSpeedTreeForest.h:267
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:290
makOsgSpeedTree::TreeInstanceDescriptor myScratchTreeInstanceDesc
Definition: DtSpeedTreeForest.h:253
const std::string mySpeedTreeDefaultUserFuncsPixelShader
Definition: DtSpeedTreeForest.h:293
Definition: DtSkyObjectManager.h:30
makOsgSpeedTree::TreeInstanceCollection myScratchInstanceCollection
Definition: DtSpeedTreeForest.h:256
Contains DLL export macros.
std::vector< DtTreeRecord * > DtVectorTreeRecords
Definition: DtTreeRecord.h:139
DtSpeedTreeCore & myCore
Definition: DtSpeedTreeForest.h:276
Contains makVrv::DtForestObject class.
DtForestObject provides a way to make lots of trees.
Definition: DtForestObject.h:26
osg::BoundingBox myBoundingBox
Definition: DtSpeedTreeForest.h:275
float modelDefScale
Definition: DtSpeedTreeForest.h:159
MapTreeIDToTree myMapTreeIDtoTree
Definition: DtSpeedTreeForest.h:284
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:243
const std::string mySpeedTreeDefaultUserFuncsVertexShader
Definition: DtSpeedTreeForest.h:292
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
bool myShouldUpdateForCamera
Definition: DtSpeedTreeForest.h:304
DtSpeedTreeForest is the SpeedTree implementation of a distributed DtForestObject.
Definition: DtSpeedTreeForest.h:50
bool myReceiveShadows
Definition: DtSpeedTreeForest.h:302
unsigned int myRestoreVisibilityNodeMask
Definition: DtSpeedTreeForest.h:316
osg::ref_ptr< osg::PositionAttitudeTransform > myPat
Definition: DtSpeedTreeForest.h:273
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:43
DtCoordinateConverter * myMergeBackgroundConverter
Definition: DtSpeedTreeForest.h:314
std::unordered_map< DtUniqueID, makOsgSpeedTree::TreeInstanceCollection > MapCellsToTrees
Definition: DtSpeedTreeForest.h:279
DtCoordinateConverter * myMainThreadConverter
Definition: DtSpeedTreeForest.h:313
unsigned long long DtUniqueID
Definition: DtUniqueID.h:19
MapCellsToTrees myMapCellsToTrees
Definition: DtSpeedTreeForest.h:280
DtSkyObjectManager & mySkyObjectManager
Definition: DtSpeedTreeForest.h:318
osg::ref_ptr< osg::Uniform > myNormalMatrixUniform
Definition: DtSpeedTreeForest.h:300
Base class to provide boost signal/slot management.
osg::Camera * myCamera
Definition: DtSpeedTreeForest.h:263
osg::ref_ptr< makOsgSpeedTree::Forest > myForest
Definition: DtSpeedTreeForest.h:274
makOsgSpeedTree::TreeInstanceDescriptorCollection myScratchTreeInstanceDescCollection
Definition: DtSpeedTreeForest.h:255
DtSignalConnectionManager myConnections
Definition: DtSpeedTreeForest.h:265
int myPreviousTU
Definition: DtSpeedTreeForest.h:261
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:72
std::unordered_map< DtUniqueID, makOsgSpeedTree::TreeInstance * > MapTreeIDToTree
Definition: DtSpeedTreeForest.h:283
tbb::mutex myForestMergeDrawMutex
Definition: DtSpeedTreeForest.h:309
std::map< std::string, ModelDefParams > MapModelDefToSTFileName
Definition: DtSpeedTreeForest.h:258
Contains the DtCVMarkerSeries and DtCVMarkerSeries class declarations responsible for wrapping up to ...
osg::ref_ptr< osg::Uniform > myProjectionMatrixInverseUniform
Definition: DtSpeedTreeForest.h:297
Contains makVrv::DtTreeRecord class.
unsigned int myLastShaderHash
shader hash for the last shaders passed down to SpeedTree
Definition: DtSpeedTreeForest.h:287
osg::ref_ptr< osg::Group > myRoot
The forest is a collection of trees under a group node.
Definition: DtSpeedTreeForest.h:272
Definition: DtSpeedTreeForest.h:156
tbb::mutex myForestMergeUpdateMutex
Definition: DtSpeedTreeForest.h:311
tbb::mutex myForestAddRemoveMutex
Definition: DtSpeedTreeForest.h:310

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)