Add enums for area type and flags

pull/1633/head
elsid 7 years ago
parent fa23b590a4
commit 72f211ef28
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -40,7 +40,7 @@ namespace
const auto recastMesh = builder.create(); const auto recastMesh = builder.create();
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>()); EXPECT_EQ(recastMesh->getVertices(), std::vector<float>());
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>()); EXPECT_EQ(recastMesh->getIndices(), std::vector<int>());
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>()); EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>());
} }
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_bhv_triangle_mesh_shape) TEST_F(DetourNavigatorRecastMeshBuilderTest, add_bhv_triangle_mesh_shape)
@ -49,7 +49,7 @@ namespace
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); btBvhTriangleMeshShape shape(&mesh, true);
RecastMeshBuilder builder(mSettings, mBounds); RecastMeshBuilder builder(mSettings, mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), 1); builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), AreaType_ground);
const auto recastMesh = builder.create(); const auto recastMesh = builder.create();
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
1, 0, -1, 1, 0, -1,
@ -57,7 +57,7 @@ namespace
-1, 0, -1, -1, 0, -1,
})); }));
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2})); EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1})); EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
} }
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_transformed_bhv_triangle_mesh_shape) TEST_F(DetourNavigatorRecastMeshBuilderTest, add_transformed_bhv_triangle_mesh_shape)
@ -69,7 +69,7 @@ namespace
builder.addObject( builder.addObject(
static_cast<const btCollisionShape&>(shape), 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 AreaType_ground
); );
const auto recastMesh = builder.create(); const auto recastMesh = builder.create();
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
@ -78,7 +78,7 @@ namespace
0, 3, 0, 0, 3, 0,
})); }));
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2})); EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1})); EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
} }
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_heightfield_terrian_shape) TEST_F(DetourNavigatorRecastMeshBuilderTest, add_heightfield_terrian_shape)
@ -86,7 +86,7 @@ namespace
const std::array<btScalar, 4> heightfieldData {{0, 0, 0, 0}}; const std::array<btScalar, 4> heightfieldData {{0, 0, 0, 0}};
btHeightfieldTerrainShape shape(2, 2, heightfieldData.data(), 1, 0, 0, 2, PHY_FLOAT, false); btHeightfieldTerrainShape shape(2, 2, heightfieldData.data(), 1, 0, 0, 2, PHY_FLOAT, false);
RecastMeshBuilder builder(mSettings, mBounds); RecastMeshBuilder builder(mSettings, mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), 1); builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), AreaType_ground);
const auto recastMesh = builder.create(); const auto recastMesh = builder.create();
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
-0.5, 0, -0.5, -0.5, 0, -0.5,
@ -97,14 +97,14 @@ namespace
0.5, 0, 0.5, 0.5, 0, 0.5,
})); }));
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2, 3, 4, 5})); EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2, 3, 4, 5}));
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1, 1})); EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>({AreaType_ground, AreaType_ground}));
} }
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_box_shape_should_produce_12_triangles) TEST_F(DetourNavigatorRecastMeshBuilderTest, add_box_shape_should_produce_12_triangles)
{ {
btBoxShape shape(btVector3(1, 1, 2)); btBoxShape shape(btVector3(1, 1, 2));
RecastMeshBuilder builder(mSettings, mBounds); RecastMeshBuilder builder(mSettings, mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), 1); builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), AreaType_ground);
const auto recastMesh = builder.create(); const auto recastMesh = builder.create();
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
1, 2, 1, 1, 2, 1,
@ -130,7 +130,7 @@ namespace
7, 6, 4, 7, 6, 4,
4, 5, 7, 4, 5, 7,
})); }));
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})); EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>(12, AreaType_ground));
} }
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_compound_shape) TEST_F(DetourNavigatorRecastMeshBuilderTest, add_compound_shape)
@ -147,7 +147,11 @@ namespace
shape.addChildShape(btTransform::getIdentity(), &box); shape.addChildShape(btTransform::getIdentity(), &box);
shape.addChildShape(btTransform::getIdentity(), &triangle2); shape.addChildShape(btTransform::getIdentity(), &triangle2);
RecastMeshBuilder builder(mSettings, mBounds); RecastMeshBuilder builder(mSettings, mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), 1); builder.addObject(
static_cast<const btCollisionShape&>(shape),
btTransform::getIdentity(),
AreaType_ground
);
const auto recastMesh = builder.create(); const auto recastMesh = builder.create();
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
1, 0, -1, 1, 0, -1,
@ -181,7 +185,7 @@ namespace
7, 8, 10, 7, 8, 10,
11, 12, 13, 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})); EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>(14, AreaType_ground));
} }
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_transformed_compound_shape) TEST_F(DetourNavigatorRecastMeshBuilderTest, add_transformed_compound_shape)
@ -192,9 +196,11 @@ namespace
btCompoundShape shape; btCompoundShape shape;
shape.addChildShape(btTransform::getIdentity(), &triangle); shape.addChildShape(btTransform::getIdentity(), &triangle);
RecastMeshBuilder builder(mSettings, mBounds); RecastMeshBuilder builder(mSettings, mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape), builder.addObject(
btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)), static_cast<const btCollisionShape&>(shape),
1); btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)),
AreaType_ground
);
const auto recastMesh = builder.create(); const auto recastMesh = builder.create();
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
2, 3, 0, 2, 3, 0,
@ -202,7 +208,7 @@ namespace
0, 3, 0, 0, 3, 0,
})); }));
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2})); EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1})); EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
} }
TEST_F(DetourNavigatorRecastMeshBuilderTest, add_transformed_compound_shape_with_transformed_bhv_triangle_shape) TEST_F(DetourNavigatorRecastMeshBuilderTest, add_transformed_compound_shape_with_transformed_bhv_triangle_shape)
@ -217,7 +223,7 @@ namespace
builder.addObject( builder.addObject(
static_cast<const btCollisionShape&>(shape), 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 AreaType_ground
); );
const auto recastMesh = builder.create(); const auto recastMesh = builder.create();
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
@ -226,7 +232,7 @@ namespace
1, 12, 2, 1, 12, 2,
})); }));
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2})); EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1})); EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
} }
TEST_F(DetourNavigatorRecastMeshBuilderTest, without_bounds_add_bhv_triangle_shape_should_not_filter_by_bounds) TEST_F(DetourNavigatorRecastMeshBuilderTest, without_bounds_add_bhv_triangle_shape_should_not_filter_by_bounds)
@ -236,7 +242,11 @@ namespace
mesh.addTriangle(btVector3(-3, -3, 0), btVector3(-3, -2, 0), btVector3(-2, -3, 0)); mesh.addTriangle(btVector3(-3, -3, 0), btVector3(-3, -2, 0), btVector3(-2, -3, 0));
btBvhTriangleMeshShape shape(&mesh, true); btBvhTriangleMeshShape shape(&mesh, true);
RecastMeshBuilder builder(mSettings, mBounds); RecastMeshBuilder builder(mSettings, mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), 1); builder.addObject(
static_cast<const btCollisionShape&>(shape),
btTransform::getIdentity(),
AreaType_ground
);
const auto recastMesh = builder.create(); const auto recastMesh = builder.create();
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
1, 0, -1, 1, 0, -1,
@ -247,7 +257,7 @@ namespace
-3, 0, -3, -3, 0, -3,
})); }));
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2, 3, 4, 5})); EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2, 3, 4, 5}));
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1, 1})); EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>(2, AreaType_ground));
} }
TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_bhv_triangle_shape_should_filter_by_bounds) TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_bhv_triangle_shape_should_filter_by_bounds)
@ -260,7 +270,11 @@ namespace
mesh.addTriangle(btVector3(-3, -3, 0), btVector3(-3, -2, 0), btVector3(-2, -3, 0)); mesh.addTriangle(btVector3(-3, -3, 0), btVector3(-3, -2, 0), btVector3(-2, -3, 0));
btBvhTriangleMeshShape shape(&mesh, true); btBvhTriangleMeshShape shape(&mesh, true);
RecastMeshBuilder builder(mSettings, mBounds); RecastMeshBuilder builder(mSettings, mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), 1); builder.addObject(
static_cast<const btCollisionShape&>(shape),
btTransform::getIdentity(),
AreaType_ground
);
const auto recastMesh = builder.create(); const auto recastMesh = builder.create();
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
-0.2f, 0, -0.3f, -0.2f, 0, -0.3f,
@ -268,7 +282,7 @@ namespace
-0.3f, 0, -0.3f, -0.3f, 0, -0.3f,
})); }));
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2})); EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1})); EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
} }
TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_rotated_by_x_bhv_triangle_shape_should_filter_by_bounds) TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_rotated_by_x_bhv_triangle_shape_should_filter_by_bounds)
@ -280,8 +294,12 @@ namespace
mesh.addTriangle(btVector3(0, -3, -3), btVector3(0, -3, -2), btVector3(0, -2, -3)); mesh.addTriangle(btVector3(0, -3, -3), btVector3(0, -3, -2), btVector3(0, -2, -3));
btBvhTriangleMeshShape shape(&mesh, true); btBvhTriangleMeshShape shape(&mesh, true);
RecastMeshBuilder builder(mSettings, mBounds); RecastMeshBuilder builder(mSettings, mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape), builder.addObject(
btTransform(btQuaternion(btVector3(1, 0, 0), static_cast<btScalar>(-osg::PI_4))), 1); static_cast<const btCollisionShape&>(shape),
btTransform(btQuaternion(btVector3(1, 0, 0),
static_cast<btScalar>(-osg::PI_4))),
AreaType_ground
);
const auto recastMesh = builder.create(); const auto recastMesh = builder.create();
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
0, -0.70710659027099609375, -3.535533905029296875, 0, -0.70710659027099609375, -3.535533905029296875,
@ -289,7 +307,7 @@ namespace
0, 2.384185791015625e-07, -4.24264049530029296875, 0, 2.384185791015625e-07, -4.24264049530029296875,
})); }));
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2})); EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1})); EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
} }
TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_rotated_by_y_bhv_triangle_shape_should_filter_by_bounds) TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_rotated_by_y_bhv_triangle_shape_should_filter_by_bounds)
@ -301,8 +319,12 @@ namespace
mesh.addTriangle(btVector3(-3, 0, -3), btVector3(-3, 0, -2), btVector3(-2, 0, -3)); mesh.addTriangle(btVector3(-3, 0, -3), btVector3(-3, 0, -2), btVector3(-2, 0, -3));
btBvhTriangleMeshShape shape(&mesh, true); btBvhTriangleMeshShape shape(&mesh, true);
RecastMeshBuilder builder(mSettings, mBounds); RecastMeshBuilder builder(mSettings, mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape), builder.addObject(
btTransform(btQuaternion(btVector3(0, 1, 0), static_cast<btScalar>(osg::PI_4))), 1); static_cast<const btCollisionShape&>(shape),
btTransform(btQuaternion(btVector3(0, 1, 0),
static_cast<btScalar>(osg::PI_4))),
AreaType_ground
);
const auto recastMesh = builder.create(); const auto recastMesh = builder.create();
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
-3.535533905029296875, -0.70710659027099609375, 0, -3.535533905029296875, -0.70710659027099609375, 0,
@ -310,7 +332,7 @@ namespace
-4.24264049530029296875, 2.384185791015625e-07, 0, -4.24264049530029296875, 2.384185791015625e-07, 0,
})); }));
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2})); EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1})); EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
} }
TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_rotated_by_z_bhv_triangle_shape_should_filter_by_bounds) TEST_F(DetourNavigatorRecastMeshBuilderTest, with_bounds_add_rotated_by_z_bhv_triangle_shape_should_filter_by_bounds)
@ -322,8 +344,12 @@ namespace
mesh.addTriangle(btVector3(-3, -3, 0), btVector3(-3, -2, 0), btVector3(-2, -3, 0)); mesh.addTriangle(btVector3(-3, -3, 0), btVector3(-3, -2, 0), btVector3(-2, -3, 0));
btBvhTriangleMeshShape shape(&mesh, true); btBvhTriangleMeshShape shape(&mesh, true);
RecastMeshBuilder builder(mSettings, mBounds); RecastMeshBuilder builder(mSettings, mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape), builder.addObject(
btTransform(btQuaternion(btVector3(0, 0, 1), static_cast<btScalar>(osg::PI_4))), 1); static_cast<const btCollisionShape&>(shape),
btTransform(btQuaternion(btVector3(0, 0, 1),
static_cast<btScalar>(osg::PI_4))),
AreaType_ground
);
const auto recastMesh = builder.create(); const auto recastMesh = builder.create();
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
0.707107067108154296875, 0, -3.535533905029296875, 0.707107067108154296875, 0, -3.535533905029296875,
@ -331,7 +357,7 @@ namespace
2.384185791015625e-07, 0, -4.24264049530029296875, 2.384185791015625e-07, 0, -4.24264049530029296875,
})); }));
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2})); EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1})); EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
} }
TEST_F(DetourNavigatorRecastMeshBuilderTest, flags_values_should_be_corresponding_to_added_objects) TEST_F(DetourNavigatorRecastMeshBuilderTest, flags_values_should_be_corresponding_to_added_objects)
@ -343,8 +369,16 @@ namespace
mesh2.addTriangle(btVector3(-3, -3, 0), btVector3(-3, -2, 0), btVector3(-2, -3, 0)); mesh2.addTriangle(btVector3(-3, -3, 0), btVector3(-3, -2, 0), btVector3(-2, -3, 0));
btBvhTriangleMeshShape shape2(&mesh2, true); btBvhTriangleMeshShape shape2(&mesh2, true);
RecastMeshBuilder builder(mSettings, mBounds); RecastMeshBuilder builder(mSettings, mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape1), btTransform::getIdentity(), 1); builder.addObject(
builder.addObject(static_cast<const btCollisionShape&>(shape2), btTransform::getIdentity(), 0); static_cast<const btCollisionShape&>(shape1),
btTransform::getIdentity(),
AreaType_ground
);
builder.addObject(
static_cast<const btCollisionShape&>(shape2),
btTransform::getIdentity(),
AreaType_null
);
const auto recastMesh = builder.create(); const auto recastMesh = builder.create();
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
1, 0, -1, 1, 0, -1,
@ -355,6 +389,6 @@ namespace
-3, 0, -3, -3, 0, -3,
})); }));
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2, 3, 4, 5})); EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2, 3, 4, 5}));
EXPECT_EQ(recastMesh->getFlags(), std::vector<unsigned char>({1, 0})); EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>({AreaType_ground, AreaType_null}));
} }
} }

