mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Recast: allow loading OBJ and PLY geometry from project files
Deduplicated mesh load function and implemented a simple type handler instead. Code can now load OBJ and PLY geometry from the user interface and project files.
This commit is contained in:
parent
b4b0e22d61
commit
d9432129b2
@ -125,7 +125,7 @@ InputGeom::~InputGeom()
|
|||||||
delete m_mesh;
|
delete m_mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputGeom::loadMesh(rcContext* ctx, const std::string& filepath)
|
bool InputGeom::loadMesh(rcContext* ctx, const std::string& filepath, const MeshFormat format)
|
||||||
{
|
{
|
||||||
if (m_mesh)
|
if (m_mesh)
|
||||||
{
|
{
|
||||||
@ -137,49 +137,18 @@ bool InputGeom::loadMesh(rcContext* ctx, const std::string& filepath)
|
|||||||
m_offMeshConCount = 0;
|
m_offMeshConCount = 0;
|
||||||
m_volumeCount = 0;
|
m_volumeCount = 0;
|
||||||
|
|
||||||
m_mesh = new rcMeshLoaderObj;
|
switch (format)
|
||||||
if (!m_mesh)
|
|
||||||
{
|
{
|
||||||
ctx->log(RC_LOG_ERROR, "loadMesh: Out of memory 'm_mesh'.");
|
case MESH_OBJ:
|
||||||
return false;
|
m_mesh = new rcMeshLoaderObj;
|
||||||
}
|
break;
|
||||||
if (!m_mesh->load(filepath))
|
case MESH_PLY:
|
||||||
{
|
m_mesh = new rcMeshLoaderPly;
|
||||||
ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not load '%s'", filepath.c_str());
|
break;
|
||||||
return false;
|
default: // Unhandled mesh format.
|
||||||
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
rcCalcBounds(m_mesh->getVerts(), m_mesh->getVertCount(), m_meshBMin, m_meshBMax);
|
|
||||||
rdVcopy(m_navMeshBMin, m_meshBMin);
|
|
||||||
rdVcopy(m_navMeshBMax, m_meshBMax);
|
|
||||||
|
|
||||||
m_chunkyMesh = new rcChunkyTriMesh;
|
|
||||||
if (!m_chunkyMesh)
|
|
||||||
{
|
|
||||||
ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Out of memory 'm_chunkyMesh'.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!rcCreateChunkyTriMesh(m_mesh->getVerts(), m_mesh->getTris(), m_mesh->getTriCount(), 256, m_chunkyMesh))
|
|
||||||
{
|
|
||||||
ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Failed to build chunky mesh.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool InputGeom::loadPlyMesh(rcContext* ctx, const std::string& filepath)
|
|
||||||
{
|
|
||||||
if (m_mesh)
|
|
||||||
{
|
|
||||||
delete m_chunkyMesh;
|
|
||||||
m_chunkyMesh = 0;
|
|
||||||
delete m_mesh;
|
|
||||||
m_mesh = 0;
|
|
||||||
}
|
|
||||||
m_offMeshConCount = 0;
|
|
||||||
m_volumeCount = 0;
|
|
||||||
|
|
||||||
m_mesh = new rcMeshLoaderPly;
|
|
||||||
if (!m_mesh)
|
if (!m_mesh)
|
||||||
{
|
{
|
||||||
ctx->log(RC_LOG_ERROR, "loadMesh: Out of memory 'm_mesh'.");
|
ctx->log(RC_LOG_ERROR, "loadMesh: Out of memory 'm_mesh'.");
|
||||||
@ -209,6 +178,7 @@ bool InputGeom::loadPlyMesh(rcContext* ctx, const std::string& filepath)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputGeom::loadGeomSet(rcContext* ctx, const std::string& filepath)
|
bool InputGeom::loadGeomSet(rcContext* ctx, const std::string& filepath)
|
||||||
{
|
{
|
||||||
//NB(warmist): tf2 not implemented here
|
//NB(warmist): tf2 not implemented here
|
||||||
@ -271,7 +241,7 @@ bool InputGeom::loadGeomSet(rcContext* ctx, const std::string& filepath)
|
|||||||
name++;
|
name++;
|
||||||
if (*name)
|
if (*name)
|
||||||
{
|
{
|
||||||
if (!loadMesh(ctx, name))
|
if (!load(ctx, name))
|
||||||
{
|
{
|
||||||
delete [] buf;
|
delete [] buf;
|
||||||
return false;
|
return false;
|
||||||
@ -410,9 +380,9 @@ bool InputGeom::load(rcContext* ctx, const std::string& filepath)
|
|||||||
if (extension == ".gset")
|
if (extension == ".gset")
|
||||||
return loadGeomSet(ctx, filepath);
|
return loadGeomSet(ctx, filepath);
|
||||||
if (extension == ".obj")
|
if (extension == ".obj")
|
||||||
return loadMesh(ctx, filepath);
|
return loadMesh(ctx, filepath, MESH_OBJ);
|
||||||
if (extension == ".ply")
|
if (extension == ".ply")
|
||||||
return loadPlyMesh(ctx, filepath);
|
return loadMesh(ctx, filepath, MESH_PLY);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -108,6 +108,12 @@ struct BuildSettings
|
|||||||
|
|
||||||
class InputGeom
|
class InputGeom
|
||||||
{
|
{
|
||||||
|
enum MeshFormat
|
||||||
|
{
|
||||||
|
MESH_OBJ,
|
||||||
|
MESH_PLY
|
||||||
|
};
|
||||||
|
|
||||||
rcChunkyTriMesh* m_chunkyMesh;
|
rcChunkyTriMesh* m_chunkyMesh;
|
||||||
IMeshLoader* m_mesh;
|
IMeshLoader* m_mesh;
|
||||||
float m_meshBMin[3], m_meshBMax[3];
|
float m_meshBMin[3], m_meshBMax[3];
|
||||||
@ -138,8 +144,7 @@ class InputGeom
|
|||||||
int m_volumeCount;
|
int m_volumeCount;
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
bool loadMesh(class rcContext* ctx, const std::string& filepath);
|
bool loadMesh(class rcContext* ctx, const std::string& filepath, const MeshFormat format);
|
||||||
bool loadPlyMesh(class rcContext* ctx, const std::string& filepath);
|
|
||||||
bool loadGeomSet(class rcContext* ctx, const std::string& filepath);
|
bool loadGeomSet(class rcContext* ctx, const std::string& filepath);
|
||||||
public:
|
public:
|
||||||
InputGeom();
|
InputGeom();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user