VR-Forces 4.7 Class Documentation
 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) 2017 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvSt/vrvSt.h>
13 #include <vrvCore/DtForestObject.h>
15 #include <osg/ref_ptr>
16 #include <osg/PositionAttitudeTransform>
17 #include <osg/Geode>
18 #include <osg/BoundingBox>
19 
20 #include <vrvCore/DtTreeRecord.h>
22 
23 #include <OsgST_Forest.h>
24 
25 #include <boost/unordered_map.hpp>
26 
27 
28 namespace makOsgSpeedTree
29 {
30  class TreeInstance;
31  struct TreeInstanceDescriptor;
32 }
33 
34 namespace makVrv
35 {
36  class DtAgentUpdateResolverInterface;
37  class DtSpeedTreeModelInstance;
38  class DtSpeedTreeCore;
39  class DtEnvironmentInfo;
40  class DtOsgCullVisitorParameters;
41 
46  {
47  public:
48  friend class DtSpeedTreeForestClassesCreator;
50 
51  virtual ~DtSpeedTreeForest();
52 
53  virtual void addUniqueTree(DtTreeRecord& record);
54  virtual void removeTree(DtUniqueID record);
55  virtual void removeAllTrees();
56 
57  virtual DtUniqueID addUniqueTreesToUniqueCell(
58  DtVectorTreeRecords& records);
59  virtual void removeAllUniqueTreesAndUniqueCell(DtUniqueID cellID);
60 
61  virtual void setTreeClippingPlane(float fFar);
62  virtual void getTreeClippingPlane( float& fFar );
63 
64  virtual void setTree3DLodDistances(float fNear, float fFar);
65  virtual void getTree3DLodDistances( float& fNear, float& fFar );
66 
67  virtual void setTreeBillboardDistances(float fStart, float fEnd);
68  virtual void getTreeBillboardDistances(float& fStart, float& fEnd);
69 
70  virtual void enableBillboardRendering(bool enable);
71  virtual bool isBillboardRenderingEnabled() const;
72 
73  virtual void enable3DTreeRendering(bool enable);
74  virtual bool is3DTreeRenderingEnabled() const;
75 
76  virtual void enableReceiveShadows(bool enable);
77  virtual bool isReceiveShadowsEnabled() const { return myReceiveShadows; }
78 
79  void setBoundingBox(const osg::BoundingBox& box);
80  const osg::BoundingBox& getBoundingBox(void) const;
81 
84  osg::ref_ptr<osg::Node> getRootNode(void);
85 
88  void programBoundCallback(osg::ref_ptr<makOsgSpeedTree::Forest> pForest,
89  const makOsgSpeedTree::TreeType* pTreeType, uint32 programID);
90 
93  virtual void slot_reloadShaders();
94 
96  virtual void slot_useGlobalAmbientChanged(bool enabled);
97 
99  virtual void slot_useGlobalDiffuseChanged(bool enabled);
100 
103  virtual void slot_perPixelLightingEnabledChanged(bool enabled);
104 
106  virtual void slot_planarReflectionsShowSpeedTreesChanged(bool enabled);
107 
108 
109  protected:
110 
115  const std::string& strVisManagerType);
116 
117  void init(const std::string& strVisManagerType);
118 
119  // The tree scale from the .earth file and the terrain patch
120  // are applied in DtStreamedSpeedTreeThread::handleRequest
121  // However, the user could also set the model definition
122  // scale. Store model def scale when we store the ST file name
123  // so we can multiply it into the record.scale().
125  {
126  std::string strSRTFileName;
128  };
129 
130  protected:
131  void connectSignals(void);
132 
133  osg::Vec3f computeWindDirection(float fDirection);
134 
135  void setWindStrength(float fStrength);
136  void setWindDirection(float fDirection);
137 
138  bool preUpdateCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
139  osg::RenderInfo& renderInfo);
140 
141  bool preRenderCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
142  osg::RenderInfo& renderInfo);
143  void postUpdateCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
144  osg::RenderInfo& renderInfo);
145  void postRenderCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
146  osg::RenderInfo& renderInfo);
147  void provideTimeCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
148  double& fTime);
149 
150  void pushGraphicsState(osg::RenderInfo& renderInfo);
151  void popGraphicsState(osg::RenderInfo& renderInfo);
152 
154  virtual DtModelDefinition* findModelDefinition(
155  const std::string& modelDef);
156 
158  bool createTree(DtTreeRecord& record);
159 
160  void initTreeDesc(makOsgSpeedTree::TreeInstanceDescriptor& desc,
161  DtTreeRecord& record, const DtVector& up);
162  void initTreeDesc(makOsgSpeedTree::TreeInstanceDescriptor& desc,
163  DtTreeRecord& record, bool setupTopoFrame=true);
164  void applyModelDefParameters(makOsgSpeedTree::TreeInstanceDescriptor& desc,
165  DtTreeRecord& record);
166 
167  protected:
168  static DtOsgCullVisitorParameters* getCullParameters(
169  osg::RenderInfo& renderInfo);
170 
171  static bool isCameraOrthographic(DtOsgCullVisitorParameters* params);
172 
174  static bool isReflectionCamera(osg::Camera *camera);
175 
176  static float getZoomFactor(DtOsgCullVisitorParameters* params, DtDe& de);
177 
178  protected:
179 
180  static const float myCellSize;
181 
182  protected:
183 
184  makOsgSpeedTree::TreeInstanceDescriptor myScratchTreeInstanceDesc;
185  makOsgSpeedTree::TreeInstanceDescriptorCollection
187  makOsgSpeedTree::TreeInstanceCollection myScratchInstanceCollection;
188 
189  typedef std::map<std::string, ModelDefParams> MapModelDefToSTFileName;
191 
193 
194  osg::Camera* myCamera;
195 
197 
198  boost::unordered_map<int, bool> myShaderBoundMap;
199  boost::unordered_map<int, int> myAlphaThresholdBlockLoc;
200 
201  float myFarPlane;
202 
204  osg::ref_ptr<osg::Group> myRoot;
205  osg::ref_ptr<osg::PositionAttitudeTransform> myPat;
206  osg::ref_ptr<makOsgSpeedTree::Forest> myForest;
207  osg::BoundingBox myBoundingBox;
210 
211  typedef boost::unordered_map<DtUniqueID,
212  makOsgSpeedTree::TreeInstanceCollection> MapCellsToTrees;
214 
215  typedef boost::unordered_map<DtUniqueID, makOsgSpeedTree::TreeInstance*>
218 
220  unsigned int myLastShaderHash;
221 
224 
227 
228  osg::ref_ptr<osg::Uniform> myProjectionMatrixInverseUniform;
229 
230  // REMOVE POST UBO CHANGE:
231  osg::ref_ptr<osg::Uniform> myNormalMatrixUniform;
232 
235  osg::GLExtensions * myExt;
237  };
238 
243  {
244  public:
246  virtual DtForestObject* create(DtDe& de, DtUniqueID id);
247  virtual DtForestObject* create(DtDe& de, DtUniqueID id,
248  const std::string& strVisManagerType);
249 
250  private:
251 
252  };
253 }

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)