diff --git a/RecastDemo/Include/Sample.h b/RecastDemo/Include/Sample.h index 315defeb..a3f6f0c6 100644 --- a/RecastDemo/Include/Sample.h +++ b/RecastDemo/Include/Sample.h @@ -55,18 +55,12 @@ enum SamplePolyAreas }; enum SamplePolyFlags { - SAMPLE_POLYFLAGS_WALK = 0x01, // Ability to walk (ground, grass, road) - SAMPLE_POLYFLAGS_SWIM = 0x02, // Ability to swim (water). - SAMPLE_POLYFLAGS_DOOR = 0x04, // Ability to move through doors. - SAMPLE_POLYFLAGS_JUMP = 0x08, // Ability to jump. - SAMPLE_POLYFLAGS_DISABLED = 0x10, // Disabled polygon - SAMPLE_POLYFLAGS_ALL = 0xffff // All abilities. -}; - -class SampleDebugDraw : public DebugDrawGL -{ -public: - virtual unsigned int areaToCol(unsigned int area); + SAMPLE_POLYFLAGS_WALK = 1 << 0, //0x01, // Ability to walk (ground, grass, road) + SAMPLE_POLYFLAGS_SWIM = 1 << 1, //0x02, // Ability to swim (water). + SAMPLE_POLYFLAGS_DOOR = 1 << 2, //0x04, // Ability to move through doors. + SAMPLE_POLYFLAGS_JUMP = 1 << 3, //0x08, // Ability to jump. + SAMPLE_POLYFLAGS_DISABLED = 1 << 4, //0x10, // Disabled polygon + SAMPLE_POLYFLAGS_ALL = ~0 //0xffff // All abilities. }; enum SamplePartitionType @@ -76,6 +70,12 @@ enum SamplePartitionType SAMPLE_PARTITION_LAYERS }; +class SampleDebugDraw : public DebugDrawGL +{ +public: + virtual unsigned int areaToCol(unsigned int area); +}; + struct SampleTool { virtual ~SampleTool(); @@ -103,7 +103,7 @@ struct SampleToolState { class Sample { protected: - InputGeom* m_geom; + InputGeom* m_inputGeometry; dtNavMesh* m_navMesh; dtNavMeshQuery* m_navQuery; dtCrowd* m_crowd; @@ -132,9 +132,9 @@ protected: SampleTool* m_tool; SampleToolState* m_toolStates[MAX_TOOLS]; - BuildContext* m_ctx; + BuildContext* m_buildContext; - SampleDebugDraw m_dd; + SampleDebugDraw m_debugDraw; dtNavMesh* loadAll(const char* path); void saveAll(const char* path, const dtNavMesh* mesh); @@ -147,13 +147,13 @@ public: Sample& operator=(const Sample&) = delete; Sample& operator=(const Sample&&) = delete; - void setContext(BuildContext* ctx) { m_ctx = ctx; } + void setContext(BuildContext* ctx) { m_buildContext = ctx; } void setTool(SampleTool* tool); SampleToolState* getToolState(const int type) const { return m_toolStates[type]; } void setToolState(const int type, SampleToolState* s) { m_toolStates[type] = s; } - SampleDebugDraw& getDebugDraw() { return m_dd; } + SampleDebugDraw& getDebugDraw() { return m_debugDraw; } virtual void handleSettings(); virtual void handleTools(); @@ -168,7 +168,7 @@ public: virtual void handleUpdate(float dt); virtual void collectSettings(struct BuildSettings& settings); - virtual InputGeom* getInputGeom() { return m_geom; } + virtual InputGeom* getInputGeom() { return m_inputGeometry; } virtual dtNavMesh* getNavMesh() { return m_navMesh; } virtual dtNavMeshQuery* getNavMeshQuery() { return m_navQuery; } virtual dtCrowd* getCrowd() { return m_crowd; } diff --git a/RecastDemo/Source/Sample.cpp b/RecastDemo/Source/Sample.cpp index 2cafa9c6..773a2754 100644 --- a/RecastDemo/Source/Sample.cpp +++ b/RecastDemo/Source/Sample.cpp @@ -16,18 +16,16 @@ // 3. This notice may not be removed or altered from any source distribution. // -#include -#include #include "Sample.h" -#include "InputGeom.h" -#include "Recast.h" -#include "RecastDebugDraw.h" +#include +#include "DetourCrowd.h" #include "DetourDebugDraw.h" #include "DetourNavMesh.h" #include "DetourNavMeshQuery.h" -#include "DetourCrowd.h" #include "imgui.h" -#include "SDL.h" +#include "InputGeom.h" +#include "Recast.h" +#include "RecastDebugDraw.h" #include "SDL_opengl.h" #ifdef WIN32 @@ -66,7 +64,7 @@ unsigned int SampleDebugDraw::areaToCol(unsigned int area) } Sample::Sample() : - m_geom(0), + m_inputGeometry(0), m_navMesh(0), m_navQuery(0), m_crowd(0), @@ -75,7 +73,7 @@ Sample::Sample() : m_filterLedgeSpans(true), m_filterWalkableLowHeightSpans(true), m_tool(0), - m_ctx(0) + m_buildContext(0) { resetCommonSettings(); m_navQuery = dtAllocNavMeshQuery(); @@ -117,16 +115,16 @@ void Sample::handleDebugMode() void Sample::handleRender() { - if (!m_geom) + if (!m_inputGeometry) return; // Draw mesh - duDebugDrawTriMesh(&m_dd, m_geom->getMesh()->getVerts(), m_geom->getMesh()->getVertCount(), - m_geom->getMesh()->getTris(), m_geom->getMesh()->getNormals(), m_geom->getMesh()->getTriCount(), 0, 1.0f); + duDebugDrawTriMesh(&m_debugDraw, m_inputGeometry->getMesh()->getVerts(), m_inputGeometry->getMesh()->getVertCount(), + m_inputGeometry->getMesh()->getTris(), m_inputGeometry->getMesh()->getNormals(), m_inputGeometry->getMesh()->getTriCount(), 0, 1.0f); // Draw bounds - const float* bmin = m_geom->getMeshBoundsMin(); - const float* bmax = m_geom->getMeshBoundsMax(); - duDebugDrawBoxWire(&m_dd, bmin[0],bmin[1],bmin[2], bmax[0],bmax[1],bmax[2], duRGBA(255,255,255,128), 1.0f); + const float* bmin = m_inputGeometry->getMeshBoundsMin(); + const float* bmax = m_inputGeometry->getMeshBoundsMax(); + duDebugDrawBoxWire(&m_debugDraw, bmin[0],bmin[1],bmin[2], bmax[0],bmax[1],bmax[2], duRGBA(255,255,255,128), 1.0f); } void Sample::handleRenderOverlay(double* /*proj*/, double* /*model*/, int* /*view*/) @@ -135,7 +133,7 @@ void Sample::handleRenderOverlay(double* /*proj*/, double* /*model*/, int* /*vie void Sample::handleMeshChanged(InputGeom* geom) { - m_geom = geom; + m_inputGeometry = geom; const BuildSettings* buildSettings = geom->getBuildSettings(); if (buildSettings) @@ -175,7 +173,6 @@ void Sample::collectSettings(BuildSettings& settings) settings.partitionType = m_partitionType; } - void Sample::resetCommonSettings() { m_cellSize = 0.3f; @@ -200,10 +197,10 @@ void Sample::handleCommonSettings() imguiSlider("Cell Size", &m_cellSize, 0.1f, 1.0f, 0.01f); imguiSlider("Cell Height", &m_cellHeight, 0.1f, 1.0f, 0.01f); - if (m_geom) + if (m_inputGeometry) { - const float* bmin = m_geom->getNavMeshBoundsMin(); - const float* bmax = m_geom->getNavMeshBoundsMax(); + const float* bmin = m_inputGeometry->getNavMeshBoundsMin(); + const float* bmax = m_inputGeometry->getNavMeshBoundsMax(); int gw = 0, gh = 0; rcCalcGridSize(bmin, bmax, m_cellSize, &gw, &gh); char text[64]; @@ -359,30 +356,30 @@ dtNavMesh* Sample::loadAll(const char* path) if (readLen != 1) { fclose(fp); - return 0; + return nullptr; } if (header.magic != NAVMESHSET_MAGIC) { fclose(fp); - return 0; + return nullptr; } if (header.version != NAVMESHSET_VERSION) { fclose(fp); - return 0; + return nullptr; } dtNavMesh* mesh = dtAllocNavMesh(); if (!mesh) { fclose(fp); - return 0; + return nullptr; } dtStatus status = mesh->init(&header.params); if (dtStatusFailed(status)) { fclose(fp); - return 0; + return nullptr; } // Read tiles. diff --git a/RecastDemo/Source/Sample_Debug.cpp b/RecastDemo/Source/Sample_Debug.cpp index 6dc6c141..73b91317 100644 --- a/RecastDemo/Source/Sample_Debug.cpp +++ b/RecastDemo/Source/Sample_Debug.cpp @@ -192,15 +192,15 @@ void Sample_Debug::handleRender() { if (m_chf) { - duDebugDrawCompactHeightfieldRegions(&m_dd, *m_chf); + duDebugDrawCompactHeightfieldRegions(&m_debugDraw, *m_chf); // duDebugDrawCompactHeightfieldSolid(&dd, *m_chf); } if (m_navMesh) - duDebugDrawNavMesh(&m_dd, *m_navMesh, DU_DRAWNAVMESH_OFFMESHCONS); + duDebugDrawNavMesh(&m_debugDraw, *m_navMesh, DU_DRAWNAVMESH_OFFMESHCONS); if (m_ref && m_navMesh) - duDebugDrawNavMeshPoly(&m_dd, *m_navMesh, m_ref, duRGBA(255,0,0,128)); + duDebugDrawNavMeshPoly(&m_debugDraw, *m_navMesh, m_ref, duRGBA(255,0,0,128)); /* float bmin[3], bmax[3]; rcVsub(bmin, m_center, m_halfExtents); @@ -210,13 +210,13 @@ void Sample_Debug::handleRender() if (m_cset) { - duDebugDrawRawContours(&m_dd, *m_cset, 0.25f); - duDebugDrawContours(&m_dd, *m_cset); + duDebugDrawRawContours(&m_debugDraw, *m_cset, 0.25f); + duDebugDrawContours(&m_debugDraw, *m_cset); } if (m_pmesh) { - duDebugDrawPolyMesh(&m_dd, *m_pmesh); + duDebugDrawPolyMesh(&m_debugDraw, *m_pmesh); } /* @@ -323,7 +323,7 @@ void Sample_Debug::handleRenderOverlay(double* /*proj*/, double* /*model*/, int* void Sample_Debug::handleMeshChanged(InputGeom* geom) { - m_geom = geom; + m_inputGeometry = geom; } const float* Sample_Debug::getBoundsMin() @@ -372,12 +372,12 @@ bool Sample_Debug::handleBuild() m_cset = rcAllocContourSet(); if (!m_cset) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'cset'."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'cset'."); return false; } - if (!rcBuildContours(m_ctx, *m_chf, /*m_cfg.maxSimplificationError*/1.3f, /*m_cfg.maxEdgeLen*/12, *m_cset)) + if (!rcBuildContours(m_buildContext, *m_chf, /*m_cfg.maxSimplificationError*/1.3f, /*m_cfg.maxEdgeLen*/12, *m_cset)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not create contours."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not create contours."); return false; } } diff --git a/RecastDemo/Source/Sample_SoloMesh.cpp b/RecastDemo/Source/Sample_SoloMesh.cpp index 82d8d081..82ca8e94 100644 --- a/RecastDemo/Source/Sample_SoloMesh.cpp +++ b/RecastDemo/Source/Sample_SoloMesh.cpp @@ -154,7 +154,7 @@ void Sample_SoloMesh::handleDebugMode() void Sample_SoloMesh::handleRender() { - if (!m_geom || !m_geom->getMesh()) + if (!m_inputGeometry || !m_inputGeometry->getMesh()) { return; } @@ -167,22 +167,22 @@ void Sample_SoloMesh::handleRender() if (m_drawMode != DrawMode::NAVMESH_TRANS) { // Draw mesh - duDebugDrawTriMeshSlope(&m_dd, m_geom->getMesh()->getVerts(), m_geom->getMesh()->getVertCount(), - m_geom->getMesh()->getTris(), m_geom->getMesh()->getNormals(), m_geom->getMesh()->getTriCount(), + duDebugDrawTriMeshSlope(&m_debugDraw, m_inputGeometry->getMesh()->getVerts(), m_inputGeometry->getMesh()->getVertCount(), + m_inputGeometry->getMesh()->getTris(), m_inputGeometry->getMesh()->getNormals(), m_inputGeometry->getMesh()->getTriCount(), m_agentMaxSlope, texScale); - m_geom->drawOffMeshConnections(&m_dd); + m_inputGeometry->drawOffMeshConnections(&m_debugDraw); } glDisable(GL_FOG); glDepthMask(GL_FALSE); // Draw bounds - const float* navmeshBoundsMin = m_geom->getNavMeshBoundsMin(); - const float* navmeshBoundsMax = m_geom->getNavMeshBoundsMax(); - duDebugDrawBoxWire(&m_dd, navmeshBoundsMin[0],navmeshBoundsMin[1],navmeshBoundsMin[2], navmeshBoundsMax[0],navmeshBoundsMax[1],navmeshBoundsMax[2], duRGBA(255,255,255,128), 1.0f); - m_dd.begin(DU_DRAW_POINTS, 5.0f); - m_dd.vertex(navmeshBoundsMin[0],navmeshBoundsMin[1],navmeshBoundsMin[2],duRGBA(255,255,255,128)); - m_dd.end(); + const float* navmeshBoundsMin = m_inputGeometry->getNavMeshBoundsMin(); + const float* navmeshBoundsMax = m_inputGeometry->getNavMeshBoundsMax(); + duDebugDrawBoxWire(&m_debugDraw, navmeshBoundsMin[0],navmeshBoundsMin[1],navmeshBoundsMin[2], navmeshBoundsMax[0],navmeshBoundsMax[1],navmeshBoundsMax[2], duRGBA(255,255,255,128), 1.0f); + m_debugDraw.begin(DU_DRAW_POINTS, 5.0f); + m_debugDraw.vertex(navmeshBoundsMin[0],navmeshBoundsMin[1],navmeshBoundsMin[2],duRGBA(255,255,255,128)); + m_debugDraw.end(); if (m_navMesh && m_navQuery && (m_drawMode == DrawMode::NAVMESH || @@ -193,87 +193,87 @@ void Sample_SoloMesh::handleRender() { if (m_drawMode != DrawMode::NAVMESH_INVIS) { - duDebugDrawNavMeshWithClosedList(&m_dd, *m_navMesh, *m_navQuery, m_navMeshDrawFlags); + duDebugDrawNavMeshWithClosedList(&m_debugDraw, *m_navMesh, *m_navQuery, m_navMeshDrawFlags); } if (m_drawMode == DrawMode::NAVMESH_BVTREE) { - duDebugDrawNavMeshBVTree(&m_dd, *m_navMesh); + duDebugDrawNavMeshBVTree(&m_debugDraw, *m_navMesh); } if (m_drawMode == DrawMode::NAVMESH_NODES) { - duDebugDrawNavMeshNodes(&m_dd, *m_navQuery); + duDebugDrawNavMeshNodes(&m_debugDraw, *m_navQuery); } - duDebugDrawNavMeshPolysWithFlags(&m_dd, *m_navMesh, SAMPLE_POLYFLAGS_DISABLED, duRGBA(0,0,0,128)); + duDebugDrawNavMeshPolysWithFlags(&m_debugDraw, *m_navMesh, SAMPLE_POLYFLAGS_DISABLED, duRGBA(0,0,0,128)); } glDepthMask(GL_TRUE); if (m_compactHeightfield && m_drawMode == DrawMode::COMPACT) { - duDebugDrawCompactHeightfieldSolid(&m_dd, *m_compactHeightfield); + duDebugDrawCompactHeightfieldSolid(&m_debugDraw, *m_compactHeightfield); } if (m_compactHeightfield && m_drawMode == DrawMode::COMPACT_DISTANCE) { - duDebugDrawCompactHeightfieldDistance(&m_dd, *m_compactHeightfield); + duDebugDrawCompactHeightfieldDistance(&m_debugDraw, *m_compactHeightfield); } if (m_compactHeightfield && m_drawMode == DrawMode::COMPACT_REGIONS) { - duDebugDrawCompactHeightfieldRegions(&m_dd, *m_compactHeightfield); + duDebugDrawCompactHeightfieldRegions(&m_debugDraw, *m_compactHeightfield); } if (m_heightfield && m_drawMode == DrawMode::VOXELS) { glEnable(GL_FOG); - duDebugDrawHeightfieldSolid(&m_dd, *m_heightfield); + duDebugDrawHeightfieldSolid(&m_debugDraw, *m_heightfield); glDisable(GL_FOG); } if (m_heightfield && m_drawMode == DrawMode::VOXELS_WALKABLE) { glEnable(GL_FOG); - duDebugDrawHeightfieldWalkable(&m_dd, *m_heightfield); + duDebugDrawHeightfieldWalkable(&m_debugDraw, *m_heightfield); glDisable(GL_FOG); } if (m_contourSet && m_drawMode == DrawMode::RAW_CONTOURS) { glDepthMask(GL_FALSE); - duDebugDrawRawContours(&m_dd, *m_contourSet); + duDebugDrawRawContours(&m_debugDraw, *m_contourSet); glDepthMask(GL_TRUE); } if (m_contourSet && m_drawMode == DrawMode::BOTH_CONTOURS) { glDepthMask(GL_FALSE); - duDebugDrawRawContours(&m_dd, *m_contourSet, 0.5f); - duDebugDrawContours(&m_dd, *m_contourSet); + duDebugDrawRawContours(&m_debugDraw, *m_contourSet, 0.5f); + duDebugDrawContours(&m_debugDraw, *m_contourSet); glDepthMask(GL_TRUE); } if (m_contourSet && m_drawMode == DrawMode::CONTOURS) { glDepthMask(GL_FALSE); - duDebugDrawContours(&m_dd, *m_contourSet); + duDebugDrawContours(&m_debugDraw, *m_contourSet); glDepthMask(GL_TRUE); } if (m_compactHeightfield && m_contourSet && m_drawMode == DrawMode::REGION_CONNECTIONS) { - duDebugDrawCompactHeightfieldRegions(&m_dd, *m_compactHeightfield); + duDebugDrawCompactHeightfieldRegions(&m_debugDraw, *m_compactHeightfield); glDepthMask(GL_FALSE); - duDebugDrawRegionConnections(&m_dd, *m_contourSet); + duDebugDrawRegionConnections(&m_debugDraw, *m_contourSet); glDepthMask(GL_TRUE); } if (m_polyMesh && m_drawMode == DrawMode::POLYMESH) { glDepthMask(GL_FALSE); - duDebugDrawPolyMesh(&m_dd, *m_polyMesh); + duDebugDrawPolyMesh(&m_debugDraw, *m_polyMesh); glDepthMask(GL_TRUE); } if (m_detailMesh && m_drawMode == DrawMode::POLYMESH_DETAIL) { glDepthMask(GL_FALSE); - duDebugDrawPolyMeshDetail(&m_dd, *m_detailMesh); + duDebugDrawPolyMeshDetail(&m_debugDraw, *m_detailMesh); glDepthMask(GL_TRUE); } - m_geom->drawConvexVolumes(&m_dd); + m_inputGeometry->drawConvexVolumes(&m_debugDraw); if (m_tool) { @@ -310,20 +310,20 @@ void Sample_SoloMesh::handleMeshChanged(InputGeom* geom) bool Sample_SoloMesh::handleBuild() { - if (!m_geom || !m_geom->getMesh()) + if (!m_inputGeometry || !m_inputGeometry->getMesh()) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Input mesh is not specified."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Input mesh is not specified."); return false; } cleanup(); - const float* bmin = m_geom->getNavMeshBoundsMin(); - const float* bmax = m_geom->getNavMeshBoundsMax(); - const float* verts = m_geom->getMesh()->getVerts(); - const int nverts = m_geom->getMesh()->getVertCount(); - const int* tris = m_geom->getMesh()->getTris(); - const int ntris = m_geom->getMesh()->getTriCount(); + const float* bmin = m_inputGeometry->getNavMeshBoundsMin(); + const float* bmax = m_inputGeometry->getNavMeshBoundsMax(); + const float* verts = m_inputGeometry->getMesh()->getVerts(); + const int nverts = m_inputGeometry->getMesh()->getVertCount(); + const int* tris = m_inputGeometry->getMesh()->getTris(); + const int ntris = m_inputGeometry->getMesh()->getTriCount(); // // Step 1. Initialize build config. @@ -353,14 +353,14 @@ bool Sample_SoloMesh::handleBuild() rcCalcGridSize(m_config.bmin, m_config.bmax, m_config.cs, &m_config.width, &m_config.height); // Reset build times gathering. - m_ctx->resetTimers(); + m_buildContext->resetTimers(); // Start the build process. - m_ctx->startTimer(RC_TIMER_TOTAL); + m_buildContext->startTimer(RC_TIMER_TOTAL); - m_ctx->log(RC_LOG_PROGRESS, "Building navigation:"); - m_ctx->log(RC_LOG_PROGRESS, " - %d x %d cells", m_config.width, m_config.height); - m_ctx->log(RC_LOG_PROGRESS, " - %.1fK verts, %.1fK tris", static_cast(nverts) / 1000.0f, static_cast(ntris) / 1000.0f); + m_buildContext->log(RC_LOG_PROGRESS, "Building navigation:"); + m_buildContext->log(RC_LOG_PROGRESS, " - %d x %d cells", m_config.width, m_config.height); + m_buildContext->log(RC_LOG_PROGRESS, " - %.1fK verts, %.1fK tris", static_cast(nverts) / 1000.0f, static_cast(ntris) / 1000.0f); // // Step 2. Rasterize input polygon soup. @@ -370,12 +370,12 @@ bool Sample_SoloMesh::handleBuild() m_heightfield = rcAllocHeightfield(); if (!m_heightfield) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'solid'."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'solid'."); return false; } - if (!rcCreateHeightfield(m_ctx, *m_heightfield, m_config.width, m_config.height, m_config.bmin, m_config.bmax, m_config.cs, m_config.ch)) + if (!rcCreateHeightfield(m_buildContext, *m_heightfield, m_config.width, m_config.height, m_config.bmin, m_config.bmax, m_config.cs, m_config.ch)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not create solid heightfield."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not create solid heightfield."); return false; } @@ -385,7 +385,7 @@ bool Sample_SoloMesh::handleBuild() m_triareas = new unsigned char[ntris]; if (!m_triareas) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'm_triareas' (%d).", ntris); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'm_triareas' (%d).", ntris); return false; } @@ -393,10 +393,10 @@ bool Sample_SoloMesh::handleBuild() // If your input data is multiple meshes, you can transform them here, calculate // the type for each mesh, and rasterize them. memset(m_triareas, 0, ntris*sizeof(unsigned char)); - rcMarkWalkableTriangles(m_ctx, m_config.walkableSlopeAngle, verts, nverts, tris, ntris, m_triareas); - if (!rcRasterizeTriangles(m_ctx, verts, nverts, tris, m_triareas, ntris, *m_heightfield, m_config.walkableClimb)) + rcMarkWalkableTriangles(m_buildContext, m_config.walkableSlopeAngle, verts, nverts, tris, ntris, m_triareas); + if (!rcRasterizeTriangles(m_buildContext, verts, nverts, tris, m_triareas, ntris, *m_heightfield, m_config.walkableClimb)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not rasterize triangles."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not rasterize triangles."); return false; } @@ -415,15 +415,15 @@ bool Sample_SoloMesh::handleBuild() // as well as filter spans where the character cannot possibly stand. if (m_filterLowHangingObstacles) { - rcFilterLowHangingWalkableObstacles(m_ctx, m_config.walkableClimb, *m_heightfield); + rcFilterLowHangingWalkableObstacles(m_buildContext, m_config.walkableClimb, *m_heightfield); } if (m_filterLedgeSpans) { - rcFilterLedgeSpans(m_ctx, m_config.walkableHeight, m_config.walkableClimb, *m_heightfield); + rcFilterLedgeSpans(m_buildContext, m_config.walkableHeight, m_config.walkableClimb, *m_heightfield); } if (m_filterWalkableLowHeightSpans) { - rcFilterWalkableLowHeightSpans(m_ctx, m_config.walkableHeight, *m_heightfield); + rcFilterWalkableLowHeightSpans(m_buildContext, m_config.walkableHeight, *m_heightfield); } // @@ -436,12 +436,12 @@ bool Sample_SoloMesh::handleBuild() m_compactHeightfield = rcAllocCompactHeightfield(); if (!m_compactHeightfield) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'chf'."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'chf'."); return false; } - if (!rcBuildCompactHeightfield(m_ctx, m_config.walkableHeight, m_config.walkableClimb, *m_heightfield, *m_compactHeightfield)) + if (!rcBuildCompactHeightfield(m_buildContext, m_config.walkableHeight, m_config.walkableClimb, *m_heightfield, *m_compactHeightfield)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build compact data."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not build compact data."); return false; } @@ -452,17 +452,17 @@ bool Sample_SoloMesh::handleBuild() } // Erode the walkable area by agent radius. - if (!rcErodeWalkableArea(m_ctx, m_config.walkableRadius, *m_compactHeightfield)) + if (!rcErodeWalkableArea(m_buildContext, m_config.walkableRadius, *m_compactHeightfield)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not erode."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not erode."); return false; } // (Optional) Mark areas. - const ConvexVolume* vols = m_geom->getConvexVolumes(); - for (int i = 0; i < m_geom->getConvexVolumeCount(); ++i) + const ConvexVolume* vols = m_inputGeometry->getConvexVolumes(); + for (int i = 0; i < m_inputGeometry->getConvexVolumeCount(); ++i) { - rcMarkConvexPolyArea(m_ctx, vols[i].verts, vols[i].nverts, vols[i].hmin, vols[i].hmax, (unsigned char)vols[i].area, *m_compactHeightfield); + rcMarkConvexPolyArea(m_buildContext, vols[i].verts, vols[i].nverts, vols[i].hmin, vols[i].hmax, (unsigned char)vols[i].area, *m_compactHeightfield); } // Partition the heightfield so that we can use simple algorithm later to triangulate the walkable areas. @@ -494,16 +494,16 @@ bool Sample_SoloMesh::handleBuild() if (m_partitionType == SAMPLE_PARTITION_WATERSHED) { // Prepare for region partitioning, by calculating distance field along the walkable surface. - if (!rcBuildDistanceField(m_ctx, *m_compactHeightfield)) + if (!rcBuildDistanceField(m_buildContext, *m_compactHeightfield)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build distance field."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not build distance field."); return false; } // Partition the walkable surface into simple regions without holes. - if (!rcBuildRegions(m_ctx, *m_compactHeightfield, 0, m_config.minRegionArea, m_config.mergeRegionArea)) + if (!rcBuildRegions(m_buildContext, *m_compactHeightfield, 0, m_config.minRegionArea, m_config.mergeRegionArea)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build watershed regions."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not build watershed regions."); return false; } } @@ -511,18 +511,18 @@ bool Sample_SoloMesh::handleBuild() { // Partition the walkable surface into simple regions without holes. // Monotone partitioning does not need distancefield. - if (!rcBuildRegionsMonotone(m_ctx, *m_compactHeightfield, 0, m_config.minRegionArea, m_config.mergeRegionArea)) + if (!rcBuildRegionsMonotone(m_buildContext, *m_compactHeightfield, 0, m_config.minRegionArea, m_config.mergeRegionArea)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build monotone regions."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not build monotone regions."); return false; } } else // SAMPLE_PARTITION_LAYERS { // Partition the walkable surface into simple regions without holes. - if (!rcBuildLayerRegions(m_ctx, *m_compactHeightfield, 0, m_config.minRegionArea)) + if (!rcBuildLayerRegions(m_buildContext, *m_compactHeightfield, 0, m_config.minRegionArea)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build layer regions."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not build layer regions."); return false; } } @@ -535,12 +535,12 @@ bool Sample_SoloMesh::handleBuild() m_contourSet = rcAllocContourSet(); if (!m_contourSet) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'cset'."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'cset'."); return false; } - if (!rcBuildContours(m_ctx, *m_compactHeightfield, m_config.maxSimplificationError, m_config.maxEdgeLen, *m_contourSet)) + if (!rcBuildContours(m_buildContext, *m_compactHeightfield, m_config.maxSimplificationError, m_config.maxEdgeLen, *m_contourSet)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not create contours."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not create contours."); return false; } @@ -552,12 +552,12 @@ bool Sample_SoloMesh::handleBuild() m_polyMesh = rcAllocPolyMesh(); if (!m_polyMesh) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'pmesh'."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'pmesh'."); return false; } - if (!rcBuildPolyMesh(m_ctx, *m_contourSet, m_config.maxVertsPerPoly, *m_polyMesh)) + if (!rcBuildPolyMesh(m_buildContext, *m_contourSet, m_config.maxVertsPerPoly, *m_polyMesh)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not triangulate contours."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not triangulate contours."); return false; } @@ -568,13 +568,13 @@ bool Sample_SoloMesh::handleBuild() m_detailMesh = rcAllocPolyMeshDetail(); if (!m_detailMesh) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'pmdtl'."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'pmdtl'."); return false; } - if (!rcBuildPolyMeshDetail(m_ctx, *m_polyMesh, *m_compactHeightfield, m_config.detailSampleDist, m_config.detailSampleMaxError, *m_detailMesh)) + if (!rcBuildPolyMeshDetail(m_buildContext, *m_polyMesh, *m_compactHeightfield, m_config.detailSampleDist, m_config.detailSampleMaxError, *m_detailMesh)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build detail mesh."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not build detail mesh."); return false; } @@ -638,13 +638,13 @@ bool Sample_SoloMesh::handleBuild() params.detailVertsCount = m_detailMesh->nverts; params.detailTris = m_detailMesh->tris; params.detailTriCount = m_detailMesh->ntris; - params.offMeshConVerts = m_geom->getOffMeshConnectionVerts(); - params.offMeshConRad = m_geom->getOffMeshConnectionRads(); - params.offMeshConDir = m_geom->getOffMeshConnectionDirs(); - params.offMeshConAreas = m_geom->getOffMeshConnectionAreas(); - params.offMeshConFlags = m_geom->getOffMeshConnectionFlags(); - params.offMeshConUserID = m_geom->getOffMeshConnectionId(); - params.offMeshConCount = m_geom->getOffMeshConnectionCount(); + params.offMeshConVerts = m_inputGeometry->getOffMeshConnectionVerts(); + params.offMeshConRad = m_inputGeometry->getOffMeshConnectionRads(); + params.offMeshConDir = m_inputGeometry->getOffMeshConnectionDirs(); + params.offMeshConAreas = m_inputGeometry->getOffMeshConnectionAreas(); + params.offMeshConFlags = m_inputGeometry->getOffMeshConnectionFlags(); + params.offMeshConUserID = m_inputGeometry->getOffMeshConnectionId(); + params.offMeshConCount = m_inputGeometry->getOffMeshConnectionCount(); params.walkableHeight = m_agentHeight; params.walkableRadius = m_agentRadius; params.walkableClimb = m_agentMaxClimb; @@ -656,7 +656,7 @@ bool Sample_SoloMesh::handleBuild() if (!dtCreateNavMeshData(¶ms, &navData, &navDataSize)) { - m_ctx->log(RC_LOG_ERROR, "Could not build Detour navmesh."); + m_buildContext->log(RC_LOG_ERROR, "Could not build Detour navmesh."); return false; } @@ -664,7 +664,7 @@ bool Sample_SoloMesh::handleBuild() if (!m_navMesh) { dtFree(navData); - m_ctx->log(RC_LOG_ERROR, "Could not create Detour navmesh"); + m_buildContext->log(RC_LOG_ERROR, "Could not create Detour navmesh"); return false; } @@ -672,25 +672,25 @@ bool Sample_SoloMesh::handleBuild() if (dtStatusFailed(status)) { dtFree(navData); - m_ctx->log(RC_LOG_ERROR, "Could not init Detour navmesh"); + m_buildContext->log(RC_LOG_ERROR, "Could not init Detour navmesh"); return false; } status = m_navQuery->init(m_navMesh, 2048); if (dtStatusFailed(status)) { - m_ctx->log(RC_LOG_ERROR, "Could not init Detour navmesh query"); + m_buildContext->log(RC_LOG_ERROR, "Could not init Detour navmesh query"); return false; } } - m_ctx->stopTimer(RC_TIMER_TOTAL); + m_buildContext->stopTimer(RC_TIMER_TOTAL); // Show performance stats. - duLogBuildTimes(*m_ctx, m_ctx->getAccumulatedTime(RC_TIMER_TOTAL)); - m_ctx->log(RC_LOG_PROGRESS, ">> Polymesh: %d vertices %d polygons", m_polyMesh->nverts, m_polyMesh->npolys); + duLogBuildTimes(*m_buildContext, m_buildContext->getAccumulatedTime(RC_TIMER_TOTAL)); + m_buildContext->log(RC_LOG_PROGRESS, ">> Polymesh: %d vertices %d polygons", m_polyMesh->nverts, m_polyMesh->npolys); - m_totalBuildTimeMs = static_cast(m_ctx->getAccumulatedTime(RC_TIMER_TOTAL)) / 1000.0f; + m_totalBuildTimeMs = static_cast(m_buildContext->getAccumulatedTime(RC_TIMER_TOTAL)) / 1000.0f; if (m_tool) { diff --git a/RecastDemo/Source/Sample_TempObstacles.cpp b/RecastDemo/Source/Sample_TempObstacles.cpp index 294372be..b413906e 100644 --- a/RecastDemo/Source/Sample_TempObstacles.cpp +++ b/RecastDemo/Source/Sample_TempObstacles.cpp @@ -291,18 +291,18 @@ int Sample_TempObstacles::rasterizeTileLayers( TileCacheData* tiles, const int maxTiles) { - if (!m_geom || !m_geom->getMesh() || !m_geom->getChunkyMesh()) + if (!m_inputGeometry || !m_inputGeometry->getMesh() || !m_inputGeometry->getChunkyMesh()) { - m_ctx->log(RC_LOG_ERROR, "buildTile: Input mesh is not specified."); + m_buildContext->log(RC_LOG_ERROR, "buildTile: Input mesh is not specified."); return 0; } FastLZCompressor comp; RasterizationContext rc; - const float* verts = m_geom->getMesh()->getVerts(); - const int nverts = m_geom->getMesh()->getVertCount(); - const rcChunkyTriMesh* chunkyMesh = m_geom->getChunkyMesh(); + const float* verts = m_inputGeometry->getMesh()->getVerts(); + const int nverts = m_inputGeometry->getMesh()->getVertCount(); + const rcChunkyTriMesh* chunkyMesh = m_inputGeometry->getChunkyMesh(); // Tile bounds. const float tcs = cfg.tileSize * cfg.cs; @@ -325,12 +325,12 @@ int Sample_TempObstacles::rasterizeTileLayers( rc.solid = rcAllocHeightfield(); if (!rc.solid) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'solid'."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'solid'."); return 0; } - if (!rcCreateHeightfield(m_ctx, *rc.solid, tcfg.width, tcfg.height, tcfg.bmin, tcfg.bmax, tcfg.cs, tcfg.ch)) + if (!rcCreateHeightfield(m_buildContext, *rc.solid, tcfg.width, tcfg.height, tcfg.bmin, tcfg.bmax, tcfg.cs, tcfg.ch)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not create solid heightfield."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not create solid heightfield."); return 0; } @@ -340,7 +340,7 @@ int Sample_TempObstacles::rasterizeTileLayers( rc.triareas = new unsigned char[chunkyMesh->maxTrisPerChunk]; if (!rc.triareas) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'm_triareas' (%d).", chunkyMesh->maxTrisPerChunk); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'm_triareas' (%d).", chunkyMesh->maxTrisPerChunk); return 0; } @@ -363,10 +363,10 @@ int Sample_TempObstacles::rasterizeTileLayers( const int ntris = node.n; memset(rc.triareas, 0, ntris*sizeof(unsigned char)); - rcMarkWalkableTriangles(m_ctx, tcfg.walkableSlopeAngle, + rcMarkWalkableTriangles(m_buildContext, tcfg.walkableSlopeAngle, verts, nverts, tris, ntris, rc.triareas); - if (!rcRasterizeTriangles(m_ctx, verts, nverts, tris, rc.triareas, ntris, *rc.solid, tcfg.walkableClimb)) + if (!rcRasterizeTriangles(m_buildContext, verts, nverts, tris, rc.triareas, ntris, *rc.solid, tcfg.walkableClimb)) return 0; } @@ -374,37 +374,37 @@ int Sample_TempObstacles::rasterizeTileLayers( // remove unwanted overhangs caused by the conservative rasterization // as well as filter spans where the character cannot possibly stand. if (m_filterLowHangingObstacles) - rcFilterLowHangingWalkableObstacles(m_ctx, tcfg.walkableClimb, *rc.solid); + rcFilterLowHangingWalkableObstacles(m_buildContext, tcfg.walkableClimb, *rc.solid); if (m_filterLedgeSpans) - rcFilterLedgeSpans(m_ctx, tcfg.walkableHeight, tcfg.walkableClimb, *rc.solid); + rcFilterLedgeSpans(m_buildContext, tcfg.walkableHeight, tcfg.walkableClimb, *rc.solid); if (m_filterWalkableLowHeightSpans) - rcFilterWalkableLowHeightSpans(m_ctx, tcfg.walkableHeight, *rc.solid); + rcFilterWalkableLowHeightSpans(m_buildContext, tcfg.walkableHeight, *rc.solid); rc.chf = rcAllocCompactHeightfield(); if (!rc.chf) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'chf'."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'chf'."); return 0; } - if (!rcBuildCompactHeightfield(m_ctx, tcfg.walkableHeight, tcfg.walkableClimb, *rc.solid, *rc.chf)) + if (!rcBuildCompactHeightfield(m_buildContext, tcfg.walkableHeight, tcfg.walkableClimb, *rc.solid, *rc.chf)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build compact data."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not build compact data."); return 0; } // Erode the walkable area by agent radius. - if (!rcErodeWalkableArea(m_ctx, tcfg.walkableRadius, *rc.chf)) + if (!rcErodeWalkableArea(m_buildContext, tcfg.walkableRadius, *rc.chf)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not erode."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not erode."); return 0; } // (Optional) Mark areas. - const ConvexVolume* vols = m_geom->getConvexVolumes(); - for (int i = 0; i < m_geom->getConvexVolumeCount(); ++i) + const ConvexVolume* vols = m_inputGeometry->getConvexVolumes(); + for (int i = 0; i < m_inputGeometry->getConvexVolumeCount(); ++i) { - rcMarkConvexPolyArea(m_ctx, vols[i].verts, vols[i].nverts, + rcMarkConvexPolyArea(m_buildContext, vols[i].verts, vols[i].nverts, vols[i].hmin, vols[i].hmax, (unsigned char)vols[i].area, *rc.chf); } @@ -412,12 +412,12 @@ int Sample_TempObstacles::rasterizeTileLayers( rc.lset = rcAllocHeightfieldLayerSet(); if (!rc.lset) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'lset'."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'lset'."); return 0; } - if (!rcBuildHeightfieldLayers(m_ctx, *rc.chf, tcfg.borderSize, tcfg.walkableHeight, *rc.lset)) + if (!rcBuildHeightfieldLayers(m_buildContext, *rc.chf, tcfg.borderSize, tcfg.walkableHeight, *rc.lset)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build heighfield layers."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not build heighfield layers."); return 0; } @@ -874,10 +874,10 @@ void Sample_TempObstacles::handleSettings() imguiSlider("TileSize", &m_tileSize, 16.0f, 128.0f, 8.0f); int gridSize = 1; - if (m_geom) + if (m_inputGeometry) { - const float* bmin = m_geom->getNavMeshBoundsMin(); - const float* bmax = m_geom->getNavMeshBoundsMax(); + const float* bmin = m_inputGeometry->getNavMeshBoundsMin(); + const float* bmax = m_inputGeometry->getNavMeshBoundsMax(); char text[64]; int gw = 0, gh = 0; rcCalcGridSize(bmin, bmax, m_cellSize, &gw, &gh); @@ -995,7 +995,7 @@ void Sample_TempObstacles::handleDebugMode() for (int i = 0; i < MAX_DRAWMODE; ++i) valid[i] = false; - if (m_geom) + if (m_inputGeometry) { valid[DRAWMODE_NAVMESH] = m_navMesh != 0; valid[DRAWMODE_NAVMESH_TRANS] = m_navMesh != 0; @@ -1042,7 +1042,7 @@ void Sample_TempObstacles::handleDebugMode() void Sample_TempObstacles::handleRender() { - if (!m_geom || !m_geom->getMesh()) + if (!m_inputGeometry || !m_inputGeometry->getMesh()) return; const float texScale = 1.0f / (m_cellSize * 10.0f); @@ -1051,25 +1051,25 @@ void Sample_TempObstacles::handleRender() if (m_drawMode != DRAWMODE_NAVMESH_TRANS) { // Draw mesh - duDebugDrawTriMeshSlope(&m_dd, m_geom->getMesh()->getVerts(), m_geom->getMesh()->getVertCount(), - m_geom->getMesh()->getTris(), m_geom->getMesh()->getNormals(), m_geom->getMesh()->getTriCount(), + duDebugDrawTriMeshSlope(&m_debugDraw, m_inputGeometry->getMesh()->getVerts(), m_inputGeometry->getMesh()->getVertCount(), + m_inputGeometry->getMesh()->getTris(), m_inputGeometry->getMesh()->getNormals(), m_inputGeometry->getMesh()->getTriCount(), m_agentMaxSlope, texScale); - m_geom->drawOffMeshConnections(&m_dd); + m_inputGeometry->drawOffMeshConnections(&m_debugDraw); } if (m_tileCache && m_drawMode == DRAWMODE_CACHE_BOUNDS) - drawTiles(&m_dd, m_tileCache); + drawTiles(&m_debugDraw, m_tileCache); if (m_tileCache) - drawObstacles(&m_dd, m_tileCache); + drawObstacles(&m_debugDraw, m_tileCache); glDepthMask(GL_FALSE); // Draw bounds - const float* bmin = m_geom->getNavMeshBoundsMin(); - const float* bmax = m_geom->getNavMeshBoundsMax(); - duDebugDrawBoxWire(&m_dd, bmin[0],bmin[1],bmin[2], bmax[0],bmax[1],bmax[2], duRGBA(255,255,255,128), 1.0f); + const float* bmin = m_inputGeometry->getNavMeshBoundsMin(); + const float* bmax = m_inputGeometry->getNavMeshBoundsMax(); + duDebugDrawBoxWire(&m_debugDraw, bmin[0],bmin[1],bmin[2], bmax[0],bmax[1],bmax[2], duRGBA(255,255,255,128), 1.0f); // Tiling grid. int gw = 0, gh = 0; @@ -1077,7 +1077,7 @@ void Sample_TempObstacles::handleRender() const int tw = (gw + (int)m_tileSize-1) / (int)m_tileSize; const int th = (gh + (int)m_tileSize-1) / (int)m_tileSize; const float s = m_tileSize*m_cellSize; - duDebugDrawGridXZ(&m_dd, bmin[0],bmin[1],bmin[2], tw,th, s, duRGBA(0,0,0,64), 1.0f); + duDebugDrawGridXZ(&m_debugDraw, bmin[0],bmin[1],bmin[2], tw,th, s, duRGBA(0,0,0,64), 1.0f); if (m_navMesh && m_navQuery && (m_drawMode == DRAWMODE_NAVMESH || @@ -1088,20 +1088,20 @@ void Sample_TempObstacles::handleRender() m_drawMode == DRAWMODE_NAVMESH_INVIS)) { if (m_drawMode != DRAWMODE_NAVMESH_INVIS) - duDebugDrawNavMeshWithClosedList(&m_dd, *m_navMesh, *m_navQuery, m_navMeshDrawFlags/*|DU_DRAWNAVMESH_COLOR_TILES*/); + duDebugDrawNavMeshWithClosedList(&m_debugDraw, *m_navMesh, *m_navQuery, m_navMeshDrawFlags/*|DU_DRAWNAVMESH_COLOR_TILES*/); if (m_drawMode == DRAWMODE_NAVMESH_BVTREE) - duDebugDrawNavMeshBVTree(&m_dd, *m_navMesh); + duDebugDrawNavMeshBVTree(&m_debugDraw, *m_navMesh); if (m_drawMode == DRAWMODE_NAVMESH_PORTALS) - duDebugDrawNavMeshPortals(&m_dd, *m_navMesh); + duDebugDrawNavMeshPortals(&m_debugDraw, *m_navMesh); if (m_drawMode == DRAWMODE_NAVMESH_NODES) - duDebugDrawNavMeshNodes(&m_dd, *m_navQuery); - duDebugDrawNavMeshPolysWithFlags(&m_dd, *m_navMesh, SAMPLE_POLYFLAGS_DISABLED, duRGBA(0,0,0,128)); + duDebugDrawNavMeshNodes(&m_debugDraw, *m_navQuery); + duDebugDrawNavMeshPolysWithFlags(&m_debugDraw, *m_navMesh, SAMPLE_POLYFLAGS_DISABLED, duRGBA(0,0,0,128)); } glDepthMask(GL_TRUE); - m_geom->drawConvexVolumes(&m_dd); + m_inputGeometry->drawConvexVolumes(&m_debugDraw); if (m_tool) m_tool->handleRender(); @@ -1113,7 +1113,7 @@ void Sample_TempObstacles::handleRender() void Sample_TempObstacles::renderCachedTile(const int tx, const int ty, const int type) { if (m_tileCache) - drawDetail(&m_dd,m_tileCache,tx,ty,type); + drawDetail(&m_debugDraw,m_tileCache,tx,ty,type); } void Sample_TempObstacles::renderCachedTileOverlay(const int tx, const int ty, double* proj, double* model, int* view) @@ -1166,7 +1166,7 @@ void Sample_TempObstacles::handleMeshChanged(class InputGeom* geom) { m_tool->reset(); m_tool->init(this); - m_tmproc->init(m_geom); + m_tmproc->init(m_inputGeometry); } resetToolStates(); initToolStates(this); @@ -1206,17 +1206,17 @@ bool Sample_TempObstacles::handleBuild() { dtStatus status; - if (!m_geom || !m_geom->getMesh()) + if (!m_inputGeometry || !m_inputGeometry->getMesh()) { - m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: No vertices and triangles."); + m_buildContext->log(RC_LOG_ERROR, "buildTiledNavigation: No vertices and triangles."); return false; } - m_tmproc->init(m_geom); + m_tmproc->init(m_inputGeometry); // Init cache - const float* bmin = m_geom->getNavMeshBoundsMin(); - const float* bmax = m_geom->getNavMeshBoundsMax(); + const float* bmin = m_inputGeometry->getNavMeshBoundsMin(); + const float* bmax = m_inputGeometry->getNavMeshBoundsMax(); int gw = 0, gh = 0; rcCalcGridSize(bmin, bmax, m_cellSize, &gw, &gh); const int ts = (int)m_tileSize; @@ -1266,13 +1266,13 @@ bool Sample_TempObstacles::handleBuild() m_tileCache = dtAllocTileCache(); if (!m_tileCache) { - m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not allocate tile cache."); + m_buildContext->log(RC_LOG_ERROR, "buildTiledNavigation: Could not allocate tile cache."); return false; } status = m_tileCache->init(&tcparams, m_talloc, m_tcomp, m_tmproc); if (dtStatusFailed(status)) { - m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init tile cache."); + m_buildContext->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init tile cache."); return false; } @@ -1281,7 +1281,7 @@ bool Sample_TempObstacles::handleBuild() m_navMesh = dtAllocNavMesh(); if (!m_navMesh) { - m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not allocate navmesh."); + m_buildContext->log(RC_LOG_ERROR, "buildTiledNavigation: Could not allocate navmesh."); return false; } @@ -1296,21 +1296,21 @@ bool Sample_TempObstacles::handleBuild() status = m_navMesh->init(¶ms); if (dtStatusFailed(status)) { - m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init navmesh."); + m_buildContext->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init navmesh."); return false; } status = m_navQuery->init(m_navMesh, 2048); if (dtStatusFailed(status)) { - m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init Detour navmesh query"); + m_buildContext->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init Detour navmesh query"); return false; } // Preprocess tiles. - m_ctx->resetTimers(); + m_buildContext->resetTimers(); m_cacheLayerCount = 0; m_cacheCompressedSize = 0; @@ -1343,13 +1343,13 @@ bool Sample_TempObstacles::handleBuild() } // Build initial meshes - m_ctx->startTimer(RC_TIMER_TOTAL); + m_buildContext->startTimer(RC_TIMER_TOTAL); for (int y = 0; y < th; ++y) for (int x = 0; x < tw; ++x) m_tileCache->buildNavMeshTilesAt(x,y, m_navMesh); - m_ctx->stopTimer(RC_TIMER_TOTAL); + m_buildContext->stopTimer(RC_TIMER_TOTAL); - m_cacheBuildTimeMs = m_ctx->getAccumulatedTime(RC_TIMER_TOTAL)/1000.0f; + m_cacheBuildTimeMs = m_buildContext->getAccumulatedTime(RC_TIMER_TOTAL)/1000.0f; m_cacheBuildMemUsage = static_cast(m_talloc->high); @@ -1385,9 +1385,9 @@ void Sample_TempObstacles::handleUpdate(const float dt) void Sample_TempObstacles::getTilePos(const float* pos, int& tx, int& ty) { - if (!m_geom) return; + if (!m_inputGeometry) return; - const float* bmin = m_geom->getNavMeshBoundsMin(); + const float* bmin = m_inputGeometry->getNavMeshBoundsMin(); const float ts = m_tileSize*m_cellSize; tx = (int)((pos[0] - bmin[0]) / ts); diff --git a/RecastDemo/Source/Sample_TileMesh.cpp b/RecastDemo/Source/Sample_TileMesh.cpp index 2c86f548..e0d5c81a 100644 --- a/RecastDemo/Source/Sample_TileMesh.cpp +++ b/RecastDemo/Source/Sample_TileMesh.cpp @@ -196,10 +196,10 @@ void Sample_TileMesh::handleSettings() imguiLabel("Tiling"); imguiSlider("TileSize", &m_tileSize, 16.0f, 1024.0f, 16.0f); - if (m_geom) + if (m_inputGeometry) { - const float* navMeshBoundsMin = m_geom->getNavMeshBoundsMin(); - const float* navMeshBoundsMax = m_geom->getNavMeshBoundsMax(); + const float* navMeshBoundsMin = m_inputGeometry->getNavMeshBoundsMin(); + const float* navMeshBoundsMax = m_inputGeometry->getNavMeshBoundsMax(); int gridWidth = 0; int gridHeight = 0; rcCalcGridSize(navMeshBoundsMin, navMeshBoundsMax, m_cellSize, &gridWidth, &gridHeight); @@ -313,7 +313,7 @@ void Sample_TileMesh::handleDebugMode() void Sample_TileMesh::handleRender() { - if (!m_geom || !m_geom->getMesh()) { return; } + if (!m_inputGeometry || !m_inputGeometry->getMesh()) { return; } const float texScale = 1.0f / (m_cellSize * 10.0f); @@ -322,23 +322,23 @@ void Sample_TileMesh::handleRender() { // Draw mesh duDebugDrawTriMeshSlope( - &m_dd, - m_geom->getMesh()->getVerts(), - m_geom->getMesh()->getVertCount(), - m_geom->getMesh()->getTris(), - m_geom->getMesh()->getNormals(), - m_geom->getMesh()->getTriCount(), + &m_debugDraw, + m_inputGeometry->getMesh()->getVerts(), + m_inputGeometry->getMesh()->getVertCount(), + m_inputGeometry->getMesh()->getTris(), + m_inputGeometry->getMesh()->getNormals(), + m_inputGeometry->getMesh()->getTriCount(), m_agentMaxSlope, texScale); - m_geom->drawOffMeshConnections(&m_dd); + m_inputGeometry->drawOffMeshConnections(&m_debugDraw); } glDepthMask(GL_FALSE); // Draw bounds - const float* navMeshBoundsMin = m_geom->getNavMeshBoundsMin(); - const float* navMeshBoundsMax = m_geom->getNavMeshBoundsMax(); - duDebugDrawBoxWire(&m_dd, + const float* navMeshBoundsMin = m_inputGeometry->getNavMeshBoundsMin(); + const float* navMeshBoundsMax = m_inputGeometry->getNavMeshBoundsMax(); + duDebugDrawBoxWire(&m_debugDraw, navMeshBoundsMin[0], navMeshBoundsMin[1], navMeshBoundsMin[2], @@ -354,7 +354,7 @@ void Sample_TileMesh::handleRender() const int tileWidth = (gridWith + static_cast(m_tileSize) - 1) / static_cast(m_tileSize); const int tileHeight = (gridHeight + static_cast(m_tileSize) - 1) / static_cast(m_tileSize); const float size = m_tileSize * m_cellSize; - duDebugDrawGridXZ(&m_dd, + duDebugDrawGridXZ(&m_debugDraw, navMeshBoundsMin[0], navMeshBoundsMin[1], navMeshBoundsMin[2], @@ -366,7 +366,7 @@ void Sample_TileMesh::handleRender() // Draw active tile duDebugDrawBoxWire( - &m_dd, + &m_debugDraw, m_lastBuiltTileBoundsMin[0], m_lastBuiltTileBoundsMin[1], m_lastBuiltTileBoundsMin[2], @@ -386,93 +386,93 @@ void Sample_TileMesh::handleRender() { if (m_drawMode != DrawMode::NAVMESH_INVIS) { - duDebugDrawNavMeshWithClosedList(&m_dd, *m_navMesh, *m_navQuery, m_navMeshDrawFlags); + duDebugDrawNavMeshWithClosedList(&m_debugDraw, *m_navMesh, *m_navQuery, m_navMeshDrawFlags); } if (m_drawMode == DrawMode::NAVMESH_BVTREE) { - duDebugDrawNavMeshBVTree(&m_dd, *m_navMesh); + duDebugDrawNavMeshBVTree(&m_debugDraw, *m_navMesh); } if (m_drawMode == DrawMode::NAVMESH_PORTALS) { - duDebugDrawNavMeshPortals(&m_dd, *m_navMesh); + duDebugDrawNavMeshPortals(&m_debugDraw, *m_navMesh); } if (m_drawMode == DrawMode::NAVMESH_NODES) { - duDebugDrawNavMeshNodes(&m_dd, *m_navQuery); + duDebugDrawNavMeshNodes(&m_debugDraw, *m_navQuery); } - duDebugDrawNavMeshPolysWithFlags(&m_dd, *m_navMesh, SAMPLE_POLYFLAGS_DISABLED, duRGBA(0, 0, 0, 128)); + duDebugDrawNavMeshPolysWithFlags(&m_debugDraw, *m_navMesh, SAMPLE_POLYFLAGS_DISABLED, duRGBA(0, 0, 0, 128)); } glDepthMask(GL_TRUE); if (m_compactHeightfield && m_drawMode == DrawMode::COMPACT) { - duDebugDrawCompactHeightfieldSolid(&m_dd, *m_compactHeightfield); + duDebugDrawCompactHeightfieldSolid(&m_debugDraw, *m_compactHeightfield); } if (m_compactHeightfield && m_drawMode == DrawMode::COMPACT_DISTANCE) { - duDebugDrawCompactHeightfieldDistance(&m_dd, *m_compactHeightfield); + duDebugDrawCompactHeightfieldDistance(&m_debugDraw, *m_compactHeightfield); } if (m_compactHeightfield && m_drawMode == DrawMode::COMPACT_REGIONS) { - duDebugDrawCompactHeightfieldRegions(&m_dd, *m_compactHeightfield); + duDebugDrawCompactHeightfieldRegions(&m_debugDraw, *m_compactHeightfield); } if (m_heightfield && m_drawMode == DrawMode::VOXELS) { glEnable(GL_FOG); - duDebugDrawHeightfieldSolid(&m_dd, *m_heightfield); + duDebugDrawHeightfieldSolid(&m_debugDraw, *m_heightfield); glDisable(GL_FOG); } if (m_heightfield && m_drawMode == DrawMode::VOXELS_WALKABLE) { glEnable(GL_FOG); - duDebugDrawHeightfieldWalkable(&m_dd, *m_heightfield); + duDebugDrawHeightfieldWalkable(&m_debugDraw, *m_heightfield); glDisable(GL_FOG); } if (m_contourSet && m_drawMode == DrawMode::RAW_CONTOURS) { glDepthMask(GL_FALSE); - duDebugDrawRawContours(&m_dd, *m_contourSet); + duDebugDrawRawContours(&m_debugDraw, *m_contourSet); glDepthMask(GL_TRUE); } if (m_contourSet && m_drawMode == DrawMode::BOTH_CONTOURS) { glDepthMask(GL_FALSE); - duDebugDrawRawContours(&m_dd, *m_contourSet, 0.5f); - duDebugDrawContours(&m_dd, *m_contourSet); + duDebugDrawRawContours(&m_debugDraw, *m_contourSet, 0.5f); + duDebugDrawContours(&m_debugDraw, *m_contourSet); glDepthMask(GL_TRUE); } if (m_contourSet && m_drawMode == DrawMode::CONTOURS) { glDepthMask(GL_FALSE); - duDebugDrawContours(&m_dd, *m_contourSet); + duDebugDrawContours(&m_debugDraw, *m_contourSet); glDepthMask(GL_TRUE); } if (m_compactHeightfield && m_contourSet && m_drawMode == DrawMode::REGION_CONNECTIONS) { - duDebugDrawCompactHeightfieldRegions(&m_dd, *m_compactHeightfield); + duDebugDrawCompactHeightfieldRegions(&m_debugDraw, *m_compactHeightfield); glDepthMask(GL_FALSE); - duDebugDrawRegionConnections(&m_dd, *m_contourSet); + duDebugDrawRegionConnections(&m_debugDraw, *m_contourSet); glDepthMask(GL_TRUE); } if (m_polyMesh && m_drawMode == DrawMode::POLYMESH) { glDepthMask(GL_FALSE); - duDebugDrawPolyMesh(&m_dd, *m_polyMesh); + duDebugDrawPolyMesh(&m_debugDraw, *m_polyMesh); glDepthMask(GL_TRUE); } if (m_detailPolyMesh && m_drawMode == DrawMode::POLYMESH_DETAIL) { glDepthMask(GL_FALSE); - duDebugDrawPolyMeshDetail(&m_dd, *m_detailPolyMesh); + duDebugDrawPolyMeshDetail(&m_debugDraw, *m_detailPolyMesh); glDepthMask(GL_TRUE); } - m_geom->drawConvexVolumes(&m_dd); + m_inputGeometry->drawConvexVolumes(&m_debugDraw); if (m_tool) { @@ -537,9 +537,9 @@ void Sample_TileMesh::handleMeshChanged(InputGeom* geom) bool Sample_TileMesh::handleBuild() { - if (!m_geom || !m_geom->getMesh()) + if (!m_inputGeometry || !m_inputGeometry->getMesh()) { - m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: No vertices and triangles."); + m_buildContext->log(RC_LOG_ERROR, "buildTiledNavigation: No vertices and triangles."); return false; } @@ -548,12 +548,12 @@ bool Sample_TileMesh::handleBuild() m_navMesh = dtAllocNavMesh(); if (!m_navMesh) { - m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not allocate navmesh."); + m_buildContext->log(RC_LOG_ERROR, "buildTiledNavigation: Could not allocate navmesh."); return false; } dtNavMeshParams params; - rcVcopy(params.orig, m_geom->getNavMeshBoundsMin()); + rcVcopy(params.orig, m_inputGeometry->getNavMeshBoundsMin()); params.tileWidth = m_tileSize * m_cellSize; params.tileHeight = m_tileSize * m_cellSize; params.maxTiles = m_maxTiles; @@ -562,14 +562,14 @@ bool Sample_TileMesh::handleBuild() dtStatus status = m_navMesh->init(¶ms); if (dtStatusFailed(status)) { - m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init navmesh."); + m_buildContext->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init navmesh."); return false; } status = m_navQuery->init(m_navMesh, 2048); if (dtStatusFailed(status)) { - m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init Detour navmesh query"); + m_buildContext->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init Detour navmesh query"); return false; } @@ -596,11 +596,11 @@ void Sample_TileMesh::collectSettings(BuildSettings& settings) void Sample_TileMesh::buildTile(const float* pos) { - if (!m_geom) { return; } + if (!m_inputGeometry) { return; } if (!m_navMesh) { return; } - const float* navMeshBoundsMin = m_geom->getNavMeshBoundsMin(); - const float* navMeshBoundsMax = m_geom->getNavMeshBoundsMax(); + const float* navMeshBoundsMin = m_inputGeometry->getNavMeshBoundsMin(); + const float* navMeshBoundsMax = m_inputGeometry->getNavMeshBoundsMax(); const float tileSize = m_tileSize * m_cellSize; const int tileX = static_cast((pos[0] - navMeshBoundsMin[0]) / tileSize); @@ -616,7 +616,7 @@ void Sample_TileMesh::buildTile(const float* pos) m_tileColor = duRGBA(255, 255, 255, 64); - m_ctx->resetLog(); + m_buildContext->resetLog(); int tileMeshDataSize = 0; unsigned char* tileMeshData = buildTileMesh(tileX, tileY, m_lastBuiltTileBoundsMin, m_lastBuiltTileBoundsMax, tileMeshDataSize); @@ -635,14 +635,14 @@ void Sample_TileMesh::buildTile(const float* pos) } } - m_ctx->dumpLog("Build Tile (%d,%d):", tileX, tileY); + m_buildContext->dumpLog("Build Tile (%d,%d):", tileX, tileY); } void Sample_TileMesh::getTilePos(const float* pos, int& tileX, int& tileY) const { - if (!m_geom) { return; } + if (!m_inputGeometry) { return; } - const float* navMeshBoundsMin = m_geom->getNavMeshBoundsMin(); + const float* navMeshBoundsMin = m_inputGeometry->getNavMeshBoundsMin(); const float ts = m_tileSize * m_cellSize; tileX = static_cast((pos[0] - navMeshBoundsMin[0]) / ts); @@ -651,11 +651,11 @@ void Sample_TileMesh::getTilePos(const float* pos, int& tileX, int& tileY) const void Sample_TileMesh::removeTile(const float* pos) { - if (!m_geom) { return; } + if (!m_inputGeometry) { return; } if (!m_navMesh) { return; } - const float* navMeshBoundsMin = m_geom->getNavMeshBoundsMin(); - const float* navmeshBoundsMax = m_geom->getNavMeshBoundsMax(); + const float* navMeshBoundsMin = m_inputGeometry->getNavMeshBoundsMin(); + const float* navmeshBoundsMax = m_inputGeometry->getNavMeshBoundsMax(); const float tileSize = m_tileSize * m_cellSize; const int tileX = static_cast((pos[0] - navMeshBoundsMin[0]) / tileSize); @@ -676,11 +676,11 @@ void Sample_TileMesh::removeTile(const float* pos) void Sample_TileMesh::buildAllTiles() { - if (!m_geom) { return; } + if (!m_inputGeometry) { return; } if (!m_navMesh) { return; } - const float* navMeshBoundsMin = m_geom->getNavMeshBoundsMin(); - const float* navMeshBoundsMax = m_geom->getNavMeshBoundsMax(); + const float* navMeshBoundsMin = m_inputGeometry->getNavMeshBoundsMin(); + const float* navMeshBoundsMax = m_inputGeometry->getNavMeshBoundsMax(); int gridWidth = 0; int gridHeight = 0; rcCalcGridSize(navMeshBoundsMin, navMeshBoundsMax, m_cellSize, &gridWidth, &gridHeight); @@ -690,7 +690,7 @@ void Sample_TileMesh::buildAllTiles() const float tileCellSize = m_tileSize * m_cellSize; // Start the build process. - m_ctx->startTimer(RC_TIMER_TEMP); + m_buildContext->startTimer(RC_TIMER_TEMP); for (int y = 0; y < tileHeight; ++y) { @@ -720,16 +720,16 @@ void Sample_TileMesh::buildAllTiles() } // Record the total build time. - m_ctx->stopTimer(RC_TIMER_TEMP); - m_totalBuildTimeMs = static_cast(m_ctx->getAccumulatedTime(RC_TIMER_TEMP)) / 1000.0f; + m_buildContext->stopTimer(RC_TIMER_TEMP); + m_totalBuildTimeMs = static_cast(m_buildContext->getAccumulatedTime(RC_TIMER_TEMP)) / 1000.0f; } void Sample_TileMesh::removeAllTiles() const { - if (!m_geom || !m_navMesh) { return; } + if (!m_inputGeometry || !m_navMesh) { return; } - const float* navMeshBoundsMin = m_geom->getNavMeshBoundsMin(); - const float* navMeshBoundsMax = m_geom->getNavMeshBoundsMax(); + const float* navMeshBoundsMin = m_inputGeometry->getNavMeshBoundsMin(); + const float* navMeshBoundsMax = m_inputGeometry->getNavMeshBoundsMax(); int gridWidth = 0; int gridHeight = 0; rcCalcGridSize(navMeshBoundsMin, navMeshBoundsMax, m_cellSize, &gridWidth, &gridHeight); @@ -748,9 +748,9 @@ void Sample_TileMesh::removeAllTiles() const unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, const float* boundsMin, const float* boundsMax, int& outDataSize) { - if (!m_geom || !m_geom->getMesh() || !m_geom->getChunkyMesh()) + if (!m_inputGeometry || !m_inputGeometry->getMesh() || !m_inputGeometry->getChunkyMesh()) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Input mesh is not specified."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Input mesh is not specified."); return 0; } @@ -759,10 +759,10 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, cleanup(); - const float* verts = m_geom->getMesh()->getVerts(); - const int numVerts = m_geom->getMesh()->getVertCount(); - const int numTris = m_geom->getMesh()->getTriCount(); - const rcChunkyTriMesh* chunkyMesh = m_geom->getChunkyMesh(); + const float* verts = m_inputGeometry->getMesh()->getVerts(); + const int numVerts = m_inputGeometry->getMesh()->getVertCount(); + const int numTris = m_inputGeometry->getMesh()->getTriCount(); + const rcChunkyTriMesh* chunkyMesh = m_inputGeometry->getChunkyMesh(); // Init build configuration from GUI memset(&m_config, 0, sizeof(m_config)); @@ -813,25 +813,25 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, m_config.bmax[2] += static_cast(m_config.borderSize) * m_config.cs; // Reset build times gathering. - m_ctx->resetTimers(); + m_buildContext->resetTimers(); // Start the build process. - m_ctx->startTimer(RC_TIMER_TOTAL); + m_buildContext->startTimer(RC_TIMER_TOTAL); - m_ctx->log(RC_LOG_PROGRESS, "Building navigation:"); - m_ctx->log(RC_LOG_PROGRESS, " - %d x %d cells", m_config.width, m_config.height); - m_ctx->log(RC_LOG_PROGRESS, " - %.1fK verts, %.1fK tris", static_cast(numVerts) / 1000.0f, static_cast(numTris) / 1000.0f); + m_buildContext->log(RC_LOG_PROGRESS, "Building navigation:"); + m_buildContext->log(RC_LOG_PROGRESS, " - %d x %d cells", m_config.width, m_config.height); + m_buildContext->log(RC_LOG_PROGRESS, " - %.1fK verts, %.1fK tris", static_cast(numVerts) / 1000.0f, static_cast(numTris) / 1000.0f); // Allocate voxel heightfield where we rasterize our input data to. m_heightfield = rcAllocHeightfield(); if (!m_heightfield) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'solid'."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'solid'."); return 0; } - if (!rcCreateHeightfield(m_ctx, *m_heightfield, m_config.width, m_config.height, m_config.bmin, m_config.bmax, m_config.cs, m_config.ch)) + if (!rcCreateHeightfield(m_buildContext, *m_heightfield, m_config.width, m_config.height, m_config.bmin, m_config.bmax, m_config.cs, m_config.ch)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not create solid heightfield."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not create solid heightfield."); return 0; } @@ -841,7 +841,7 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, m_triareas = new unsigned char[chunkyMesh->maxTrisPerChunk]; if (!m_triareas) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'm_triareas' (%d).", chunkyMesh->maxTrisPerChunk); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'm_triareas' (%d).", chunkyMesh->maxTrisPerChunk); return 0; } @@ -869,9 +869,9 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, m_tileTriCount += numNodeTris; memset(m_triareas, 0, numNodeTris * sizeof(unsigned char)); - rcMarkWalkableTriangles(m_ctx, m_config.walkableSlopeAngle, verts, numVerts, nodeTris, numNodeTris, m_triareas); + rcMarkWalkableTriangles(m_buildContext, m_config.walkableSlopeAngle, verts, numVerts, nodeTris, numNodeTris, m_triareas); - if (!rcRasterizeTriangles(m_ctx, verts, numVerts, nodeTris, m_triareas, numNodeTris, *m_heightfield, m_config.walkableClimb)) + if (!rcRasterizeTriangles(m_buildContext, verts, numVerts, nodeTris, m_triareas, numNodeTris, *m_heightfield, m_config.walkableClimb)) { return 0; } @@ -887,15 +887,15 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, // as well as filter spans where the character cannot possibly stand. if (m_filterLowHangingObstacles) { - rcFilterLowHangingWalkableObstacles(m_ctx, m_config.walkableClimb, *m_heightfield); + rcFilterLowHangingWalkableObstacles(m_buildContext, m_config.walkableClimb, *m_heightfield); } if (m_filterLedgeSpans) { - rcFilterLedgeSpans(m_ctx, m_config.walkableHeight, m_config.walkableClimb, *m_heightfield); + rcFilterLedgeSpans(m_buildContext, m_config.walkableHeight, m_config.walkableClimb, *m_heightfield); } if (m_filterWalkableLowHeightSpans) { - rcFilterWalkableLowHeightSpans(m_ctx, m_config.walkableHeight, *m_heightfield); + rcFilterWalkableLowHeightSpans(m_buildContext, m_config.walkableHeight, *m_heightfield); } // Compact the heightfield so that it is faster to handle from now on. @@ -904,12 +904,12 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, m_compactHeightfield = rcAllocCompactHeightfield(); if (!m_compactHeightfield) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'chf'."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'chf'."); return 0; } - if (!rcBuildCompactHeightfield(m_ctx, m_config.walkableHeight, m_config.walkableClimb, *m_heightfield, *m_compactHeightfield)) + if (!rcBuildCompactHeightfield(m_buildContext, m_config.walkableHeight, m_config.walkableClimb, *m_heightfield, *m_compactHeightfield)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build compact data."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not build compact data."); return 0; } @@ -920,17 +920,17 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, } // Erode the walkable area by agent radius. - if (!rcErodeWalkableArea(m_ctx, m_config.walkableRadius, *m_compactHeightfield)) + if (!rcErodeWalkableArea(m_buildContext, m_config.walkableRadius, *m_compactHeightfield)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not erode."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not erode."); return 0; } // (Optional) Mark areas. - const ConvexVolume* convexVolumes = m_geom->getConvexVolumes(); - for (int i = 0; i < m_geom->getConvexVolumeCount(); ++i) + const ConvexVolume* convexVolumes = m_inputGeometry->getConvexVolumes(); + for (int i = 0; i < m_inputGeometry->getConvexVolumeCount(); ++i) { - rcMarkConvexPolyArea(m_ctx, convexVolumes[i].verts, convexVolumes[i].nverts, convexVolumes[i].hmin, convexVolumes[i].hmax, static_cast(convexVolumes[i].area), *m_compactHeightfield); + rcMarkConvexPolyArea(m_buildContext, convexVolumes[i].verts, convexVolumes[i].nverts, convexVolumes[i].hmin, convexVolumes[i].hmax, static_cast(convexVolumes[i].area), *m_compactHeightfield); } // Partition the heightfield so that we can use simple algorithm later to triangulate the walkable areas. @@ -962,16 +962,16 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, if (m_partitionType == SAMPLE_PARTITION_WATERSHED) { // Prepare for region partitioning, by calculating distance field along the walkable surface. - if (!rcBuildDistanceField(m_ctx, *m_compactHeightfield)) + if (!rcBuildDistanceField(m_buildContext, *m_compactHeightfield)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build distance field."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not build distance field."); return 0; } // Partition the walkable surface into simple regions without holes. - if (!rcBuildRegions(m_ctx, *m_compactHeightfield, m_config.borderSize, m_config.minRegionArea, m_config.mergeRegionArea)) + if (!rcBuildRegions(m_buildContext, *m_compactHeightfield, m_config.borderSize, m_config.minRegionArea, m_config.mergeRegionArea)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build watershed regions."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not build watershed regions."); return 0; } } @@ -979,18 +979,18 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, { // Partition the walkable surface into simple regions without holes. // Monotone partitioning does not need distancefield. - if (!rcBuildRegionsMonotone(m_ctx, *m_compactHeightfield, m_config.borderSize, m_config.minRegionArea, m_config.mergeRegionArea)) + if (!rcBuildRegionsMonotone(m_buildContext, *m_compactHeightfield, m_config.borderSize, m_config.minRegionArea, m_config.mergeRegionArea)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build monotone regions."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not build monotone regions."); return 0; } } else // SAMPLE_PARTITION_LAYERS { // Partition the walkable surface into simple regions without holes. - if (!rcBuildLayerRegions(m_ctx, *m_compactHeightfield, m_config.borderSize, m_config.minRegionArea)) + if (!rcBuildLayerRegions(m_buildContext, *m_compactHeightfield, m_config.borderSize, m_config.minRegionArea)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build layer regions."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not build layer regions."); return 0; } } @@ -999,12 +999,12 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, m_contourSet = rcAllocContourSet(); if (!m_contourSet) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'cset'."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'cset'."); return 0; } - if (!rcBuildContours(m_ctx, *m_compactHeightfield, m_config.maxSimplificationError, m_config.maxEdgeLen, *m_contourSet)) + if (!rcBuildContours(m_buildContext, *m_compactHeightfield, m_config.maxSimplificationError, m_config.maxEdgeLen, *m_contourSet)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not create contours."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not create contours."); return 0; } @@ -1017,12 +1017,12 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, m_polyMesh = rcAllocPolyMesh(); if (!m_polyMesh) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'pmesh'."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'pmesh'."); return 0; } - if (!rcBuildPolyMesh(m_ctx, *m_contourSet, m_config.maxVertsPerPoly, *m_polyMesh)) + if (!rcBuildPolyMesh(m_buildContext, *m_contourSet, m_config.maxVertsPerPoly, *m_polyMesh)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not triangulate contours."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not triangulate contours."); return 0; } @@ -1030,13 +1030,13 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, m_detailPolyMesh = rcAllocPolyMeshDetail(); if (!m_detailPolyMesh) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'dmesh'."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'dmesh'."); return 0; } - if (!rcBuildPolyMeshDetail(m_ctx, *m_polyMesh, *m_compactHeightfield, m_config.detailSampleDist, m_config.detailSampleMaxError, *m_detailPolyMesh)) + if (!rcBuildPolyMeshDetail(m_buildContext, *m_polyMesh, *m_compactHeightfield, m_config.detailSampleDist, m_config.detailSampleMaxError, *m_detailPolyMesh)) { - m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could build polymesh detail."); + m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could build polymesh detail."); return 0; } @@ -1053,7 +1053,7 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, if (m_polyMesh->nverts >= 0xffff) { // The vertex indices are ushorts, and cannot point to more than 0xffff vertices. - m_ctx->log(RC_LOG_ERROR, "Too many vertices per tile %d (max: %d).", m_polyMesh->nverts, 0xffff); + m_buildContext->log(RC_LOG_ERROR, "Too many vertices per tile %d (max: %d).", m_polyMesh->nverts, 0xffff); return 0; } @@ -1095,13 +1095,13 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, params.detailVertsCount = m_detailPolyMesh->nverts; params.detailTris = m_detailPolyMesh->tris; params.detailTriCount = m_detailPolyMesh->ntris; - params.offMeshConVerts = m_geom->getOffMeshConnectionVerts(); - params.offMeshConRad = m_geom->getOffMeshConnectionRads(); - params.offMeshConDir = m_geom->getOffMeshConnectionDirs(); - params.offMeshConAreas = m_geom->getOffMeshConnectionAreas(); - params.offMeshConFlags = m_geom->getOffMeshConnectionFlags(); - params.offMeshConUserID = m_geom->getOffMeshConnectionId(); - params.offMeshConCount = m_geom->getOffMeshConnectionCount(); + params.offMeshConVerts = m_inputGeometry->getOffMeshConnectionVerts(); + params.offMeshConRad = m_inputGeometry->getOffMeshConnectionRads(); + params.offMeshConDir = m_inputGeometry->getOffMeshConnectionDirs(); + params.offMeshConAreas = m_inputGeometry->getOffMeshConnectionAreas(); + params.offMeshConFlags = m_inputGeometry->getOffMeshConnectionFlags(); + params.offMeshConUserID = m_inputGeometry->getOffMeshConnectionId(); + params.offMeshConCount = m_inputGeometry->getOffMeshConnectionCount(); params.walkableHeight = m_agentHeight; params.walkableRadius = m_agentRadius; params.walkableClimb = m_agentMaxClimb; @@ -1116,19 +1116,19 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tileX, const int tileY, if (!dtCreateNavMeshData(¶ms, &navData, &navDataSize)) { - m_ctx->log(RC_LOG_ERROR, "Could not build Detour navmesh."); + m_buildContext->log(RC_LOG_ERROR, "Could not build Detour navmesh."); return 0; } } m_tileMemUsage = static_cast(navDataSize) / 1024.0f; - m_ctx->stopTimer(RC_TIMER_TOTAL); + m_buildContext->stopTimer(RC_TIMER_TOTAL); // Show performance stats. - duLogBuildTimes(*m_ctx, m_ctx->getAccumulatedTime(RC_TIMER_TOTAL)); - m_ctx->log(RC_LOG_PROGRESS, ">> Polymesh: %d vertices %d polygons", m_polyMesh->nverts, m_polyMesh->npolys); + duLogBuildTimes(*m_buildContext, m_buildContext->getAccumulatedTime(RC_TIMER_TOTAL)); + m_buildContext->log(RC_LOG_PROGRESS, ">> Polymesh: %d vertices %d polygons", m_polyMesh->nverts, m_polyMesh->npolys); - m_tileBuildTime = static_cast(m_ctx->getAccumulatedTime(RC_TIMER_TOTAL)) / 1000.0f; + m_tileBuildTime = static_cast(m_buildContext->getAccumulatedTime(RC_TIMER_TOTAL)) / 1000.0f; outDataSize = navDataSize; return navData;