Atoms Crowd  7.0.0
Bvh.h
1 #pragma once
2 #ifndef DISABLE_BVH
3 #include <AtomsUtils/AtomsMath.h>
4 #include <AtomsUtils/Mesh.h>
5 #include <vector>
6 
7 namespace AtomsUtils {
8 
9  enum BVHNodeType { INTERNAL, LEAF };
10  struct BVHNode {
11 
12  int leftChildIndex;
13  int rightChildIndex;
14  int start;
15  int end;
16  BVHNodeType leftType;
17  BVHNodeType rightType;
18  };
19 
20  struct MortonCode {
21  unsigned int code;
22  int index;
23  };
24 
25  class Bvh {
26  public:
27  Bvh();
28 
29  ~Bvh();
30 
31  void init(Mesh *mesh);
32  void clear();
33 
34  bool intersect(const AtomsMath::Vector3f &orig, const AtomsMath::Vector3f &dir, float &param,
35  unsigned int &outFaceId, float &outU, float &outV,
36  bool bothDirection) const;
37  bool RayIntersectsTriangle(const AtomsMath::Vector3f rayOrigin,
38  const AtomsMath::Vector3f rayVector, int i,
39  AtomsMath::Vector3f &outIntersectionPoint,
40  float &param) const;
41 
42  std::vector<MortonCode> mortons;
43  std::vector<BVHNode> internalNodes;
44  std::vector<AtomsMath::Vector3f> treeAABBs;
45  AtomsUtils::Mesh *m_mesh;
46  std::vector<AtomsMath::Vector3f> m_outMesh;
47  };
48 } // namespace AtomsUtils
49 #else
50 namespace AtomsUtils {
51 
52 class Bvh {
53 public:
54  Bvh() {}
55 
56  ~Bvh() {}
57 
58  void init(Mesh *mesh) {}
59  void clear() {}
60 
61  bool intersect(const AtomsMath::Vector3f &orig, const AtomsMath::Vector3f &dir, float &param,
62  unsigned int &outFaceId, float &outU, float &outV,
63  bool bothDirection) const {
64  return false;
65  }
66  bool RayIntersectsTriangle(const AtomsMath::Vector3f rayOrigin,
67  const AtomsMath::Vector3f rayVector, int i,
68  AtomsMath::Vector3f &outIntersectionPoint,
69  float &param) const {
70  return false;
71  }
72 };
73 }
74 #endif
Definition: Bvh.h:25
Mesh class.
Definition: Mesh.h:30
AtomsCore namespace.
Definition: Base64.h:13
Definition: Bvh.h:10
Definition: Bvh.h:20