Skip to content

Commit b3b92e0

Browse files
authored
Extract and apply diffuse textures (#80)
1 parent 6831243 commit b3b92e0

34 files changed

Lines changed: 738 additions & 175 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_policy(SET CMP0141 NEW)
33
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<CONFIG:Debug>,EditAndContinue,ProgramDatabase>" CACHE STRING "MSVC debug information format")
44
project(
55
NavKit
6-
VERSION 2.10.0
6+
VERSION 2.11.0
77
DESCRIPTION "An app to create NAVP and AIRG files for use with Hitman: World of Assassination"
88
LANGUAGES CXX)
99
set(CMAKE_CXX_STANDARD 20)

include/NavKit/NavKitConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#define NavKit_VERSION_MAJOR "2"
2-
#define NavKit_VERSION_MINOR "10"
2+
#define NavKit_VERSION_MINOR "11"
33
#define NavKit_VERSION_PATCH "0"

include/NavKit/Resource.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
#define IDC_STATIC_TILING_INFO_MAX_TILES 30336
134134
#define IDC_STATIC_TILING_INFO_MAX_POLYS 30337
135135

136-
#define IDD_OBJ_SETTINGS 30400
136+
#define IDD_SCENE_MESH_SETTINGS 30400
137137
#define IDC_RADIO_MESH_TYPE_ALOC 30401
138138
#define IDC_RADIO_MESH_TYPE_PRIM 30402
139139
#define IDC_CHECK_PRIM_LOD_1 30403
@@ -149,6 +149,8 @@
149149
#define IDC_CHECK_FILTER_TO_INCLUDE_BOX 30413
150150
#define IDC_CHECK_SKIP_RPKG_EXTRACT 30414
151151
#define IDC_CHECK_SHOW_BLENDER_DEBUG_LOGS 30415
152+
#define IDC_CHECK_EXTRACT_TEXTURE_FILES 30416
153+
#define IDC_CHECK_APPLY_TEXTURES 30417
152154

153155
#define IDD_EXTRACT_NAVP_DIALOG 30500
154156
#define IDC_COMBOBOX_NAVP 30501

include/NavKit/adapter/RecastAdapter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
struct ConvexVolume;
1616

17-
namespace ZPathfinding {
17+
namespace Json {
1818
class Vec3;
1919
class PfBox;
2020
}
@@ -93,7 +93,7 @@ class RecastAdapter {
9393

9494
std::deque<std::string> &getLogBuffer() const;
9595

96-
void addConvexVolume(ZPathfinding::PfBox &pfBox) const;
96+
void addConvexVolume(Json::PfBox &pfBox) const;
9797

9898
[[nodiscard]] const ConvexVolume *getConvexVolumes() const;
9999

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#pragma once
22

33
#include <filesystem>
4+
#include <map>
45
#include <string>
56
#include <vector>
67
#include "../../../extern/simdjson/simdjson.h"
78

8-
namespace ZPathfinding {
9+
namespace Json {
910
class Vec3 {
1011
public:
1112
Vec3(): x(0), y(0), z(0) {
@@ -190,4 +191,53 @@ namespace ZPathfinding {
190191

191192
std::vector<Entity> entities{};
192193
};
194+
195+
class Mati {
196+
public:
197+
Mati() = default;
198+
199+
void readJsonFromMatiFile(simdjson::simdjson_result<simdjson::ondemand::document>& jsonDocument);
200+
201+
void readJsonFromScene(simdjson::ondemand::object jsonDocument);
202+
203+
void writeJson(std::ostream& f) const;
204+
205+
std::string hash;
206+
std::string className;
207+
std::string diffuse;
208+
std::string normal;
209+
std::string specular;
210+
};
211+
212+
class Matis {
213+
public:
214+
Matis() {
215+
}
216+
217+
Matis(simdjson::ondemand::array matisJson);
218+
219+
std::vector<Mati> matis{};
220+
};
221+
222+
class PrimMati {
223+
public:
224+
PrimMati() {
225+
226+
}
227+
std::string primHash;
228+
std::vector<std::string> matiHashes{};
229+
void readJson(simdjson::ondemand::object jsonDocument);
230+
231+
void writeJson(std::ostream& f) const;
232+
};
233+
234+
class PrimMatis {
235+
public:
236+
PrimMatis() {
237+
}
238+
239+
PrimMatis(simdjson::ondemand::array primMatisJson);
240+
241+
std::vector<PrimMati> primMatis{};
242+
};
193243
}

include/NavKit/module/Navp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <windows.h>
77
#include <GL/glew.h>
88

9-
#include "../model/ZPathfinding.h"
9+
#include "../model/Json.h"
1010

1111
struct Vec3;
1212

include/NavKit/module/Obj.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
#include <thread>
66
#include <vector>
77
#define WIN32_LEAN_AND_MEAN
8+
#include <set>
89
#include <windows.h>
910
#include <GL/glew.h>
1011

1112
#include "../../include/NavKit/render/Model.h"
1213
#include "../../include/NavKit/render/Shader.h"
14+
#include "../model/Json.h"
15+
1316
enum MeshType {
1417
ALOC,
1518
PRIM
@@ -56,18 +59,20 @@ class Obj {
5659
bool errorBuilding;
5760
bool skipExtractingAlocsOrPrims;
5861
bool errorExtracting;
59-
bool extractingAlocsOrPrims;
62+
bool extractingResources;
6063
bool doneExtractingAlocsOrPrims;
6164
std::map<std::string, std::pair<int, int> > objectTriangleRanges;
6265
bool doObjHitTest;
6366
MeshType meshTypeForBuild;
6467
SceneMeshBuildType sceneMeshBuildType;
6568
bool primLods[8];
6669
bool blendFileBuilt;
70+
bool extractTextures;
71+
bool applyTextures;
6772
static HWND hObjDialog;
6873
Model model;
6974

70-
static char *openSetBlenderFileDialog(const char *lastBlenderFile);
75+
static char *openSetBlenderFileDialog();
7176

7277
void loadSettings();
7378

@@ -137,7 +142,9 @@ class Obj {
137142

138143
std::optional<std::jthread> backgroundWorker;
139144

140-
void finalizeExtractAlocsOrPrims();
145+
void finalizeExtractResources();
146+
147+
bool shouldExtractTextures() const;
141148

142-
void extractAlocsOrPrimsAndStartObjBuild();
149+
void extractResourcesAndStartObjBuild();
143150
};

include/NavKit/module/Rpkg.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
#pragma once
2+
#include <map>
23
#include <optional>
4+
#include <set>
35
#include <string>
46
#include <thread>
7+
#include <vector>
58

69
struct PartitionManager;
10+
struct HashList;
711

812
enum ResourceType {
913
NAVP,
10-
AIRG
14+
AIRG,
15+
TEXT
16+
};
17+
18+
class HashListEntry {
19+
public:
20+
HashListEntry(const std::string& hash, const std::string& ioiString, const std::string& type) :
21+
hash(hash), ioiString(ioiString), type(type) {};
22+
23+
std::string hash;
24+
std::string ioiString;
25+
std::string type;
1126
};
1227

1328
class Rpkg {
@@ -16,11 +31,16 @@ class Rpkg {
1631

1732
static bool canExtract();
1833

19-
static int extractResourceFromRpkgs(const std::string& hash, ResourceType type);
34+
static int extractResourcesFromRpkgs(const std::vector<std::string>& hashes, ResourceType type);
35+
36+
static int getHashList();
2037

2138
static bool extractionDataInitComplete;
2239
static std::string gameVersion;
2340
static PartitionManager* partitionManager;
41+
static HashList* hashList;
42+
static std::map<std::string, HashListEntry> hashToHashListEntryMap;
43+
static std::map<std::string, HashListEntry> ioiStringToHashListEntryMap;
2444

2545
static std::optional<std::jthread> backgroundWorker;
2646
};

include/NavKit/module/Scene.h

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#pragma once
22
#include <functional>
33
#define WIN32_LEAN_AND_MEAN
4+
#include <map>
45
#include <windows.h>
5-
#include "../model/ZPathfinding.h"
6+
#include "../model/Json.h"
67

78
class Scene {
89
public:
@@ -18,26 +19,32 @@ class Scene {
1819

1920
void setLastSaveFileName(char *file_name);
2021

21-
void loadScene(const std::string &fileName, const std::function<void()> &callback,
22-
const std::function<void()> &errorCallback);
23-
24-
void saveScene(char *fileName) const;
22+
void saveScene(const std::string& fileName) const;
2523

2624
void handleOpenSceneClicked();
2725

2826
void handleSaveSceneClicked();
2927

30-
void loadMeshes(const std::function<void()> &errorCallback,
31-
simdjson::simdjson_result<simdjson::ondemand::document> &jsonDocument);
32-
33-
void loadPfBoxes(const std::function<void()> &errorCallback,
34-
simdjson::simdjson_result<simdjson::ondemand::document> &jsonDocument);
28+
void loadScene(const std::string &fileName, const std::function<void()> &callback,
29+
const std::function<void()> &errorCallback);
3530

3631
void loadVersion(
3732
simdjson::simdjson_result<simdjson::ondemand::document> &jsonDocument);
3833

34+
void loadMeshes(const std::function<void()> &errorCallback,
35+
simdjson::simdjson_result<simdjson::ondemand::document> &jsonDocument);
36+
37+
void loadPfBoxes(const std::function<void()> &errorCallback,
38+
simdjson::simdjson_result<simdjson::ondemand::document> &jsonDocument);
39+
3940
void loadPfSeedPoints(const std::function<void()> &errorCallback,
40-
simdjson::simdjson_result<simdjson::ondemand::document> &jsonDocument);
41+
simdjson::simdjson_result<simdjson::ondemand::document> &jsonDocument);
42+
43+
void loadMatis(const std::function<void()>& errorCallback,
44+
simdjson::simdjson_result<simdjson::ondemand::document>& jsonDocument);
45+
46+
void loadPrimMatis(const std::function<void()>& errorCallback,
47+
simdjson::simdjson_result<simdjson::ondemand::document>& jsonDocument);
4148

4249
void showSceneDialog();
4350

@@ -55,20 +62,23 @@ class Scene {
5562
std::string lastLoadSceneFile;
5663
bool sceneLoaded;
5764

58-
std::vector<ZPathfinding::Mesh> meshes;
59-
std::vector<ZPathfinding::Mesh> prims;
60-
ZPathfinding::PfBox includeBox;
61-
std::vector<ZPathfinding::PfBox> exclusionBoxes;
62-
std::vector<ZPathfinding::PfSeedPoint> pfSeedPoints;
65+
std::vector<Json::Mesh> meshes;
66+
std::vector<Json::Mesh> prims;
67+
Json::PfBox includeBox;
68+
std::vector<Json::PfBox> exclusionBoxes;
69+
std::vector<Json::PfSeedPoint> pfSeedPoints;
70+
std::map<std::string, Json::Mati> matis;
71+
std::map<std::string, Json::PrimMati> primMatis;
6372
std::optional<std::jthread> backgroundWorker;
6473
float bBoxPos[3]{};
6574
float bBoxScale[3]{};
6675
bool showBBox;
6776
int version;
6877
static HWND hSceneDialog;
6978

70-
const ZPathfinding::Mesh *findMeshByHashAndIdAndPos(const std::string &hash, const std::string &id, const float *pos) const;
79+
const Json::Mesh *findMeshByHashAndIdAndPos(const std::string &hash, const std::string &id, const float *pos) const;
7180

81+
static inline const std::string OUTPUT_SCENE_FILE_NAME = "output.nav.json";
7282
private:
7383
std::string loadSceneName;
7484
std::string saveSceneName;

include/NavKit/util/CommandRunner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class CommandRunner {
1414
return instance;
1515
}
1616

17-
void runCommand(std::string command, std::string logFileName, std::function<void()> callback,
18-
std::function<void()> errorCallback);
17+
void runCommand(const std::string& command, const std::string& logFileName, const std::function<void()>& callback,
18+
const std::function<void()>& errorCallback);
1919

2020
bool closing;
2121
int commandsRun;

0 commit comments

Comments
 (0)