1 #ifndef DALI_SCENE3D_INTERNAL_NAVIGATION_MESH_H
2 #define DALI_SCENE3D_INTERNAL_NAVIGATION_MESH_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali-scene3d/public-api/algorithm/navigation-mesh.h>
22 #include <dali-scene3d/public-api/algorithm/path-finder.h>
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>
34 #include "navigation-mesh-header.h"
36 namespace Dali::Scene3D::Loader
38 class NavigationMeshFactory;
41 namespace Dali::Scene3D::Internal::Algorithm
47 * @class NavigationMesh
52 using Face = Dali::Scene3D::Algorithm::NavigationMesh::Face;
53 using Edge = Dali::Scene3D::Algorithm::NavigationMesh::Edge;
54 using Vertex = Dali::Scene3D::Algorithm::NavigationMesh::Vertex;
58 friend class Scene3D::Loader::NavigationMeshFactory;
63 NavigationMesh(const std::vector<uint8_t>& buffer);
70 ~NavigationMesh() = default;
73 * Result of Ray/Polygon intersection
75 struct IntersectResult
84 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetFaceCount()
86 [[nodiscard]] uint32_t GetFaceCount() const;
89 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetEdgeCount()
91 [[nodiscard]] uint32_t GetEdgeCount() const;
94 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetVertexCount()
96 [[nodiscard]] uint32_t GetVertexCount() const;
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
105 * @return true if success
107 bool FindFloorForFace(const Dali::Vector3& position, uint32_t faceIndex, bool dontCheckNeighbours, Dali::Vector3& outPosition);
110 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::FindFloor()
112 bool FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition);
115 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::FindFloor()
117 bool FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition, uint32_t& faceIndex);
120 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetFace()
122 [[nodiscard]] const Face* GetFace(int index) const;
125 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetEdge()
127 [[nodiscard]] const Edge* GetEdge(int index) const;
130 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetVertex()
132 [[nodiscard]] const Vertex* GetVertex(int index) const;
135 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::SetSceneTransform()
137 void SetTransform(const Dali::Matrix& transform);
140 * Tests intersection between navigation ray and face
142 IntersectResult NavigationRayFaceIntersection(NavigationRay& ray, const Face& face);
145 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::PointSceneToLocal()
147 Dali::Vector3 PointSceneToLocal(const Dali::Vector3& point);
150 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::PointLocalToScene()
152 Dali::Vector3 PointLocalToScene(const Dali::Vector3& point);
155 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetGravityVector()
157 [[nodiscard]] Dali::Vector3 GetGravityVector() const;
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
167 inline Internal::Algorithm::NavigationMesh& GetImplementation(Dali::Scene3D::Algorithm::NavigationMesh& navigationMesh)
169 return *navigationMesh.mImpl;
172 } // namespace Dali::Scene3D::Internal::Algorithm
174 #endif // DALI_SCENE3D_INTERNAL_NAVIGATION_MESH_H