@ -26,47 +26,47 @@ namespace
TEST_F(DetourNavigatorRecastMeshObjectTest, constructed_object_should_have_shape_and_transform) TEST_F(DetourNavigatorRecastMeshObjectTest, constructed_object_should_have_shape_and_transform)
{ {
const RecastMeshObject object(mBoxShape, mTransform, 1); const RecastMeshObject object(mBoxShape, mTransform, AreaType_ground);
EXPECT_EQ(std::addressof(object.getShape()), std::addressof(mBoxShape)); EXPECT_EQ(std::addressof(object.getShape()), std::addressof(mBoxShape));
EXPECT_EQ(object.getTransform(), mTransform); EXPECT_EQ(object.getTransform(), mTransform);
} }
TEST_F(DetourNavigatorRecastMeshObjectTest, update_with_same_transform_for_not_compound_shape_should_return_false) TEST_F(DetourNavigatorRecastMeshObjectTest, update_with_same_transform_for_not_compound_shape_should_return_false)
{ {
RecastMeshObject object(mBoxShape, mTransform, 1); RecastMeshObject object(mBoxShape, mTransform, AreaType_ground);
EXPECT_FALSE(object.update(mTransform, 1)); EXPECT_FALSE(object.update(mTransform, AreaType_ground));
} }
TEST_F(DetourNavigatorRecastMeshObjectTest, update_with_different_transform_should_return_true) TEST_F(DetourNavigatorRecastMeshObjectTest, update_with_different_transform_should_return_true)
{ {
RecastMeshObject object(mBoxShape, mTransform, 1); RecastMeshObject object(mBoxShape, mTransform, AreaType_ground);
EXPECT_TRUE(object.update(btTransform::getIdentity(), 1)); EXPECT_TRUE(object.update(btTransform::getIdentity(), AreaType_ground));
} }
TEST_F(DetourNavigatorRecastMeshObjectTest, update_with_different_flags_should_return_true) TEST_F(DetourNavigatorRecastMeshObjectTest, update_with_different_flags_should_return_true)
{ {
RecastMeshObject object(mBoxShape, mTransform, 1); RecastMeshObject object(mBoxShape, mTransform, AreaType_ground);
EXPECT_TRUE(object.update(mTransform, 2)); EXPECT_TRUE(object.update(mTransform, AreaType_null));
} }
TEST_F(DetourNavigatorRecastMeshObjectTest, update_for_compound_shape_with_same_transform_and_not_changed_child_transform_should_return_false) TEST_F(DetourNavigatorRecastMeshObjectTest, update_for_compound_shape_with_same_transform_and_not_changed_child_transform_should_return_false)
{ {
RecastMeshObject object(mCompoundShape, mTransform, 1); RecastMeshObject object(mCompoundShape, mTransform, AreaType_ground);
EXPECT_FALSE(object.update(mTransform, 1)); EXPECT_FALSE(object.update(mTransform, AreaType_ground));
} }
TEST_F(DetourNavigatorRecastMeshObjectTest, update_for_compound_shape_with_same_transform_and_changed_child_transform_should_return_true) TEST_F(DetourNavigatorRecastMeshObjectTest, update_for_compound_shape_with_same_transform_and_changed_child_transform_should_return_true)
{ {
RecastMeshObject object(mCompoundShape, mTransform, 1); RecastMeshObject object(mCompoundShape, mTransform, AreaType_ground);
mCompoundShape.updateChildTransform(0, btTransform::getIdentity()); mCompoundShape.updateChildTransform(0, btTransform::getIdentity());
EXPECT_TRUE(object.update(mTransform, 1)); EXPECT_TRUE(object.update(mTransform, AreaType_ground));
} }
TEST_F(DetourNavigatorRecastMeshObjectTest, repeated_update_for_compound_shape_without_changes_should_return_false) TEST_F(DetourNavigatorRecastMeshObjectTest, repeated_update_for_compound_shape_without_changes_should_return_false)
{ {
RecastMeshObject object(mCompoundShape, mTransform, 1); RecastMeshObject object(mCompoundShape, mTransform, AreaType_ground);
mCompoundShape.updateChildTransform(0, btTransform::getIdentity()); mCompoundShape.updateChildTransform(0, btTransform::getIdentity());
object.update(mTransform, 1); object.update(mTransform, AreaType_ground);
EXPECT_FALSE(object.update(mTransform, 1)); EXPECT_FALSE(object.update(mTransform, AreaType_ground));
} }
} }

