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/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>
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>
36 namespace Dali::Scene3D::Loader
38 class NavigationMeshFactory;
41 namespace Dali::Scene3D::Internal::Algorithm
46 * @class NavigationMesh
51 using Face = Dali::Scene3D::Algorithm::NavigationMesh::Face;
52 using Edge = Dali::Scene3D::Algorithm::NavigationMesh::Edge;
53 using Vertex = Dali::Scene3D::Algorithm::NavigationMesh::Vertex;
56 friend class Scene3D::Loader::NavigationMeshFactory;
61 NavigationMesh(const std::vector<uint8_t>& buffer);
67 ~NavigationMesh() = default;
70 * Result of Ray/Polygon intersection
72 struct IntersectResult
81 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetFaceCount()
83 [[nodiscard]] uint32_t GetFaceCount() const;
86 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetEdgeCount()
88 [[nodiscard]] uint32_t GetEdgeCount() const;
91 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetVertexCount()
93 [[nodiscard]] uint32_t GetVertexCount() const;
96 * Looks for floor only within the face
97 * @param[in] position Position to be projected onto the face
98 * @param[in] faceIndex Face index
99 * @param[in] dontCheckNeighbours states whether to traverse onto neighbouring faces
100 * @param[out] outPosition Output position
102 * @return true if success
104 bool FindFloorForFace(const Dali::Vector3& position, uint32_t faceIndex, bool dontCheckNeighbours, Dali::Vector3& outPosition);
107 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::FindFloor()
109 bool FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition);
112 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::FindFloor()
114 bool FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition, uint32_t& faceIndex);
117 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetFace()
119 [[nodiscard]] const Face* GetFace(int index) const;
122 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetEdge()
124 [[nodiscard]] const Edge* GetEdge(int index) const;
127 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetVertex()
129 [[nodiscard]] const Vertex* GetVertex(int index) const;
132 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::SetSceneTransform()
134 void SetTransform(const Dali::Matrix& transform);
137 * Tests intersection between navigation ray and face
139 IntersectResult NavigationRayFaceIntersection(NavigationRay& ray, const Face& face);
142 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::PointSceneToLocal()
144 Dali::Vector3 PointSceneToLocal(const Dali::Vector3& point);
147 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::PointLocalToScene()
149 Dali::Vector3 PointLocalToScene(const Dali::Vector3& point);
152 * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetGravityVector()
154 [[nodiscard]] Dali::Vector3 GetGravityVector() const;
157 std::vector<uint8_t> mBuffer; //< Data buffer
158 NavigationMeshHeader_V10 mHeader; //< Navigation mesh header
159 uint16_t mCurrentFace; //< Current face (last floor position)
160 Dali::Matrix mTransform; //< Transform matrix
161 Dali::Matrix mTransformInverse; //< Inverse of the transform matrix
164 inline Internal::Algorithm::NavigationMesh& GetImplementation(Dali::Scene3D::Algorithm::NavigationMesh& navigationMesh)
166 return *navigationMesh.mImpl;
169 } // namespace Dali::Scene3D::Internal::Algorithm
171 #endif // DALI_SCENE3D_INTERNAL_NAVIGATION_MESH_H