2018-03-13 22:49:08 +00:00
|
|
|
#include "operators.hpp"
|
|
|
|
|
|
|
|
#include <components/detournavigator/recastmeshbuilder.hpp>
|
|
|
|
#include <components/detournavigator/recastmesh.hpp>
|
|
|
|
#include <components/detournavigator/exceptions.hpp>
|
|
|
|
|
|
|
|
#include <BulletCollision/CollisionShapes/btBoxShape.h>
|
|
|
|
#include <BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h>
|
|
|
|
#include <BulletCollision/CollisionShapes/btTriangleMesh.h>
|
|
|
|
#include <BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h>
|
|
|
|
#include <BulletCollision/CollisionShapes/btCompoundShape.h>
|
|
|
|
|
2021-07-11 19:43:19 +00:00
|
|
|
#include <DetourCommon.h>
|
|
|
|
|
2018-03-13 22:49:08 +00:00
|
|
|
#include <gtest/gtest.h>
|
2020-02-16 01:26:23 +00:00
|
|
|
#include <gmock/gmock.h>
|
2018-03-13 22:49:08 +00:00
|
|
|
|
2021-05-17 23:21:42 +00:00
|
|
|
#include <array>
|
|
|
|
|
2018-07-20 19:11:34 +00:00
|
|
|
namespace DetourNavigator
|
|
|
|
{
|
2021-07-14 15:30:47 +00:00
|
|
|
static inline bool operator ==(const Water& lhs, const Water& rhs)
|
2018-07-20 19:11:34 +00:00
|
|
|
{
|
2021-07-14 19:54:41 +00:00
|
|
|
return lhs.mCellSize == rhs.mCellSize && lhs.mShift == rhs.mShift;
|
2018-07-20 19:11:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-13 22:49:08 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using namespace testing;
|
|
|
|
using namespace DetourNavigator;
|
|
|
|
|
|
|
|
struct DetourNavigatorRecastMeshBuilderTest : Test
|
|
|
|
{
|
2018-04-15 22:07:18 +00:00
|
|
|
TileBounds mBounds;
|
2019-11-27 22:45:01 +00:00
|
|
|
const std::size_t mGeneration = 0;
|
|
|
|
const std::size_t mRevision = 0;
|
2018-03-13 22:49:08 +00:00
|
|
|
|
|
|
|
DetourNavigatorRecastMeshBuilderTest()
|
|
|
|
{
|
2018-04-15 22:07:18 +00:00
|
|
|
mBounds.mMin = osg::Vec2f(-std::numeric_limits<float>::max() * std::numeric_limits<float>::epsilon(),
|
|
|
|
-std::numeric_limits<float>::max() * std::numeric_limits<float>::epsilon());
|
|
|
|
mBounds.mMax = osg::Vec2f(std::numeric_limits<float>::max() * std::numeric_limits<float>::epsilon(),
|
|
|
|
std::numeric_limits<float>::max() * std::numeric_limits<float>::epsilon());
|
2018-03-13 22:49:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-15 22:39:51 +00:00
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, create_for_empty_should_return_empty)
|
2018-04-07 20:09:42 +00:00
|
|
|
{
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>());
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>());
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>());
|
2018-04-07 20:09:42 +00:00
|
|
|
}
|
|
|
|
|
2018-03-13 22:49:08 +00:00
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_bhv_triangle_mesh_shape)
|
|
|
|
{
|
|
|
|
btTriangleMesh mesh;
|
|
|
|
mesh.addTriangle(btVector3(-1, -1, 0), btVector3(-1, 1, 0), btVector3(1, -1, 0));
|
|
|
|
btBvhTriangleMeshShape shape(&mesh, true);
|
2018-09-30 22:33:25 +00:00
|
|
|
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2018-07-18 19:09:50 +00:00
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), AreaType_ground);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
|
2021-07-16 18:19:11 +00:00
|
|
|
-1, -1, 0,
|
|
|
|
-1, 1, 0,
|
|
|
|
1, -1, 0,
|
2021-07-11 19:43:19 +00:00
|
|
|
})) << recastMesh->getMesh().getVertices();
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>({2, 1, 0}));
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
|
2018-03-13 22:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_transformed_bhv_triangle_mesh_shape)
|
|
|
|
{
|
|
|
|
btTriangleMesh mesh;
|
|
|
|
mesh.addTriangle(btVector3(-1, -1, 0), btVector3(-1, 1, 0), btVector3(1, -1, 0));
|
|
|
|
btBvhTriangleMeshShape shape(&mesh, true);
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2018-07-12 08:44:11 +00:00
|
|
|
builder.addObject(
|
|
|
|
static_cast<const btCollisionShape&>(shape),
|
|
|
|
btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)),
|
2018-07-18 19:09:50 +00:00
|
|
|
AreaType_ground
|
2018-07-12 08:44:11 +00:00
|
|
|
);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
|
2021-07-16 18:19:11 +00:00
|
|
|
0, 0, 3,
|
|
|
|
0, 4, 3,
|
|
|
|
2, 0, 3,
|
2021-07-11 19:43:19 +00:00
|
|
|
})) << recastMesh->getMesh().getVertices();
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>({2, 1, 0}));
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
|
2018-03-13 22:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_heightfield_terrian_shape)
|
|
|
|
{
|
|
|
|
const std::array<btScalar, 4> heightfieldData {{0, 0, 0, 0}};
|
|
|
|
btHeightfieldTerrainShape shape(2, 2, heightfieldData.data(), 1, 0, 0, 2, PHY_FLOAT, false);
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2018-07-18 19:09:50 +00:00
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), AreaType_ground);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
|
2021-07-16 18:19:11 +00:00
|
|
|
-0.5, -0.5, 0,
|
|
|
|
-0.5, 0.5, 0,
|
|
|
|
0.5, -0.5, 0,
|
|
|
|
0.5, 0.5, 0,
|
|
|
|
})) << recastMesh->getMesh().getVertices();
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>({0, 1, 2, 2, 1, 3}));
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>({AreaType_ground, AreaType_ground}));
|
2018-03-13 22:49:08 +00:00
|
|
|
}
|
2018-04-07 20:09:42 +00:00
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_box_shape_should_produce_12_triangles)
|
|
|
|
{
|
|
|
|
btBoxShape shape(btVector3(1, 1, 2));
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2018-07-18 19:09:50 +00:00
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), AreaType_ground);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
|
2021-07-16 18:19:11 +00:00
|
|
|
-1, -1, -2,
|
|
|
|
-1, -1, 2,
|
|
|
|
-1, 1, -2,
|
|
|
|
-1, 1, 2,
|
|
|
|
1, -1, -2,
|
|
|
|
1, -1, 2,
|
|
|
|
1, 1, -2,
|
|
|
|
1, 1, 2,
|
2021-07-11 19:43:19 +00:00
|
|
|
})) << recastMesh->getMesh().getVertices();
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>({
|
2021-07-16 18:19:11 +00:00
|
|
|
0, 1, 5,
|
|
|
|
0, 2, 3,
|
|
|
|
0, 4, 6,
|
|
|
|
1, 3, 7,
|
|
|
|
2, 6, 7,
|
|
|
|
3, 1, 0,
|
|
|
|
4, 5, 7,
|
|
|
|
5, 4, 0,
|
|
|
|
6, 2, 0,
|
|
|
|
7, 3, 2,
|
|
|
|
7, 5, 1,
|
|
|
|
7, 6, 4,
|
2021-07-11 19:43:19 +00:00
|
|
|
})) << recastMesh->getMesh().getIndices();
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>(12, AreaType_ground));
|
2018-04-07 20:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_compound_shape)
|
|
|
|
{
|
|
|
|
btTriangleMesh mesh1;
|
|
|
|
mesh1.addTriangle(btVector3(-1, -1, 0), btVector3(-1, 1, 0), btVector3(1, -1, 0));
|
|
|
|
btBvhTriangleMeshShape triangle1(&mesh1, true);
|
|
|
|
btBoxShape box(btVector3(1, 1, 2));
|
|
|
|
btTriangleMesh mesh2;
|
|
|
|
mesh2.addTriangle(btVector3(1, 1, 0), btVector3(-1, 1, 0), btVector3(1, -1, 0));
|
|
|
|
btBvhTriangleMeshShape triangle2(&mesh2, true);
|
|
|
|
btCompoundShape shape;
|
|
|
|
shape.addChildShape(btTransform::getIdentity(), &triangle1);
|
|
|
|
shape.addChildShape(btTransform::getIdentity(), &box);
|
|
|
|
shape.addChildShape(btTransform::getIdentity(), &triangle2);
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2018-07-18 19:09:50 +00:00
|
|
|
builder.addObject(
|
|
|
|
static_cast<const btCollisionShape&>(shape),
|
|
|
|
btTransform::getIdentity(),
|
|
|
|
AreaType_ground
|
|
|
|
);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
|
2021-07-16 18:19:11 +00:00
|
|
|
-1, -1, -2,
|
|
|
|
-1, -1, 0,
|
|
|
|
-1, -1, 2,
|
|
|
|
-1, 1, -2,
|
|
|
|
-1, 1, 0,
|
|
|
|
-1, 1, 2,
|
|
|
|
1, -1, -2,
|
|
|
|
1, -1, 0,
|
|
|
|
1, -1, 2,
|
|
|
|
1, 1, -2,
|
|
|
|
1, 1, 0,
|
|
|
|
1, 1, 2,
|
2021-07-11 19:43:19 +00:00
|
|
|
})) << recastMesh->getMesh().getVertices();
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>({
|
2021-07-16 18:19:11 +00:00
|
|
|
0, 2, 8,
|
|
|
|
0, 3, 5,
|
|
|
|
0, 6, 9,
|
|
|
|
2, 5, 11,
|
|
|
|
3, 9, 11,
|
|
|
|
5, 2, 0,
|
|
|
|
6, 8, 11,
|
|
|
|
7, 4, 1,
|
|
|
|
7, 4, 10,
|
|
|
|
8, 6, 0,
|
|
|
|
9, 3, 0,
|
|
|
|
11, 5, 3,
|
|
|
|
11, 8, 2,
|
|
|
|
11, 9, 6,
|
2021-07-11 19:43:19 +00:00
|
|
|
})) << recastMesh->getMesh().getIndices();
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>(14, AreaType_ground));
|
2018-04-07 20:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_transformed_compound_shape)
|
|
|
|
{
|
|
|
|
btTriangleMesh mesh;
|
|
|
|
mesh.addTriangle(btVector3(-1, -1, 0), btVector3(-1, 1, 0), btVector3(1, -1, 0));
|
|
|
|
btBvhTriangleMeshShape triangle(&mesh, true);
|
|
|
|
btCompoundShape shape;
|
|
|
|
shape.addChildShape(btTransform::getIdentity(), &triangle);
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2018-07-18 19:09:50 +00:00
|
|
|
builder.addObject(
|
|
|
|
static_cast<const btCollisionShape&>(shape),
|
|
|
|
btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)),
|
|
|
|
AreaType_ground
|
|
|
|
);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
|
2021-07-16 18:19:11 +00:00
|
|
|
0, 0, 3,
|
|
|
|
0, 4, 3,
|
|
|
|
2, 0, 3,
|
2021-07-11 19:43:19 +00:00
|
|
|
})) << recastMesh->getMesh().getVertices();
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>({2, 1, 0}));
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
|
2018-04-07 20:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_transformed_compound_shape_with_transformed_bhv_triangle_shape)
|
|
|
|
{
|
|
|
|
btTriangleMesh mesh;
|
|
|
|
mesh.addTriangle(btVector3(-1, -1, 0), btVector3(-1, 1, 0), btVector3(1, -1, 0));
|
|
|
|
btBvhTriangleMeshShape triangle(&mesh, true);
|
|
|
|
btCompoundShape shape;
|
|
|
|
shape.addChildShape(btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)),
|
|
|
|
&triangle);
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2018-07-12 08:44:11 +00:00
|
|
|
builder.addObject(
|
|
|
|
static_cast<const btCollisionShape&>(shape),
|
|
|
|
btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)),
|
2018-07-18 19:09:50 +00:00
|
|
|
AreaType_ground
|
2018-07-12 08:44:11 +00:00
|
|
|
);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
|
2021-07-16 18:19:11 +00:00
|
|
|
1, 2, 12,
|
|
|
|
1, 10, 12,
|
|
|
|
3, 2, 12,
|
2021-07-11 19:43:19 +00:00
|
|
|
})) << recastMesh->getMesh().getVertices();
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>({2, 1, 0}));
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
|
2018-04-07 20:09:42 +00:00
|
|
|
}
|
2018-04-15 22:07:18 +00:00
|
|
|
|
2018-07-12 08:44:11 +00:00
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, without_bounds_add_bhv_triangle_shape_should_not_filter_by_bounds)
|
2018-04-15 22:07:18 +00:00
|
|
|
{
|
|
|
|
btTriangleMesh mesh;
|
|
|
|
mesh.addTriangle(btVector3(-1, -1, 0), btVector3(-1, 1, 0), btVector3(1, -1, 0));
|
|
|
|
mesh.addTriangle(btVector3(-3, -3, 0), btVector3(-3, -2, 0), btVector3(-2, -3, 0));
|
|
|
|
btBvhTriangleMeshShape shape(&mesh, true);
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2018-07-18 19:09:50 +00:00
|
|
|
builder.addObject(
|
|
|
|
static_cast<const btCollisionShape&>(shape),
|
|
|
|
btTransform::getIdentity(),
|
|
|
|
AreaType_ground
|
|
|
|
);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
|
2021-07-16 18:19:11 +00:00
|
|
|
-3, -3, 0,
|
|
|
|
-3, -2, 0,
|
|
|
|
-2, -3, 0,
|
|
|
|
-1, -1, 0,
|
|
|
|
-1, 1, 0,
|
|
|
|
1, -1, 0,
|
2021-07-11 19:43:19 +00:00
|
|
|
})) << recastMesh->getMesh().getVertices();
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>({2, 1, 0, 5, 4, 3}));
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>(2, AreaType_ground));
|
2018-04-15 22:07:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 08:44:11 +00:00
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_bhv_triangle_shape_should_filter_by_bounds)
|
2018-04-15 22:07:18 +00:00
|
|
|
{
|
2021-07-16 18:19:11 +00:00
|
|
|
mBounds.mMin = osg::Vec2f(-3, -3);
|
|
|
|
mBounds.mMax = osg::Vec2f(-2, -2);
|
2018-04-15 22:07:18 +00:00
|
|
|
btTriangleMesh mesh;
|
|
|
|
mesh.addTriangle(btVector3(-1, -1, 0), btVector3(-1, 1, 0), btVector3(1, -1, 0));
|
|
|
|
mesh.addTriangle(btVector3(-3, -3, 0), btVector3(-3, -2, 0), btVector3(-2, -3, 0));
|
|
|
|
btBvhTriangleMeshShape shape(&mesh, true);
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2018-07-18 19:09:50 +00:00
|
|
|
builder.addObject(
|
|
|
|
static_cast<const btCollisionShape&>(shape),
|
|
|
|
btTransform::getIdentity(),
|
|
|
|
AreaType_ground
|
|
|
|
);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
|
2021-07-16 18:19:11 +00:00
|
|
|
-3, -3, 0,
|
|
|
|
-3, -2, 0,
|
|
|
|
-2, -3, 0,
|
2021-07-11 19:43:19 +00:00
|
|
|
})) << recastMesh->getMesh().getVertices();
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>({2, 1, 0}));
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
|
2018-04-15 22:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_rotated_by_x_bhv_triangle_shape_should_filter_by_bounds)
|
|
|
|
{
|
|
|
|
mBounds.mMin = osg::Vec2f(-5, -5);
|
2018-10-28 13:54:47 +00:00
|
|
|
mBounds.mMax = osg::Vec2f(5, -2);
|
2018-04-15 22:07:18 +00:00
|
|
|
btTriangleMesh mesh;
|
|
|
|
mesh.addTriangle(btVector3(0, -1, -1), btVector3(0, -1, -1), btVector3(0, 1, -1));
|
|
|
|
mesh.addTriangle(btVector3(0, -3, -3), btVector3(0, -3, -2), btVector3(0, -2, -3));
|
|
|
|
btBvhTriangleMeshShape shape(&mesh, true);
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2018-07-18 19:09:50 +00:00
|
|
|
builder.addObject(
|
|
|
|
static_cast<const btCollisionShape&>(shape),
|
|
|
|
btTransform(btQuaternion(btVector3(1, 0, 0),
|
|
|
|
static_cast<btScalar>(-osg::PI_4))),
|
|
|
|
AreaType_ground
|
|
|
|
);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_THAT(recastMesh->getMesh().getVertices(), Pointwise(FloatNear(1e-5), std::vector<float>({
|
2021-07-16 18:19:11 +00:00
|
|
|
0, -4.24264049530029296875, 4.44089209850062616169452667236328125e-16,
|
|
|
|
0, -3.535533905029296875, -0.707106769084930419921875,
|
|
|
|
0, -3.535533905029296875, 0.707106769084930419921875,
|
2021-07-11 19:43:19 +00:00
|
|
|
}))) << recastMesh->getMesh().getVertices();
|
2021-07-16 18:19:11 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>({1, 2, 0}));
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
|
2018-04-15 22:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_rotated_by_y_bhv_triangle_shape_should_filter_by_bounds)
|
|
|
|
{
|
|
|
|
mBounds.mMin = osg::Vec2f(-5, -5);
|
|
|
|
mBounds.mMax = osg::Vec2f(-3, 5);
|
|
|
|
btTriangleMesh mesh;
|
|
|
|
mesh.addTriangle(btVector3(-1, 0, -1), btVector3(-1, 0, 1), btVector3(1, 0, -1));
|
|
|
|
mesh.addTriangle(btVector3(-3, 0, -3), btVector3(-3, 0, -2), btVector3(-2, 0, -3));
|
|
|
|
btBvhTriangleMeshShape shape(&mesh, true);
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2018-07-18 19:09:50 +00:00
|
|
|
builder.addObject(
|
|
|
|
static_cast<const btCollisionShape&>(shape),
|
|
|
|
btTransform(btQuaternion(btVector3(0, 1, 0),
|
|
|
|
static_cast<btScalar>(osg::PI_4))),
|
|
|
|
AreaType_ground
|
|
|
|
);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_THAT(recastMesh->getMesh().getVertices(), Pointwise(FloatNear(1e-5), std::vector<float>({
|
2021-07-16 18:19:11 +00:00
|
|
|
-4.24264049530029296875, 0, 4.44089209850062616169452667236328125e-16,
|
|
|
|
-3.535533905029296875, 0, -0.707106769084930419921875,
|
|
|
|
-3.535533905029296875, 0, 0.707106769084930419921875,
|
2021-07-11 19:43:19 +00:00
|
|
|
}))) << recastMesh->getMesh().getVertices();
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>({1, 2, 0}));
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
|
2018-04-15 22:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_rotated_by_z_bhv_triangle_shape_should_filter_by_bounds)
|
|
|
|
{
|
|
|
|
mBounds.mMin = osg::Vec2f(-5, -5);
|
|
|
|
mBounds.mMax = osg::Vec2f(-1, -1);
|
|
|
|
btTriangleMesh mesh;
|
|
|
|
mesh.addTriangle(btVector3(-1, -1, 0), btVector3(-1, 1, 0), btVector3(1, -1, 0));
|
|
|
|
mesh.addTriangle(btVector3(-3, -3, 0), btVector3(-3, -2, 0), btVector3(-2, -3, 0));
|
|
|
|
btBvhTriangleMeshShape shape(&mesh, true);
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2018-07-18 19:09:50 +00:00
|
|
|
builder.addObject(
|
|
|
|
static_cast<const btCollisionShape&>(shape),
|
|
|
|
btTransform(btQuaternion(btVector3(0, 0, 1),
|
|
|
|
static_cast<btScalar>(osg::PI_4))),
|
|
|
|
AreaType_ground
|
|
|
|
);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_THAT(recastMesh->getMesh().getVertices(), Pointwise(FloatNear(1e-5), std::vector<float>({
|
2021-07-16 18:19:11 +00:00
|
|
|
-1.41421353816986083984375, -1.1102230246251565404236316680908203125e-16, 0,
|
|
|
|
1.1102230246251565404236316680908203125e-16, -1.41421353816986083984375, 0,
|
|
|
|
1.41421353816986083984375, 1.1102230246251565404236316680908203125e-16, 0,
|
2021-07-11 19:43:19 +00:00
|
|
|
}))) << recastMesh->getMesh().getVertices();
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>({2, 0, 1}));
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
|
2018-07-12 08:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, flags_values_should_be_corresponding_to_added_objects)
|
|
|
|
{
|
|
|
|
btTriangleMesh mesh1;
|
|
|
|
mesh1.addTriangle(btVector3(-1, -1, 0), btVector3(-1, 1, 0), btVector3(1, -1, 0));
|
|
|
|
btBvhTriangleMeshShape shape1(&mesh1, true);
|
|
|
|
btTriangleMesh mesh2;
|
|
|
|
mesh2.addTriangle(btVector3(-3, -3, 0), btVector3(-3, -2, 0), btVector3(-2, -3, 0));
|
|
|
|
btBvhTriangleMeshShape shape2(&mesh2, true);
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2018-07-18 19:09:50 +00:00
|
|
|
builder.addObject(
|
|
|
|
static_cast<const btCollisionShape&>(shape1),
|
|
|
|
btTransform::getIdentity(),
|
|
|
|
AreaType_ground
|
|
|
|
);
|
|
|
|
builder.addObject(
|
|
|
|
static_cast<const btCollisionShape&>(shape2),
|
|
|
|
btTransform::getIdentity(),
|
|
|
|
AreaType_null
|
|
|
|
);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
|
2021-07-16 18:19:11 +00:00
|
|
|
-3, -3, 0,
|
|
|
|
-3, -2, 0,
|
|
|
|
-2, -3, 0,
|
|
|
|
-1, -1, 0,
|
|
|
|
-1, 1, 0,
|
|
|
|
1, -1, 0,
|
2021-07-11 19:43:19 +00:00
|
|
|
})) << recastMesh->getMesh().getVertices();
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>({2, 1, 0, 5, 4, 3}));
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>({AreaType_null, AreaType_ground}));
|
2018-04-15 22:07:18 +00:00
|
|
|
}
|
2018-07-20 19:11:34 +00:00
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_water_then_get_water_should_return_it)
|
|
|
|
{
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2021-07-14 19:54:41 +00:00
|
|
|
builder.addWater(1000, osg::Vec3f(100, 200, 300));
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-14 15:30:47 +00:00
|
|
|
EXPECT_EQ(recastMesh->getWater(), std::vector<Water>({
|
2021-07-14 19:54:41 +00:00
|
|
|
Water {1000, osg::Vec3f(100, 200, 300)}
|
2018-07-20 19:11:34 +00:00
|
|
|
}));
|
|
|
|
}
|
2020-06-15 21:53:22 +00:00
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_bhv_triangle_mesh_shape_with_duplicated_vertices)
|
|
|
|
{
|
|
|
|
btTriangleMesh mesh;
|
|
|
|
mesh.addTriangle(btVector3(-1, -1, 0), btVector3(-1, 1, 0), btVector3(1, -1, 0));
|
|
|
|
mesh.addTriangle(btVector3(1, 1, 0), btVector3(-1, 1, 0), btVector3(1, -1, 0));
|
|
|
|
btBvhTriangleMeshShape shape(&mesh, true);
|
|
|
|
|
2021-07-16 18:19:11 +00:00
|
|
|
RecastMeshBuilder builder(mBounds);
|
2020-06-15 21:53:22 +00:00
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), AreaType_ground);
|
2021-07-03 00:59:07 +00:00
|
|
|
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
|
2021-07-11 19:43:19 +00:00
|
|
|
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
|
2021-07-16 18:19:11 +00:00
|
|
|
-1, -1, 0,
|
|
|
|
-1, 1, 0,
|
|
|
|
1, -1, 0,
|
|
|
|
1, 1, 0,
|
2021-07-11 19:43:19 +00:00
|
|
|
})) << recastMesh->getMesh().getVertices();
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>({2, 1, 0, 2, 1, 3}));
|
|
|
|
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>({AreaType_ground, AreaType_ground}));
|
2020-06-15 21:53:22 +00:00
|
|
|
}
|
2018-03-13 22:49:08 +00:00
|
|
|
}
|