@ -0,0 +1,15 @@
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_AREATYPE_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_AREATYPE_H
#include <Recast.h>
namespace DetourNavigator
{
enum AreaType : unsigned char
{
AreaType_null = RC_NULL_AREA,
AreaType_ground = RC_WALKABLE_AREA,
};
}
#endif

@ -8,17 +8,17 @@ namespace DetourNavigator
{} {}
bool CachedRecastMeshManager::addObject(std::size_t id, const btCollisionShape& shape, bool CachedRecastMeshManager::addObject(std::size_t id, const btCollisionShape& shape,
const btTransform& transform, const unsigned char flags) const btTransform& transform, const AreaType areaType)
{ {
if (!mImpl.addObject(id, shape, transform, flags)) if (!mImpl.addObject(id, shape, transform, areaType))
return false; return false;
mCached.reset(); mCached.reset();
return true; return true;
} }
bool CachedRecastMeshManager::updateObject(std::size_t id, const btTransform& transform, const unsigned char flags) bool CachedRecastMeshManager::updateObject(std::size_t id, const btTransform& transform, const AreaType areaType)
{ {
if (!mImpl.updateObject(id, transform, flags)) if (!mImpl.updateObject(id, transform, areaType))
return false; return false;
mCached.reset(); mCached.reset();
return true; return true;

@ -13,9 +13,9 @@ namespace DetourNavigator
CachedRecastMeshManager(const Settings& settings, const TileBounds& bounds); CachedRecastMeshManager(const Settings& settings, const TileBounds& bounds);
bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform,
const unsigned char flags); const AreaType areaType);
bool updateObject(std::size_t id, const btTransform& transform, const unsigned char flags); bool updateObject(std::size_t id, const btTransform& transform, const AreaType areaType);
boost::optional<RemovedRecastMeshObject> removeObject(std::size_t id); boost::optional<RemovedRecastMeshObject> removeObject(std::size_t id);

