Ocean
TracingMesh.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_RENDERING_GI_TRACING_MESH_H
9 #define META_OCEAN_RENDERING_GI_TRACING_MESH_H
10 
14 
15 #include "ocean/math/BoundingBox.h"
17 #include "ocean/math/Triangle3.h"
18 
21 
22 namespace Ocean
23 {
24 
25 namespace Rendering
26 {
27 
28 namespace GlobalIllumination
29 {
30 
31 /**
32  * This class implements the tracing object for a mesh.
33  * @ingroup renderinggi
34  */
35 class OCEAN_RENDERING_GI_EXPORT TracingMesh : public TracingObject
36 {
37  private:
38 
39  /**
40  * This class implements a simple octree-like structure allowing to optimized the intersection performance.
41  * An octree instance is composed of a bounding box, a set of vertices belonging to the octree and optional octree children.
42  */
43  class Octree
44  {
45  public:
46 
47  /**
48  * Creates a new octree object by a set of given indices and an corresponding mesh object.
49  * @param indices The indices of all vertices which will be covert by the new octree object
50  * @param mesh The mesh holding the entire mesh already
51  */
52  Octree(const VertexIndices& indices, const TracingMesh& mesh);
53 
54  /**
55  * Destructs an octree object.
56  */
58 
59  /**
60  * Determines the nearest intersection with between this tracing object and a given 3D ray.
61  * @see TracingObject::findNearestIntersection().
62  */
63  void findNearestIntersection(const Line3& ray, const HomogenousMatrix4& objectTransformation, const HomogenousMatrix4& invertedObjectTransformation, const TracingMesh& mesh, RayIntersection& intersection, const bool frontFace, const Scalar eps, const TracingObject* excludedObject = nullptr) const;
64 
65  /**
66  * Determines whether this tracing object has an intersection with a provided 3D ray.
67  * @see TracingObject::hasIntersection().
68  */
69  bool hasIntersection(const Line3& ray, const HomogenousMatrix4& objectTransformation, const HomogenousMatrix4& invertedObjectTransformation, const TracingMesh& mesh, const Scalar maximalDistance = Numeric::maxValue(), const TracingObject* excludedObject = nullptr) const;
70 
71  protected:
72 
73  /// The bounding box of this octree object.
75 
76  /// This indices of all vertices which are covert by this octree object.
78 
79  /// Up to eight octree children object, nullptr if a child does not exist.
80  Octree* octreeChildren[8];
81  };
82 
83  public:
84 
85  /**
86  * Creates a new tracing object.
87  */
89 
90  /**
91  * Destructs this tracing object.
92  */
93  ~TracingMesh() override;
94 
95  /**
96  * Defines the mesh by setting individual triangles.
97  * @param localVertices The entire set of vertices, defined in the local coordinate system
98  * @param localNormals The entire set of normals, defined in the local coordinate system, one normal for each vertex
99  * @param textureCoordinates The entire set of texture coordinates, one texture coordinate for each vertex
100  * @param faces The topology of the mesh, defining the individual triangles, indices with range [0, localVertices.size())
101  * @param objectTransformation The transformation of the local coordinate system transforming points defined in the local coordinate system to points defined in the world coordinate system
102  * @param localBoundingBox The bounding box of all used vertices, defined in the local coordinate system
103  */
104  void setTriangles(const Vertices& localVertices, const Normals& localNormals, const TextureCoordinates& textureCoordinates, const TriangleFaces& faces, const HomogenousMatrix4& objectTransformation, const BoundingBox& localBoundingBox);
105 
106  /**
107  * Defines the mesh by setting a triangle strip.
108  * @param localVertices The entire set of vertices, defined in the local coordinate system
109  * @param localNormals The entire set of normals, defined in the local coordinate system, one normal for each vertex
110  * @param textureCoordinates The entire set of texture coordinates, one texture coordinate for each vertex
111  * @param indicesSet The topology of the mesh, defining the individual triangles, indices with range [0, localVertices.size())
112  * @param objectTransformation The transformation of the local coordinate system transforming points defined in the local coordinate system to points defined in the world coordinate system
113  * @param localBoundingBox The bounding box of all used vertices, defined in the local coordinate system
114  */
115  void setTriangleStrips(const Vertices& localVertices, const Normals& localNormals, const TextureCoordinates& textureCoordinates, const VertexIndexGroups& indicesSet, const HomogenousMatrix4& objectTransformation, const BoundingBox& localBoundingBox);
116 
117  /**
118  * Determines the nearest intersection with between this tracing object and a given 3D ray.
119  * @see TracingObject::findNearestIntersection().
120  */
121  void findNearestIntersection(const Line3& ray, RayIntersection& intersection, const bool frontFace, const Scalar eps, const TracingObject* excludedObject = nullptr) const override;
122 
123  /**
124  * Determines whether this tracing object has an intersection with a provided 3D ray.
125  * @see TracingObject::hasIntersection().
126  */
127  bool hasIntersection(const Line3& ray, const Scalar maximalDistance = Numeric::maxValue(), const TracingObject* excludedObject = nullptr) const override;
128 
129  /**
130  * Determines the amount of light that transmits trough this object in the case e.g., this object is transparent.
131  * @see TracingObject::determineDampingColor().
132  */
133  bool determineDampingColor(const Line3& ray, RGBAColor& color, const Scalar maximalDistance = Numeric::maxValue()) const override;
134 
135  /**
136  * Determines the light (the color) for a specified viewing ray this object does reflect.
137  * @see TracingObject::determineColor().
138  */
139  bool determineColor(const Vector3& viewPosition, const Vector3& viewObjectDirection, const RayIntersection& intersection, const TracingGroup& group, const unsigned int bounces, const TracingObject* excludedObject, const Lighting::LightingModes lightingModes, RGBAColor& color) const override;
140 
141  private:
142 
143  /// The bounding box of this tracing object.
145 
146  /// The bounding sphere of this tracing object.
148 
149  /// The 3D triangles representing the mesh.
151 
152  /// The set of normals connected with the mesh's triangles.
154 
155  /// The set of texture coordinates connected with the mesh's triangles.
157 
158  /// The octree used to improved the performance of the intersection determination process.
160 };
161 
162 }
163 
164 }
165 
166 }
167 
168 #endif // META_OCEAN_RENDERING_GI_TRACING_MESH_H
This class implements a 3D bounding box.
Definition: BoundingBox.h:23
This class implements a bounding sphere.
Definition: BoundingSphere.h:23
This class implements an infinite line in 3D space.
Definition: Line3.h:70
static constexpr T maxValue()
Returns the max scalar value.
Definition: Numeric.h:3244
This class implements a color defined by red, green, blue and alpha parameters.
Definition: RGBAColor.h:41
LightingModes
Definition of individual lighting modes.
Definition: Lighting.h:47
This class implements a ray intersection object.
Definition: RayIntersection.h:44
This class implements a group of tracing objects.
Definition: TracingGroup.h:28
This class implements a simple octree-like structure allowing to optimized the intersection performan...
Definition: TracingMesh.h:44
void findNearestIntersection(const Line3 &ray, const HomogenousMatrix4 &objectTransformation, const HomogenousMatrix4 &invertedObjectTransformation, const TracingMesh &mesh, RayIntersection &intersection, const bool frontFace, const Scalar eps, const TracingObject *excludedObject=nullptr) const
Determines the nearest intersection with between this tracing object and a given 3D ray.
VertexIndices octreeIndices
This indices of all vertices which are covert by this octree object.
Definition: TracingMesh.h:77
bool hasIntersection(const Line3 &ray, const HomogenousMatrix4 &objectTransformation, const HomogenousMatrix4 &invertedObjectTransformation, const TracingMesh &mesh, const Scalar maximalDistance=Numeric::maxValue(), const TracingObject *excludedObject=nullptr) const
Determines whether this tracing object has an intersection with a provided 3D ray.
Octree(const VertexIndices &indices, const TracingMesh &mesh)
Creates a new octree object by a set of given indices and an corresponding mesh object.
BoundingBox octreeBoundingBox
The bounding box of this octree object.
Definition: TracingMesh.h:74
This class implements the tracing object for a mesh.
Definition: TracingMesh.h:36
Triangles3 tracingTriangles
The 3D triangles representing the mesh.
Definition: TracingMesh.h:150
BoundingSphere tracingLocalBoundingSphere
The bounding sphere of this tracing object.
Definition: TracingMesh.h:147
BoundingBox tracingLocalBoundingBox
The bounding box of this tracing object.
Definition: TracingMesh.h:144
~TracingMesh() override
Destructs this tracing object.
Octree * tracingOctree
The octree used to improved the performance of the intersection determination process.
Definition: TracingMesh.h:159
bool hasIntersection(const Line3 &ray, const Scalar maximalDistance=Numeric::maxValue(), const TracingObject *excludedObject=nullptr) const override
Determines whether this tracing object has an intersection with a provided 3D ray.
Normals tracingNormals
The set of normals connected with the mesh's triangles.
Definition: TracingMesh.h:153
bool determineDampingColor(const Line3 &ray, RGBAColor &color, const Scalar maximalDistance=Numeric::maxValue()) const override
Determines the amount of light that transmits trough this object in the case e.g.,...
void setTriangles(const Vertices &localVertices, const Normals &localNormals, const TextureCoordinates &textureCoordinates, const TriangleFaces &faces, const HomogenousMatrix4 &objectTransformation, const BoundingBox &localBoundingBox)
Defines the mesh by setting individual triangles.
void findNearestIntersection(const Line3 &ray, RayIntersection &intersection, const bool frontFace, const Scalar eps, const TracingObject *excludedObject=nullptr) const override
Determines the nearest intersection with between this tracing object and a given 3D ray.
TextureCoordinates tracingTextureCoordinates
The set of texture coordinates connected with the mesh's triangles.
Definition: TracingMesh.h:156
TracingMesh()
Creates a new tracing object.
bool determineColor(const Vector3 &viewPosition, const Vector3 &viewObjectDirection, const RayIntersection &intersection, const TracingGroup &group, const unsigned int bounces, const TracingObject *excludedObject, const Lighting::LightingModes lightingModes, RGBAColor &color) const override
Determines the light (the color) for a specified viewing ray this object does reflect.
void setTriangleStrips(const Vertices &localVertices, const Normals &localNormals, const TextureCoordinates &textureCoordinates, const VertexIndexGroups &indicesSet, const HomogenousMatrix4 &objectTransformation, const BoundingBox &localBoundingBox)
Defines the mesh by setting a triangle strip.
This class is the abstract base class for all tracing objects.
Definition: TracingObject.h:39
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< Triangle3 > Triangles3
Definition of a vector holding 3D triangles.
Definition: Triangle3.h:57
std::vector< Vertex > Vertices
Definition of a vector holding vertices.
Definition: rendering/Rendering.h:119
std::vector< TextureCoordinate > TextureCoordinates
Definition of a vector holding texture coordinates.
Definition: rendering/Rendering.h:113
std::vector< Normal > Normals
Definition of a vector holding normals.
Definition: rendering/Rendering.h:107
std::vector< TriangleFace > TriangleFaces
Definition of a vector holding triangle faces.
Definition: TriangleFace.h:23
std::vector< VertexIndices > VertexIndexGroups
Definition of a vector holding vertex indices.
Definition: rendering/Rendering.h:125
std::vector< VertexIndex > VertexIndices
Definition of a vector holding vertex indices.
Definition: rendering/Rendering.h:101
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15