bool VictoriaPhysics::handleBuild(const std::vector<float>& combinedVerts, const…
- User
bool VictoriaPhysics::handleBuild(const std::vector& combinedVerts, const std::vector& combinedTris) { std::vector swappedVerts; swappedVerts.reserve(combinedVerts.size()); for (size_t i = 0; i < combinedVerts.size(); i += 3) { swappedVerts.push_back(combinedVerts[i]); // X swappedVerts.push_back(combinedVerts[i + 2]); // Z becomes Y swappedVerts.push_back(combinedVerts[i + 1]); // Y becomes Z } rcContext* m_ctx = new BuildContext(); // Step 1. Initialize build config rcConfig m_cfg; memset(&m_cfg, 0, sizeof(m_cfg)); // Set cell size and height m_cfg.cs = 1.0f; // Increase cell size m_cfg.ch = 0.5f; // Increase cell height // Agent properties m_cfg.walkableSlopeAngle = 45.0f; // Maximum slope angle (in degrees) m_cfg.walkableHeight = (int)ceilf(3.0f / m_cfg.ch); m_cfg.walkableClimb = (int)floorf(1.5f / m_cfg.ch); m_cfg.walkableRadius = (int)ceilf(1.0f / m_cfg.cs); // Region properties m_cfg.minRegionArea = (int)rcSqr(8); // Minimum region size of 8x8 cells m_cfg.mergeRegionArea = (int)rcSqr(20); // Merge regions smaller than 20x20 cells // Polygonization properties m_cfg.maxEdgeLen = (int)(12 / m_cfg.cs); // Maximum edge length of 12 meters m_cfg.maxSimplificationError = 1.3f; // Maximum distance error for simplification m_cfg.maxVertsPerPoly = 12; // Maximum vertices per polygon // Detail mesh properties m_cfg.detailSampleDist = m_cfg.cs * 6.0f; // Sample distance for detail mesh m_cfg.detailSampleMaxError = m_cfg.ch * 1.0f; // Maximum error for detail mesh sampling // Calculate bounds float bmin[3], bmax[3]; rcCalcBounds(swappedVerts.data(), swappedVerts.size() / 3, bmin, bmax); rcVcopy(m_cfg.bmin, bmin); rcVcopy(m_cfg.bmax, bmax); rcCalcGridSize(m_cfg.bmin, m_cfg.bmax, m_cfg.cs, &m_cfg.width, &m_cfg.height); // Step 2. Rasterize input polygon soup rcHeightfield* m_solid = rcAllocHeightfield(); if (!m_solid) { m_ctx->log(RC_LOG_ERROR, "handleBuild: Out of memory 'solid'."); return false; } if (!rcCreateHeightfield(m_ctx, m_solid, m_cfg.width, m_cfg.height, m_cfg.bmin, m_cfg.bmax, m_cfg.cs, m_cfg.ch)) { m_ctx->log(RC_LOG_ERROR, "handleBuild: Could not create solid heightfield."); return false; } unsigned char m_triareas = new unsigned char[combinedTris.size() / 3]; if (!m_triareas) { m_ctx->log(RC_LOG_ERROR, "handleBuild: Out of memory 'm_triareas' (%d).", combinedTris.size() / 3); return false; } memset(m_triareas, 0, combinedTris.size() / 3 * sizeof(unsigned char)); rcMarkWalkableTriangles(m_ctx, m_cfg.walkableSlopeAngle, swappedVerts.data(), swappedVerts.size() / 3, combinedTris.data(), combinedTris.size() / 3, m_triareas); rcRasterizeTriangles(m_ctx, swappedVerts.data(), swappedVerts.size() / 3, combinedTris.data(), m_triareas, combinedTris.size() / 3, *m_solid, m_cfg.walkableClimb); delete[] m_triareas; // Step 3. Filter walkable surfaces rcFilterLowHangingWalkableObstacles(m_ctx, m_cfg.walkableClimb, *m_solid); rcFilterLedgeSpans(m_ctx, m_cfg.walkableHeight, m_cfg.walkableClimb, *m_solid); rcFilterWalkableLowHeightSpans(m_ctx, m_cfg.walkableHeight, m_solid); // Step 4. Partition walkable surface to simple regions rcCompactHeightfield m_chf = rcAllocCompactHeightfield(); if (!m_chf) { m_ctx->log(RC_LOG_ERROR, "handleBuild: Out of memory 'chf'."); return false; } if (!rcBuildCompactHeightfield(m_ctx, m_cfg.walkableHeight, m_cfg.walkableClimb, *m_solid, *m_chf)) { m_ctx->log(RC_LOG_ERROR, "handleBuild: Could not build compact data."); return false; } rcFreeHeightField(m_solid); m_solid = 0; if (!rcErodeWalkableArea(m_ctx, m_cfg.walkableRadius, *m_chf)) { m_ctx->log(RC_LOG_ERROR, "handleBuild: Could not erode."); return false; } if (!rcBuildDistanceField(m_ctx, *m_chf)) { m_ctx->log(RC_LOG_ERROR, "handleBuild: Could not build distance field."); return false; } if (!rcBuildRegions(m_ctx, m_cset = rcAllocContourSet(); if (!m_cset) { m_ctx->log(RC_LOG_ERROR, "handleBuild: Out of memory 'cset'."); return false; } if (!rcBuildContours(m_ctx, *m_chf, m_cfg.maxSimplificationError, m_cfg.maxEdgeLen, m_pmesh = rcAllocPolyMesh(); if (!m_pmesh) { m_ctx->log(RC_LOG_ERROR, "handleBuild: Out of memory 'pmesh'."); return false; } if (!rcBuildPolyMesh(m_ctx, *m_cset, m_cfg.maxVertsPerPoly, m_dmesh = rcAllocPolyMeshDetail(); if (!m_dmesh) { m_ctx->log(RC_LOG_ERROR, "handleBuild: Out of memory 'pmdtl'."); return false; } if (!rcBuildPolyMeshDetail(m_ctx, *m_pmesh, m_navQuery = dtAllocNavMeshQuery(); status = m_navQuery->init(m_navMesh, 2048); if (dtStatusFailed(status)) { m_ctx->log(RC_LOG_ERROR, "Could not init Detour navmesh query"); return false; } m_ctx->log(RC_LOG_PROGRESS, "NavMesh created successfully."); delete m_ctx; return true; }. Why i got Could not build Detour navmesh. Params: verts=0, polys=0 ?
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.