@ -13,7 +13,7 @@ namespace DetourNavigator
{ {
Rect mBounds; Rect mBounds;
std::ptrdiff_t mOffset; std::ptrdiff_t mOffset;
unsigned char mFlags; unsigned char mAreaTypes;
}; };
template <std::size_t axis> template <std::size_t axis>
@ -44,9 +44,9 @@ namespace DetourNavigator
} }
void subdivide(std::vector<BoundsItem>& items, const std::size_t imin, const std::size_t imax, void subdivide(std::vector<BoundsItem>& items, const std::size_t imin, const std::size_t imax,
const std::size_t trisPerChunk, const std::vector<int>& inIndices, const std::vector<unsigned char>& inFlags, const std::size_t trisPerChunk, const std::vector<int>& inIndices, const std::vector<AreaType>& inAreaTypes,
std::size_t& curNode, std::vector<ChunkyTriMeshNode>& nodes, std::size_t& curTri, std::size_t& curNode, std::vector<ChunkyTriMeshNode>& nodes, std::size_t& curTri,
std::vector<int>& outIndices, std::vector<unsigned char>& outFlags) std::vector<int>& outIndices, std::vector<AreaType>& outAreaTypes)
{ {
const auto inum = imax - imin; const auto inum = imax - imin;
const auto icur = curNode; const auto icur = curNode;
@ -72,7 +72,7 @@ namespace DetourNavigator
inIndices.begin() + items[i].mOffset * 3 + 3, inIndices.begin() + items[i].mOffset * 3 + 3,
outIndices.begin() + static_cast<std::ptrdiff_t>(curTri) * 3 outIndices.begin() + static_cast<std::ptrdiff_t>(curTri) * 3
); );
outFlags[curTri] = inFlags[static_cast<std::size_t>(items[i].mOffset)]; outAreaTypes[curTri] = inAreaTypes[static_cast<std::size_t>(items[i].mOffset)];
curTri++; curTri++;
} }
} }
@ -104,9 +104,9 @@ namespace DetourNavigator
const auto isplit = imin + inum / 2; const auto isplit = imin + inum / 2;
// Left // Left
subdivide(items, imin, isplit, trisPerChunk, inIndices, inFlags, curNode, nodes, curTri, outIndices, outFlags); subdivide(items, imin, isplit, trisPerChunk, inIndices, inAreaTypes, curNode, nodes, curTri, outIndices, outAreaTypes);
// Right // Right
subdivide(items, isplit, imax, trisPerChunk, inIndices, inFlags, curNode, nodes, curTri, outIndices, outFlags); subdivide(items, isplit, imax, trisPerChunk, inIndices, inAreaTypes, curNode, nodes, curTri, outIndices, outAreaTypes);
const auto iescape = static_cast<std::ptrdiff_t>(curNode) - static_cast<std::ptrdiff_t>(icur); const auto iescape = static_cast<std::ptrdiff_t>(curNode) - static_cast<std::ptrdiff_t>(icur);
// Negative index means escape. // Negative index means escape.
@ -116,7 +116,7 @@ namespace DetourNavigator
} }
ChunkyTriMesh::ChunkyTriMesh(const std::vector<float>& verts, const std::vector<int>& indices, ChunkyTriMesh::ChunkyTriMesh(const std::vector<float>& verts, const std::vector<int>& indices,
const std::vector<unsigned char>& flags, const std::size_t trisPerChunk) const std::vector<AreaType>& flags, const std::size_t trisPerChunk)
: mMaxTrisPerChunk(0) : mMaxTrisPerChunk(0)
{ {
const auto trianglesCount = indices.size() / 3; const auto trianglesCount = indices.size() / 3;
@ -128,7 +128,7 @@ namespace DetourNavigator
mNodes.resize(nchunks * 4); mNodes.resize(nchunks * 4);
mIndices.resize(trianglesCount * 3); mIndices.resize(trianglesCount * 3);
mFlags.resize(trianglesCount); mAreaTypes.resize(trianglesCount);
// Build tree // Build tree
std::vector<BoundsItem> items(trianglesCount); std::vector<BoundsItem> items(trianglesCount);
@ -138,7 +138,7 @@ namespace DetourNavigator
auto& item = items[i]; auto& item = items[i];
item.mOffset = static_cast<std::ptrdiff_t>(i); item.mOffset = static_cast<std::ptrdiff_t>(i);
item.mFlags = flags[i]; item.mAreaTypes = flags[i];
// Calc triangle XZ bounds. // Calc triangle XZ bounds.
const auto baseIndex = static_cast<std::size_t>(indices[i * 3]) * 3; const auto baseIndex = static_cast<std::size_t>(indices[i * 3]) * 3;
@ -160,7 +160,7 @@ namespace DetourNavigator
std::size_t curTri = 0; std::size_t curTri = 0;
std::size_t curNode = 0; std::size_t curNode = 0;
subdivide(items, 0, trianglesCount, trisPerChunk, indices, flags, curNode, mNodes, curTri, mIndices, mFlags); subdivide(items, 0, trianglesCount, trisPerChunk, indices, flags, curNode, mNodes, curTri, mIndices, mAreaTypes);
items.clear(); items.clear();

@ -1,6 +1,8 @@
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_CHUNKYTRIMESH_H #ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_CHUNKYTRIMESH_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_CHUNKYTRIMESH_H #define OPENMW_COMPONENTS_DETOURNAVIGATOR_CHUNKYTRIMESH_H
#include "areatype.hpp"
#include <osg/Vec2f> #include <osg/Vec2f>
#include <array> #include <array>
@ -24,7 +26,7 @@ namespace DetourNavigator
struct Chunk struct Chunk
{ {
const int* const mIndices; const int* const mIndices;
const unsigned char* const mFlags; const AreaType* const mAreaTypes;
const std::size_t mSize; const std::size_t mSize;
}; };
@ -42,7 +44,7 @@ namespace DetourNavigator
/// Creates partitioned triangle mesh (AABB tree), /// Creates partitioned triangle mesh (AABB tree),
/// where each node contains at max trisPerChunk triangles. /// where each node contains at max trisPerChunk triangles.
ChunkyTriMesh(const std::vector<float>& verts, const std::vector<int>& tris, ChunkyTriMesh(const std::vector<float>& verts, const std::vector<int>& tris,
const std::vector<unsigned char>& flags, const std::size_t trisPerChunk); const std::vector<AreaType>& flags, const std::size_t trisPerChunk);
ChunkyTriMesh(const ChunkyTriMesh&) = delete; ChunkyTriMesh(const ChunkyTriMesh&) = delete;
ChunkyTriMesh& operator=(const ChunkyTriMesh&) = delete; ChunkyTriMesh& operator=(const ChunkyTriMesh&) = delete;
@ -76,7 +78,7 @@ namespace DetourNavigator
const auto& node = mNodes[chunkId]; const auto& node = mNodes[chunkId];
return Chunk { return Chunk {
mIndices.data() + node.mOffset * 3, mIndices.data() + node.mOffset * 3,
mFlags.data() + node.mOffset, mAreaTypes.data() + node.mOffset,
node.mSize node.mSize
}; };
} }
@ -89,7 +91,7 @@ namespace DetourNavigator
private: private:
std::vector<ChunkyTriMeshNode> mNodes; std::vector<ChunkyTriMeshNode> mNodes;
std::vector<int> mIndices; std::vector<int> mIndices;
std::vector<unsigned char> mFlags; std::vector<AreaType> mAreaTypes;
std::size_t mMaxTrisPerChunk; std::size_t mMaxTrisPerChunk;
}; };
} }

