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>
17 
18 #include <osg/Vec3>
19 #include <atomic>
20 #include <tbb/spin_mutex.h>
21 
22 class DtSurface;
23 class btVector3;
24 
26 
29 {
30 public:
31  DtTriangleMeshWithSoil(bool use32bitIndices = true, bool use4componentVertices = true);
32  virtual ~DtTriangleMeshWithSoil() override;
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 std::enable_shared_from_this<DtBvhTriangleMeshShape>
81 {
82 public:
83  using Ptr = std::shared_ptr<DtBvhTriangleMeshShape>;
84 
85  DtBvhTriangleMeshShape(DtTriangleMeshWithSoil* mesh, bool useQuantization = true, bool buildBvhNow = false,
86  bool filterTransparentPolygons = false);
87 
88  virtual ~DtBvhTriangleMeshShape() override;
89 
92  bool buildBvh();
93  bool isBvhBuilt() const;
94 
96  int getNumTriangles() const;
97 
98  DtCollisionShapeId id() const;
99  void setId(DtCollisionShapeId id);
100 
101 private:
102  using Mutex = tbb::spin_mutex;
103 
104  mutable Mutex myMutex;
106 
108  std::atomic<bool> myIsBvhBuilt;
110 };
111 
113  : public btCollisionObject
115 {
116 public:
118 
119  virtual void setCollisionShape(btCollisionShape* shape) override;
120 
121  virtual bool buildBvh() override;
122  virtual bool enabled() const override;
123  virtual bool isBvhBuilt() const override;
124 
125  virtual std::shared_ptr<btCollisionShape> bulletCollisionShape() const override;
126 
127  virtual unsigned int numberOfTriangles() const override;
128  virtual double radius() const override;
129  virtual DtSurface triangleSurface(unsigned int triangleIndex) const override;
130 
131  virtual DynamicFeatures dynamicFeatures() const override;
132 
133  virtual const btTransform& worldTransform() const override;
134 
135 protected:
137 };
138 
140 {
141  ProcessTriangle();
142  void operator() (const osg::Vec3& vec1, const osg::Vec3& vec2, const osg::Vec3& vec3, bool) const;
143 
145 };
146 
148 {
149  void operator() (const osg::Vec3& vec1, const osg::Vec3& vec2, const osg::Vec3& vec3) const;
150 
152  osg::Vec3d myScale;
153  bool myIsScale;
154 };
std::vector< std::shared_ptr< makVrv::DtDynamicTerrainFeature > > DynamicFeatures
Definition: bulletUtil.h:53
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:153
tbb::spin_mutex Mutex
Definition: bvhTriangleMeshShape.h:102
Definition: bvhTriangleMeshShape.h:147
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 std::shared_ptr< btCollisionShape > bulletCollisionShape() const =0
Access the underlying bullet collision shape.
virtual bool enabled() const =0
Intersections will ignore this object if this returns false.
Definition: surface.h:181
unsigned int DtTerrainGeometryId
Unique ID numbers that reference a specific geometry (or set of triangles) in the terrain...
Definition: terrainProcessPolygonsBox.h:38
DtBvhTriangleMeshShape::Ptr myShape
Definition: bvhTriangleMeshShape.h:136
Definition: bvhTriangleMeshShape.h:78
std::atomic< bool > myIsBvhBuilt
Definition: bvhTriangleMeshShape.h:108
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:144
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:152
btVector3 myMin
Definition: bvhTriangleMeshShape.h:73
int myTrianglesCount
Definition: bvhTriangleMeshShape.h:107
btVector3 myMax
Definition: bvhTriangleMeshShape.h:74
#define vec3
Definition: DtGlslToDtDefines.h:12
Definition: bvhTriangleMeshShape.h:112
Mutex myMutex
Definition: bvhTriangleMeshShape.h:104
DtTerrainGeometryId DtCollisionShapeId
Definition: bvhTriangleMeshShape.h:25
void operator()(const osg::Vec3 &vec1, const osg::Vec3 &vec2, const osg::Vec3 &vec3) const
Definition: bulletUtil.h:49
virtual DynamicFeatures dynamicFeatures() const =0
Return all the dynamic features which contain this object.
#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:151
std::shared_ptr< DtBvhTriangleMeshShape > Ptr
Definition: bvhTriangleMeshShape.h:83
DtTriangleMeshWithSoil * myMesh
Definition: bvhTriangleMeshShape.h:105
virtual const btTransform & worldTransform() const =0
Access the world transform of the collision object.
btAlignedObjectArray< DtSurface > mySurfaceTypes
Definition: bvhTriangleMeshShape.h:72
Definition: bvhTriangleMeshShape.h:139

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)