1
This commit is contained in:
parent
f7951cb780
commit
be26364882
@ -14,6 +14,7 @@
|
|||||||
#include "entityfactory.h"
|
#include "entityfactory.h"
|
||||||
#include "collider.h"
|
#include "collider.h"
|
||||||
#include "navmeshbuilder.h"
|
#include "navmeshbuilder.h"
|
||||||
|
#include "navmeshhelper.h"
|
||||||
|
|
||||||
#ifdef FIND_PATH_TEST
|
#ifdef FIND_PATH_TEST
|
||||||
const int MAP_GRID_WIDTH = 40;
|
const int MAP_GRID_WIDTH = 40;
|
||||||
@ -62,7 +63,7 @@ void MapInstance::Init()
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
NavMeshBuilder::Instance()->OutputObjFile(this);
|
NavMeshHelper::OutputObjFile(this);
|
||||||
#endif
|
#endif
|
||||||
#ifdef FIND_PATH_TEST
|
#ifdef FIND_PATH_TEST
|
||||||
navmesh_ = NavMeshBuilder::Instance()->Build(this);
|
navmesh_ = NavMeshBuilder::Instance()->Build(this);
|
||||||
|
@ -57,4 +57,5 @@ class MapInstance
|
|||||||
int obstacle2_num_ = 0;
|
int obstacle2_num_ = 0;
|
||||||
|
|
||||||
friend class NavMeshBuilder;
|
friend class NavMeshBuilder;
|
||||||
|
friend class NavMeshHelper;
|
||||||
};
|
};
|
||||||
|
@ -2,17 +2,6 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "Recast.h"
|
|
||||||
#include "RecastAlloc.h"
|
|
||||||
#include "DetourTileCache.h"
|
|
||||||
#include "DetourTileCacheBuilder.h"
|
|
||||||
|
|
||||||
#include "DetourNavMeshBuilder.h"
|
|
||||||
#include "DetourNavMeshQuery.h"
|
|
||||||
#include "DetourCommon.h"
|
|
||||||
#include "DetourNavMesh.h"
|
|
||||||
#include "fastlz.h"
|
|
||||||
|
|
||||||
#include "navmeshbuilder.h"
|
#include "navmeshbuilder.h"
|
||||||
#include "mapinstance.h"
|
#include "mapinstance.h"
|
||||||
#include "collider.h"
|
#include "collider.h"
|
||||||
@ -42,108 +31,6 @@ dtNavMesh* NavMeshBuilder::Build(MapInstance* map_instance)
|
|||||||
return builder_params.navmesh;
|
return builder_params.navmesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMeshBuilder::OutputObjFile(MapInstance* map_instance)
|
|
||||||
{
|
|
||||||
std::vector<a8::Vec2> vertexs;
|
|
||||||
std::vector<std::tuple<int, int, int>> faces;
|
|
||||||
vertexs.reserve(10000);
|
|
||||||
for (auto& pair : map_instance->uniid_hash_) {
|
|
||||||
for (ColliderComponent* collider : *pair.second->GetColliders()) {
|
|
||||||
if (collider->type == CT_Aabb) {
|
|
||||||
AabbCollider* aabb_box = (AabbCollider*)collider;
|
|
||||||
{
|
|
||||||
a8::Vec2 vert = collider->owner->GetPos() + aabb_box->_min;
|
|
||||||
vert.x = vert.x - map_instance->map_meta_->i->map_width() / 2.0f;
|
|
||||||
vert.y = vert.y - map_instance->map_meta_->i->map_height() / 2.0f;
|
|
||||||
|
|
||||||
vertexs.push_back(vert);
|
|
||||||
vert.y += aabb_box->_max.y - aabb_box->_min.y;
|
|
||||||
vertexs.push_back(vert);
|
|
||||||
vert.x += aabb_box->_max.x - aabb_box->_min.x;
|
|
||||||
vertexs.push_back(vert);
|
|
||||||
vert.y -= aabb_box->_max.y - aabb_box->_min.y;
|
|
||||||
vertexs.push_back(vert);
|
|
||||||
}
|
|
||||||
//0 1 2
|
|
||||||
faces.push_back
|
|
||||||
(std::make_tuple
|
|
||||||
(
|
|
||||||
vertexs.size() - 4 + 1,
|
|
||||||
vertexs.size() - 3 + 1,
|
|
||||||
vertexs.size() - 2 + 1
|
|
||||||
));
|
|
||||||
//0 2 3
|
|
||||||
faces.push_back
|
|
||||||
(std::make_tuple
|
|
||||||
(
|
|
||||||
vertexs.size() - 4 + 1,
|
|
||||||
vertexs.size() - 2 + 1,
|
|
||||||
vertexs.size() - 1 + 1
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
std::string filename = a8::Format("%s.obj", {map_instance->map_tpl_name_});
|
|
||||||
FILE* fp = fopen(filename.c_str(), "wb");
|
|
||||||
#if 1
|
|
||||||
{
|
|
||||||
vertexs.clear();
|
|
||||||
faces.clear();
|
|
||||||
{
|
|
||||||
a8::Vec2 vert;
|
|
||||||
vert.x = 0 - map_instance->map_meta_->i->map_width() / 2.0f;
|
|
||||||
vert.y = 0 - map_instance->map_meta_->i->map_height() / 2.0f;
|
|
||||||
|
|
||||||
vertexs.push_back(vert);
|
|
||||||
vert.y += map_instance->map_meta_->i->map_height();
|
|
||||||
vertexs.push_back(vert);
|
|
||||||
vert.x += map_instance->map_meta_->i->map_width();
|
|
||||||
vertexs.push_back(vert);
|
|
||||||
vert.y -= map_instance->map_meta_->i->map_height();
|
|
||||||
vertexs.push_back(vert);
|
|
||||||
|
|
||||||
//0 1 2
|
|
||||||
faces.push_back
|
|
||||||
(std::make_tuple
|
|
||||||
(
|
|
||||||
vertexs.size() - 4 + 1,
|
|
||||||
vertexs.size() - 3 + 1,
|
|
||||||
vertexs.size() - 2 + 1
|
|
||||||
));
|
|
||||||
//0 2 3
|
|
||||||
faces.push_back
|
|
||||||
(std::make_tuple
|
|
||||||
(
|
|
||||||
vertexs.size() - 4 + 1,
|
|
||||||
vertexs.size() - 2 + 1,
|
|
||||||
vertexs.size() - 1 + 1
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
for (auto& vert : vertexs) {
|
|
||||||
std::string data = a8::Format("v %f %f %f\r\n",
|
|
||||||
{
|
|
||||||
vert.x,
|
|
||||||
-10,
|
|
||||||
vert.y,
|
|
||||||
});
|
|
||||||
fwrite(data.data(), 1, data.size(), fp);
|
|
||||||
}
|
|
||||||
for (auto& tuple : faces) {
|
|
||||||
std::string data = a8::Format("f %d %d %d\r\n",
|
|
||||||
{
|
|
||||||
std::get<0>(tuple),
|
|
||||||
std::get<1>(tuple),
|
|
||||||
std::get<2>(tuple)
|
|
||||||
});
|
|
||||||
fwrite(data.data(), 1, data.size(), fp);
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NavMeshBuilder::InitBasic(BuilderParams& builder_params)
|
void NavMeshBuilder::InitBasic(BuilderParams& builder_params)
|
||||||
{
|
{
|
||||||
// Init cache
|
// Init cache
|
||||||
|
@ -18,7 +18,6 @@ public:
|
|||||||
void UnInit();
|
void UnInit();
|
||||||
|
|
||||||
dtNavMesh* Build(MapInstance* map_instance);
|
dtNavMesh* Build(MapInstance* map_instance);
|
||||||
void OutputObjFile(MapInstance* map_instance);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitBasic(BuilderParams& builder_params);
|
void InitBasic(BuilderParams& builder_params);
|
||||||
|
@ -0,0 +1,109 @@
|
|||||||
|
#include "precompile.h"
|
||||||
|
|
||||||
|
#include "mapinstance.h"
|
||||||
|
#include "metamgr.h"
|
||||||
|
#include "navmeshhelper.h"
|
||||||
|
#include "collider.h"
|
||||||
|
#include "entity.h"
|
||||||
|
|
||||||
|
void NavMeshHelper::OutputObjFile(MapInstance* map_instance)
|
||||||
|
{
|
||||||
|
std::vector<a8::Vec2> vertexs;
|
||||||
|
std::vector<std::tuple<int, int, int>> faces;
|
||||||
|
vertexs.reserve(10000);
|
||||||
|
for (auto& pair : map_instance->uniid_hash_) {
|
||||||
|
for (ColliderComponent* collider : *pair.second->GetColliders()) {
|
||||||
|
if (collider->type == CT_Aabb) {
|
||||||
|
AabbCollider* aabb_box = (AabbCollider*)collider;
|
||||||
|
{
|
||||||
|
a8::Vec2 vert = collider->owner->GetPos() + aabb_box->_min;
|
||||||
|
vert.x = vert.x - map_instance->map_meta_->i->map_width() / 2.0f;
|
||||||
|
vert.y = vert.y - map_instance->map_meta_->i->map_height() / 2.0f;
|
||||||
|
|
||||||
|
vertexs.push_back(vert);
|
||||||
|
vert.y += aabb_box->_max.y - aabb_box->_min.y;
|
||||||
|
vertexs.push_back(vert);
|
||||||
|
vert.x += aabb_box->_max.x - aabb_box->_min.x;
|
||||||
|
vertexs.push_back(vert);
|
||||||
|
vert.y -= aabb_box->_max.y - aabb_box->_min.y;
|
||||||
|
vertexs.push_back(vert);
|
||||||
|
}
|
||||||
|
//0 1 2
|
||||||
|
faces.push_back
|
||||||
|
(std::make_tuple
|
||||||
|
(
|
||||||
|
vertexs.size() - 4 + 1,
|
||||||
|
vertexs.size() - 3 + 1,
|
||||||
|
vertexs.size() - 2 + 1
|
||||||
|
));
|
||||||
|
//0 2 3
|
||||||
|
faces.push_back
|
||||||
|
(std::make_tuple
|
||||||
|
(
|
||||||
|
vertexs.size() - 4 + 1,
|
||||||
|
vertexs.size() - 2 + 1,
|
||||||
|
vertexs.size() - 1 + 1
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string filename = a8::Format("%s.obj", {map_instance->map_tpl_name_});
|
||||||
|
FILE* fp = fopen(filename.c_str(), "wb");
|
||||||
|
#if 1
|
||||||
|
{
|
||||||
|
vertexs.clear();
|
||||||
|
faces.clear();
|
||||||
|
{
|
||||||
|
a8::Vec2 vert;
|
||||||
|
vert.x = 0 - map_instance->map_meta_->i->map_width() / 2.0f;
|
||||||
|
vert.y = 0 - map_instance->map_meta_->i->map_height() / 2.0f;
|
||||||
|
|
||||||
|
vertexs.push_back(vert);
|
||||||
|
vert.y += map_instance->map_meta_->i->map_height();
|
||||||
|
vertexs.push_back(vert);
|
||||||
|
vert.x += map_instance->map_meta_->i->map_width();
|
||||||
|
vertexs.push_back(vert);
|
||||||
|
vert.y -= map_instance->map_meta_->i->map_height();
|
||||||
|
vertexs.push_back(vert);
|
||||||
|
|
||||||
|
//0 1 2
|
||||||
|
faces.push_back
|
||||||
|
(std::make_tuple
|
||||||
|
(
|
||||||
|
vertexs.size() - 4 + 1,
|
||||||
|
vertexs.size() - 3 + 1,
|
||||||
|
vertexs.size() - 2 + 1
|
||||||
|
));
|
||||||
|
//0 2 3
|
||||||
|
faces.push_back
|
||||||
|
(std::make_tuple
|
||||||
|
(
|
||||||
|
vertexs.size() - 4 + 1,
|
||||||
|
vertexs.size() - 2 + 1,
|
||||||
|
vertexs.size() - 1 + 1
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
for (auto& vert : vertexs) {
|
||||||
|
std::string data = a8::Format("v %f %f %f\r\n",
|
||||||
|
{
|
||||||
|
vert.x,
|
||||||
|
-10,
|
||||||
|
vert.y,
|
||||||
|
});
|
||||||
|
fwrite(data.data(), 1, data.size(), fp);
|
||||||
|
}
|
||||||
|
for (auto& tuple : faces) {
|
||||||
|
std::string data = a8::Format("f %d %d %d\r\n",
|
||||||
|
{
|
||||||
|
std::get<0>(tuple),
|
||||||
|
std::get<1>(tuple),
|
||||||
|
std::get<2>(tuple)
|
||||||
|
});
|
||||||
|
fwrite(data.data(), 1, data.size(), fp);
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Recast.h"
|
||||||
|
#include "RecastAlloc.h"
|
||||||
|
#include "DetourTileCache.h"
|
||||||
|
#include "DetourTileCacheBuilder.h"
|
||||||
|
|
||||||
|
#include "DetourNavMeshBuilder.h"
|
||||||
|
#include "DetourNavMeshQuery.h"
|
||||||
|
#include "DetourCommon.h"
|
||||||
|
#include "DetourNavMesh.h"
|
||||||
|
#include "fastlz.h"
|
||||||
|
|
||||||
static const int EXPECTED_LAYERS_PER_TILE = 4;
|
static const int EXPECTED_LAYERS_PER_TILE = 4;
|
||||||
|
|
||||||
static const int MAX_LAYERS = 32;
|
static const int MAX_LAYERS = 32;
|
||||||
@ -72,7 +83,8 @@ inline bool checkOverlapRect(const float amin[2], const float amax[2],
|
|||||||
return overlap;
|
return overlap;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rcGetChunksOverlappingRect(const rcChunkyTriMesh* cm,
|
#if 1
|
||||||
|
static int rcGetChunksOverlappingRect(const rcChunkyTriMesh* cm,
|
||||||
float bmin[2], float bmax[2],
|
float bmin[2], float bmax[2],
|
||||||
int* ids, const int maxIds)
|
int* ids, const int maxIds)
|
||||||
{
|
{
|
||||||
@ -100,6 +112,7 @@ int rcGetChunksOverlappingRect(const rcChunkyTriMesh* cm,
|
|||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
struct RasterizationContext
|
struct RasterizationContext
|
||||||
{
|
{
|
||||||
@ -277,3 +290,10 @@ struct BuilderParams
|
|||||||
int tw = 0;
|
int tw = 0;
|
||||||
int th = 0;
|
int th = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MapInstance;
|
||||||
|
class NavMeshHelper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void OutputObjFile(MapInstance* map_instance);
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user