@ -0,0 +1,15 @@
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_FLAGS_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_FLAGS_H
namespace DetourNavigator
{
using Flags = unsigned short;
enum Flag : Flags
{
Flag_none = 0,
Flag_walk = 1 << 0,
};
}
#endif

@ -8,6 +8,7 @@
#include "settingsutils.hpp" #include "settingsutils.hpp"
#include "sharednavmesh.hpp" #include "sharednavmesh.hpp"
#include "settingsutils.hpp" #include "settingsutils.hpp"
#include "flags.hpp"
#include <DetourNavMesh.h> #include <DetourNavMesh.h>
#include <DetourNavMeshBuilder.h> #include <DetourNavMeshBuilder.h>
@ -99,7 +100,7 @@ namespace
{ {
const auto& chunkyMesh = recastMesh.getChunkyTriMesh(); const auto& chunkyMesh = recastMesh.getChunkyTriMesh();
std::vector<unsigned char> areas(chunkyMesh.getMaxTrisPerChunk(), RC_NULL_AREA); std::vector<unsigned char> areas(chunkyMesh.getMaxTrisPerChunk(), AreaType_null);
const osg::Vec2f tileBoundsMin(config.bmin[0], config.bmin[2]); const osg::Vec2f tileBoundsMin(config.bmin[0], config.bmin[2]);
const osg::Vec2f tileBoundsMax(config.bmax[0], config.bmax[2]); const osg::Vec2f tileBoundsMax(config.bmax[0], config.bmax[2]);
std::vector<std::size_t> cids; std::vector<std::size_t> cids;
@ -116,7 +117,7 @@ namespace
areas.begin(), areas.begin(),
std::min(areas.begin() + static_cast<std::ptrdiff_t>(chunk.mSize), std::min(areas.begin() + static_cast<std::ptrdiff_t>(chunk.mSize),
areas.end()), areas.end()),
RC_NULL_AREA AreaType_null
); );
rcMarkWalkableTriangles( rcMarkWalkableTriangles(
@ -130,7 +131,7 @@ namespace
); );
for (std::size_t i = 0; i < chunk.mSize; ++i) for (std::size_t i = 0; i < chunk.mSize; ++i)
areas[i] &= chunk.mFlags[i]; areas[i] = chunk.mAreaTypes[i];
rcClearUnwalkableTriangles( rcClearUnwalkableTriangles(
&context, &context,
@ -186,8 +187,8 @@ namespace
} }
for (int i = 0; i < polyMesh.npolys; ++i) for (int i = 0; i < polyMesh.npolys; ++i)
if (polyMesh.areas[i] == RC_WALKABLE_AREA) if (polyMesh.areas[i] == AreaType_ground)
polyMesh.flags[i] = 1; polyMesh.flags[i] = Flag_walk;
dtNavMeshCreateParams params; dtNavMeshCreateParams params;
params.verts = polyMesh.verts; params.verts = polyMesh.verts;

@ -29,7 +29,7 @@ namespace DetourNavigator
bool Navigator::addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform) bool Navigator::addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform)
{ {
return mNavMeshManager.addObject(id, shape, transform, RC_WALKABLE_AREA); return mNavMeshManager.addObject(id, shape, transform, AreaType_ground);
} }
bool Navigator::addObject(std::size_t id, const ObjectShapes& shapes, const btTransform& transform) bool Navigator::addObject(std::size_t id, const ObjectShapes& shapes, const btTransform& transform)
@ -38,7 +38,7 @@ namespace DetourNavigator
if (shapes.mAvoid) if (shapes.mAvoid)
{ {
const auto avoidId = reinterpret_cast<std::size_t>(shapes.mAvoid); const auto avoidId = reinterpret_cast<std::size_t>(shapes.mAvoid);
if (mNavMeshManager.addObject(avoidId, *shapes.mAvoid, transform, RC_NULL_AREA)) if (mNavMeshManager.addObject(avoidId, *shapes.mAvoid, transform, AreaType_null))
{ {
updateAvoidShapeId(id, avoidId); updateAvoidShapeId(id, avoidId);
result = true; result = true;
@ -49,7 +49,7 @@ namespace DetourNavigator
bool Navigator::updateObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform) bool Navigator::updateObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform)
{ {
return mNavMeshManager.updateObject(id, shape, transform, RC_WALKABLE_AREA); return mNavMeshManager.updateObject(id, shape, transform, AreaType_ground);
} }
bool Navigator::updateObject(std::size_t id, const ObjectShapes& shapes, const btTransform& transform) bool Navigator::updateObject(std::size_t id, const ObjectShapes& shapes, const btTransform& transform)
@ -58,7 +58,7 @@ namespace DetourNavigator
if (shapes.mAvoid) if (shapes.mAvoid)
{ {
const auto avoidId = reinterpret_cast<std::size_t>(shapes.mAvoid); const auto avoidId = reinterpret_cast<std::size_t>(shapes.mAvoid);
if (mNavMeshManager.updateObject(avoidId, *shapes.mAvoid, transform, RC_NULL_AREA)) if (mNavMeshManager.updateObject(avoidId, *shapes.mAvoid, transform, AreaType_null))
{ {
updateAvoidShapeId(id, avoidId); updateAvoidShapeId(id, avoidId);
result = true; result = true;

@ -15,8 +15,7 @@ namespace DetourNavigator
ObjectShapes(const btCollisionShape& shape, const btCollisionShape* avoid) ObjectShapes(const btCollisionShape& shape, const btCollisionShape* avoid)
: mShape(shape), mAvoid(avoid) : mShape(shape), mAvoid(avoid)
{ {}
}
}; };
class Navigator class Navigator

@ -32,18 +32,18 @@ namespace DetourNavigator
{} {}
bool NavMeshManager::addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, bool NavMeshManager::addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform,
const unsigned char flags) const AreaType areaType)
{ {
if (!mRecastMeshManager.addObject(id, shape, transform, flags)) if (!mRecastMeshManager.addObject(id, shape, transform, areaType))
return false; return false;
addChangedTiles(shape, transform, ChangeType::add); addChangedTiles(shape, transform, ChangeType::add);
return true; return true;
} }
bool NavMeshManager::updateObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, bool NavMeshManager::updateObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform,
const unsigned char flags) const AreaType areaType)
{ {
if (!mRecastMeshManager.updateObject(id, transform, flags)) if (!mRecastMeshManager.updateObject(id, transform, areaType))
return false; return false;
addChangedTiles(shape, transform, ChangeType::mixed); addChangedTiles(shape, transform, ChangeType::mixed);
return true; return true;

@ -24,10 +24,10 @@ namespace DetourNavigator
NavMeshManager(const Settings& settings); NavMeshManager(const Settings& settings);
bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform,
const unsigned char flags); const AreaType areaType);
bool updateObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, bool updateObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform,
const unsigned char flags); const AreaType areaType);
bool removeObject(std::size_t id); bool removeObject(std::size_t id);

