2#include "resources/Mesh.hpp"
4#include "raycaster/Intersection.hpp"
38 Hit(
float distance,
float uu,
float vv,
unsigned long lid,
unsigned long mid);
51 void addMesh(
const Mesh & mesh,
const glm::mat4 & model);
65 Hit intersects(
const glm::vec3 & origin,
const glm::vec3 & direction,
float mini = 0.0001f,
float maxi = 1e8f)
const;
74 bool intersectsAny(
const glm::vec3 & origin,
const glm::vec3 & direction,
float mini = 0.0001f,
float maxi = 1e8f)
const;
82 bool visible(
const glm::vec3 & p0,
const glm::vec3 & p1)
const;
92 const unsigned long triId = hit.
localId;
93 const unsigned long i0 = geometry.
indices[triId];
94 const unsigned long i1 = geometry.
indices[triId + 1];
95 const unsigned long i2 = geometry.
indices[triId + 2];
96 return hit.
w * attribute[i0] + hit.
u * attribute[i1] + hit.
v * attribute[i2];
119 unsigned long v0 = 0;
120 unsigned long v1 = 0;
121 unsigned long v2 = 0;
Represent the smallest axis-aligne box containing a given object or region of space.
Definition: Bounds.hpp:28
Represents a geometric mesh composed of vertices, other attributes and triangles.
Definition: Mesh.hpp:15
std::vector< unsigned int > indices
The triangular faces indices.
Definition: Mesh.hpp:132
Allows to cast rays against a polygonal mesh, on the CPU. Relies on an internal acceleration structur...
Definition: Raycaster.hpp:10
Raycaster(Raycaster &&)=delete
Hit intersects(const glm::vec3 &origin, const glm::vec3 &direction, float mini=0.0001f, float maxi=1e8f) const
Definition: Raycaster.cpp:144
bool intersectsAny(const glm::vec3 &origin, const glm::vec3 &direction, float mini=0.0001f, float maxi=1e8f) const
Definition: Raycaster.cpp:187
static T interpolateAttribute(const Hit &hit, const Mesh &geometry, const std::vector< T > &attribute)
Definition: Raycaster.hpp:91
void addMesh(const Mesh &mesh, const glm::mat4 &model)
Definition: Raycaster.cpp:14
unsigned int _meshCount
Number of meshes stored in the raycaster.
Definition: Raycaster.hpp:156
std::vector< Node > _hierarchy
Acceleration structure.
Definition: Raycaster.hpp:154
Raycaster & operator=(const Raycaster &)=delete
void updateHierarchy()
Definition: Raycaster.cpp:54
bool visible(const glm::vec3 &p0, const glm::vec3 &p1) const
Definition: Raycaster.cpp:226
std::vector< glm::vec3 > _vertices
Merged vertices.
Definition: Raycaster.hpp:153
Raycaster(const Raycaster &)=delete
std::vector< TriangleInfos > _triangles
Merged triangles informations.
Definition: Raycaster.hpp:152
static bool intersects(const Ray &ray, const BoundingBox &box, float mini, float maxi)
Raycaster & operator=(Raycaster &&)=delete
Helper that can generate information on a raycaster internal data: BVH visualisation,...
Definition: RaycasterVisualisation.hpp:10
Represent a ray, shot from a given position in a specific direction.
Definition: Intersection.hpp:10
Definition: Raycaster.hpp:16
unsigned long localId
Position of the hit triangle first vertex in the mesh index buffer.
Definition: Raycaster.hpp:25
float dist
Distance from the ray origin to the hit location.
Definition: Raycaster.hpp:21
unsigned long internalId
Index of the triangle in the raycaster internal primitive list.
Definition: Raycaster.hpp:41
bool hit
Denote if there has been a hit.
Definition: Raycaster.hpp:20
float u
First barycentric coordinate.
Definition: Raycaster.hpp:22
float v
Second barycentric coordinate.
Definition: Raycaster.hpp:23
unsigned long meshId
Index of the mesh hit by the ray.
Definition: Raycaster.hpp:26
Hit()
Definition: Raycaster.cpp:6
float w
Third barycentric coordinate.
Definition: Raycaster.hpp:24
Definition: Raycaster.hpp:127
size_t left
Index of the left child element, or first triangle index if this is a leaf.
Definition: Raycaster.hpp:129
size_t right
Index of the right child element, or number of triangles if this is a leaf.
Definition: Raycaster.hpp:130
bool leaf
Is this a leaf in the hierarchy.
Definition: Raycaster.hpp:131
BoundingBox box
Bounding box of the contained geometry.
Definition: Raycaster.hpp:128
Definition: Raycaster.hpp:117
unsigned int meshId
Index of the mesh this triangle belongs to.
Definition: Raycaster.hpp:123
unsigned long localId
Position of the triangle first vertex in the mesh initial index buffer.
Definition: Raycaster.hpp:122
unsigned long v1
Second vertex index.
Definition: Raycaster.hpp:120
unsigned long v2
Third vertex index.
Definition: Raycaster.hpp:121
unsigned long v0
First vertex index.
Definition: Raycaster.hpp:119
BoundingBox box
The triangle axis-aligned bounding box.
Definition: Raycaster.hpp:118