Skip to content

Commit b5182bc

Browse files
committed
Use normals from file, bump version to 2.12.2
1 parent c1896d7 commit b5182bc

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

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.12.1
6+
VERSION 2.12.2
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"
22
#define NavKit_VERSION_MINOR "12"
3-
#define NavKit_VERSION_PATCH "1"
3+
#define NavKit_VERSION_PATCH "2"

src/resource/glacier2obj.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,17 +1289,25 @@ def load_prim_mesh(prim, prim_name: str, mesh_index: int, load_textures=True):
12891289
mesh = bpy.data.meshes.new(name=(str(prim_name) + "_" + str(mesh_index)))
12901290

12911291
vert_locs = []
1292-
loop_vidxs = []
1292+
loop_normals = []
12931293
loop_cols = []
12941294

12951295
material_index = prim.header.object_table[mesh_index].prim_object.material_id
12961296
sub_mesh = prim.header.object_table[mesh_index].sub_mesh
12971297

12981298
loop_uvs = [[] for _ in range(sub_mesh.num_uvchannels)]
1299-
loop_vidxs.extend(sub_mesh.indices)
13001299

1301-
for i, vert in enumerate(sub_mesh.vertexBuffer.vertices):
1302-
vert_locs.extend([vert.position[0], vert.position[1], vert.position[2]])
1300+
unique_verts = {}
1301+
remap = []
1302+
1303+
for vert in sub_mesh.vertexBuffer.vertices:
1304+
pos = (vert.position[0], vert.position[1], vert.position[2])
1305+
if pos not in unique_verts:
1306+
unique_verts[pos] = len(vert_locs) // 3
1307+
vert_locs.extend(pos)
1308+
remap.append(unique_verts[pos])
1309+
1310+
loop_vidxs = [remap[i] for i in sub_mesh.indices]
13031311

13041312
mesh.vertices.add(len(vert_locs) // 3)
13051313
mesh.vertices.foreach_set("co", vert_locs)
@@ -1315,9 +1323,10 @@ def load_prim_mesh(prim, prim_name: str, mesh_index: int, load_textures=True):
13151323
mesh.polygons.foreach_set("loop_start", loop_starts)
13161324
mesh.polygons.foreach_set("loop_total", loop_totals)
13171325

1318-
if load_textures:
1319-
for index in sub_mesh.indices:
1320-
vert = sub_mesh.vertexBuffer.vertices[index]
1326+
for index in sub_mesh.indices:
1327+
vert = sub_mesh.vertexBuffer.vertices[index]
1328+
loop_normals.append((vert.normal[0], vert.normal[1], vert.normal[2]))
1329+
if load_textures:
13211330
loop_cols.extend(
13221331
[
13231332
vert.color[0] / 255,
@@ -1329,6 +1338,7 @@ def load_prim_mesh(prim, prim_name: str, mesh_index: int, load_textures=True):
13291338
for uv_i in range(sub_mesh.num_uvchannels):
13301339
loop_uvs[uv_i].extend([vert.uv[uv_i][0], 1 - vert.uv[uv_i][1]])
13311340

1341+
if load_textures:
13321342
for uv_i in range(sub_mesh.num_uvchannels):
13331343
name = "UVMap" if uv_i == 0 else "UVMap.%03d" % uv_i
13341344
layer = mesh.uv_layers.new(name=name)
@@ -1337,7 +1347,13 @@ def load_prim_mesh(prim, prim_name: str, mesh_index: int, load_textures=True):
13371347
layer = mesh.vertex_colors.new(name="Col")
13381348
mesh.color_attributes[layer.name].data.foreach_set("color", loop_cols)
13391349

1340-
mesh.polygons.foreach_set("use_smooth", [False] * len(mesh.polygons))
1350+
mesh.update()
1351+
1352+
mesh.normals_split_custom_set(loop_normals)
1353+
if bpy.app.version < (4, 1, 0):
1354+
mesh.use_auto_smooth = True
1355+
1356+
mesh.polygons.foreach_set("use_smooth", [True] * len(mesh.polygons))
13411357

13421358
mesh.validate()
13431359
mesh.update()
@@ -2086,7 +2102,7 @@ def convex_hull(bm):
20862102
bmesh.ops.convex_hull(bm, input=bm.verts)
20872103

20882104

2089-
def finalize_mesh(bm, obj):
2105+
def finalize_aloc_mesh(bm, obj):
20902106
bm.to_mesh(obj.data)
20912107
obj.data.polygons.foreach_set("use_smooth", [False] * len(obj.data.polygons))
20922108
bm.free()
@@ -2269,7 +2285,7 @@ def load_aloc(filepath):
22692285
log("ERROR", "Unknown data type: " + str(aloc.data_type) + " for Mesh ALOC " + aloc_name, "load_aloc")
22702286
return -1, []
22712287

2272-
finalize_mesh(bm, aloc_obj)
2288+
finalize_aloc_mesh(bm, aloc_obj)
22732289
log("DEBUG", "Finished converting ALOC: " + aloc_name + " to blender mesh.", aloc_name)
22742290
return aloc, [aloc_obj]
22752291

0 commit comments

Comments
 (0)