*
*/
-#include "dali-scene3d/public-api/algorithm/navigation-mesh.h"
-#include "dali-scene3d/public-api/loader/navigation-mesh-factory.h"
#include <dali-test-suite-utils.h>
#include <dlfcn.h>
+#include "dali-scene3d/public-api/algorithm/navigation-mesh.h"
+#include "dali-scene3d/public-api/loader/navigation-mesh-factory.h"
using namespace Dali;
using namespace Dali::Scene3D::Algorithm;
using namespace Dali::Scene3D::Loader;
}
}
- void SetReturnValue( R value, uint32_t n )
+ void SetReturnValue(R value, uint32_t n)
{
if(overrideEnabled)
{
tet_infoline("Warning! Overriding return value is already enabled! Ignoring!\n");
return;
}
- result = value;
+ result = value;
overrideCounter = n;
overrideEnabled = true;
}
}
std::string funcNameStr;
- R result{R{}};
- F* func{nullptr};
- uint32_t overrideCounter = 0;
- bool overrideEnabled = false;
+ R result{R{}};
+ F* func{nullptr};
+ uint32_t overrideCounter = 0;
+ bool overrideEnabled = false;
};
// Override fseek()
static thread_local SysOverride<int, decltype(fseek)> call_fseek("fseek");
-extern "C" int fseek (FILE *s, long int o, int w)
+extern "C" int fseek(FILE* s, long int o, int w)
{
- return call_fseek.Invoke( s, o, w );
+ return call_fseek.Invoke(s, o, w);
}
// Override ftell()
static thread_local SysOverride<int, decltype(ftell)> call_ftell("ftell");
-extern "C" long int ftell(FILE *s)
+extern "C" long int ftell(FILE* s)
{
- return call_ftell.Invoke( s );
+ return call_ftell.Invoke(s);
}
// Override fread()
static thread_local SysOverride<int, decltype(fread)> call_fread("fread");
-extern "C" size_t fread (void *__restrict p, size_t s, size_t n, FILE *__restrict st)
+extern "C" size_t fread(void* __restrict p, size_t s, size_t n, FILE* __restrict st)
{
return call_fread.Invoke(p, s, n, st);
}
{
tet_infoline("UtcDaliNavigationMeshCreateFromBufferP: Creates navigation mesh using binary buffer");
- auto fin = fopen("resources/navmesh-test.bin", "rb");
- [[maybe_unused]] auto err = fseek(fin, 0, SEEK_END);
- auto length = ftell(fin);
- fseek( fin, 0, SEEK_SET);
+ auto fin = fopen("resources/navmesh-test.bin", "rb");
+ [[maybe_unused]] auto err = fseek(fin, 0, SEEK_END);
+ auto length = ftell(fin);
+ fseek(fin, 0, SEEK_SET);
std::vector<uint8_t> buffer;
buffer.resize(length);
- fread( buffer.data(), 1, length, fin );
+ fread(buffer.data(), 1, length, fin);
fclose(fin);
- auto result = NavigationMeshFactory::CreateFromBuffer( buffer );
+ auto result = NavigationMeshFactory::CreateFromBuffer(buffer);
DALI_TEST_CHECK(result != nullptr);
END_TEST;
DALI_TEST_CHECK(result != nullptr);
auto vertexCount = result->GetVertexCount();
- auto edgeCount = result->GetEdgeCount();
- auto faceCount = result->GetFaceCount();
+ auto edgeCount = result->GetEdgeCount();
+ auto faceCount = result->GetFaceCount();
- DALI_TEST_EQUALS( vertexCount, 132, TEST_LOCATION );
- DALI_TEST_EQUALS( edgeCount, 300, TEST_LOCATION );
- DALI_TEST_EQUALS( faceCount, 165, TEST_LOCATION );
+ DALI_TEST_EQUALS(vertexCount, 132, TEST_LOCATION);
+ DALI_TEST_EQUALS(edgeCount, 300, TEST_LOCATION);
+ DALI_TEST_EQUALS(faceCount, 165, TEST_LOCATION);
END_TEST;
}
auto vertexCount = navmesh->GetVertexCount();
- DALI_TEST_EQUALS( vertexCount, 132, TEST_LOCATION );
+ DALI_TEST_EQUALS(vertexCount, 132, TEST_LOCATION);
// List of coords, must be verified with Blender exporter
// clang-format off
// clang-format on
auto j = 0;
- for( auto i = 0u; i < 132; i+= 10, j+= 3)
+ for(auto i = 0u; i < 132; i += 10, j += 3)
{
const auto* vertex = navmesh->GetVertex(i);
- Vector3 v0(vertex->co);
- Vector3 v1(vertexData[j], vertexData[j+1], vertexData[j+2]);
- DALI_TEST_EQUALS( v0, v1, TEST_LOCATION);
+ Vector3 v0(vertex->coordinates);
+ Vector3 v1(vertexData[j], vertexData[j + 1], vertexData[j + 2]);
+ DALI_TEST_EQUALS(v0, v1, TEST_LOCATION);
}
END_TEST;
auto edgeCount = navmesh->GetEdgeCount();
- DALI_TEST_EQUALS( edgeCount, 300, TEST_LOCATION );
+ DALI_TEST_EQUALS(edgeCount, 300, TEST_LOCATION);
// List of coords, must be verified with Blender exporter
// clang-format off
- std::vector<uint16_t> edgeData = {
+ std::vector<EdgeIndex> edgeData = {
2, 65535, 8, 1,
8, 109, 124, 108,
10, 158, 32, 35,
};
// clang-format on
auto j = 0;
- for( auto i = 0u; i < 300; i+= 30, j+= 4)
+ for(auto i = 0u; i < 300; i += 30, j += 4)
{
const auto* edge = navmesh->GetEdge(i);
- auto e0 = edge->face[0];
- auto e1 = edge->face[1];
- auto v0 = edge->vertex[0];
- auto v1 = edge->vertex[1];
-
- DALI_TEST_EQUALS(e0, edgeData[j+0], TEST_LOCATION);
- DALI_TEST_EQUALS(e1, edgeData[j+1], TEST_LOCATION);
- DALI_TEST_EQUALS(v0, edgeData[j+2], TEST_LOCATION);
- DALI_TEST_EQUALS(v1, edgeData[j+3], TEST_LOCATION);
+ auto e0 = edge->face[0];
+ auto e1 = edge->face[1];
+ auto v0 = edge->vertex[0];
+ auto v1 = edge->vertex[1];
+
+ DALI_TEST_EQUALS(e0, edgeData[j + 0], TEST_LOCATION);
+ DALI_TEST_EQUALS(e1, edgeData[j + 1], TEST_LOCATION);
+ DALI_TEST_EQUALS(v0, edgeData[j + 2], TEST_LOCATION);
+ DALI_TEST_EQUALS(v1, edgeData[j + 3], TEST_LOCATION);
}
END_TEST;
auto faceCount = navmesh->GetFaceCount();
- DALI_TEST_EQUALS( faceCount, 165, TEST_LOCATION );
+ DALI_TEST_EQUALS(faceCount, 165, TEST_LOCATION);
// List of coords, must be verified with Blender exporter
// clang-format off
};
// clang-format on
auto j = 0;
- for( auto i = 0u; i < 165; i+= 16, j++)
+ for(auto i = 0u; i < 165; i += 16, j++)
{
const auto* face = navmesh->GetFace(i);
- Vector3 n0(face->normal);
- Vector3 c0(face->center);
+ Vector3 n0(face->normal);
+ Vector3 c0(face->center);
Vector3 n1(faceData[j].normal);
Vector3 c1(faceData[j].center);
- DALI_TEST_EQUALS( n0, n1, TEST_LOCATION);
- DALI_TEST_EQUALS( c0, c1, TEST_LOCATION);
+ DALI_TEST_EQUALS(n0, n1, TEST_LOCATION);
+ DALI_TEST_EQUALS(c0, c1, TEST_LOCATION);
- DALI_TEST_EQUALS( faceData[j].vertex[0], face->vertex[0], TEST_LOCATION);
- DALI_TEST_EQUALS( faceData[j].vertex[1], face->vertex[1], TEST_LOCATION);
- DALI_TEST_EQUALS( faceData[j].vertex[2], face->vertex[2], TEST_LOCATION);
+ DALI_TEST_EQUALS(faceData[j].vertex[0], face->vertex[0], TEST_LOCATION);
+ DALI_TEST_EQUALS(faceData[j].vertex[1], face->vertex[1], TEST_LOCATION);
+ DALI_TEST_EQUALS(faceData[j].vertex[2], face->vertex[2], TEST_LOCATION);
- DALI_TEST_EQUALS( faceData[j].edge[0], face->edge[0], TEST_LOCATION);
- DALI_TEST_EQUALS( faceData[j].edge[1], face->edge[1], TEST_LOCATION);
- DALI_TEST_EQUALS( faceData[j].edge[2], face->edge[2], TEST_LOCATION);
+ DALI_TEST_EQUALS(faceData[j].edge[0], face->edge[0], TEST_LOCATION);
+ DALI_TEST_EQUALS(faceData[j].edge[1], face->edge[1], TEST_LOCATION);
+ DALI_TEST_EQUALS(faceData[j].edge[2], face->edge[2], TEST_LOCATION);
}
END_TEST;
}
-
int UtcDaliNavigationGetGravityP(void)
{
tet_infoline("UtcDaliNavigationGetGravityP: Tests gravity vector");
auto gravity = navmesh->GetGravityVector();
// navmesh-test.bin is exported in Blender and the default gravity is Z = -1
- Dali::Vector3 expectedGravity( 0.0f, 0.0f, -1.0f );
+ Dali::Vector3 expectedGravity(0.0f, 0.0f, -1.0f);
- DALI_TEST_EQUALS( gravity, expectedGravity, TEST_LOCATION);
+ DALI_TEST_EQUALS(gravity, expectedGravity, TEST_LOCATION);
END_TEST;
}
Matrix matrix;
matrix.SetIdentity();
- Quaternion q = Quaternion( Radian(Degree(-90)), Vector3(1.0, 0.0, 0.0));
- Matrix newMatrix;
- matrix.Multiply( newMatrix, matrix, q); // Rotate matrix along X-axis
+ Quaternion q = Quaternion(Radian(Degree(-90)), Vector3(1.0, 0.0, 0.0));
+ Matrix newMatrix;
+ matrix.Multiply(newMatrix, matrix, q); // Rotate matrix along X-axis
navmesh->SetSceneTransform(newMatrix);
auto gravityVector = navmesh->GetGravityVector();
// 'point' should be turned into the gravity vector after transforming into the local space
- DALI_TEST_EQUALS( navMeshLocalSpace, gravityVector, TEST_LOCATION);
+ DALI_TEST_EQUALS(navMeshLocalSpace, gravityVector, TEST_LOCATION);
navMeshParentSpace = navmesh->PointLocalToScene(gravityVector);
// The gravity should be transformed back into point
- DALI_TEST_EQUALS( navMeshParentSpace, point, TEST_LOCATION);
+ DALI_TEST_EQUALS(navMeshParentSpace, point, TEST_LOCATION);
END_TEST;
}
// All calculations in the navmesh local space
navmesh->SetSceneTransform(Matrix(Matrix::IDENTITY));
- std::vector<Vector3> inPositions;
- std::vector<Vector3> expectedPositions;
- std::vector<uint32_t> expectedFaceIndex;
- std::vector<bool> expectedResult;
+ std::vector<Vector3> inPositions;
+ std::vector<Vector3> expectedPositions;
+ std::vector<FaceIndex> expectedFaceIndex;
+ std::vector<bool> expectedResult;
// Lift slightly over the floor level
auto upFromGravity = navmesh->GetGravityVector() * (0.05f);
auto size = navmesh->GetFaceCount();
- for( auto i = 0u; i < size; ++i)
+ for(auto i = 0u; i < size; ++i)
{
const auto* face = navmesh->GetFace(i);
Vector3(face->center);
inPositions.emplace_back(Vector3(face->center));
- inPositions.back() -= Vector3( upFromGravity );
+ inPositions.back() -= Vector3(upFromGravity);
expectedResult.emplace_back(true);
expectedPositions.emplace_back(face->center);
// Middle 'circle' of scene
inPositions.emplace_back(Vector3(-0.048838f, 0.039285f, 0.013085f));
expectedPositions.emplace_back();
- expectedFaceIndex.emplace_back( NavigationMesh::NULL_FACE );
+ expectedFaceIndex.emplace_back(NavigationMesh::NULL_FACE);
expectedResult.emplace_back(false);
// Triangle under stairs
inPositions.emplace_back(Vector3(0.44365f, -1.787f, 0.13085f));
expectedPositions.emplace_back();
- expectedFaceIndex.emplace_back( NavigationMesh::NULL_FACE );
+ expectedFaceIndex.emplace_back(NavigationMesh::NULL_FACE);
expectedResult.emplace_back(false);
// Outside area
inPositions.emplace_back(Vector3(0.77197f, -3.8596f, 0.13085f));
expectedPositions.emplace_back();
- expectedFaceIndex.emplace_back( NavigationMesh::NULL_FACE );
+ expectedFaceIndex.emplace_back(NavigationMesh::NULL_FACE);
expectedResult.emplace_back(false);
- for( auto i = 0u; i < inPositions.size(); ++i )
+ for(auto i = 0u; i < inPositions.size(); ++i)
{
- Vector3 outPosition;
- uint32_t faceIndex {NavigationMesh::NULL_FACE};
- auto result = navmesh->FindFloor(inPositions[i], outPosition, faceIndex);
- DALI_TEST_EQUALS( bool(result), bool(expectedResult[i]), TEST_LOCATION);
- DALI_TEST_EQUALS( faceIndex, expectedFaceIndex[i], TEST_LOCATION);
- DALI_TEST_EQUALS( outPosition, expectedPositions[i], TEST_LOCATION);
+ Vector3 outPosition;
+ FaceIndex faceIndex{NavigationMesh::NULL_FACE};
+ auto result = navmesh->FindFloor(inPositions[i], outPosition, faceIndex);
+ DALI_TEST_EQUALS(bool(result), bool(expectedResult[i]), TEST_LOCATION);
+ DALI_TEST_EQUALS(faceIndex, expectedFaceIndex[i], TEST_LOCATION);
+ DALI_TEST_EQUALS(outPosition, expectedPositions[i], TEST_LOCATION);
}
END_TEST;
navmesh->SetSceneTransform(Matrix(Matrix::IDENTITY));
{
- auto faceIndex = 0u;
- auto position = Vector3( 0, 0, 0);
+ auto faceIndex = FaceIndex(0u);
+ auto position = Vector3(0, 0, 0);
auto dontCheckNeighbours = true;
- auto outPosition = Vector3();
- auto expectedPosition = Vector3();
- bool result = false;
+ auto outPosition = Vector3();
+ auto expectedPosition = Vector3();
+ bool result = false;
{
// test 1. position lies within selected triangle
- faceIndex = 137;
- position = Vector3(-6.0767f, -1.7268f, 4.287f);
- expectedPosition = Vector3(-6.0767f, -1.7268f, 3.83f);
+ faceIndex = 137;
+ position = Vector3(-6.0767f, -1.7268f, 4.287f);
+ expectedPosition = Vector3(-6.0767f, -1.7268f, 3.83f);
dontCheckNeighbours = true;
- result = navmesh->FindFloorForFace(position, faceIndex, dontCheckNeighbours, outPosition);
+ result = navmesh->FindFloorForFace(position, faceIndex, dontCheckNeighbours, outPosition);
- DALI_TEST_EQUALS( result, true, TEST_LOCATION);
- DALI_TEST_EQUALS( outPosition, expectedPosition, TEST_LOCATION);
+ DALI_TEST_EQUALS(result, true, TEST_LOCATION);
+ DALI_TEST_EQUALS(outPosition, expectedPosition, TEST_LOCATION);
}
{
// test 2. position lies outside selected triangle, not checking neighbours
- faceIndex = 137;
- position = Vector3(-5.3073f, -0.6023f, 4.287f);
- expectedPosition = Vector3::ZERO;
- outPosition = Vector3::ZERO;
+ faceIndex = 137;
+ position = Vector3(-5.3073f, -0.6023f, 4.287f);
+ expectedPosition = Vector3::ZERO;
+ outPosition = Vector3::ZERO;
dontCheckNeighbours = true;
- result = navmesh->FindFloorForFace(position, faceIndex, dontCheckNeighbours, outPosition);
+ result = navmesh->FindFloorForFace(position, faceIndex, dontCheckNeighbours, outPosition);
- DALI_TEST_EQUALS( result, false, TEST_LOCATION);
- DALI_TEST_EQUALS( outPosition, expectedPosition, TEST_LOCATION);
+ DALI_TEST_EQUALS(result, false, TEST_LOCATION);
+ DALI_TEST_EQUALS(outPosition, expectedPosition, TEST_LOCATION);
}
{
// test 3. position lies outside selected triangle but this time checking neighbours
- faceIndex = 137;
- position = Vector3(-5.3073f, -0.6023f, 4.287f);
- expectedPosition = Vector3(-5.3073, -0.6023, 3.83);
- outPosition = Vector3::ZERO;
+ faceIndex = 137;
+ position = Vector3(-5.3073f, -0.6023f, 4.287f);
+ expectedPosition = Vector3(-5.3073, -0.6023, 3.83);
+ outPosition = Vector3::ZERO;
dontCheckNeighbours = false;
- result = navmesh->FindFloorForFace(position, faceIndex, dontCheckNeighbours, outPosition);
+ result = navmesh->FindFloorForFace(position, faceIndex, dontCheckNeighbours, outPosition);
- DALI_TEST_EQUALS( result, true, TEST_LOCATION);
- DALI_TEST_EQUALS( outPosition, expectedPosition, TEST_LOCATION);
+ DALI_TEST_EQUALS(result, true, TEST_LOCATION);
+ DALI_TEST_EQUALS(outPosition, expectedPosition, TEST_LOCATION);
}
}
navmesh->SetSceneTransform(Matrix(Matrix::IDENTITY));
{
- [[maybe_unused]] auto faceIndex = 0u;
- auto position = Vector3( 0, 0, 0);
- auto dontCheckNeighbours = true;
- auto outPosition = Vector3();
- auto expectedPosition = Vector3();
- bool result = false;
+ [[maybe_unused]] auto faceIndex = 0u;
+ auto position = Vector3(0, 0, 0);
+ auto dontCheckNeighbours = true;
+ auto outPosition = Vector3();
+ auto expectedPosition = Vector3();
+ bool result = false;
{
// test 4. position lies within a triangle but this time full search forced,
// the navmesh must have no previous searches (mCurrentFace shouldn't be set)
- faceIndex = 137;
- position = Vector3(-6.0767f, -1.7268f, 4.287f);
- expectedPosition = Vector3(-6.0767f, -1.7268f, 3.83f);
+ faceIndex = 137;
+ position = Vector3(-6.0767f, -1.7268f, 4.287f);
+ expectedPosition = Vector3(-6.0767f, -1.7268f, 3.83f);
dontCheckNeighbours = true;
- result = navmesh->FindFloorForFace(position, NavigationMesh::NULL_FACE, dontCheckNeighbours, outPosition);
+ result = navmesh->FindFloorForFace(position, NavigationMesh::NULL_FACE, dontCheckNeighbours, outPosition);
- DALI_TEST_EQUALS( result, true, TEST_LOCATION);
- DALI_TEST_EQUALS( outPosition, expectedPosition, TEST_LOCATION);
+ DALI_TEST_EQUALS(result, true, TEST_LOCATION);
+ DALI_TEST_EQUALS(outPosition, expectedPosition, TEST_LOCATION);
}
-
}
END_TEST;
*
*/
+#include <dali-test-suite-utils.h>
#include "dali-scene3d/public-api/algorithm/navigation-mesh.h"
#include "dali-scene3d/public-api/algorithm/path-finder.h"
#include "dali-scene3d/public-api/loader/navigation-mesh-factory.h"
-#include <dali-test-suite-utils.h>
using namespace Dali;
using namespace Dali::Scene3D::Algorithm;
using namespace Dali::Scene3D::Loader;
-bool CompareResults( const std::vector<uint32_t>& nodes, const WayPointList& waypoints )
+bool CompareResults(const std::vector<FaceIndex>& nodes, const WayPointList& waypoints)
{
if(nodes.size() != waypoints.size())
{
oss << waypoint.GetNavigationMeshFaceIndex() << ", ";
}
oss << "]\n";
- tet_printf("%s\n",oss.str().c_str());
+ tet_printf("%s\n", oss.str().c_str());
return false;
}
- for(auto i = 0u; i < nodes.size(); ++i )
+ for(auto i = 0u; i < nodes.size(); ++i)
{
if(nodes[i] != waypoints[i].GetNavigationMeshFaceIndex())
{
oss << waypoint.GetNavigationMeshFaceIndex() << ", ";
}
oss << "]\n";
- tet_printf("%s\n",oss.str().c_str());
+ tet_printf("%s\n", oss.str().c_str());
return false;
}
}
int UtcDaliPathFinderNewP(void)
{
- auto navmesh = NavigationMeshFactory::CreateFromFile( "resources/navmesh-test.bin");
+ auto navmesh = NavigationMeshFactory::CreateFromFile("resources/navmesh-test.bin");
- auto pathfinder = PathFinder::New( *navmesh, PathFinderAlgorithm::DEFAULT );
+ auto pathfinder = PathFinder::New(*navmesh, PathFinderAlgorithm::DEFAULT);
DALI_TEST_CHECK(navmesh);
DALI_TEST_CHECK(pathfinder);
int UtcDaliPathFinderNewFail(void)
{
- auto navmesh = NavigationMeshFactory::CreateFromFile( "resources/navmesh-test.bin");
+ auto navmesh = NavigationMeshFactory::CreateFromFile("resources/navmesh-test.bin");
- auto pathfinder = PathFinder::New( *navmesh, static_cast<PathFinderAlgorithm>(-1) );
+ auto pathfinder = PathFinder::New(*navmesh, static_cast<PathFinderAlgorithm>(-1));
DALI_TEST_CHECK(navmesh);
DALI_TEST_CHECK(!pathfinder);
END_TEST;
}
-void printWaypointForPython( WayPointList& waypoints)
+void printWaypointForPython(WayPointList& waypoints)
{
- tet_printf( "size: %d\n", waypoints.size());
- tet_printf( "[");
+ tet_printf("size: %d\n", waypoints.size());
+ tet_printf("[");
for(auto& wp : waypoints)
{
auto index = wp.GetNavigationMeshFaceIndex();
tet_printf("%d, ", index);
}
- tet_printf( "]");
+ tet_printf("]");
}
int UtcDaliPathFinderFindShortestPath0(void)
{
- auto navmesh = NavigationMeshFactory::CreateFromFile( "resources/navmesh-test.bin");
+ auto navmesh = NavigationMeshFactory::CreateFromFile("resources/navmesh-test.bin");
std::vector<PathFinderAlgorithm> testAlgorithms = {
PathFinderAlgorithm::DJIKSTRA_SHORTEST_PATH,
for(const auto& algorithm : testAlgorithms)
{
tet_printf("Test algorithm type : %d\n", static_cast<int>(algorithm));
- auto pathfinder = PathFinder::New( *navmesh, algorithm );
+ auto pathfinder = PathFinder::New(*navmesh, algorithm);
DALI_TEST_CHECK(navmesh);
DALI_TEST_CHECK(pathfinder);
DALI_TEST_NOT_EQUALS(int(waypoints.size()), 0, 0, TEST_LOCATION);
// Results are verified in the Blender
- std::vector<uint32_t> expectedResults =
+ std::vector<FaceIndex> expectedResults =
{18, 97, 106, 82, 50, 139};
DALI_TEST_EQUALS(CompareResults(expectedResults, waypoints), true, TEST_LOCATION);
//printWaypointForPython(waypoints);
// Results are verified in the Blender
- std::vector<uint32_t> expectedResults =
+ std::vector<FaceIndex> expectedResults =
{18, 97, 106, 82, 50, 6, 89, 33, 157};
DALI_TEST_EQUALS(CompareResults(expectedResults, waypoints), true, TEST_LOCATION);
-
}
}
int UtcDaliPathFinderFindShortestPath1(void)
{
- auto navmesh = NavigationMeshFactory::CreateFromFile( "resources/navmesh-test.bin");
+ auto navmesh = NavigationMeshFactory::CreateFromFile("resources/navmesh-test.bin");
// All coordinates in navmesh local space
- navmesh->SetSceneTransform( Matrix(Matrix::IDENTITY));
+ navmesh->SetSceneTransform(Matrix(Matrix::IDENTITY));
std::vector<PathFinderAlgorithm> testAlgorithms = {
PathFinderAlgorithm::DJIKSTRA_SHORTEST_PATH,
for(const auto& algorithm : testAlgorithms)
{
tet_printf("Test algorithm type : %d\n", static_cast<int>(algorithm));
- auto pathfinder = PathFinder::New( *navmesh, algorithm );
+ auto pathfinder = PathFinder::New(*navmesh, algorithm);
DALI_TEST_CHECK(navmesh);
DALI_TEST_CHECK(pathfinder);
{
Vector3 from(-6.0767, -1.7268, 0.1438); // ground floor
- Vector3 to(-6.0767, -1.7268, 4.287); // first floor
+ Vector3 to(-6.0767, -1.7268, 4.287); // first floor
auto waypoints = pathfinder->FindPath(from, to);
DALI_TEST_NOT_EQUALS(int(waypoints.size()), 0, 0, TEST_LOCATION);
// Results are verified in the Blender
- std::vector<uint32_t> expectedResults =
- {154, 58, 85, 106, 128, 132, 137};
+ std::vector<FaceIndex> expectedResults =
+ {154, 58, 85, 106, 128, 132, 137};
DALI_TEST_EQUALS(CompareResults(expectedResults, waypoints), true, TEST_LOCATION);
// Verify last and first points by finding floor points
{
- Vector3 verifyPos = Vector3::ZERO;
- uint32_t verifyIndex = NavigationMesh::NULL_FACE;
- auto result = navmesh->FindFloor(from, verifyPos, verifyIndex);
+ Vector3 verifyPos = Vector3::ZERO;
+ FaceIndex verifyIndex = NavigationMesh::NULL_FACE;
+ auto result = navmesh->FindFloor(from, verifyPos, verifyIndex);
DALI_TEST_EQUALS(result, true, TEST_LOCATION);
DALI_TEST_EQUALS(verifyPos, waypoints[0].GetScenePosition(), TEST_LOCATION);
}
{
- Vector3 verifyPos = Vector3::ZERO;
- uint32_t verifyIndex = NavigationMesh::NULL_FACE;
- auto result = navmesh->FindFloor(to, verifyPos, verifyIndex);
+ Vector3 verifyPos = Vector3::ZERO;
+ FaceIndex verifyIndex = NavigationMesh::NULL_FACE;
+ auto result = navmesh->FindFloor(to, verifyPos, verifyIndex);
DALI_TEST_EQUALS(result, true, TEST_LOCATION);
DALI_TEST_EQUALS(verifyPos, waypoints.back().GetScenePosition(), TEST_LOCATION);
return mHeader.vertexCount;
}
-bool NavigationMesh::FindFloorForFace(const Dali::Vector3& position, uint32_t faceIndex, bool dontCheckNeighbours, Dali::Vector3& outPosition)
+bool NavigationMesh::FindFloorForFace(const Dali::Vector3& position, FaceIndex faceIndex, bool dontCheckNeighbours, Dali::Vector3& outPosition)
{
if(faceIndex == ::Dali::Scene3D::Algorithm::NavigationMesh::NULL_FACE)
{
// Ray direction matches gravity direction
ray.direction = Vector3(mHeader.gravityVector);
- IntersectResult result = NavigationRayFaceIntersection(ray, *GetFace(uint16_t(faceIndex)));
+ IntersectResult result = NavigationRayFaceIntersection(ray, *GetFace(faceIndex));
if(result.result)
{
outPosition = PointLocalToScene(result.point);
}
// Test neighbouring by edges
- const auto& poly = GetFace(uint16_t(faceIndex));
+ const auto& poly = GetFace(faceIndex);
// collect faces sharing edges
- std::vector<uint32_t> faces;
+ std::vector<FaceIndex> neighbourFaces;
- for(unsigned short i : poly->edge)
+ for(auto edgeIndex : poly->edge)
{
- const auto& edge = *GetEdge(i);
+ const auto& edge = *GetEdge(edgeIndex);
// store faces
- for(unsigned short j : edge.face)
+ for(auto edgeFaceIndex : edge.face)
{
- if(j != ::Dali::Scene3D::Algorithm::NavigationMesh::NULL_FACE && j != faceIndex)
+ if(edgeFaceIndex != ::Dali::Scene3D::Algorithm::NavigationMesh::NULL_FACE && edgeFaceIndex != faceIndex)
{
- faces.emplace_back(j);
+ neighbourFaces.emplace_back(edgeFaceIndex);
}
}
}
- if(faces.empty())
+ if(neighbourFaces.empty())
{
return false;
}
- for(const auto& p : faces)
+ for(const auto& neighbourFaceIndex : neighbourFaces)
{
- if(FindFloorForFace(position, p, true, outPosition))
+ if(FindFloorForFace(position, neighbourFaceIndex, true, outPosition))
{
- mCurrentFace = p;
+ mCurrentFace = neighbourFaceIndex;
return true;
}
}
*/
bool NavigationMesh::FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition)
{
- uint32_t polyIndex = 0;
- return FindFloor(position, outPosition, polyIndex);
+ FaceIndex faceIndex = 0u;
+ return FindFloor(position, outPosition, faceIndex);
}
-bool NavigationMesh::FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition, uint32_t& faceIndex)
+bool NavigationMesh::FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition, FaceIndex& faceIndex)
{
[[maybe_unused]] auto newPos = PointSceneToLocal(Dali::Vector3(position));
const auto POLY_COUNT = GetFaceCount();
std::vector<IntersectResult> results;
- for(auto i = 0u; i < POLY_COUNT; ++i)
+ for(auto faceIndex = 0u; faceIndex < POLY_COUNT; ++faceIndex)
{
- auto result = NavigationRayFaceIntersection(ray, *GetFace(i));
+ auto result = NavigationRayFaceIntersection(ray, *GetFace(faceIndex));
if(result.result)
{
- result.faceIndex = i;
+ result.faceIndex = faceIndex;
results.emplace_back(result);
}
}
return true;
}
-const Poly* NavigationMesh::GetFace(int index) const
+const Poly* NavigationMesh::GetFace(FaceIndex index) const
{
auto* basePtr = reinterpret_cast<const Poly*>(mBuffer.data() + mHeader.dataOffset + mHeader.polyDataOffset);
return &basePtr[index];
}
-const Edge* NavigationMesh::GetEdge(int index) const
+const Edge* NavigationMesh::GetEdge(EdgeIndex index) const
{
auto* basePtr = reinterpret_cast<const Edge*>(mBuffer.data() + mHeader.dataOffset + mHeader.edgeDataOffset);
return &basePtr[index];
}
-const Vertex* NavigationMesh::GetVertex(int index) const
+const Vertex* NavigationMesh::GetVertex(VertexIndex index) const
{
auto* basePtr = reinterpret_cast<const Vertex*>(mBuffer.data() + mHeader.dataOffset + mHeader.vertexDataOffset);
return &basePtr[index];
}
-NavigationMesh::IntersectResult NavigationMesh::NavigationRayFaceIntersection(NavigationRay& ray, const Face& face)
+NavigationMesh::IntersectResult NavigationMesh::NavigationRayFaceIntersection(NavigationRay& ray, const Face& face) const
{
auto vi0 = *GetVertex(face.vertex[0]);
auto vi1 = *GetVertex(face.vertex[1]);
transform.InvertTransform(mTransformInverse);
}
-Dali::Vector3 NavigationMesh::PointSceneToLocal(const Dali::Vector3& point)
+Dali::Vector3 NavigationMesh::PointSceneToLocal(const Dali::Vector3& point) const
{
// Transform point into navmesh space
Dali::Vector4 invNewPos = mTransformInverse * Dali::Vector4(point.x, -point.y, point.z, 1.0f);
return Dali::Vector3(invNewPos.AsFloat());
}
-Dali::Vector3 NavigationMesh::PointLocalToScene(const Dali::Vector3& point)
+Dali::Vector3 NavigationMesh::PointLocalToScene(const Dali::Vector3& point) const
{
// Transform point into scene transform space
Dali::Vector4 newPos = mTransform * Dali::Vector4(point.x, -point.y, point.z, 1.0f);
{
class NavigationRay;
+// Make each to change each index value's type here.
+using VertexIndex = Dali::Scene3D::Algorithm::VertexIndex;
+using EdgeIndex = Dali::Scene3D::Algorithm::EdgeIndex;
+using FaceIndex = Dali::Scene3D::Algorithm::FaceIndex;
+
/**
* @class NavigationMesh
*/
{
Dali::Vector3 point;
float distance;
- uint16_t faceIndex;
+ FaceIndex faceIndex;
bool result;
};
[[nodiscard]] uint32_t GetVertexCount() const;
/**
- * Looks for floor only within the face
- * @param[in] position Position to be projected onto the face
- * @param[in] faceIndex Face index
- * @param[in] dontCheckNeighbours states whether to traverse onto neighbouring faces
- * @param[out] outPosition Output position
- *
- * @return true if success
+ * @copydoc Dali::Scene3D::Algorithm::NavigationMesh::FindFloorForFace()
*/
- bool FindFloorForFace(const Dali::Vector3& position, uint32_t faceIndex, bool dontCheckNeighbours, Dali::Vector3& outPosition);
+ bool FindFloorForFace(const Dali::Vector3& position, FaceIndex faceIndex, bool dontCheckNeighbours, Dali::Vector3& outPosition);
/**
* @copydoc Dali::Scene3D::Algorithm::NavigationMesh::FindFloor()
/**
* @copydoc Dali::Scene3D::Algorithm::NavigationMesh::FindFloor()
*/
- bool FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition, uint32_t& faceIndex);
+ bool FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition, FaceIndex& faceIndex);
/**
* @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetFace()
*/
- [[nodiscard]] const Face* GetFace(int index) const;
+ [[nodiscard]] const Face* GetFace(FaceIndex index) const;
/**
* @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetEdge()
*/
- [[nodiscard]] const Edge* GetEdge(int index) const;
+ [[nodiscard]] const Edge* GetEdge(EdgeIndex index) const;
/**
* @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetVertex()
*/
- [[nodiscard]] const Vertex* GetVertex(int index) const;
+ [[nodiscard]] const Vertex* GetVertex(VertexIndex index) const;
/**
* @copydoc Dali::Scene3D::Algorithm::NavigationMesh::SetSceneTransform()
/**
* Tests intersection between navigation ray and face
*/
- IntersectResult NavigationRayFaceIntersection(NavigationRay& ray, const Face& face);
+ IntersectResult NavigationRayFaceIntersection(NavigationRay& ray, const Face& face) const;
/**
* @copydoc Dali::Scene3D::Algorithm::NavigationMesh::PointSceneToLocal()
*/
- Dali::Vector3 PointSceneToLocal(const Dali::Vector3& point);
+ Dali::Vector3 PointSceneToLocal(const Dali::Vector3& point) const;
/**
* @copydoc Dali::Scene3D::Algorithm::NavigationMesh::PointLocalToScene()
*/
- Dali::Vector3 PointLocalToScene(const Dali::Vector3& point);
+ Dali::Vector3 PointLocalToScene(const Dali::Vector3& point) const;
/**
* @copydoc Dali::Scene3D::Algorithm::NavigationMesh::GetGravityVector()
private:
std::vector<uint8_t> mBuffer; //< Data buffer
NavigationMeshHeader_V10 mHeader; //< Navigation mesh header
- uint16_t mCurrentFace; //< Current face (last floor position)
+ FaceIndex mCurrentFace; //< Current face (last floor position)
Dali::Matrix mTransform; //< Transform matrix
Dali::Matrix mTransformInverse; //< Inverse of the transform matrix
};
Scene3D::Algorithm::WayPointList PathFinderAlgorithmDjikstra::FindPath(const Dali::Vector3& positionFrom, const Dali::Vector3& positionTo)
{
Dali::Vector3 outPosFrom;
- uint32_t polyIndexFrom;
+ FaceIndex polyIndexFrom;
auto result = mNavigationMesh->FindFloor(positionFrom, outPosFrom, polyIndexFrom);
Scene3D::Algorithm::WayPointList waypoints;
if(result)
{
Dali::Vector3 outPosTo;
- uint32_t polyIndexTo;
+ FaceIndex polyIndexTo;
result = mNavigationMesh->FindFloor(positionTo, outPosTo, polyIndexTo);
if(result)
return waypoints;
}
-Scene3D::Algorithm::WayPointList PathFinderAlgorithmDjikstra::FindPath(uint32_t sourcePolyIndex, uint32_t targetPolyIndex)
+Scene3D::Algorithm::WayPointList PathFinderAlgorithmDjikstra::FindPath(FaceIndex sourcePolyIndex, FaceIndex targetPolyIndex)
{
- auto nodeCount = uint32_t(mNodes.size());
- std::vector<float> dist;
- std::vector<uint32_t> prev;
+ auto nodeCount = uint32_t(mNodes.size());
+ std::vector<float> dist;
+ std::vector<FaceIndex> prev;
dist.resize(mNodes.size());
prev.resize(mNodes.size());
} while(removeCount != nodeCount);
// Compute distances for each node back to the source
- auto u = targetPolyIndex;
- std::list<uint32_t> q;
+ auto u = targetPolyIndex;
+ std::list<FaceIndex> q;
if(prev[u] != Scene3D::Algorithm::NavigationMesh::NULL_FACE || u == sourcePolyIndex)
{
while(u != Scene3D::Algorithm::NavigationMesh::NULL_FACE)
mNodes.resize(faceCount);
// for each face build the list
+ // TODO : Currently, we are assume that FaceNodeIndex is matched with FaceIndex 1:1. This might be changed in future.
for(auto i = 0u; i < faceCount; ++i)
{
auto& node = mNodes[i];
* @param[in] polyIndexTo Index of end polygon
* @return List of waypoints for path
*/
- Scene3D::Algorithm::WayPointList FindPath(uint32_t sourcePolyIndex, uint32_t targetPolyIndex) override;
+ Scene3D::Algorithm::WayPointList FindPath(FaceIndex sourcePolyIndex, FaceIndex targetPolyIndex) override;
- [[nodiscard]] inline const NavigationMesh::Face* Face(uint32_t i) const
+ [[nodiscard]] inline const NavigationMesh::Face* Face(FaceIndex faceIndex) const
{
- return mNavigationMesh->GetFace(i);
+ return mNavigationMesh->GetFace(faceIndex);
}
/**
*/
struct FaceNode
{
- uint32_t faceIndex; ///< Index of face which is associated with node
-
// neighbours
- uint32_t faces[3]; ///< List of neighbouring faces (max 3 for a triangle)
- uint32_t edges[3]; ///< List of edges (max 3 for a triangle)
- float weight[3]; ///< List of weights (by distance) to each neighbour
+ FaceIndex faces[3]; ///< List of neighbouring faces (max 3 for a triangle)
+ EdgeIndex edges[3]; ///< List of edges (max 3 for a triangle)
+ float weight[3]; ///< List of weights (by distance) to each neighbour
};
+ using FaceNodeIndex = FaceIndex;
NavigationMesh* mNavigationMesh; ///< Pointer to a valid NavigationMesh
- std::vector<FaceNode> mNodes; ///< List of nodes
+ std::vector<FaceNode> mNodes; ///< List of nodes
};
} // namespace Dali::Scene3D::Internal::Algorithm
#endif // DALI_SCENE3D_INTERNAL_PATH_FINDER_DJIKSTRA_H
#include <dali-scene3d/internal/algorithm/path-finder-waypoint-data.h>
#include <dali-scene3d/public-api/algorithm/path-finder-waypoint.h>
-using WayPointList = Dali::Scene3D::Algorithm::WayPointList;
+using WayPointList = Dali::Scene3D::Algorithm::WayPointList;
+using FaceNodeIndex = Dali::Scene3D::Internal::Algorithm::PathFinderAlgorithmSPFADoubleWay::FaceNodeIndex;
namespace
{
*
* @param[in,out] components Container of components id stored.
* @param[in] index index what we want to get components's id.
- * @return uint32_t top-value of this components.
+ * @return FaceIndex top-value of this components.
*/
-uint32_t GetComponentId(std::vector<uint32_t>& components, uint32_t index)
+FaceNodeIndex GetComponentId(std::vector<FaceNodeIndex>& components, FaceNodeIndex index)
{
if(components[index] == index)
{
return index;
}
// Get my parent's components id, and update myself.
- uint32_t ret = GetComponentId(components, components[index]);
+ FaceNodeIndex ret = GetComponentId(components, components[index]);
return components[index] = ret;
}
* @param[in] index0 index of components what we want to be combined.
* @param[in] index1 index of components what we want to be combined.
*/
-void ComponentsCombine(std::vector<uint32_t>& components, std::vector<uint32_t>& componentsLevel, uint32_t index0, uint32_t index1)
+void ComponentsCombine(std::vector<FaceNodeIndex>& components, std::vector<FaceNodeIndex>& componentsLevel, FaceNodeIndex index0, FaceNodeIndex index1)
{
- uint32_t p0 = GetComponentId(components, index0);
- uint32_t p1 = GetComponentId(components, index1);
- if(p0 == p1)
+ FaceNodeIndex ancestor0 = GetComponentId(components, index0);
+ FaceNodeIndex ancestor1 = GetComponentId(components, index1);
+ if(ancestor0 == ancestor1)
{
return;
}
- if(componentsLevel[p0] < componentsLevel[p1])
+ if(componentsLevel[ancestor0] < componentsLevel[ancestor1])
{
- components[p0] = p1;
+ components[ancestor0] = ancestor1;
}
else
{
- components[p1] = p0;
- if(componentsLevel[p0] == componentsLevel[p1])
+ components[ancestor1] = ancestor0;
+ if(componentsLevel[ancestor0] == componentsLevel[ancestor1])
{
- ++componentsLevel[p0];
+ ++componentsLevel[ancestor0];
}
}
}
PathFinderAlgorithmSPFADoubleWay::~PathFinderAlgorithmSPFADoubleWay() = default;
-float PathFinderAlgorithmSPFADoubleWay::DistancePanaltyCalculate(uint32_t index) const noexcept
+float PathFinderAlgorithmSPFADoubleWay::DistancePanaltyCalculate(FaceIndex index) const noexcept
{
return dist[index] - priority[index] * PRIORITY_SCALE_FACTOR;
}
Scene3D::Algorithm::WayPointList PathFinderAlgorithmSPFADoubleWay::FindPath(const Dali::Vector3& positionFrom, const Dali::Vector3& positionTo)
{
Dali::Vector3 outPosFrom;
- uint32_t polyIndexFrom;
+ FaceIndex polyIndexFrom;
auto result = mNavigationMesh->FindFloor(positionFrom, outPosFrom, polyIndexFrom);
Scene3D::Algorithm::WayPointList waypoints;
if(result)
{
Dali::Vector3 outPosTo;
- uint32_t polyIndexTo;
+ FaceIndex polyIndexTo;
result = mNavigationMesh->FindFloor(positionTo, outPosTo, polyIndexTo);
if(result)
return waypoints;
}
-Scene3D::Algorithm::WayPointList PathFinderAlgorithmSPFADoubleWay::FindPath(uint32_t sourcePolyIndex, uint32_t targetPolyIndex)
+Scene3D::Algorithm::WayPointList PathFinderAlgorithmSPFADoubleWay::FindPath(FaceIndex sourcePolyIndex, FaceIndex targetPolyIndex)
{
// Fast return if source and target index is same.
if(sourcePolyIndex == targetPolyIndex)
}
// pair<navimesh FaceIndex, is backward direction>
- using queueItem = std::pair<uint32_t, uint8_t>;
+ using queueItem = std::pair<FaceIndex, uint8_t>;
std::list<queueItem> nodeQueue;
- std::unordered_set<uint32_t> usedPolyIndexs[2];
+ std::unordered_set<FaceIndex> usedPolyIndexs[2];
// Set distance of source and target
dist[sourcePolyIndex] = 0.0f;
usedPolyIndexs[0].insert(sourcePolyIndex);
usedPolyIndexs[1].insert(targetPolyIndex);
- bool foundPath = false;
- uint32_t forwardEndIndex = Scene3D::Algorithm::NavigationMesh::NULL_FACE;
- uint32_t backwardStartIndex = Scene3D::Algorithm::NavigationMesh::NULL_FACE;
+ bool foundPath = false;
+ FaceIndex forwardEndIndex = Scene3D::Algorithm::NavigationMesh::NULL_FACE;
+ FaceIndex backwardStartIndex = Scene3D::Algorithm::NavigationMesh::NULL_FACE;
const auto sourcePos = Dali::Vector3(Face(sourcePolyIndex)->center);
const auto targetPos = Dali::Vector3(Face(targetPolyIndex)->center);
}
// Build path of face index
- std::list<uint32_t> q;
+ std::list<FaceIndex> q;
{
- uint32_t u = forwardEndIndex;
+ FaceIndex u = forwardEndIndex;
while(u != Scene3D::Algorithm::NavigationMesh::NULL_FACE)
{
q.push_front(u);
}
}
{
- uint32_t u = backwardStartIndex;
+ FaceIndex u = backwardStartIndex;
while(u != Scene3D::Algorithm::NavigationMesh::NULL_FACE)
{
q.push_back(u);
queued.resize(faceCount);
// Temperal container for components level. It will be used for Union-Find algorithm.
- std::vector<uint32_t> componentLevels(faceCount);
+ std::vector<FaceNodeIndex> componentLevels(faceCount);
// Initialize path informations.
- for(auto i = 0u; i < faceCount; ++i)
+ for(FaceNodeIndex i = 0u; i < faceCount; ++i)
{
dist[i] = std::numeric_limits<float>::infinity();
priority[i] = -1.0f; // Initialize by negative value, that we didn't calculate yet.
}
// for each face build the list
- for(auto i = 0u; i < faceCount; ++i)
+ // TODO : Currently, we are assume that FaceNodeIndex is matched with FaceIndex 1:1. This might be changed in future.
+ for(FaceNodeIndex i = 0u; i < faceCount; ++i)
{
auto& node = mNodes[i];
const auto* face = mNavigationMesh->GetFace(i);
* @param[in] polyIndexTo Index of end polygon
* @return List of waypoints for path
*/
- Scene3D::Algorithm::WayPointList FindPath(uint32_t sourcePolyIndex, uint32_t targetPolyIndex) override;
+ Scene3D::Algorithm::WayPointList FindPath(FaceIndex sourcePolyIndex, FaceIndex targetPolyIndex) override;
- [[nodiscard]] inline const NavigationMesh::Face* Face(uint32_t i) const
+ [[nodiscard]] inline const NavigationMesh::Face* Face(FaceIndex faceIndex) const
{
- return mNavigationMesh->GetFace(i);
+ return mNavigationMesh->GetFace(faceIndex);
}
/**
*
* @param[in] index index of node what we want to calculate panantly.
*/
- float DistancePanaltyCalculate(uint32_t index) const noexcept;
+ float DistancePanaltyCalculate(FaceIndex index) const noexcept;
/**
* Structure describes single node of pathfinding algorithm
*/
struct FaceNode
{
- uint32_t faceIndex; ///< Index of face which is associated with node
-
// neighbours
- uint32_t faces[3]; ///< List of neighbouring faces (max 3 for a triangle)
- uint32_t edges[3]; ///< List of edges (max 3 for a triangle)
- float weight[3]; ///< List of weights (by distance) to each neighbour
+ FaceIndex faces[3]; ///< List of neighbouring faces (max 3 for a triangle)
+ EdgeIndex edges[3]; ///< List of edges (max 3 for a triangle)
+ float weight[3]; ///< List of weights (by distance) to each neighbour
};
+ using FaceNodeIndex = FaceIndex;
NavigationMesh* mNavigationMesh; ///< Pointer to a valid NavigationMesh
std::vector<FaceNode> mNodes; ///< List of nodes
private:
- std::vector<float> dist;
- std::vector<float> priority; ///< Cached priority value. It will be calculated by source & target poly index per every queries.
- std::vector<uint32_t> prevForward;
- std::vector<uint32_t> prevBackward;
- std::vector<uint32_t> componentIds; ///< Id of connected components per each nodes. It should be one of node's index.
- std::vector<bool> queued;
+ std::vector<float> dist;
+ std::vector<float> priority; ///< Cached priority value. It will be calculated by source & target poly index per every queries.
+ std::vector<FaceIndex> prevForward;
+ std::vector<FaceIndex> prevBackward;
+ std::vector<FaceNodeIndex> componentIds; ///< Id of connected components per each nodes. It should be one of node's index.
+ std::vector<bool> queued;
};
} // namespace Dali::Scene3D::Internal::Algorithm
#endif // DALI_SCENE3D_INTERNAL_PATH_FINDER_SPFA_DOUBLE_WAY_H
Scene3D::Algorithm::WayPointList PathFinderAlgorithmSPFA::FindPath(const Dali::Vector3& positionFrom, const Dali::Vector3& positionTo)
{
Dali::Vector3 outPosFrom;
- uint32_t polyIndexFrom;
+ FaceIndex polyIndexFrom;
auto result = mNavigationMesh->FindFloor(positionFrom, outPosFrom, polyIndexFrom);
Scene3D::Algorithm::WayPointList waypoints;
if(result)
{
Dali::Vector3 outPosTo;
- uint32_t polyIndexTo;
+ FaceIndex polyIndexTo;
result = mNavigationMesh->FindFloor(positionTo, outPosTo, polyIndexTo);
if(result)
return waypoints;
}
-Scene3D::Algorithm::WayPointList PathFinderAlgorithmSPFA::FindPath(uint32_t sourcePolyIndex, uint32_t targetPolyIndex)
+Scene3D::Algorithm::WayPointList PathFinderAlgorithmSPFA::FindPath(FaceIndex sourcePolyIndex, FaceIndex targetPolyIndex)
{
- auto nodeCount = uint32_t(mNodes.size());
- std::vector<float> dist;
- std::vector<uint32_t> prev;
- std::vector<bool> queued;
+ auto nodeCount = uint32_t(mNodes.size());
+ std::vector<float> dist;
+ std::vector<FaceIndex> prev;
+ std::vector<bool> queued;
dist.resize(mNodes.size());
prev.resize(mNodes.size());
queued.resize(mNodes.size());
- std::list<uint32_t> nodeQueue;
+ std::list<FaceIndex> nodeQueue;
[[maybe_unused]] auto sourcePos = Dali::Vector3(Face(sourcePolyIndex)->center);
}
// Compute distances for each node back to the source
- auto u = targetPolyIndex;
- std::list<uint32_t> q;
+ auto u = targetPolyIndex;
+ std::list<FaceIndex> q;
if(prev[u] != Scene3D::Algorithm::NavigationMesh::NULL_FACE || u == sourcePolyIndex)
{
while(u != Scene3D::Algorithm::NavigationMesh::NULL_FACE)
mNodes.resize(faceCount);
// for each face build the list
- for(auto i = 0u; i < faceCount; ++i)
+ // TODO : Currently, we are assume that FaceNodeIndex is matched with FaceIndex 1:1. This might be changed in future.
+ for(FaceNodeIndex i = 0u; i < faceCount; ++i)
{
auto& node = mNodes[i];
const auto* face = mNavigationMesh->GetFace(i);
* @param[in] polyIndexTo Index of end polygon
* @return List of waypoints for path
*/
- Scene3D::Algorithm::WayPointList FindPath(uint32_t sourcePolyIndex, uint32_t targetPolyIndex) override;
+ Scene3D::Algorithm::WayPointList FindPath(FaceIndex sourcePolyIndex, FaceIndex targetPolyIndex) override;
- [[nodiscard]] inline const NavigationMesh::Face* Face(uint32_t i) const
+ [[nodiscard]] inline const NavigationMesh::Face* Face(FaceIndex faceIndex) const
{
- return mNavigationMesh->GetFace(i);
+ return mNavigationMesh->GetFace(faceIndex);
}
/**
*/
struct FaceNode
{
- uint32_t faceIndex; ///< Index of face which is associated with node
-
// neighbours
- uint32_t faces[3]; ///< List of neighbouring faces (max 3 for a triangle)
- uint32_t edges[3]; ///< List of edges (max 3 for a triangle)
- float weight[3]; ///< List of weights (by distance) to each neighbour
+ FaceIndex faces[3]; ///< List of neighbouring faces (max 3 for a triangle)
+ EdgeIndex edges[3]; ///< List of edges (max 3 for a triangle)
+ float weight[3]; ///< List of weights (by distance) to each neighbour
};
+ using FaceNodeIndex = FaceIndex;
NavigationMesh* mNavigationMesh; ///< Pointer to a valid NavigationMesh
std::vector<FaceNode> mNodes; ///< List of nodes
namespace Dali::Scene3D::Algorithm
{
-
-NavigationMesh::NavigationMesh( NavigationMeshImpl* impl )
+NavigationMesh::NavigationMesh(NavigationMeshImpl* impl)
{
- mImpl.reset( impl );
+ mImpl.reset(impl);
}
NavigationMesh::~NavigationMesh() = default;
return mImpl->GetVertexCount();
}
-bool NavigationMesh::FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition, uint32_t& polyIndex)
+bool NavigationMesh::FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition, FaceIndex& faceIndex)
{
- return mImpl->FindFloor(position, outPosition, polyIndex);
+ return mImpl->FindFloor(position, outPosition, faceIndex);
}
-bool NavigationMesh::FindFloorForFace(const Dali::Vector3& position, uint32_t faceIndex, bool dontCheckNeighbours, Dali::Vector3& outPosition)
+bool NavigationMesh::FindFloorForFace(const Dali::Vector3& position, FaceIndex faceIndex, bool dontCheckNeighbours, Dali::Vector3& outPosition)
{
return mImpl->FindFloorForFace(position, faceIndex, dontCheckNeighbours, outPosition);
}
-[[nodiscard]] const NavigationMesh::Face* NavigationMesh::GetFace(int index) const
+[[nodiscard]] const NavigationMesh::Face* NavigationMesh::GetFace(FaceIndex index) const
{
return mImpl->GetFace(index);
}
-[[nodiscard]] const NavigationMesh::Edge* NavigationMesh::GetEdge(int index) const
+[[nodiscard]] const NavigationMesh::Edge* NavigationMesh::GetEdge(EdgeIndex index) const
{
return mImpl->GetEdge(index);
}
-[[nodiscard]] const NavigationMesh::Vertex* NavigationMesh::GetVertex(int index) const
+[[nodiscard]] const NavigationMesh::Vertex* NavigationMesh::GetVertex(VertexIndex index) const
{
return mImpl->GetVertex(index);
}
mImpl->SetTransform(transform);
}
-Dali::Vector3 NavigationMesh::PointSceneToLocal(const Dali::Vector3& point)
+Dali::Vector3 NavigationMesh::PointSceneToLocal(const Dali::Vector3& point) const
{
return mImpl->PointSceneToLocal(point);
}
-Dali::Vector3 NavigationMesh::PointLocalToScene(const Dali::Vector3& point)
+Dali::Vector3 NavigationMesh::PointLocalToScene(const Dali::Vector3& point) const
{
return mImpl->PointLocalToScene(point);
}
return mImpl->GetGravityVector();
}
-}
\ No newline at end of file
+} // namespace Dali::Scene3D::Algorithm
\ No newline at end of file
// Using PImpling but not usual DALi handles as this object isn't supposed to be refcounted
using NavigationMeshImpl = Dali::Scene3D::Internal::Algorithm::NavigationMesh;
+// Make each to change each index value's type here.
+using VertexIndex = uint16_t;
+using EdgeIndex = uint16_t;
+using FaceIndex = uint16_t;
+
/**
* @class NavigationMesh
*
/**
* @struct Face
*
- * Describes a single polygon
+ * Describes a single polygon's face
*/
struct Face
{
- uint16_t vertex[NAVIGATION_MESH_MAX_VERTICES_PER_FACE]; ///< Vertices per face
- uint16_t edge[NAVIGATION_MESH_MAX_EDGES_PER_FACE]; ///< Edges per face
- float normal[NAVIGATION_MESH_MAX_COMPONENTS_3D]; ///< Normal vector
- float center[NAVIGATION_MESH_MAX_COMPONENTS_3D]; ///< Barycentric coordinates
+ VertexIndex vertex[NAVIGATION_MESH_MAX_VERTICES_PER_FACE]; ///< Vertices per face
+ EdgeIndex edge[NAVIGATION_MESH_MAX_EDGES_PER_FACE]; ///< Edges per face
+ float normal[NAVIGATION_MESH_MAX_COMPONENTS_3D]; ///< Normal vector
+ float center[NAVIGATION_MESH_MAX_COMPONENTS_3D]; ///< Barycentric coordinates
};
/**
*/
struct Edge
{
- uint16_t vertex[NAVIGATION_MESH_MAX_COMPONENTS_2D]; ///< Vertices making the edge
- uint16_t face[NAVIGATION_MESH_MAX_COMPONENTS_2D]; ///< Faces on both sides of edge
+ VertexIndex vertex[NAVIGATION_MESH_MAX_COMPONENTS_2D]; ///< Vertices making the edge
+ FaceIndex face[NAVIGATION_MESH_MAX_COMPONENTS_2D]; ///< Faces on both sides of edge
};
/**
{
union
{
- float co[NAVIGATION_MESH_MAX_COMPONENTS_3D]; ///< Coordinates of vertex
+ float coordinates[NAVIGATION_MESH_MAX_COMPONENTS_3D]; ///< Coordinates of vertex
struct
{
float x, y, z;
* @brief Looks for the floor under specified position
* @param[in] position Position to investigate
* @param[in] outPosition Position on the floor in found
- * @param[in] faceIndex Index of NavigationMesh face associated with floor
+ * @param[out] faceIndex Index of NavigationMesh face associated with floor
*
* @return True if floor has been found, False otherwise
*/
- bool FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition, uint32_t& faceIndex);
+ bool FindFloor(const Dali::Vector3& position, Dali::Vector3& outPosition, FaceIndex& faceIndex);
/**
* @brief Looks for a floor starting from specified face
*
* @return True on success, false otherwise
*/
- bool FindFloorForFace(const Dali::Vector3& position, uint32_t faceIndex, bool dontCheckNeighbours, Dali::Vector3& outPosition);
+ bool FindFloorForFace(const Dali::Vector3& position, FaceIndex faceIndex, bool dontCheckNeighbours, Dali::Vector3& outPosition);
/**
* @brief Returns pointer to Face structure
* @param[in] index Index of face to retrieve
* @return Pointer to valid Face structure or nullptr
*/
- [[nodiscard]] const Face* GetFace(int index) const;
+ [[nodiscard]] const Face* GetFace(FaceIndex index) const;
/**
* @brief Returns edge structure
* @param[in] index Index of edge to retrieve
* @return Pointer to valid Edge structure or nullptr
*/
- [[nodiscard]] const Edge* GetEdge(int index) const;
+ [[nodiscard]] const Edge* GetEdge(EdgeIndex index) const;
/**
* @brief Returns vertex structure
* @param[in] index Index of vertex to retrieve
* @return Pointer to valid Vertex structure or nullptr
*/
- [[nodiscard]] const Vertex* GetVertex(int index) const;
+ [[nodiscard]] const Vertex* GetVertex(VertexIndex index) const;
/**
* @brief Sets static transform for the navigation mesh object
* @param[in] point Point to transform
* @return Point transformed to the local space
*/
- Dali::Vector3 PointSceneToLocal(const Dali::Vector3& point);
+ Dali::Vector3 PointSceneToLocal(const Dali::Vector3& point) const;
/**
* @brief Transforms point into the parent transform space
* @param[in] point Point to transform
* @return Point transformed into the parent space
*/
- Dali::Vector3 PointLocalToScene(const Dali::Vector3& point);
+ Dali::Vector3 PointLocalToScene(const Dali::Vector3& point) const;
/**
* @brief Returns direction of the gravity vector
*/
Dali::Vector3 GetGravityVector() const;
- static constexpr uint16_t NULL_FACE{0xffff}; ///< Represents null polygon
- static constexpr uint16_t NULL_EDGE{0xffff}; ///< represents null edge
+ static constexpr FaceIndex NULL_FACE{std::numeric_limits<FaceIndex>::max()}; ///< Represents null face
+ static constexpr EdgeIndex NULL_EDGE{std::numeric_limits<EdgeIndex>::max()}; ///< Represents null edge
public:
DALI_INTERNAL explicit NavigationMesh(NavigationMeshImpl* impl);
return mImpl->FindPath(positionFrom, positionTo);
}
-WayPointList PathFinder::FindPath(uint32_t polyIndexFrom, uint32_t polyIndexTo)
+WayPointList PathFinder::FindPath(FaceIndex polyIndexFrom, FaceIndex polyIndexTo)
{
return mImpl->FindPath(polyIndexFrom, polyIndexTo);
}
* @param[in] polyIndexTo Index of end polygon
* @return List of waypoints for path or empty vector if no success
*/
- virtual WayPointList FindPath(uint32_t polyIndexFrom, uint32_t polyIndexTo) = 0;
+ virtual WayPointList FindPath(FaceIndex polyIndexFrom, FaceIndex polyIndexTo) = 0;
};
/**
* @param[in] faceIndexTo Target face index
* @return List of waypoints for path or empty list on failure
*/
- WayPointList FindPath(uint32_t faceIndexFrom, uint32_t faceIndexTo);
+ WayPointList FindPath(FaceIndex faceIndexFrom, FaceIndex faceIndexTo);
private:
PathFinder() = delete;