@ -7,15 +7,15 @@
namespace DetourNavigator namespace DetourNavigator
{ {
RecastMesh::RecastMesh(std::vector<int> indices, std::vector<float> vertices, RecastMesh::RecastMesh(std::vector<int> indices, std::vector<float> vertices,
std::vector<unsigned char> flags, const Settings& settings) std::vector<AreaType> areaTypes, const Settings& settings)
: mIndices(std::move(indices)) : mIndices(std::move(indices))
, mVertices(std::move(vertices)) , mVertices(std::move(vertices))
, mFlags(std::move(flags)) , mAreaTypes(std::move(areaTypes))
, mChunkyTriMesh(mVertices, mIndices, mFlags, settings.mTrianglesPerChunk) , mChunkyTriMesh(mVertices, mIndices, mAreaTypes, settings.mTrianglesPerChunk)
{ {
if (getTrianglesCount() != mFlags.size()) if (getTrianglesCount() != mAreaTypes.size())
throw InvalidArgument("number of flags doesn't match number of triangles: triangles=" throw InvalidArgument("number of flags doesn't match number of triangles: triangles="
+ std::to_string(getTrianglesCount()) + ", flags=" + std::to_string(mFlags.size())); + std::to_string(getTrianglesCount()) + ", areaTypes=" + std::to_string(mAreaTypes.size()));
if (getVerticesCount()) if (getVerticesCount())
rcCalcBounds(mVertices.data(), static_cast<int>(getVerticesCount()), mBoundsMin.ptr(), mBoundsMax.ptr()); rcCalcBounds(mVertices.data(), static_cast<int>(getVerticesCount()), mBoundsMin.ptr(), mBoundsMax.ptr());
} }

@ -1,6 +1,7 @@
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESH_H #ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESH_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESH_H #define OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESH_H
#include "areatype.hpp"
#include "chunkytrimesh.hpp" #include "chunkytrimesh.hpp"
#include <memory> #include <memory>
@ -16,7 +17,7 @@ namespace DetourNavigator
{ {
public: public:
RecastMesh(std::vector<int> indices, std::vector<float> vertices, RecastMesh(std::vector<int> indices, std::vector<float> vertices,
std::vector<unsigned char> flags, const Settings& settings); std::vector<AreaType> areaTypes, const Settings& settings);
const std::vector<int>& getIndices() const const std::vector<int>& getIndices() const
{ {
@ -28,9 +29,9 @@ namespace DetourNavigator
return mVertices; return mVertices;
} }
const std::vector<unsigned char>& getFlags() const const std::vector<AreaType>& getAreaTypes() const
{ {
return mFlags; return mAreaTypes;
} }
std::size_t getVerticesCount() const std::size_t getVerticesCount() const
@ -61,7 +62,7 @@ namespace DetourNavigator
private: private:
std::vector<int> mIndices; std::vector<int> mIndices;
std::vector<float> mVertices; std::vector<float> mVertices;
std::vector<unsigned char> mFlags; std::vector<AreaType> mAreaTypes;
ChunkyTriMesh mChunkyTriMesh; ChunkyTriMesh mChunkyTriMesh;
osg::Vec3f mBoundsMin; osg::Vec3f mBoundsMin;
osg::Vec3f mBoundsMax; osg::Vec3f mBoundsMax;

@ -36,51 +36,51 @@ namespace DetourNavigator
} }
void RecastMeshBuilder::addObject(const btCollisionShape& shape, const btTransform& transform, void RecastMeshBuilder::addObject(const btCollisionShape& shape, const btTransform& transform,
const unsigned char flags) const AreaType areaType)
{ {
if (shape.isCompound()) if (shape.isCompound())
return addObject(static_cast<const btCompoundShape&>(shape), transform, flags); return addObject(static_cast<const btCompoundShape&>(shape), transform, areaType);
else if (shape.getShapeType() == TERRAIN_SHAPE_PROXYTYPE) else if (shape.getShapeType() == TERRAIN_SHAPE_PROXYTYPE)
return addObject(static_cast<const btHeightfieldTerrainShape&>(shape), transform, flags); return addObject(static_cast<const btHeightfieldTerrainShape&>(shape), transform, areaType);
else if (shape.isConcave()) else if (shape.isConcave())
return addObject(static_cast<const btConcaveShape&>(shape), transform, flags); return addObject(static_cast<const btConcaveShape&>(shape), transform, areaType);
else if (shape.getShapeType() == BOX_SHAPE_PROXYTYPE) else if (shape.getShapeType() == BOX_SHAPE_PROXYTYPE)
return addObject(static_cast<const btBoxShape&>(shape), transform, flags); return addObject(static_cast<const btBoxShape&>(shape), transform, areaType);
std::ostringstream message; std::ostringstream message;
message << "Unsupported shape type: " << BroadphaseNativeTypes(shape.getShapeType()); message << "Unsupported shape type: " << BroadphaseNativeTypes(shape.getShapeType());
throw InvalidArgument(message.str()); throw InvalidArgument(message.str());
} }
void RecastMeshBuilder::addObject(const btCompoundShape& shape, const btTransform& transform, void RecastMeshBuilder::addObject(const btCompoundShape& shape, const btTransform& transform,
const unsigned char flags) const AreaType areaType)
{ {
for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i) for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i)
addObject(*shape.getChildShape(i), transform * shape.getChildTransform(i), flags); addObject(*shape.getChildShape(i), transform * shape.getChildTransform(i), areaType);
} }
void RecastMeshBuilder::addObject(const btConcaveShape& shape, const btTransform& transform, void RecastMeshBuilder::addObject(const btConcaveShape& shape, const btTransform& transform,
const unsigned char flags) const AreaType areaType)
{ {
return addObject(shape, transform, makeProcessTriangleCallback([&] (btVector3* triangle, int, int) return addObject(shape, transform, makeProcessTriangleCallback([&] (btVector3* triangle, int, int)
{ {
for (std::size_t i = 3; i > 0; --i) for (std::size_t i = 3; i > 0; --i)
addTriangleVertex(transform(triangle[i - 1])); addTriangleVertex(transform(triangle[i - 1]));
mFlags.push_back(flags); mAreaTypes.push_back(areaType);
})); }));
} }
void RecastMeshBuilder::addObject(const btHeightfieldTerrainShape& shape, const btTransform& transform, void RecastMeshBuilder::addObject(const btHeightfieldTerrainShape& shape, const btTransform& transform,
const unsigned char flags) const AreaType areaType)
{ {
return addObject(shape, transform, makeProcessTriangleCallback([&] (btVector3* triangle, int, int) return addObject(shape, transform, makeProcessTriangleCallback([&] (btVector3* triangle, int, int)
{ {
for (std::size_t i = 0; i < 3; ++i) for (std::size_t i = 0; i < 3; ++i)
addTriangleVertex(transform(triangle[i])); addTriangleVertex(transform(triangle[i]));
mFlags.push_back(flags); mAreaTypes.push_back(areaType);
})); }));
} }
void RecastMeshBuilder::addObject(const btBoxShape& shape, const btTransform& transform, const unsigned char flags) void RecastMeshBuilder::addObject(const btBoxShape& shape, const btTransform& transform, const AreaType areaType)
{ {
const auto indexOffset = int(mVertices.size() / 3); const auto indexOffset = int(mVertices.size() / 3);
@ -92,7 +92,7 @@ namespace DetourNavigator
} }
for (int vertex = 0; vertex < 12; ++vertex) for (int vertex = 0; vertex < 12; ++vertex)
mFlags.push_back(flags); mAreaTypes.push_back(areaType);
static const std::array<int, 36> indices {{ static const std::array<int, 36> indices {{
0, 2, 3, 0, 2, 3,
@ -115,14 +115,14 @@ namespace DetourNavigator
std::shared_ptr<RecastMesh> RecastMeshBuilder::create() const std::shared_ptr<RecastMesh> RecastMeshBuilder::create() const
{ {
return std::make_shared<RecastMesh>(mIndices, mVertices, mFlags, mSettings); return std::make_shared<RecastMesh>(mIndices, mVertices, mAreaTypes, mSettings);
} }
void RecastMeshBuilder::reset() void RecastMeshBuilder::reset()
{ {
mIndices.clear(); mIndices.clear();
mVertices.clear(); mVertices.clear();
mFlags.clear(); mAreaTypes.clear();
} }
void RecastMeshBuilder::addObject(const btConcaveShape& shape, const btTransform& transform, void RecastMeshBuilder::addObject(const btConcaveShape& shape, const btTransform& transform,

@ -20,15 +20,15 @@ namespace DetourNavigator
public: public:
RecastMeshBuilder(const Settings& settings, const TileBounds& bounds); RecastMeshBuilder(const Settings& settings, const TileBounds& bounds);
void addObject(const btCollisionShape& shape, const btTransform& transform, const unsigned char flags); void addObject(const btCollisionShape& shape, const btTransform& transform, const AreaType areaType);
void addObject(const btCompoundShape& shape, const btTransform& transform, const unsigned char flags); void addObject(const btCompoundShape& shape, const btTransform& transform, const AreaType areaType);
void addObject(const btConcaveShape& shape, const btTransform& transform, const unsigned char flags); void addObject(const btConcaveShape& shape, const btTransform& transform, const AreaType areaType);
void addObject(const btHeightfieldTerrainShape& shape, const btTransform& transform, const unsigned char flags); void addObject(const btHeightfieldTerrainShape& shape, const btTransform& transform, const AreaType areaType);
void addObject(const btBoxShape& shape, const btTransform& transform, const unsigned char flags); void addObject(const btBoxShape& shape, const btTransform& transform, const AreaType areaType);
std::shared_ptr<RecastMesh> create() const; std::shared_ptr<RecastMesh> create() const;
@ -39,7 +39,7 @@ namespace DetourNavigator
TileBounds mBounds; TileBounds mBounds;
std::vector<int> mIndices; std::vector<int> mIndices;
std::vector<float> mVertices; std::vector<float> mVertices;
std::vector<unsigned char> mFlags; std::vector<AreaType> mAreaTypes;
void addObject(const btConcaveShape& shape, const btTransform& transform, btTriangleCallback&& callback); void addObject(const btConcaveShape& shape, const btTransform& transform, btTriangleCallback&& callback);

@ -12,20 +12,20 @@ namespace DetourNavigator
} }
bool RecastMeshManager::addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, bool RecastMeshManager::addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform,
const unsigned char flags) const AreaType areaType)
{ {
if (!mObjects.emplace(id, RecastMeshObject(shape, transform, flags)).second) if (!mObjects.emplace(id, RecastMeshObject(shape, transform, areaType)).second)
return false; return false;
mShouldRebuild = true; mShouldRebuild = true;
return mShouldRebuild; return mShouldRebuild;
} }
bool RecastMeshManager::updateObject(std::size_t id, const btTransform& transform, const unsigned char flags) bool RecastMeshManager::updateObject(std::size_t id, const btTransform& transform, const AreaType areaType)
{ {
const auto object = mObjects.find(id); const auto object = mObjects.find(id);
if (object == mObjects.end()) if (object == mObjects.end())
return false; return false;
if (!object->second.update(transform, flags)) if (!object->second.update(transform, areaType))
return false; return false;
mShouldRebuild = true; mShouldRebuild = true;
return mShouldRebuild; return mShouldRebuild;
@ -59,7 +59,7 @@ namespace DetourNavigator
return; return;
mMeshBuilder.reset(); mMeshBuilder.reset();
for (const auto& v : mObjects) for (const auto& v : mObjects)
mMeshBuilder.addObject(v.second.getShape(), v.second.getTransform(), v.second.getFlags()); mMeshBuilder.addObject(v.second.getShape(), v.second.getTransform(), v.second.getAreaType());
mShouldRebuild = false; mShouldRebuild = false;
} }
} }

