Revert "[Tizen] Add log if destroyed visual get some signal"
[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 // EXTERNAL EXTERNAL
21 #include <dali/public-api/actors/actor.h>
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/math/matrix.h>
24 #include <dali/public-api/math/vector3.h>
25 #include <dali/public-api/math/vector4.h>
26
27 #include <cinttypes>
28 #include <cstdio>
29 #include <mutex>
30
31 // INTERNAL INCLUDES
32 #include <dali-scene3d/internal/algorithm/navigation-mesh-header.h>
33 #include <dali-scene3d/public-api/algorithm/navigation-mesh.h>
34 #include <dali-scene3d/public-api/algorithm/path-finder.h>
35
36 namespace Dali::Scene3D::Loader
37 {
38 class NavigationMeshFactory;
39 }
40
41 namespace Dali::Scene3D::Internal::Algorithm
42 {
43 class NavigationRay;
44
45 // Make each to change each index value's type here.
46 using VertexIndex = Dali::Scene3D::Algorithm::VertexIndex;
47 using EdgeIndex   = Dali::Scene3D::Algorithm::EdgeIndex;
48 using FaceIndex   = Dali::Scene3D::Algorithm::FaceIndex;
49
50 /**
51  * @class NavigationMesh
52  */
53 class NavigationMesh
54 {
55 public:
56   using Face   = Dali::Scene3D::Algorithm::NavigationMesh::Face;
57   using Edge   = Dali::Scene3D::Algorithm::NavigationMesh::Edge;
58   using Vertex = Dali::Scene3D::Algorithm::NavigationMesh::Vertex;
59
60 private:
61   friend class Scene3D::Loader::NavigationMeshFactory;
62
63   /**
64    * Constructor
65    */
66   NavigationMesh(const std::vector<uint8_t>& buffer);
67
68 public:
69   /**
70    * Destructor
71    */
72   ~NavigationMesh() = default;
73
74   /**
75    * Result of Ray/Polygon intersection
76    */
77   struct IntersectResult
78   {
79     Dali::Vector3 point;
80     float         distance;
81     FaceIndex     faceIndex;
82     bool          result;
83   };
84
85   /**
86    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetFaceCount()
87    */
88   [[nodiscard]] uint32_t GetFaceCount() const;
89
90   /**
91    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetEdgeCount()
92    */
93   [[nodiscard]] uint32_t GetEdgeCount() const;
94
95   /**
96    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetVertexCount()
97    */
98   [[nodiscard]] uint32_t GetVertexCount() const;
99
100   /**
101    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::FindFloorForFace()
102    */
103   bool FindFloorForFace(const Dali::Vector3& position, FaceIndex faceIndex, bool dontCheckNeighbours, Dali::Vector3& outPosition);
104
105   /**
106    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::FindFloor()
107    */
108   bool FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition);
109
110   /**
111    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::FindFloor()
112    */
113   bool FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition, FaceIndex& faceIndex);
114
115   /**
116    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetFace()
117    */
118   [[nodiscard]] const Face* GetFace(FaceIndex index) const;
119
120   /**
121    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetEdge()
122    */
123   [[nodiscard]] const Edge* GetEdge(EdgeIndex index) const;
124
125   /**
126    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetVertex()
127    */
128   [[nodiscard]] const Vertex* GetVertex(VertexIndex index) const;
129
130   /**
131    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::SetSceneTransform()
132    */
133   void SetTransform(const Dali::Matrix& transform);
134
135   /**
136    * Tests intersection between navigation ray and face
137    */
138   IntersectResult NavigationRayFaceIntersection(NavigationRay& ray, const Face& face) const;
139
140   /**
141    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::PointSceneToLocal()
142    */
143   Dali::Vector3 PointSceneToLocal(const Dali::Vector3& point) const;
144
145   /**
146    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::PointLocalToScene()
147    */
148   Dali::Vector3 PointLocalToScene(const Dali::Vector3& point) const;
149
150   /**
151    * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetGravityVector()
152    */
153   [[nodiscard]] Dali::Vector3 GetGravityVector() const;
154
155 private:
156   std::vector<uint8_t>     mBuffer;           //< Data buffer
157   NavigationMeshHeader_V10 mHeader;           //< Navigation mesh header
158   FaceIndex                mCurrentFace;      //< Current face (last floor position)
159   Dali::Matrix             mTransform;        //< Transform matrix
160   Dali::Matrix             mTransformInverse; //< Inverse of the transform matrix
161 };
162
163 inline Internal::Algorithm::NavigationMesh& GetImplementation(Dali::Scene3D::Algorithm::NavigationMesh& navigationMesh)
164 {
165   return *navigationMesh.mImpl;
166 }
167
168 } // namespace Dali::Scene3D::Internal::Algorithm
169
170 #endif // DALI_SCENE3D_INTERNAL_NAVIGATION_MESH_H