From f04dc6a112f3cdb137aaa94c3c3fa92044b15101 Mon Sep 17 00:00:00 2001 From: Danny Bierek Date: Thu, 19 Sep 2024 00:40:03 -0700 Subject: [PATCH] Updated default recast navmesh settings, removed blender default cube, fixed logging issue --- bin/NavKit.ini | 2 +- bin/glacier2obj.py | 119 +++++++++++++++++++------------------- include/NavKit/NavKit.h | 12 ++-- src/GameConnection.cpp | 2 +- src/NavKit.cpp | 11 +--- src/Navp.cpp | 6 +- src/Obj.cpp | 4 +- src/RecastDemo/Sample.cpp | 12 ++-- src/Renderer.cpp | 4 +- src/SceneExtract.cpp | 46 ++++++++++----- 10 files changed, 118 insertions(+), 100 deletions(-) diff --git a/bin/NavKit.ini b/bin/NavKit.ini index 0762ecd..2707a62 100644 --- a/bin/NavKit.ini +++ b/bin/NavKit.ini @@ -1,4 +1,4 @@ [Paths] hitman=C:\Program Files (x86)\Steam\steamapps\common\HITMAN 3 output=D:\workspace\NavKit\output -blender=C:\Program Files\Blender Foundation\Blender 3.4 \ No newline at end of file +blender=C:\Program Files\Blender Foundation\Blender 3.4\blender.exe \ No newline at end of file diff --git a/bin/glacier2obj.py b/bin/glacier2obj.py index d795acb..058bd66 100644 --- a/bin/glacier2obj.py +++ b/bin/glacier2obj.py @@ -1283,65 +1283,65 @@ def load_scenario(context, collection, path_to_alocs_json, path_to_pf_boxes_json cur.location = mathutils.Vector((p["x"], p["y"], p["z"])) cur.select_set(False) - - print("Creating PF Box") - mesh = bpy.data.meshes.new("PF_BOX") - pb_box_obj = bpy.data.objects.new("PF_BOX", mesh) - bm = bmesh.new() - bmv = [] - x = 0 - y = 0 - z = 0 - sx = .5 - sy = .5 - sz = .5 - vertices = [ - [x + sx, y + sy, z - sz], - [x + sx, y - sy, z - sz], - [x - sx, y - sy, z - sz], - [x - sx, y + sy, z - sz], - [x + sx, y + sy, z + sz], - [x + sx, y - sy, z + sz], - [x - sx, y - sy, z + sz], - [x - sx, y + sy, z + sz] - ] - for v in vertices: - bmv.append(bm.verts.new(v)) - bm.faces.new((bmv[0], bmv[1], bmv[2], bmv[3])) # bottom - bm.faces.new((bmv[4], bmv[5], bmv[6], bmv[7])) # top - bm.faces.new((bmv[0], bmv[1], bmv[5], bmv[4])) # right - bm.faces.new((bmv[2], bmv[3], bmv[7], bmv[6])) - bm.faces.new((bmv[0], bmv[3], bmv[7], bmv[4])) - bm.faces.new((bmv[1], bmv[2], bmv[6], bmv[5])) - mesh = pb_box_obj.data - bm.to_mesh(mesh) - pb_box_obj.data = mesh - bm.free() - t_size = len(pf_transforms) - for i in range(0, t_size): - transform = pf_transforms[i] - p = transform["position"] - r = transform["rotate"] - s = transform["scale"] - # print("Transforming pf box:" + " #" + str(i)) - - if i != 0: - cur = pb_box_obj.copy() - else: - cur = pb_box_obj - collection.objects.link(cur) - cur.select_set(True) - cur.scale = mathutils.Vector((s["x"], s["y"], s["z"])) - cur.rotation_mode = 'QUATERNION' - cur.rotation_quaternion = (r["w"], r["x"], r["y"], r["z"]) - cur.location = mathutils.Vector((p["x"], p["y"], p["z"])) - cur.select_set(False) + if len(pf_transforms) > 0: + print("Creating PF Box") + mesh = bpy.data.meshes.new("PF_BOX") + pb_box_obj = bpy.data.objects.new("PF_BOX", mesh) + bm = bmesh.new() + bmv = [] + x = 0 + y = 0 + z = 0 + sx = .5 + sy = .5 + sz = .5 + vertices = [ + [x + sx, y + sy, z - sz], + [x + sx, y - sy, z - sz], + [x - sx, y - sy, z - sz], + [x - sx, y + sy, z - sz], + [x + sx, y + sy, z + sz], + [x + sx, y - sy, z + sz], + [x - sx, y - sy, z + sz], + [x - sx, y + sy, z + sz] + ] + for v in vertices: + bmv.append(bm.verts.new(v)) + bm.faces.new((bmv[0], bmv[1], bmv[2], bmv[3])) # bottom + bm.faces.new((bmv[4], bmv[5], bmv[6], bmv[7])) # top + bm.faces.new((bmv[0], bmv[1], bmv[5], bmv[4])) # right + bm.faces.new((bmv[2], bmv[3], bmv[7], bmv[6])) + bm.faces.new((bmv[0], bmv[3], bmv[7], bmv[4])) + bm.faces.new((bmv[1], bmv[2], bmv[6], bmv[5])) + mesh = pb_box_obj.data + bm.to_mesh(mesh) + pb_box_obj.data = mesh + bm.free() + t_size = len(pf_transforms) + for i in range(0, t_size): + transform = pf_transforms[i] + p = transform["position"] + r = transform["rotate"] + s = transform["scale"] + # print("Transforming pf box:" + " #" + str(i)) + + if i != 0: + cur = pb_box_obj.copy() + else: + cur = pb_box_obj + collection.objects.link(cur) + cur.select_set(True) + cur.scale = mathutils.Vector((s["x"], s["y"], s["z"])) + cur.rotation_mode = 'QUATERNION' + cur.rotation_quaternion = (r["w"], r["x"], r["y"], r["z"]) + cur.location = mathutils.Vector((p["x"], p["y"], p["z"])) + cur.select_set(False) + # print("PfBox Exclusion entity ids:") + # print("[") + # for pf_box in pf_transforms: + # print(" \"" + pf_box["id"] + "\",") + # print("]") end = timer() - # print("PfBox Exclusion entity ids:") - # print("[") - # for pf_box in pf_transforms: - # print(" \"" + pf_box["id"] + "\",") - # print("]") print("Finished loading scenario in " + str(end - start) + " seconds.") return 0 @@ -1354,6 +1354,9 @@ def main(): alocs_path = argv[0] pf_boxes_path = argv[1] output_path = argv[2] + bpy.ops.object.select_all(action='SELECT') + bpy.ops.object.delete() + collection = bpy.data.collections.new( bpy.path.display_name_from_filepath(alocs_path) ) diff --git a/include/NavKit/NavKit.h b/include/NavKit/NavKit.h index ac7a33c..d00e98f 100644 --- a/include/NavKit/NavKit.h +++ b/include/NavKit/NavKit.h @@ -88,15 +88,13 @@ class NavKit { InputGeom* geom; DebugDrawGL m_dd; + CSimpleIniA ini; + int runProgram(int argc, char** argv); void log(rcLogCategory category, const char* message, ...); private: - int hitTest(BuildContext* ctx, NavPower::NavMesh* navMesh, int mx, int my, int width, int height); - rsj::ConcurrentQueue> logQueue; - void loadSettings(); + rsj::ConcurrentQueue> logQueue; + void loadSettings(); - static void logRunner(NavKit* navKit); - - CSimpleIniA ini; + static void logRunner(NavKit* navKit); }; - diff --git a/src/GameConnection.cpp b/src/GameConnection.cpp index bc3cb0e..09c29a6 100644 --- a/src/GameConnection.cpp +++ b/src/GameConnection.cpp @@ -39,7 +39,7 @@ void GameConnection::HandleMessages() { WebSocket::pointer wsp = &*ws; ws->poll(); ws->dispatch([&](const std::string& message) { - navKit->log(RC_LOG_PROGRESS, "Received message: %s", message.c_str()); + navKit->log(RC_LOG_PROGRESS, ("Received message: " + message).c_str()); if (message == "Done loading Navp.") { wsp->close(); } diff --git a/src/NavKit.cpp b/src/NavKit.cpp index 5f9ce2d..ecd3069 100644 --- a/src/NavKit.cpp +++ b/src/NavKit.cpp @@ -65,22 +65,17 @@ void NavKit::log(rcLogCategory category, const char* message, ...) { void NavKit::logRunner(NavKit* navKit) { std::optional> message; while (true) { - while (!navKit->logQueue.empty()) { - message = navKit->logQueue.try_pop(); - if (message.has_value()) { - navKit->ctx.log(message.value().first, message.value().second.c_str()); - } + message = navKit->logQueue.try_pop(); + if (message.has_value()) { + navKit->ctx.log(message.value().first, message.value().second.c_str()); } } } void NavKit::loadSettings() { sceneExtract->setHitmanFolder(ini.GetValue("Paths", "hitman", "default")); - log(rcLogCategory::RC_LOG_PROGRESS, sceneExtract->lastHitmanFolder.c_str()); sceneExtract->setOutputFolder(ini.GetValue("Paths", "output", "default")); - log(rcLogCategory::RC_LOG_PROGRESS, sceneExtract->lastOutputFolder.c_str()); sceneExtract->setBlenderFile(ini.GetValue("Paths", "blender", "default")); - log(rcLogCategory::RC_LOG_PROGRESS, sceneExtract->lastBlenderFile.c_str()); } NavKit::NavKit() { diff --git a/src/Navp.cpp b/src/Navp.cpp index 6fff5f7..1750b14 100644 --- a/src/Navp.cpp +++ b/src/Navp.cpp @@ -79,7 +79,7 @@ void Navp::setSelectedNavpAreaIndex(int index) { if (index != -1 && index < navMesh->m_areas.size()) { int edgeIndex = 0; for (auto edge : navMesh->m_areas[index].m_edges) { - navKit->log(RC_LOG_PROGRESS, "Vertex / Edge: %d Flags: %d", edgeIndex, edge->m_flags2); + navKit->log(RC_LOG_PROGRESS, ("Vertex / Edge: " + std::to_string(edgeIndex) + " Flags: " + std::to_string(edge->m_flags2)).c_str()); edgeIndex++; } } @@ -221,6 +221,7 @@ void Navp::drawMenu() { else if (extension == "NAVP") { OutputNavMesh_NAVP_Write(navMesh, lastSaveNavpFile.data()); } + navKit->log(RC_LOG_PROGRESS, "Done saving Navp."); } } imguiLabel("Send Navp to game"); @@ -241,7 +242,8 @@ void Navp::drawMenu() { selectedNavpAreaIndex != -1)) { if (selectedNavpAreaIndex != -1) { NavPower::AreaUsageFlags newType = (navMesh->m_areas[selectedNavpAreaIndex].m_area->m_usageFlags == NavPower::AreaUsageFlags::AREA_STEPS) ? NavPower::AreaUsageFlags::AREA_FLAT : NavPower::AreaUsageFlags::AREA_STEPS; - navKit->log(RC_LOG_PROGRESS, "Setting area type to: %d", newType); + std::string newTypeString = (navMesh->m_areas[selectedNavpAreaIndex].m_area->m_usageFlags == NavPower::AreaUsageFlags::AREA_STEPS) ? "AREA_FLAT" : "AREA_STEPS"; + navKit->log(RC_LOG_PROGRESS, ("Setting area type to: " + newTypeString).c_str()); navMesh->m_areas[selectedNavpAreaIndex].m_area->m_usageFlags = newType; } } diff --git a/src/Obj.cpp b/src/Obj.cpp index 8b6a500..34f0b1e 100644 --- a/src/Obj.cpp +++ b/src/Obj.cpp @@ -16,7 +16,7 @@ Obj::Obj(NavKit* navKit): navKit(navKit) { bBoxSize[0] = 600; bBoxSize[1] = 600; bBoxSize[2] = 600; - navKit->log(RC_LOG_PROGRESS, "Setting bbox to (%f, %f, %f) (%f, %f, %f)", bBoxPos[0], bBoxPos[1], bBoxPos[2], bBoxSize[0], bBoxSize[1], bBoxSize[2]); + navKit->log(RC_LOG_PROGRESS, ("Setting bbox to (" + std::to_string(bBoxPos[0]) + ", " + std::to_string(bBoxPos[1]) + ", " + std::to_string(bBoxPos[2]) + ") (" + std::to_string(bBoxSize[0]) + ", " + std::to_string(bBoxSize[1]) + ", " + std::to_string(bBoxSize[2]) + ")").c_str()); } @@ -65,7 +65,7 @@ void Obj::loadObjMesh(Obj* obj) { obj->navKit->geom->m_meshBMax[0] = obj->bBoxPos[0] + obj->bBoxSize[0] / 2; obj->navKit->geom->m_meshBMax[1] = obj->bBoxPos[1] + obj->bBoxSize[1] / 2; obj->navKit->geom->m_meshBMax[2] = obj->bBoxPos[2] + obj->bBoxSize[2] / 2; - obj->navKit->log(RC_LOG_PROGRESS, "Setting bbox to (%f, %f, %f) (%f, %f, %f)", obj->bBoxPos[0], obj->bBoxPos[1], obj->bBoxPos[2], obj->bBoxSize[0], obj->bBoxSize[1], obj->bBoxSize[2]); + obj->navKit->log(RC_LOG_PROGRESS, ("Setting bbox to (" + std::to_string(obj->bBoxPos[0]) + ", " + std::to_string(obj->bBoxPos[1]) + ", " + std::to_string(obj->bBoxPos[2]) + ") (" + std::to_string(obj->bBoxSize[0]) + ", " + std::to_string(obj->bBoxSize[1]) + ", " + std::to_string(obj->bBoxSize[2]) + ")").c_str()); obj->objLoadDone.push_back(true); auto end = std::chrono::high_resolution_clock::now(); diff --git a/src/RecastDemo/Sample.cpp b/src/RecastDemo/Sample.cpp index 549fcba..ef90978 100644 --- a/src/RecastDemo/Sample.cpp +++ b/src/RecastDemo/Sample.cpp @@ -179,13 +179,13 @@ void Sample::collectSettings(BuildSettings& settings) void Sample::resetCommonSettings() { m_cellSize = 0.1f; - m_cellHeight = 0.2f; - m_agentHeight = 2.0f; - m_agentRadius = 0.01f; + m_cellHeight = 0.1f; + m_agentHeight = 1.8f; + m_agentRadius = 0.2f; m_agentMaxClimb = 0.3f; m_agentMaxSlope = 45.0f; - m_regionMinSize = 0; - m_regionMergeSize = 0; + m_regionMinSize = 30; + m_regionMergeSize = 30; m_edgeMaxLen = 500.0f; m_edgeMaxError = 1.4f; m_vertsPerPoly = 6.0f; @@ -198,7 +198,7 @@ void Sample::handleCommonSettings() { imguiLabel("Rasterization"); imguiSlider("Cell Size", &m_cellSize, 0.1f, 1.0f, 0.01f); - imguiSlider("Cell Height", &m_cellHeight, 0.1f, 1.0f, 0.01f); + imguiSlider("Cell Height", &m_cellHeight, 0.01f, 1.0f, 0.01f); imguiSeparator(); imguiLabel("Agent"); diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 5d8f098..bbb39d5 100644 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -202,7 +202,7 @@ int Renderer::hitTestRender(int mx, int my) { GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { - navKit->log(RC_LOG_ERROR, "FB error, status: 0x%x", status); + navKit->log(RC_LOG_ERROR, ("FB error, status: 0x" + std::to_string((int)status)).c_str()); printf("FB error, status: 0x%x\n", status); return -1; @@ -218,6 +218,6 @@ int Renderer::hitTestRender(int mx, int my) { navKit->log(RC_LOG_PROGRESS, "Deselected area."); return -1; } - navKit->log(RC_LOG_PROGRESS, "Selected area: %d", selectedArea); + navKit->log(RC_LOG_PROGRESS, ("Selected area: " + std::to_string(selectedArea)).c_str()); return selectedArea; } \ No newline at end of file diff --git a/src/SceneExtract.cpp b/src/SceneExtract.cpp index 55d6963..40ee8cf 100644 --- a/src/SceneExtract.cpp +++ b/src/SceneExtract.cpp @@ -16,25 +16,45 @@ SceneExtract::SceneExtract(NavKit* navKit): navKit(navKit) { } void SceneExtract::setHitmanFolder(const char* folderName) { - hitmanSet = true; - lastHitmanFolder = folderName; - hitmanFolderName = folderName; - hitmanFolderName = hitmanFolderName.substr(hitmanFolderName.find_last_of("/\\") + 1); - + if (std::filesystem::exists(folderName) && std::filesystem::is_directory(folderName)) { + hitmanSet = true; + lastHitmanFolder = folderName; + hitmanFolderName = folderName; + hitmanFolderName = hitmanFolderName.substr(hitmanFolderName.find_last_of("/\\") + 1); + navKit->log(rcLogCategory::RC_LOG_PROGRESS, ("Setting Hitman folder to: " + lastHitmanFolder).c_str()); + navKit->ini.SetValue("Paths", "hitman", folderName); + navKit->ini.SaveFile("NavKit.ini"); + } else { + navKit->log(rcLogCategory::RC_LOG_WARNING, ("Could not find Hitman folder: " + lastHitmanFolder).c_str()); + } } void SceneExtract::setOutputFolder(const char* folderName) { - outputSet = true; - lastOutputFolder = folderName; - outputFolderName = folderName; - outputFolderName = outputFolderName.substr(outputFolderName.find_last_of("/\\") + 1); + if (std::filesystem::exists(folderName) && std::filesystem::is_directory(folderName)) { + outputSet = true; + lastOutputFolder = folderName; + outputFolderName = folderName; + outputFolderName = outputFolderName.substr(outputFolderName.find_last_of("/\\") + 1); + navKit->log(rcLogCategory::RC_LOG_PROGRESS, ("Setting output folder to: " + lastOutputFolder).c_str()); + navKit->ini.SetValue("Paths", "output", folderName); + navKit->ini.SaveFile("NavKit.ini"); + } else { + navKit->log(rcLogCategory::RC_LOG_WARNING, ("Could not find output folder: " + lastOutputFolder).c_str()); + } } void SceneExtract::setBlenderFile(const char* filename) { - blenderSet = true; - lastBlenderFile = filename; - blenderName = filename; - blenderName = blenderName.substr(blenderName.find_last_of("/\\") + 1); + if (std::filesystem::exists(filename) && !std::filesystem::is_directory(filename)) { + blenderSet = true; + lastBlenderFile = filename; + blenderName = filename; + blenderName = blenderName.substr(blenderName.find_last_of("/\\") + 1); + navKit->log(rcLogCategory::RC_LOG_PROGRESS, ("Setting Blender exe to: " + lastBlenderFile).c_str()); + navKit->ini.SetValue("Paths", "blender", filename); + navKit->ini.SaveFile("NavKit.ini"); + } else { + navKit->log(rcLogCategory::RC_LOG_WARNING, ("Could not find Blender exe: " + lastBlenderFile).c_str()); + } } void SceneExtract::drawMenu() {