VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
osgToBullet.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2023 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
10 
11 #pragma once
12 
17 #include <vrfutil/vrfPrint.h>
18 #include <btBulletCollisionCommon.h>
19 #include <btBulletDynamicsCommon.h>
20 #include <memory>
22 #include <vlutil/vlSmartPointers.h>
23 #include <vlutil/vlFilename.h>
24 #include <geometry/surface.h>
25 
27 #include <osg/Matrix>
28 #include <osg/NodeVisitor>
29 #include <osg/TextureBuffer>
30 
32 #include <osgEarth/DrawInstanced>
33 
35 #include <vrvOsg/DtOsgRenderer.h>
36 #include <vrvOsg/DtSceneRoot.h>
39 
41 #include <osgEarth/MetadataNode>
42 
44 #include <vlutil/vlSmartPointers.h>
45 
47 #include <memory>
48 
49 #include <boost/shared_ptr.hpp>
50 #include <boost/regex.hpp>
51 
52 class btTriangleMesh;
53 class Coordinate_System;
55 
56 namespace osg
57 {
58  class Node;
59  class LOD;
60 }
61 
62 typedef std::vector<osg::Drawable*> DrawablesList;
63 
68  : public osg::NodeVisitor
70 {
71 public:
73  {
74  TreatPagedLODAsLOD = 0x00000001,
75  CheckGeodesForSurfaces = 0x00000002,
76  UseQuantization = 0x00000004,
77  BuildBvhNow = 0x00000008,
80  };
81 
83  osg::NodeVisitor::VisitorType visitorType = NodeVisitor::INTERSECTION_VISITOR,
84  osg::NodeVisitor::TraversalMode traverseMode = TRAVERSE_ALL_CHILDREN);
85 
87 
88  void setLoadOnlyActiveSwitchState(bool value);
89  bool loadOnlyActiveSwitchState() const;
90  bool hasFlags(ConvertToBulletFlags flags) const;
91  void setFlagsFor(ConvertToBulletFlags flags, bool val);
92  void setIgnoreSurfacesMatching(const std::vector<std::string>& ignoreSurfacesMatching);
94  void setDefaultSurface(const DtSurface& surface);
95  const osg::Matrix& matrix() const;
96  void setMatrix(const osg::Matrix& matrix);
99  void processModelsEncodedInUserdata(osg::Node& node);
100  virtual DtSurface getCurrentSurfaceFromSMCFID(osg::Node& node, bool& hasValidSurface);
101  virtual void getCurrentSurface(osg::Group& node);
102  DtSurface convertFilenameToSurface(const std::string& fname, int& position, int& matchClass, bool& ignored);
103  virtual DtSurface convertImageToSurfaceType(osg::StateSet* stateSet, bool& hasValidSurface, bool& ignored);
104 
106  struct BtTriangle
107  {
108  btVector3 point1;
109  btVector3 point2;
110  btVector3 point3;
111  };
112  typedef std::multimap<long long, BtTriangle> Fid2BttriangleMap;
113 
115  {
116  public:
117  void addDynamicFeature(const boost::shared_ptr<makVrv::DtDynamicTerrainFeature>& feature);
119 
120  protected:
121  typedef std::vector< boost::weak_ptr<makVrv::DtDynamicTerrainFeature> > DynamicFeatureVector;
123  };
124 
126  {
128  DtSwitchableCollisionObject(long long fid);
129 
130  public:
131  static boost::shared_ptr<DtSwitchableCollisionObject> Create();
132  static boost::shared_ptr<DtSwitchableCollisionObject> Create(long long fid);
133  long long getFid();
134  bool enabled() const;
135  void hide(bool value);
138 
139  protected:
140  tbb::atomic<unsigned int> myDisabledCounter;
141  long long myFid;
142  bool myHidden;
143  };
144 
145  class NodeId
146  {
147  public:
148  typedef std::list<NodeId> List;
149  explicit NodeId(size_t hash);
150  NodeId* addChild(size_t hash);
151  const List& children() const;
152  void addCollisionObject(const boost::shared_ptr<btCollisionObject>& obj);
154 
155  private:
158  size_t myHash;
159  };
160 
161  bool ignoreDrawable(osg::Drawable* drawable) const;
162  size_t getScaleHash(const osg::Vec3d& scale) const;
163  void createMeshForDrawables(const DtSurface& surface, const DrawablesList& drawables, osg::Node& node);
164  void createMeshFromDrawables(osg::Geode& geode, DtSurface surface, bool hasValidSurface);
165  virtual bool createGeometryFromCache(osg::Node& node);
166 
168  virtual void apply(osg::Geode& geode) override;
169  virtual void apply(osg::Drawable& drawable) override;
170  virtual void apply(osg::Geometry& geometry) override;
171  virtual void apply(osg::LOD& node) override;
172  virtual void apply(osg::PagedLOD& node) override;
173  virtual void apply(osg::Group& node) override;
174  virtual void apply(osg::Sequence& node) override;
175  virtual void apply(osg::Transform& node) override;
176  virtual void apply(osg::MatrixTransform& node) override;
177  virtual void apply(osg::Node& node) override;
178 
180  {
181  public:
182  VrfSwitch();
183  void setFeature(const boost::shared_ptr<makVrv::DtDynamicTerrainFeature>& feature);
184  void addObjectToStateState(unsigned int index, const boost::shared_ptr<btCollisionObject>& obj);
185  void addObjectsToStateState(unsigned int index, DtCollisionObjectList& objects);
186  virtual void setState(unsigned int index);
187  virtual unsigned int getState() const;
188  virtual unsigned int getPreviousState() const;
189  virtual unsigned int numStates() const;
190 
191  private:
192  typedef std::vector<boost::shared_ptr<DtSwitchableCollisionObject> > CollisionObjectVector;
193  typedef std::vector<CollisionObjectVector> CollisionObjectSets;
194 
197  unsigned int myPreviousState;
198  };
199 
204 
205  typedef std::vector<osg::Matrix> MatrixStack;
206 
207 protected:
208 
209  void createCollisionObjectFromMesh(std::auto_ptr<DtTriangleMeshWithSoil>& mesh, osg::Node& node, long long fid);
210  void collectInstanceTriangles(osgEarth::DrawInstanced::InstanceGeometry* instancedGeometry, Fid2BttriangleMap& geometryMap);
211 
212  typedef std::list<DtBvhTriangleMeshShape::Ptr> ShapeList;
213  typedef std::map<size_t, ShapeList> ScaledInstanceShapeMap;
214  typedef std::unordered_map<osg::Node*, ScaledInstanceShapeMap> NodeToShapeMap;
215 
217 
221  osg::Matrix myMatrix;
222 
224  inline void pushMatrix(osg::Matrix& matrix) { myMatrixStack.push_back(matrix); }
225  inline void popMatrix() { myMatrixStack.pop_back(); }
226 
227  std::vector<boost::regex> myIgnoreRegexSurfacesMatching;
231 
232  class ParentStackGuard : boost::noncopyable
233  {
234  public:
235  explicit ParentStackGuard(osg::Node& node, ConvertToBulletVisitor& visitor);
237 
238  private:
241  };
242 
243  friend class ParentStackGuard;
244 
247 
248  typedef boost::unordered_map<size_t, NodeId*> HashToNodeIdMap;
250 
251  typedef boost::unordered_map<osg::Node*, NodeId*> NodeToNodeIdMap;
253 
255  osgEarth::MetadataNode* myMetadataNode;
257  osg::observer_ptr< osg::TextureBuffer > myTbo;
258 
259 public:
265 };
266 
267 
273 {
274 public:
276  static std::auto_ptr<DtVrfSimTerrainProcessor> Create();
277 
278  static std::auto_ptr<DtVrfSimTerrainProcessor> Create(DtVantageTerrainEngine&);
279 
281  virtual ~DtVrfSimTerrainProcessor();
282 
283  virtual unsigned int numberOfTriangles() const = 0;
284 
285  virtual void setDefaultSurface(const DtSurface&) = 0;
286  virtual void setMatrix(const osg::Matrix&) = 0;
287  virtual void setTraversalMode(osg::NodeVisitor::TraversalMode) = 0;
288  virtual void setVisitorType(osg::NodeVisitor::VisitorType) = 0;
289  virtual void setSurfaceCharacteristicsMap(makVrf::DtSurfaceCharacteristicMapConstPtr) = 0;
290  virtual void setSurfacesToIgnore(const std::vector<std::string>&) = 0;
291 
292  virtual void setTreatPagedLODAsLOD(bool) = 0;
293  virtual void setCheckGeodesForSurfaces(bool) = 0;
294  virtual void setUseQuantization(bool) = 0;
295  virtual void setBuildBvhNow(bool) = 0;
296  virtual void setFilterTransparentPolygons(bool) = 0;
297 
298  virtual makVrv::DtDynamicTerrainWorld::FeatureHandle createTerrainObjects(osg::Node*, bool LoadOnlyActiveSwitchState=false) = 0;
299 
300  virtual void getCollisionObjects(DtCollisionObjectList& objs) = 0;
301 
302 protected:
304 
306 };
List myChildNodes
Definition: osgToBullet.h:157
void setConversionFlags(ConvertToBulletVisitor::ConvertToBulletFlags f)
int myNumBulletObjects
Definition: osgToBullet.h:263
makVrf::DtSurfaceCharacteristicMapConstPtr mySurfaceCharacteristicMap
Definition: osgToBullet.h:220
long long myFid
Definition: osgToBullet.h:141
ParentStackGuard(osg::Node &node, ConvertToBulletVisitor &visitor)
void createMeshFromDrawables(osg::Geode &geode, DtSurface surface, bool hasValidSurface)
bool myLoadOnlyActiveSwitchState
Definition: osgToBullet.h:230
std::list< NodeId > List
Definition: osgToBullet.h:148
bool ignoreDrawable(osg::Drawable *drawable) const
MatrixStack myMatrixStack
Definition: osgToBullet.h:223
bool enabled() const
Intersections will ignore this object if this returns false.
Definition: osgToBullet.h:179
virtual DtSurface convertImageToSurfaceType(osg::StateSet *stateSet, bool &hasValidSurface, bool &ignored)
DtVantageTerrainEngine * myTerrainEngine
Definition: osgToBullet.h:305
HashToNodeIdMap myHashToNodeIdMap
Definition: osgToBullet.h:249
DtSurface myCurrentSurface
Definition: osgToBullet.h:219
std::vector< CollisionObjectVector > CollisionObjectSets
Definition: osgToBullet.h:193
ConvertToBulletFlags myFlags
Definition: osgToBullet.h:228
boost::unordered_map< size_t, NodeId * > HashToNodeIdMap
Definition: osgToBullet.h:248
makVrv::DtDynamicTerrainSwitch * createSwitch(const osg::ref_ptr< osgSim::MultiSwitch > &mswitch)
Create a DtDynamicTerrainSwitch which manipulates the supplied multiswitch.
btVector3 point3
Definition: osgToBullet.h:110
Definition: osgToBullet.h:74
unsigned myNumGeodeParents
Definition: osgToBullet.h:229
DynamicFeatureVector myFeatures
Definition: osgToBullet.h:122
std::vector< osg::Drawable * > DrawablesList
Definition: osgToBullet.h:62
size_t getScaleHash(const osg::Vec3d &scale) const
NodeId myRootNodeId
Definition: osgToBullet.h:245
ConvertToBulletVisitor::ConvertToBulletFlags conversionFlags() const
osg::Matrix myMatrix
Definition: osgToBullet.h:221
virtual void apply(osg::Geode &geode) override
Apply.
virtual unsigned int getPreviousState() const
Get the previous state of the switch. Return default (0) if the switch state has never been changed...
void setFeature(const boost::shared_ptr< makVrv::DtDynamicTerrainFeature > &feature)
ConvertToBulletVisitor(DtVantageTerrainEngine *terrainEngine, osg::NodeVisitor::VisitorType visitorType=NodeVisitor::INTERSECTION_VISITOR, osg::NodeVisitor::TraversalMode traverseMode=TRAVERSE_ALL_CHILDREN)
NodeToShapeMap myNodeToShapeMap
Definition: osgToBullet.h:218
Definition: osgToBullet.h:79
void setIgnoreSurfacesMatching(const std::vector< std::string > &ignoreSurfacesMatching)
DtSurface convertFilenameToSurface(const std::string &fname, int &position, int &matchClass, bool &ignored)
virtual boost::shared_ptr< DtDynamicTerrainFeature > feature() const
void createCollisionObjectFromMesh(std::auto_ptr< DtTriangleMeshWithSoil > &mesh, osg::Node &node, long long fid)
Definition: osgToBullet.h:145
Definition: surface.h:181
virtual bool createGeometryFromCache(osg::Node &node)
void collectInstanceTriangles(osgEarth::DrawInstanced::InstanceGeometry *instancedGeometry, Fid2BttriangleMap &geometryMap)
State switch. This is an interface for manipulating a switch. A switch in this context is defined as ...
Definition: DtDynamicTerrainStateManipulatorFactory.h:110
osgEarth::MetadataNode * myMetadataNode
Store the metadata node currently visiting.
Definition: osgToBullet.h:255
std::vector< boost::shared_ptr< DtSwitchableCollisionObject > > CollisionObjectVector
Definition: osgToBullet.h:192
std::vector< boost::shared_ptr< makVrv::DtDynamicTerrainFeature > > DynamicFeatures
Definition: bulletUtil.h:55
DtBoost::shared_ptr< const DtSurfaceCharacteristicMap > DtSurfaceCharacteristicMapConstPtr
Definition: surfaceCharacteristicsMap.h:31
NodeToNodeIdMap myNodeToNodeIdMap
Definition: osgToBullet.h:252
ConvertToBulletVisitor & myVisitor
Definition: osgToBullet.h:239
btVector3 point1
Definition: osgToBullet.h:108
Contains makVrv::DtDynamicTerrainStateManipulatorFactory class.
btVector3 point2
Definition: osgToBullet.h:109
bool myHidden
Definition: osgToBullet.h:142
std::map< size_t, ShapeList > ScaledInstanceShapeMap
Definition: osgToBullet.h:213
Definition: coordSystem.h:54
Definition: osgToBullet.h:232
virtual DtSurface getCurrentSurfaceFromSMCFID(osg::Node &node, bool &hasValidSurface)
DtCollisionObjectList myObjects
Definition: osgToBullet.h:156
NodeId * addChild(size_t hash)
std::multimap< long long, BtTriangle > Fid2BttriangleMap
Definition: osgToBullet.h:112
Definition: osgToBullet.h:77
Factory for creating objects which implement some kind of manipulation of the state of dynamically ch...
Definition: DtDynamicTerrainStateManipulatorFactory.h:67
CollisionObjectSets myObjects
Definition: osgToBullet.h:195
std::unordered_map< osg::Node *, ScaledInstanceShapeMap > NodeToShapeMap
Definition: osgToBullet.h:214
int myNumTriangles
Definition: osgToBullet.h:261
DtVantageTerrainEngine * myTerrainEngine
Definition: osgToBullet.h:216
void popMatrix()
Definition: osgToBullet.h:225
DynamicFeatures dynamicFeatures() const
Return all the dynamic features which contain this object.
const List & children() const
static boost::shared_ptr< DtSwitchableCollisionObject > Create()
int myNumScaledGeometries
Definition: osgToBullet.h:264
void getCollisionObjects(DtCollisionObjectList &objs)
void addObjectsToStateState(unsigned int index, DtCollisionObjectList &objects)
std::list< DtBvhTriangleMeshShape::Ptr > ShapeList
Definition: osgToBullet.h:212
Definition: bvhTriangleMeshShape.h:110
int myNumDrawables
Definition: osgToBullet.h:260
void setFlagsFor(ConvertToBulletFlags flags, bool val)
virtual void getCurrentSurface(osg::Group &node)
Bullet triangle.
Definition: osgToBullet.h:106
tbb::atomic< unsigned int > myDisabledCounter
Definition: osgToBullet.h:140
NodeId * myCurrentParentNodeId
Definition: osgToBullet.h:246
void addCollisionObject(const boost::shared_ptr< btCollisionObject > &obj)
std::vector< boost::weak_ptr< makVrv::DtDynamicTerrainFeature > > DynamicFeatureVector
Definition: osgToBullet.h:121
virtual void setState(unsigned int index)
Set the current state of the switch (0 indexed).
void setSurfaceCharMap(makVrf::DtSurfaceCharacteristicMapConstPtr surfCharMap)
ConvertToBulletFlags
Definition: osgToBullet.h:72
Contains makVrv::DtSceneRoot class.
virtual unsigned int numStates() const
void setLoadOnlyActiveSwitchState(bool value)
#define DT_DLL_vantageTerrainImplementation
This file is used to determine how to build.
Definition: vantageTerrainImplementationDefines.h:28
void addDynamicFeature(const boost::shared_ptr< makVrv::DtDynamicTerrainFeature > &feature)
Contains makVrv::DtDynamicTerrainWorld class.
Note: The implementation of this processor class can be found in osgToBullet.cxx (class called DtVrfS...
Definition: osgToBullet.h:272
void addObjectToStateState(unsigned int index, const boost::shared_ptr< btCollisionObject > &obj)
Feature Insertion/Removal/Paging Features represent parts of the terrain which are individually ident...
Definition: DtDynamicTerrainWorld.h:99
virtual unsigned int getState() const
Get the current state of the switch.
void createMeshForDrawables(const DtSurface &surface, const DrawablesList &drawables, osg::Node &node)
int myNumBulletShapes
Definition: osgToBullet.h:262
This class wraps the VR-Vantage Display Engine, and uses as a terrain loader and intersector. This is the terrain engine that powers the DtVantageTerrainImplementation. The DtVantageTerrainEngine runs the DtDe it its own thread, and processes commands thought the command queue.
Definition: vantageTerrainEngine.h:109
const osg::Matrix & matrix() const
size_t myHash
Definition: osgToBullet.h:158
std::vector< boost::regex > myIgnoreRegexSurfacesMatching
Definition: osgToBullet.h:227
int myCurrentState
Definition: osgToBullet.h:196
Contains makVrv::DtOsgRenderer class.
ConvertToBulletVisitor.
Definition: osgToBullet.h:67
void setDefaultSurface(const DtSurface &surface)
void setMatrix(const osg::Matrix &matrix)
std::list< boost::shared_ptr< btCollisionObject > > DtCollisionObjectList
Definition: bulletUtil.h:49
unsigned int myPreviousState
Definition: osgToBullet.h:197
void getAllCollisionObjects(DtCollisionObjectList &objs) const
void pushMatrix(osg::Matrix &matrix)
Definition: osgToBullet.h:224
Definition: osgToBullet.h:76
Definition: osgToBullet.h:114
std::vector< osg::Matrix > MatrixStack
Definition: osgToBullet.h:205
osg::observer_ptr< osg::TextureBuffer > myTbo
TBO to look up instance ids.
Definition: osgToBullet.h:257
bool loadOnlyActiveSwitchState() const
boost::unordered_map< osg::Node *, NodeId * > NodeToNodeIdMap
Definition: osgToBullet.h:251
void processModelsEncodedInUserdata(osg::Node &node)
NodeId * mySavedParentId
Definition: osgToBullet.h:240
bool hasFlags(ConvertToBulletFlags flags) const

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)