Merge "Doxygen check version and block low version" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / algorithm / navigation-mesh-impl.h
1 #ifndef DALI_SCENE3D_INTERNAL_NAVIGATION_MESH_H
2 #define DALI_SCENE3D_INTERNAL_NAVIGATION_MESH_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 // INTERNAL INCLUDES
21 #include <dali-scene3d/public-api/algorithm/navigation-mesh.h>
22 #include <dali-scene3d/public-api/algorithm/path-finder.h>
23
24 // INTERNAL EXTERNAL
25 #include <dali/public-api/actors/actor.h>
26 #include <dali/public-api/math/matrix.h>
27 #include <dali/public-api/math/vector3.h>
28 #include <dali/public-api/math/vector4.h>
29
30 #include <cinttypes>
31 #include <cstdio>
32 #include <mutex>
33 #include <vector>
34 #include "navigation-mesh-header.h"
35
36 namespace Dali::Scene3D::Loader
37 {
38 class NavigationMeshFactory;
39 }
40
41 namespace Dali::Scene3D::Internal::Algorithm
42 {
43
44 class NavigationRay;
45
46 /**
47  * @class NavigationMesh
48  */
49 class NavigationMesh
50 {
51 public:
52   using Face   = Dali::Scene3D::Algorithm::NavigationMesh::Face;
53   using Edge   = Dali::Scene3D::Algorithm::NavigationMesh::Edge;
54   using Vertex = Dali::Scene3D::Algorithm::NavigationMesh::Vertex;
55
56 private:
57
58   friend class Scene3D::Loader::NavigationMeshFactory;
59
60   /**
61    * Constructor
62    */
63   NavigationMesh(const std::vector<uint8_t>& buffer);
64
65 public:
66
67   /**
68    * Destructor
69    */
70   ~NavigationMesh() = default;
71
72   /**
73    * Result of Ray/Polygon intersection
74    */
75   struct IntersectResult
76   {
77     Dali::Vector3 point;
78     float         distance;
79     uint16_t      faceIndex;
80     bool          result;
81   };
82
83   /**
84    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetFaceCount()
85    */
86   [[nodiscard]] uint32_t GetFaceCount() const;
87
88   /**
89    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetEdgeCount()
90    */
91   [[nodiscard]] uint32_t GetEdgeCount() const;
92
93   /**
94    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetVertexCount()
95    */
96   [[nodiscard]] uint32_t GetVertexCount() const;
97
98   /**
99    * Looks for floor only within the face
100    * @param[in] position Position to be projected onto the face
101    * @param[in] faceIndex Face index
102    * @param[in] dontCheckNeighbours states whether to traverse onto neighbouring faces
103    * @param[out] outPosition Output position
104    *
105    * @return true if success
106    */
107   bool FindFloorForFace(const Dali::Vector3& position, uint32_t faceIndex, bool dontCheckNeighbours, Dali::Vector3& outPosition);
108
109   /**
110    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::FindFloor()
111    */
112   bool FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition);
113
114   /**
115    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::FindFloor()
116    */
117   bool FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition, uint32_t& faceIndex);
118
119   /**
120    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetFace()
121    */
122   [[nodiscard]] const Face* GetFace(int index) const;
123
124   /**
125    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetEdge()
126    */
127   [[nodiscard]] const Edge* GetEdge(int index) const;
128
129   /**
130    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetVertex()
131    */
132   [[nodiscard]] const Vertex* GetVertex(int index) const;
133
134   /**
135    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::SetSceneTransform()
136    */
137   void SetTransform(const Dali::Matrix& transform);
138
139   /**
140    * Tests intersection between navigation ray and face
141    */
142   IntersectResult NavigationRayFaceIntersection(NavigationRay& ray, const Face& face);
143
144   /**
145    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::PointSceneToLocal()
146    */
147   Dali::Vector3 PointSceneToLocal(const Dali::Vector3& point);
148
149   /**
150    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::PointLocalToScene()
151    */
152   Dali::Vector3 PointLocalToScene(const Dali::Vector3& point);
153
154   /**
155    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetGravityVector()
156    */
157   [[nodiscard]] Dali::Vector3 GetGravityVector() const;
158
159 private:
160   std::vector<uint8_t> mBuffer;                    //< Data buffer
161   NavigationMeshHeader_V10 mHeader;                //< Navigation mesh header
162   uint16_t             mCurrentFace;               //< Current face (last floor position)
163   Dali::Matrix         mTransform;                 //< Transform matrix
164   Dali::Matrix         mTransformInverse;          //< Inverse of the transform matrix
165 };
166
167 inline Internal::Algorithm::NavigationMesh& GetImplementation(Dali::Scene3D::Algorithm::NavigationMesh& navigationMesh)
168 {
169   return *navigationMesh.mImpl;
170 }
171
172 } // namespace Dali::Scene3D::Internal::Algorithm
173
174 #endif // DALI_SCENE3D_INTERNAL_NAVIGATION_MESH_H