@ -26,9 +26,9 @@ namespace DetourNavigator
RecastMeshManager(const Settings& settings, const TileBounds& bounds); RecastMeshManager(const Settings& settings, const TileBounds& bounds);
bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform,
const unsigned char flags); const AreaType areaType);
bool updateObject(std::size_t id, const btTransform& transform, const unsigned char flags); bool updateObject(std::size_t id, const btTransform& transform, const AreaType areaType);
boost::optional<RemovedRecastMeshObject> removeObject(std::size_t id); boost::optional<RemovedRecastMeshObject> removeObject(std::size_t id);

@ -9,15 +9,15 @@
namespace DetourNavigator namespace DetourNavigator
{ {
RecastMeshObject::RecastMeshObject(const btCollisionShape& shape, const btTransform& transform, RecastMeshObject::RecastMeshObject(const btCollisionShape& shape, const btTransform& transform,
const unsigned char flags) const AreaType areaType)
: mShape(shape) : mShape(shape)
, mTransform(transform) , mTransform(transform)
, mFlags(flags) , mAreaType(areaType)
, mChildren(makeChildrenObjects(shape, mFlags)) , mChildren(makeChildrenObjects(shape, mAreaType))
{ {
} }
bool RecastMeshObject::update(const btTransform& transform, const unsigned char flags) bool RecastMeshObject::update(const btTransform& transform, const AreaType areaType)
{ {
bool result = false; bool result = false;
if (!(mTransform == transform)) if (!(mTransform == transform))
@ -25,42 +25,43 @@ namespace DetourNavigator
mTransform = transform; mTransform = transform;
result = true; result = true;
} }
if (mFlags != flags) if (mAreaType != areaType)
{ {
mFlags = flags; mAreaType = areaType;
result = true; result = true;
} }
if (mShape.get().isCompound()) if (mShape.get().isCompound())
result = updateCompoundObject(static_cast<const btCompoundShape&>(mShape.get()), mFlags, mChildren) || result; result = updateCompoundObject(static_cast<const btCompoundShape&>(mShape.get()), mAreaType, mChildren)
|| result;
return result; return result;
} }
bool RecastMeshObject::updateCompoundObject(const btCompoundShape& shape, bool RecastMeshObject::updateCompoundObject(const btCompoundShape& shape,
const unsigned char flags, std::vector<RecastMeshObject>& children) const AreaType areaType, std::vector<RecastMeshObject>& children)
{ {
assert(static_cast<std::size_t>(shape.getNumChildShapes()) == children.size()); assert(static_cast<std::size_t>(shape.getNumChildShapes()) == children.size());
bool result = false; bool result = false;
for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i) for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i)
{ {
assert(shape.getChildShape(i) == std::addressof(children[static_cast<std::size_t>(i)].mShape.get())); assert(shape.getChildShape(i) == std::addressof(children[static_cast<std::size_t>(i)].mShape.get()));
result = children[static_cast<std::size_t>(i)].update(shape.getChildTransform(i), flags) || result; result = children[static_cast<std::size_t>(i)].update(shape.getChildTransform(i), areaType) || result;
} }
return result; return result;
} }
std::vector<RecastMeshObject> makeChildrenObjects(const btCollisionShape& shape, const unsigned char flags) std::vector<RecastMeshObject> makeChildrenObjects(const btCollisionShape& shape, const AreaType areaType)
{ {
if (shape.isCompound()) if (shape.isCompound())
return makeChildrenObjects(static_cast<const btCompoundShape&>(shape), flags); return makeChildrenObjects(static_cast<const btCompoundShape&>(shape), areaType);
else else
return std::vector<RecastMeshObject>(); return std::vector<RecastMeshObject>();
} }
std::vector<RecastMeshObject> makeChildrenObjects(const btCompoundShape& shape, const unsigned char flags) std::vector<RecastMeshObject> makeChildrenObjects(const btCompoundShape& shape, const AreaType areaType)
{ {
std::vector<RecastMeshObject> result; std::vector<RecastMeshObject> result;
for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i) for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i)
result.emplace_back(*shape.getChildShape(i), shape.getChildTransform(i), flags); result.emplace_back(*shape.getChildShape(i), shape.getChildTransform(i), areaType);
return result; return result;
} }
} }

