1
This commit is contained in:
parent
0ecb37d272
commit
d8c3676876
@ -66,7 +66,7 @@ void MapInstance::Init()
|
|||||||
NavMeshHelper::OutputObjFile(this);
|
NavMeshHelper::OutputObjFile(this);
|
||||||
#endif
|
#endif
|
||||||
#ifdef FIND_PATH_TEST
|
#ifdef FIND_PATH_TEST
|
||||||
navmesh_ = NavMeshBuilder::Instance()->Build(this);
|
NavMeshBuilder::Instance()->Build(this);
|
||||||
map_service_->SetNavMesh(navmesh_);
|
map_service_->SetNavMesh(navmesh_);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ namespace MetaData
|
|||||||
}
|
}
|
||||||
|
|
||||||
class dtNavMesh;
|
class dtNavMesh;
|
||||||
|
class dtTileCache;
|
||||||
class Entity;
|
class Entity;
|
||||||
class Obstacle;
|
class Obstacle;
|
||||||
class Building;
|
class Building;
|
||||||
@ -34,6 +35,7 @@ class MapInstance
|
|||||||
int AllocUniid();
|
int AllocUniid();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
dtTileCache* tile_cache_ = nullptr;
|
||||||
dtNavMesh* navmesh_ = nullptr;
|
dtNavMesh* navmesh_ = nullptr;
|
||||||
int current_uniid_ = 0;
|
int current_uniid_ = 0;
|
||||||
std::map<int, Entity*> uniid_hash_;
|
std::map<int, Entity*> uniid_hash_;
|
||||||
|
@ -20,14 +20,14 @@ void NavMeshBuilder::UnInit()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dtNavMesh* NavMeshBuilder::Build(MapInstance* map_instance)
|
void NavMeshBuilder::Build(MapInstance* map_instance)
|
||||||
{
|
{
|
||||||
BuilderParams builder_params;
|
BuilderParams builder_params;
|
||||||
InitBuilderParams(builder_params);
|
InitBuilderParams(builder_params);
|
||||||
CreateTileCache(builder_params);
|
CreateTileCache(builder_params);
|
||||||
CreateNavMesh(builder_params);
|
CreateNavMesh(builder_params);
|
||||||
BuildTiles(builder_params);
|
BuildTiles(builder_params);
|
||||||
return builder_params.navmesh;
|
BuildMapObstalce(builder_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMeshBuilder::InitBuilderParams(BuilderParams& builder_params)
|
void NavMeshBuilder::InitBuilderParams(BuilderParams& builder_params)
|
||||||
@ -359,3 +359,62 @@ bool NavMeshBuilder::CreateNavMesh(BuilderParams& builder_params)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NavMeshBuilder::BuildMapObstalce(BuilderParams& builder_params)
|
||||||
|
{
|
||||||
|
dtTileCache* tile_cache = builder_params.tile_cache;
|
||||||
|
for (auto& pair : builder_params.map_instance->uniid_hash_) {
|
||||||
|
for (ColliderComponent* collider : *pair.second->GetColliders()) {
|
||||||
|
switch (collider->type) {
|
||||||
|
case CT_Aabb:
|
||||||
|
{
|
||||||
|
AabbCollider* aabb = (AabbCollider*)collider;
|
||||||
|
|
||||||
|
float bmin[3] = {0};
|
||||||
|
bmin[0] = (aabb->owner->GetPos() + aabb->_min).x;
|
||||||
|
bmin[1] = 0;
|
||||||
|
bmin[2] = (aabb->owner->GetPos() + aabb->_min).y;
|
||||||
|
|
||||||
|
float bmax[3] = {0};
|
||||||
|
bmax[0] = (aabb->owner->GetPos() + aabb->_max).x;
|
||||||
|
bmax[1] = 0;
|
||||||
|
bmax[2] = (aabb->owner->GetPos() + aabb->_max).y;
|
||||||
|
|
||||||
|
dtObstacleRef ref;
|
||||||
|
dtStatus status = tile_cache->addBoxObstacle(bmin,
|
||||||
|
bmax,
|
||||||
|
&ref
|
||||||
|
);
|
||||||
|
if (status != DT_SUCCESS) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CT_Circle:
|
||||||
|
{
|
||||||
|
CircleCollider* circle = (CircleCollider*)collider;
|
||||||
|
|
||||||
|
float pos[3] = {0};
|
||||||
|
pos[0] = (circle->owner->GetPos() + circle->pos).x;
|
||||||
|
pos[1] = 0;
|
||||||
|
pos[2] = (circle->owner->GetPos() + circle->pos).y;
|
||||||
|
|
||||||
|
dtObstacleRef ref;
|
||||||
|
dtStatus status = tile_cache->addObstacle(pos,
|
||||||
|
circle->rad,
|
||||||
|
0,
|
||||||
|
&ref
|
||||||
|
);
|
||||||
|
if (status != DT_SUCCESS) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -17,7 +17,7 @@ public:
|
|||||||
void Init();
|
void Init();
|
||||||
void UnInit();
|
void UnInit();
|
||||||
|
|
||||||
dtNavMesh* Build(MapInstance* map_instance);
|
void Build(MapInstance* map_instance);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitBuilderParams(BuilderParams& builder_params);
|
void InitBuilderParams(BuilderParams& builder_params);
|
||||||
@ -32,4 +32,5 @@ public:
|
|||||||
const int maxTiles);
|
const int maxTiles);
|
||||||
bool CreateTileCache(BuilderParams& builder_params);
|
bool CreateTileCache(BuilderParams& builder_params);
|
||||||
bool CreateNavMesh(BuilderParams& builder_params);
|
bool CreateNavMesh(BuilderParams& builder_params);
|
||||||
|
void BuildMapObstalce(BuilderParams& builder_params);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user