VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
bvhTriangleMeshShape.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2023 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
9 #pragma once
10 
13 #include <BulletCollision/CollisionDispatch/btCollisionObject.h>
14 #include <BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h>
15 #include <BulletCollision/CollisionShapes/btTriangleMesh.h>
16 
17 #include <boost/shared_ptr.hpp>
18 #include <boost/enable_shared_from_this.hpp>
19 
20 #include <osg/Vec3>
21 
22 #include <tbb/spin_mutex.h>
23 
24 class DtSurface;
25 class btVector3;
26 
29 {
30 public:
31  DtTriangleMeshWithSoil(bool use32bitIndices = true, bool use4componentVertices = true);
32  virtual ~DtTriangleMeshWithSoil();
33 
34  bool valid(const btVector3& vertex0, const btVector3& vertex1, const btVector3& vertex2) const;
35  bool valid(const btVector3& vertex) const;
36  bool valid(const btScalar& val) const;
37 
38  bool checkAddTriangle(const btVector3& vertex0, const btVector3& vertex1, const btVector3& vertex2,
39  bool removeDuplicateVertices = false);
40 
41  void addTriangle(const btVector3& vertex0, const btVector3& vertex1, const btVector3& vertex2,
42  bool removeDuplicateVertices = false);
43 
44  void addTriangleWithSurface(const btVector3& vertex0, const btVector3& vertex1, const btVector3& vertex2,
45  const DtSurface& surface, bool removeDuplicateVertices = false);
46 
47  DtSurface triangleSurface(unsigned int triangleIndex) const;
48 
49  const btVector3& max() const;
50  const btVector3& min() const;
51 
52  bool isAabbValid() const;
53 
54  double maxDistance() const;
55 
56 protected:
57  void updateBounds(const btVector3& val);
58 
61  void initializeSurfaceArray();
62 
65  void syncSurfaceArray();
66 
72  btAlignedObjectArray<DtSurface> mySurfaceTypes;
73  btVector3 myMin;
74  btVector3 myMax;
76 };
77 
79  : public btBvhTriangleMeshShape
80  , public boost::enable_shared_from_this<DtBvhTriangleMeshShape>
81 {
82 public:
83  using Ptr = boost::shared_ptr<DtBvhTriangleMeshShape>;
84 
87  bool useQuantization = true, bool buildBvhNow = false,
88  bool filterTransparentPolygons = false);
89 
91 
94  bool buildBvh();
95  bool isBvhBuilt() const;
96 
98  int getNumTriangles() const;
99 
100 private:
101  using Mutex = tbb::spin_mutex;
102 
103  mutable Mutex myMutex;
105 
107  tbb::atomic<bool> myIsBvhBuilt;
108 };
109 
111  : public btCollisionObject
113 {
114 public:
116 
117  void setCollisionShape(btCollisionShape* shape) override;
118 
119  bool buildBvh() override;
120  bool enabled() const override;
121  bool isBvhBuilt() const;
122 
123  boost::shared_ptr<btCollisionShape> bulletCollisionShape() const override;
124 
125  unsigned int numberOfTriangles() const override;
126  double radius() const override;
127  DtSurface triangleSurface(unsigned int triangleIndex) const override;
128 
129  DynamicFeatures dynamicFeatures() const override;
130 
131  const btTransform& worldTransform() const override;
132 
133 protected:
135 };
136 
138 {
139  ProcessTriangle();
140  void operator() (const osg::Vec3& vec1, const osg::Vec3& vec2, const osg::Vec3& vec3, bool) const;
141 
143 };
144 
146 {
147  void operator() (const osg::Vec3& vec1, const osg::Vec3& vec2, const osg::Vec3& vec3) const;
148 
150  osg::Vec3d myScale;
151  bool myIsScale;
152 };
virtual double radius() const =0
Returns the maximum distance of all points from the origin of this object.
bool myUseSurfaceArray
When this is false, mySurfaceTypes is empty, and all triangles are considered to have &quot;Unspecified&quot; a...
Definition: bvhTriangleMeshShape.h:71
bool myIsScale
Definition: bvhTriangleMeshShape.h:151
tbb::spin_mutex Mutex
Definition: bvhTriangleMeshShape.h:101
Definition: bvhTriangleMeshShape.h:145
virtual DtSurface triangleSurface(unsigned int triangleIndex) const =0
Return the surface of a triangle at a given index.
A version of btTriangleMesh that also holds soil type for each polygon.
Definition: bvhTriangleMeshShape.h:28
virtual bool enabled() const =0
Intersections will ignore this object if this returns false.
Definition: surface.h:181
DtBvhTriangleMeshShape::Ptr myShape
Definition: bvhTriangleMeshShape.h:134
Definition: bvhTriangleMeshShape.h:78
std::vector< boost::shared_ptr< makVrv::DtDynamicTerrainFeature > > DynamicFeatures
Definition: bulletUtil.h:55
virtual bool isBvhBuilt() const =0
virtual bool buildBvh()=0
Build the bvh with mutex locked. Call as many times as you like, will only build once.
DtTriangleMeshWithSoil * myTriMesh
Definition: bvhTriangleMeshShape.h:142
double myMaxPointDistanceSq
Definition: bvhTriangleMeshShape.h:75
virtual unsigned int numberOfTriangles() const =0
Return number of triangles in this object (ignores instancing).
osg::Vec3d myScale
Definition: bvhTriangleMeshShape.h:150
btVector3 myMin
Definition: bvhTriangleMeshShape.h:73
int myTrianglesCount
Definition: bvhTriangleMeshShape.h:106
btVector3 myMax
Definition: bvhTriangleMeshShape.h:74
#define vec3
Definition: DtGlslToDtDefines.h:12
Definition: bvhTriangleMeshShape.h:110
virtual boost::shared_ptr< btCollisionShape > bulletCollisionShape() const =0
Access the underlying bullet collision shape.
Mutex myMutex
Definition: bvhTriangleMeshShape.h:103
void operator()(const osg::Vec3 &vec1, const osg::Vec3 &vec2, const osg::Vec3 &vec3) const
Definition: bulletUtil.h:51
virtual DynamicFeatures dynamicFeatures() const =0
Return all the dynamic features which contain this object.
tbb::atomic< bool > myIsBvhBuilt
Definition: bvhTriangleMeshShape.h:107
#define DT_DLL_vantageTerrainImplementation
This file is used to determine how to build.
Definition: vantageTerrainImplementationDefines.h:28
void operator()(const osg::Vec3 &vec1, const osg::Vec3 &vec2, const osg::Vec3 &vec3, bool) const
DtSurface mySurface
Definition: bvhTriangleMeshShape.h:149
DtTriangleMeshWithSoil * myMesh
Definition: bvhTriangleMeshShape.h:104
virtual const btTransform & worldTransform() const =0
Access the world transform of the collision object.
btAlignedObjectArray< DtSurface > mySurfaceTypes
Definition: bvhTriangleMeshShape.h:72
Definition: bvhTriangleMeshShape.h:137
boost::shared_ptr< DtBvhTriangleMeshShape > Ptr
Definition: bvhTriangleMeshShape.h:83

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)