Skip to content

Commit

Permalink
Updated default recast navmesh settings, removed blender default cube…
Browse files Browse the repository at this point in the history
…, fixed logging issue
  • Loading branch information
dbierek committed Sep 19, 2024
1 parent 952962a commit f04dc6a
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 100 deletions.
2 changes: 1 addition & 1 deletion bin/NavKit.ini
Original file line number Diff line number Diff line change
@@ -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
blender=C:\Program Files\Blender Foundation\Blender 3.4\blender.exe
119 changes: 61 additions & 58 deletions bin/glacier2obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
)
Expand Down
12 changes: 5 additions & 7 deletions include/NavKit/NavKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<rcLogCategory, std::string>> logQueue;
void loadSettings();
rsj::ConcurrentQueue<std::pair<rcLogCategory, std::string>> logQueue;
void loadSettings();

static void logRunner(NavKit* navKit);

CSimpleIniA ini;
static void logRunner(NavKit* navKit);
};

2 changes: 1 addition & 1 deletion src/GameConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
11 changes: 3 additions & 8 deletions src/NavKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,17 @@ void NavKit::log(rcLogCategory category, const char* message, ...) {
void NavKit::logRunner(NavKit* navKit) {
std::optional<std::pair<rcLogCategory, std::string>> 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() {
Expand Down
6 changes: 4 additions & 2 deletions src/Navp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
}
Expand Down Expand Up @@ -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");
Expand All @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

}

Expand Down Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions src/RecastDemo/Sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
46 changes: 33 additions & 13 deletions src/SceneExtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit f04dc6a

Please sign in to comment.