|
|
|
@ -40,6 +40,7 @@ namespace
|
|
|
|
|
const auto recastMesh = builder.create();
|
|
|
|
|
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>());
|
|
|
|
|
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>());
|
|
|
|
|
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_bhv_triangle_mesh_shape)
|
|
|
|
@ -48,7 +49,7 @@ namespace
|
|
|
|
|
mesh.addTriangle(btVector3(-1, -1, 0), btVector3(-1, 1, 0), btVector3(1, -1, 0));
|
|
|
|
|
btBvhTriangleMeshShape shape(&mesh, true);
|
|
|
|
|
RecastMeshBuilder builder(mSettings, mBounds);
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity());
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), 1);
|
|
|
|
|
const auto recastMesh = builder.create();
|
|
|
|
|
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
|
|
|
|
|
1, 0, -1,
|
|
|
|
@ -56,6 +57,7 @@ namespace
|
|
|
|
|
-1, 0, -1,
|
|
|
|
|
}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_transformed_bhv_triangle_mesh_shape)
|
|
|
|
@ -64,8 +66,11 @@ namespace
|
|
|
|
|
mesh.addTriangle(btVector3(-1, -1, 0), btVector3(-1, 1, 0), btVector3(1, -1, 0));
|
|
|
|
|
btBvhTriangleMeshShape shape(&mesh, true);
|
|
|
|
|
RecastMeshBuilder builder(mSettings, mBounds);
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape),
|
|
|
|
|
btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)));
|
|
|
|
|
builder.addObject(
|
|
|
|
|
static_cast<const btCollisionShape&>(shape),
|
|
|
|
|
btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)),
|
|
|
|
|
1
|
|
|
|
|
);
|
|
|
|
|
const auto recastMesh = builder.create();
|
|
|
|
|
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
|
|
|
|
|
2, 3, 0,
|
|
|
|
@ -73,6 +78,7 @@ namespace
|
|
|
|
|
0, 3, 0,
|
|
|
|
|
}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_heightfield_terrian_shape)
|
|
|
|
@ -80,7 +86,7 @@ namespace
|
|
|
|
|
const std::array<btScalar, 4> heightfieldData {{0, 0, 0, 0}};
|
|
|
|
|
btHeightfieldTerrainShape shape(2, 2, heightfieldData.data(), 1, 0, 0, 2, PHY_FLOAT, false);
|
|
|
|
|
RecastMeshBuilder builder(mSettings, mBounds);
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity());
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), 1);
|
|
|
|
|
const auto recastMesh = builder.create();
|
|
|
|
|
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
|
|
|
|
|
-0.5, 0, -0.5,
|
|
|
|
@ -91,13 +97,14 @@ namespace
|
|
|
|
|
0.5, 0, 0.5,
|
|
|
|
|
}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2, 3, 4, 5}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1, 1}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_box_shape_should_produce_12_triangles)
|
|
|
|
|
{
|
|
|
|
|
btBoxShape shape(btVector3(1, 1, 2));
|
|
|
|
|
RecastMeshBuilder builder(mSettings, mBounds);
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity());
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), 1);
|
|
|
|
|
const auto recastMesh = builder.create();
|
|
|
|
|
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
|
|
|
|
|
1, 2, 1,
|
|
|
|
@ -123,6 +130,7 @@ namespace
|
|
|
|
|
7, 6, 4,
|
|
|
|
|
4, 5, 7,
|
|
|
|
|
}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_compound_shape)
|
|
|
|
@ -139,7 +147,7 @@ namespace
|
|
|
|
|
shape.addChildShape(btTransform::getIdentity(), &box);
|
|
|
|
|
shape.addChildShape(btTransform::getIdentity(), &triangle2);
|
|
|
|
|
RecastMeshBuilder builder(mSettings, mBounds);
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity());
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), 1);
|
|
|
|
|
const auto recastMesh = builder.create();
|
|
|
|
|
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
|
|
|
|
|
1, 0, -1,
|
|
|
|
@ -173,6 +181,7 @@ namespace
|
|
|
|
|
7, 8, 10,
|
|
|
|
|
11, 12, 13,
|
|
|
|
|
}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_transformed_compound_shape)
|
|
|
|
@ -184,7 +193,8 @@ namespace
|
|
|
|
|
shape.addChildShape(btTransform::getIdentity(), &triangle);
|
|
|
|
|
RecastMeshBuilder builder(mSettings, mBounds);
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape),
|
|
|
|
|
btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)));
|
|
|
|
|
btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)),
|
|
|
|
|
1);
|
|
|
|
|
const auto recastMesh = builder.create();
|
|
|
|
|
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
|
|
|
|
|
2, 3, 0,
|
|
|
|
@ -192,6 +202,7 @@ namespace
|
|
|
|
|
0, 3, 0,
|
|
|
|
|
}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_transformed_compound_shape_with_transformed_bhv_triangle_shape)
|
|
|
|
@ -203,8 +214,11 @@ namespace
|
|
|
|
|
shape.addChildShape(btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)),
|
|
|
|
|
&triangle);
|
|
|
|
|
RecastMeshBuilder builder(mSettings, mBounds);
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape),
|
|
|
|
|
btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)));
|
|
|
|
|
builder.addObject(
|
|
|
|
|
static_cast<const btCollisionShape&>(shape),
|
|
|
|
|
btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)),
|
|
|
|
|
1
|
|
|
|
|
);
|
|
|
|
|
const auto recastMesh = builder.create();
|
|
|
|
|
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
|
|
|
|
|
3, 12, 2,
|
|
|
|
@ -212,16 +226,17 @@ namespace
|
|
|
|
|
1, 12, 2,
|
|
|
|
|
}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, without_bounds_add_transformed_compound_shape_with_transformed_bhv_triangle_shape_should_not_filter_by_bounds)
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, without_bounds_add_bhv_triangle_shape_should_not_filter_by_bounds)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
RecastMeshBuilder builder(mSettings, mBounds);
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity());
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), 1);
|
|
|
|
|
const auto recastMesh = builder.create();
|
|
|
|
|
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
|
|
|
|
|
1, 0, -1,
|
|
|
|
@ -232,9 +247,10 @@ namespace
|
|
|
|
|
-3, 0, -3,
|
|
|
|
|
}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2, 3, 4, 5}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1, 1}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_transformed_compound_shape_with_transformed_bhv_triangle_shape_should_filter_by_bounds)
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_bhv_triangle_shape_should_filter_by_bounds)
|
|
|
|
|
{
|
|
|
|
|
mSettings.mRecastScaleFactor = 0.1f;
|
|
|
|
|
mBounds.mMin = osg::Vec2f(-3, -3) * mSettings.mRecastScaleFactor;
|
|
|
|
@ -244,7 +260,7 @@ namespace
|
|
|
|
|
mesh.addTriangle(btVector3(-3, -3, 0), btVector3(-3, -2, 0), btVector3(-2, -3, 0));
|
|
|
|
|
btBvhTriangleMeshShape shape(&mesh, true);
|
|
|
|
|
RecastMeshBuilder builder(mSettings, mBounds);
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity());
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), 1);
|
|
|
|
|
const auto recastMesh = builder.create();
|
|
|
|
|
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
|
|
|
|
|
-0.2f, 0, -0.3f,
|
|
|
|
@ -252,6 +268,7 @@ namespace
|
|
|
|
|
-0.3f, 0, -0.3f,
|
|
|
|
|
}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_rotated_by_x_bhv_triangle_shape_should_filter_by_bounds)
|
|
|
|
@ -264,7 +281,7 @@ namespace
|
|
|
|
|
btBvhTriangleMeshShape shape(&mesh, true);
|
|
|
|
|
RecastMeshBuilder builder(mSettings, mBounds);
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape),
|
|
|
|
|
btTransform(btQuaternion(btVector3(1, 0, 0), static_cast<btScalar>(-osg::PI_4))));
|
|
|
|
|
btTransform(btQuaternion(btVector3(1, 0, 0), static_cast<btScalar>(-osg::PI_4))), 1);
|
|
|
|
|
const auto recastMesh = builder.create();
|
|
|
|
|
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
|
|
|
|
|
0, -0.70710659027099609375, -3.535533905029296875,
|
|
|
|
@ -272,6 +289,7 @@ namespace
|
|
|
|
|
0, 2.384185791015625e-07, -4.24264049530029296875,
|
|
|
|
|
}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_rotated_by_y_bhv_triangle_shape_should_filter_by_bounds)
|
|
|
|
@ -284,7 +302,7 @@ namespace
|
|
|
|
|
btBvhTriangleMeshShape shape(&mesh, true);
|
|
|
|
|
RecastMeshBuilder builder(mSettings, mBounds);
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape),
|
|
|
|
|
btTransform(btQuaternion(btVector3(0, 1, 0), static_cast<btScalar>(osg::PI_4))));
|
|
|
|
|
btTransform(btQuaternion(btVector3(0, 1, 0), static_cast<btScalar>(osg::PI_4))), 1);
|
|
|
|
|
const auto recastMesh = builder.create();
|
|
|
|
|
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
|
|
|
|
|
-3.535533905029296875, -0.70710659027099609375, 0,
|
|
|
|
@ -292,6 +310,7 @@ namespace
|
|
|
|
|
-4.24264049530029296875, 2.384185791015625e-07, 0,
|
|
|
|
|
}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_rotated_by_z_bhv_triangle_shape_should_filter_by_bounds)
|
|
|
|
@ -304,7 +323,7 @@ namespace
|
|
|
|
|
btBvhTriangleMeshShape shape(&mesh, true);
|
|
|
|
|
RecastMeshBuilder builder(mSettings, mBounds);
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape),
|
|
|
|
|
btTransform(btQuaternion(btVector3(0, 0, 1), static_cast<btScalar>(osg::PI_4))));
|
|
|
|
|
btTransform(btQuaternion(btVector3(0, 0, 1), static_cast<btScalar>(osg::PI_4))), 1);
|
|
|
|
|
const auto recastMesh = builder.create();
|
|
|
|
|
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
|
|
|
|
|
0.707107067108154296875, 0, -3.535533905029296875,
|
|
|
|
@ -312,5 +331,30 @@ namespace
|
|
|
|
|
2.384185791015625e-07, 0, -4.24264049530029296875,
|
|
|
|
|
}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
RecastMeshBuilder builder(mSettings, mBounds);
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape1), btTransform::getIdentity(), 1);
|
|
|
|
|
builder.addObject(static_cast<const btCollisionShape&>(shape2), btTransform::getIdentity(), 0);
|
|
|
|
|
const auto recastMesh = builder.create();
|
|
|
|
|
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
|
|
|
|
|
1, 0, -1,
|
|
|
|
|
-1, 0, 1,
|
|
|
|
|
-1, 0, -1,
|
|
|
|
|
-2, 0, -3,
|
|
|
|
|
-3, 0, -2,
|
|
|
|
|
-3, 0, -3,
|
|
|
|
|
}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2, 3, 4, 5}));
|
|
|
|
|
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1, 0}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|