Added rcCopyPolyMesh function.
This commit is contained in:
parent
620f8fa130
commit
f91363ff06
@ -1092,6 +1092,14 @@ bool rcBuildPolyMeshDetail(rcContext* ctx, const rcPolyMesh& mesh, const rcCompa
|
||||
const float sampleDist, const float sampleMaxError,
|
||||
rcPolyMeshDetail& dmesh);
|
||||
|
||||
/// Copies the poly mesh data from src to dst.
|
||||
/// @ingroup recast
|
||||
/// @param[in,out] ctx The build context to use during the operation.
|
||||
/// @param[in] src The source mesh to copy from.
|
||||
/// @param[out] dst The resulting detail mesh. (Must be pre-allocated, must be empty mesh.)
|
||||
/// @returns True if the operation completed successfully.
|
||||
bool rcCopyPolyMesh(rcContext* ctx, const rcPolyMesh& src, rcPolyMesh& dst);
|
||||
|
||||
/// Merges multiple detail meshes into a single detail mesh.
|
||||
/// @ingroup recast
|
||||
/// @param[in,out] ctx The build context to use during the operation.
|
||||
|
@ -1390,3 +1390,67 @@ bool rcMergePolyMeshes(rcContext* ctx, rcPolyMesh** meshes, const int nmeshes, r
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rcCopyPolyMesh(rcContext* ctx, const rcPolyMesh& src, rcPolyMesh& dst)
|
||||
{
|
||||
rcAssert(ctx);
|
||||
|
||||
// Destination must be empty.
|
||||
rcAssert(dst.verts == 0);
|
||||
rcAssert(dst.polys == 0);
|
||||
rcAssert(dst.regs == 0);
|
||||
rcAssert(dst.areas == 0);
|
||||
rcAssert(dst.flags == 0);
|
||||
|
||||
dst.nverts = src.nverts;
|
||||
dst.npolys = src.npolys;
|
||||
dst.maxpolys = src.npolys;
|
||||
dst.nvp = src.nvp;
|
||||
rcVcopy(dst.bmin, src.bmin);
|
||||
rcVcopy(dst.bmax, src.bmax);
|
||||
dst.cs = src.cs;
|
||||
dst.ch = src.ch;
|
||||
dst.borderSize = src.borderSize;
|
||||
|
||||
dst.verts = (unsigned short*)rcAlloc(sizeof(unsigned short)*src.nverts*3, RC_ALLOC_PERM);
|
||||
if (!dst.verts)
|
||||
{
|
||||
ctx->log(RC_LOG_ERROR, "rcCopyPolyMesh: Out of memory 'dst.verts' (%d).", src.nverts*3);
|
||||
return false;
|
||||
}
|
||||
memcpy(dst.verts, src.verts, sizeof(unsigned short)*src.nverts*3);
|
||||
|
||||
dst.polys = (unsigned short*)rcAlloc(sizeof(unsigned short)*src.npolys*2*src.nvp, RC_ALLOC_PERM);
|
||||
if (!dst.polys)
|
||||
{
|
||||
ctx->log(RC_LOG_ERROR, "rcCopyPolyMesh: Out of memory 'dst.polys' (%d).", src.npolys*2*src.nvp);
|
||||
return false;
|
||||
}
|
||||
memcpy(dst.polys, src.polys, sizeof(unsigned short)*src.npolys*2*src.nvp);
|
||||
|
||||
dst.regs = (unsigned short*)rcAlloc(sizeof(unsigned short)*src.npolys, RC_ALLOC_PERM);
|
||||
if (!dst.regs)
|
||||
{
|
||||
ctx->log(RC_LOG_ERROR, "rcCopyPolyMesh: Out of memory 'dst.regs' (%d).", src.npolys);
|
||||
return false;
|
||||
}
|
||||
memcpy(dst.regs, src.regs, sizeof(unsigned short)*src.npolys);
|
||||
|
||||
dst.areas = (unsigned char*)rcAlloc(sizeof(unsigned char)*src.npolys, RC_ALLOC_PERM);
|
||||
if (!dst.areas)
|
||||
{
|
||||
ctx->log(RC_LOG_ERROR, "rcCopyPolyMesh: Out of memory 'dst.areas' (%d).", src.npolys);
|
||||
return false;
|
||||
}
|
||||
memcpy(dst.areas, src.areas, sizeof(unsigned char)*src.npolys);
|
||||
|
||||
dst.flags = (unsigned short*)rcAlloc(sizeof(unsigned short)*src.npolys, RC_ALLOC_PERM);
|
||||
if (!dst.flags)
|
||||
{
|
||||
ctx->log(RC_LOG_ERROR, "rcCopyPolyMesh: Out of memory 'dst.flags' (%d).", src.npolys);
|
||||
return false;
|
||||
}
|
||||
memcpy(dst.flags, src.flags, sizeof(unsigned char)*src.npolys);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user