@ -1,6 +1,8 @@
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESHOBJECT_H #ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESHOBJECT_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESHOBJECT_H #define OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESHOBJECT_H
#include "areatype.hpp"
#include <LinearMath/btTransform.h> #include <LinearMath/btTransform.h>
#include <functional> #include <functional>
@ -14,9 +16,9 @@ namespace DetourNavigator
class RecastMeshObject class RecastMeshObject
{ {
public: public:
RecastMeshObject(const btCollisionShape& shape, const btTransform& transform, const unsigned char flags); RecastMeshObject(const btCollisionShape& shape, const btTransform& transform, const AreaType areaType);
bool update(const btTransform& transform, const unsigned char flags); bool update(const btTransform& transform, const AreaType areaType);
const btCollisionShape& getShape() const const btCollisionShape& getShape() const
{ {
@ -28,24 +30,24 @@ namespace DetourNavigator
return mTransform; return mTransform;
} }
unsigned char getFlags() const AreaType getAreaType() const
{ {
return mFlags; return mAreaType;
} }
private: private:
std::reference_wrapper<const btCollisionShape> mShape; std::reference_wrapper<const btCollisionShape> mShape;
btTransform mTransform; btTransform mTransform;
unsigned char mFlags; AreaType mAreaType;
std::vector<RecastMeshObject> mChildren; std::vector<RecastMeshObject> mChildren;
static bool updateCompoundObject(const btCompoundShape& shape, const unsigned char flags, static bool updateCompoundObject(const btCompoundShape& shape, const AreaType areaType,
std::vector<RecastMeshObject>& children); std::vector<RecastMeshObject>& children);
}; };
std::vector<RecastMeshObject> makeChildrenObjects(const btCollisionShape& shape, const unsigned char flags); std::vector<RecastMeshObject> makeChildrenObjects(const btCollisionShape& shape, const AreaType areaType);
std::vector<RecastMeshObject> makeChildrenObjects(const btCompoundShape& shape, const unsigned char flags); std::vector<RecastMeshObject> makeChildrenObjects(const btCompoundShape& shape, const AreaType areaType);
} }
#endif #endif

@ -10,7 +10,7 @@ namespace DetourNavigator
{} {}
bool TileCachedRecastMeshManager::addObject(std::size_t id, const btCollisionShape& shape, bool TileCachedRecastMeshManager::addObject(std::size_t id, const btCollisionShape& shape,
const btTransform& transform, const unsigned char flags) const btTransform& transform, const AreaType areaType)
{ {
bool result = false; bool result = false;
auto& tilesPositions = mObjectsTilesPositions[id]; auto& tilesPositions = mObjectsTilesPositions[id];
@ -27,7 +27,7 @@ namespace DetourNavigator
tile = mTiles.insert(std::make_pair(tilePosition, tile = mTiles.insert(std::make_pair(tilePosition,
CachedRecastMeshManager(mSettings, tileBounds))).first; CachedRecastMeshManager(mSettings, tileBounds))).first;
} }
if (tile->second.addObject(id, shape, transform, flags)) if (tile->second.addObject(id, shape, transform, areaType))
{ {
lock.unlock(); lock.unlock();
tilesPositions.push_back(tilePosition); tilesPositions.push_back(tilePosition);
@ -40,7 +40,7 @@ namespace DetourNavigator
} }
bool TileCachedRecastMeshManager::updateObject(std::size_t id, const btTransform& transform, bool TileCachedRecastMeshManager::updateObject(std::size_t id, const btTransform& transform,
const unsigned char flags) const AreaType areaType)
{ {
const auto object = mObjectsTilesPositions.find(id); const auto object = mObjectsTilesPositions.find(id);
if (object == mObjectsTilesPositions.end()) if (object == mObjectsTilesPositions.end())
@ -51,7 +51,7 @@ namespace DetourNavigator
{ {
const auto tile = mTiles.find(tilePosition); const auto tile = mTiles.find(tilePosition);
if (tile != mTiles.end()) if (tile != mTiles.end())
result = tile->second.updateObject(id, transform, flags) || result; result = tile->second.updateObject(id, transform, areaType) || result;
} }
lock.unlock(); lock.unlock();
if (result) if (result)

@ -15,9 +15,9 @@ namespace DetourNavigator
TileCachedRecastMeshManager(const Settings& settings); TileCachedRecastMeshManager(const Settings& settings);
bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform,
const unsigned char flags); const AreaType areaType);
bool updateObject(std::size_t id, const btTransform& transform, const unsigned char flags); bool updateObject(std::size_t id, const btTransform& transform, const AreaType areaType);
boost::optional<RemovedRecastMeshObject> removeObject(std::size_t id); boost::optional<RemovedRecastMeshObject> removeObject(std::size_t id);

Loading…
Cancel
Save