feat: Raw reading on zone load and scene tools (#1910)

* feat: raw terrain parsing for scene data

Replace old dNavigation/dTerrain raw parser with new Raw module in
dZoneManager. Parse heightmaps, color maps, and scene maps from .raw
files to determine which scene a position belongs to. Build scene
adjacency graph from terrain data and scene transitions.

Adds NiColor type, SceneColor lookup table, eSceneType enum, terrain
mesh generation with OBJ export, and debug slash commands for scene
visualization.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor: deduplicate terrain grid lookup logic, remove unnecessary cast

Add IsValidForSceneLookup(), GetSceneIDAtGrid(), and GridToWorldPos()
to Raw::Chunk. Use them in GenerateTerrainMesh, GetSceneIDFromPosition,
SpawnScenePoints, and SpawnAllScenePoints instead of duplicated inline
math. Remove unnecessary static_cast in LoadSceneTransitionInfo.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: add version < 32 support to raw terrain parser

The parser was only correct for v32 files. For v<32:
- colorMapResolution is width-1, not width
- Color map reads width*width*4 bytes (BGRA per-pixel), not colorMapRes^2*4
- No DDS lightmap
- No texture settings byte or blend DDS
- Scene map: v31 reads (colorMapRes+1)^2 cells with border skip,
  v<31 skips 1 byte
- No mesh data

Verified against all 309 .raw files across multiple client versions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: log and reject legacy raw terrain format, clean up ReadRaw API

Log a clear message and throw if the zone uses a legacy raw format
(LUZ version < 30) since no known maps use it. Remove ReadLegacyRaw
and the mapVersion parameter from ReadRaw.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: revert v33 scene field renames to unknown1/unknown2

These fields are skipped by the client in every known build (ptr += 12
and ptr += 4). No client ever reads them into a struct. Keep the
original unknown1/unknown2 names from main.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: load the zone without scene lookups when its raw terrain is missing or unreadable

Log at debug when it parses; build the terrain mesh only for the OBJ export; read the zone name and description only for version 31 and later, as the client does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: look up the scene at a position as the client does, in constant time

Chunk bounds span (width - 1) * scale; the nearest scene map cell is used and the far edge is kept one cell inside. Chunks are indexed by grid cell when they form a grid. Skipping reads instead of seeking, so a cut-off file can't seek past the end. Terrain mesh indices follow the vertex order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: scene point commands take a step and use brick LOTs from the BrickIDTable

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: rename NiColor::ToXYZ to Luminance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: raw terrain reading, scene lookup, scene graph and scene commands

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: close the OBJ file before removing it so the test passes on Windows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep the zone boundary lines and read the luz scene count as the client does

Each boundary line's destination is read as a map ID and an instance ID into a LWOZONEID. The scene count is a byte before version 37 and a u32 from it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: name the fourth flair colour byte padding

The client never sets or reads it, so it holds leftover memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep the scene map of version 31 and older raws

These files have a (resolution + 1)^2 scene map, kept in sceneMapLegacy. Version 31 uses its first resolution rows and columns; older versions are all scene 0, as in the client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor: simplify the raw heightmap size check

The dimensions are capped at kMaxResolution, so the product can't overflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: remove the scene point spawn commands and send /getadjacentscenes as one message

The spawn commands were only for testing. /getscene and /getadjacentscenes stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-10-27 09:22:28 -05:00
committed by GitHub
parent fc6a7fbd52
commit 9bf2ff4d44
29 changed files with 2102 additions and 315 deletions

View File

@@ -0,0 +1,166 @@
#ifndef SCENE_COLOR_H
#define SCENE_COLOR_H
#include "NiColor.h"
#include <array>
#include <cstdint>
namespace SceneColor {
// these are not random values, they are the actual template colors used by the game
static constexpr std::array<NiColor, 146> TEMPLATE_COLORS = {{
{ 0.5019608f, 0.5019608f, 0.5019608f },
{ 1.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, 0.0f },
{ 1.0f, 0.0f, 1.0f },
{ 0.0f, 1.0f, 1.0f },
{ 0.5019608f, 0.0f, 1.0f },
{ 1.0f, 0.5019608f, 0.0f },
{ 1.0f, 0.5019608f, 0.5019608f },
{ 0.5019608f, 0.2509804f, 0.0f },
{ 0.5019608f, 0.0f, 0.2509804f },
{ 0.0f, 0.5019608f, 0.2509804f },
{ 0.2509804f, 0.0f, 0.5019608f },
{ 0.8745098f, 0.0f, 0.2509804f },
{ 0.2509804f, 0.8745098f, 0.5019608f },
{ 1.0f, 0.7490196f, 0.0f },
{ 1.0f, 0.2509804f, 0.0627451f },
{ 0.2509804f, 0.0f, 0.8745098f },
{ 0.7490196f, 0.0627451f, 0.0627451f },
{ 0.0627451f, 0.7490196f, 0.0627451f },
{ 1.0f, 0.5019608f, 1.0f },
{ 0.9372549f, 0.8705882f, 0.8039216f },
{ 0.8039216f, 0.5843138f, 0.4588235f },
{ 0.9921569f, 0.8509804f, 0.7098039f },
{ 0.4705882f, 0.8588235f, 0.8862745f },
{ 0.5294118f, 0.6627451f, 0.4196078f },
{ 1.0f, 0.6431373f, 0.454902f },
{ 0.9803922f, 0.9058824f, 0.7098039f },
{ 0.6235294f, 0.5058824f, 0.4392157f },
{ 0.9921569f, 0.4862745f, 0.4313726f },
{ 0.0f, 0.0f, 0.0f },
{ 0.6745098f, 0.8980392f, 0.9333333f },
{ 0.1215686f, 0.4588235f, 0.9960784f },
{ 0.6352941f, 0.6352941f, 0.8156863f },
{ 0.4f, 0.6f, 0.8f },
{ 0.05098039f, 0.5960785f, 0.7294118f },
{ 0.4509804f, 0.4f, 0.7411765f },
{ 0.8705882f, 0.3647059f, 0.5137255f },
{ 0.7960784f, 0.254902f, 0.3294118f },
{ 0.7058824f, 0.4039216f, 0.3019608f },
{ 1.0f, 0.4980392f, 0.2862745f },
{ 0.9176471f, 0.4941176f, 0.3647059f },
{ 0.6901961f, 0.7176471f, 0.7764706f },
{ 1.0f, 1.0f, 0.6f },
{ 0.1098039f, 0.827451f, 0.6352941f },
{ 1.0f, 0.6666667f, 0.8f },
{ 0.8666667f, 0.2666667f, 0.572549f },
{ 0.1137255f, 0.6745098f, 0.8392157f },
{ 0.7372549f, 0.3647059f, 0.345098f },
{ 0.8666667f, 0.5803922f, 0.4588235f },
{ 0.6039216f, 0.8078431f, 0.9215686f },
{ 1.0f, 0.7372549f, 0.8509804f },
{ 0.9921569f, 0.8588235f, 0.427451f },
{ 0.1686275f, 0.4235294f, 0.7686275f },
{ 0.9372549f, 0.8039216f, 0.7215686f },
{ 0.4313726f, 0.3176471f, 0.3764706f },
{ 0.8078431f, 1.0f, 0.1137255f },
{ 0.427451f, 0.682353f, 0.5058824f },
{ 0.7647059f, 0.3921569f, 0.772549f },
{ 0.8f, 0.4f, 0.4f },
{ 0.9058824f, 0.7764706f, 0.5921569f },
{ 0.9882353f, 0.8509804f, 0.4588235f },
{ 0.6588235f, 0.8941177f, 0.627451f },
{ 0.5843138f, 0.5686275f, 0.5490196f },
{ 0.1098039f, 0.6745098f, 0.4705882f },
{ 0.06666667f, 0.3921569f, 0.7058824f },
{ 0.9411765f, 0.9098039f, 0.5686275f },
{ 1.0f, 0.1137255f, 0.8078431f },
{ 0.6980392f, 0.9254902f, 0.3647059f },
{ 0.3647059f, 0.4627451f, 0.7960784f },
{ 0.7921569f, 0.2156863f, 0.4039216f },
{ 0.2313726f, 0.6901961f, 0.5607843f },
{ 0.9882353f, 0.7058824f, 0.8352941f },
{ 1.0f, 0.9568627f, 0.3098039f },
{ 1.0f, 0.7411765f, 0.5333334f },
{ 0.9647059f, 0.3921569f, 0.6862745f },
{ 0.6666667f, 0.9411765f, 0.8196079f },
{ 0.8039216f, 0.2901961f, 0.2980392f },
{ 0.9294118f, 0.8196079f, 0.6117647f },
{ 0.5921569f, 0.6039216f, 0.6666667f },
{ 0.7843137f, 0.2196078f, 0.3529412f },
{ 0.9372549f, 0.5960785f, 0.6666667f },
{ 0.9921569f, 0.7372549f, 0.7058824f },
{ 0.1019608f, 0.282353f, 0.4627451f },
{ 0.1882353f, 0.7294118f, 0.5607843f },
{ 0.772549f, 0.2941177f, 0.5490196f },
{ 0.09803922f, 0.454902f, 0.8235294f },
{ 0.7294118f, 0.7215686f, 0.4235294f },
{ 1.0f, 0.4588235f, 0.2196078f },
{ 1.0f, 0.1686275f, 0.1686275f },
{ 0.972549f, 0.8352941f, 0.4078431f },
{ 0.9019608f, 0.6588235f, 0.8431373f },
{ 0.254902f, 0.2901961f, 0.2980392f },
{ 1.0f, 0.4313726f, 0.2901961f },
{ 0.1098039f, 0.6627451f, 0.7882353f },
{ 1.0f, 0.8117647f, 0.6705883f },
{ 0.772549f, 0.8156863f, 0.9019608f },
{ 0.9921569f, 0.8666667f, 0.9019608f },
{ 0.08235294f, 0.5019608f, 0.4705882f },
{ 0.9882353f, 0.454902f, 0.9921569f },
{ 0.9686275f, 0.5607843f, 0.654902f },
{ 0.5568628f, 0.2705882f, 0.5215687f },
{ 0.454902f, 0.2588235f, 0.7843137f },
{ 0.6156863f, 0.5058824f, 0.7294118f },
{ 1.0f, 0.2862745f, 0.4235294f },
{ 0.8392157f, 0.5411765f, 0.3490196f },
{ 0.4431373f, 0.2941177f, 0.1372549f },
{ 1.0f, 0.282353f, 0.8156863f },
{ 0.9333333f, 0.1254902f, 0.3019608f },
{ 1.0f, 0.3254902f, 0.2862745f },
{ 0.7529412f, 0.2666667f, 0.5607843f },
{ 0.1215686f, 0.8078431f, 0.7960784f },
{ 0.4705882f, 0.3176471f, 0.6627451f },
{ 1.0f, 0.6078432f, 0.6666667f },
{ 0.9882353f, 0.1568628f, 0.2784314f },
{ 0.4627451f, 1.0f, 0.4784314f },
{ 0.6235294f, 0.8862745f, 0.7490196f },
{ 0.6470588f, 0.4117647f, 0.3098039f },
{ 0.5411765f, 0.4745098f, 0.3647059f },
{ 0.2705882f, 0.8078431f, 0.6352941f },
{ 0.8039216f, 0.772549f, 0.7607843f },
{ 0.5019608f, 0.854902f, 0.9215686f },
{ 0.9254902f, 0.9176471f, 0.7450981f },
{ 1.0f, 0.8117647f, 0.282353f },
{ 0.9921569f, 0.3686275f, 0.3254902f },
{ 0.9803922f, 0.654902f, 0.4235294f },
{ 0.09411765f, 0.654902f, 0.7098039f },
{ 0.9215686f, 0.7803922f, 0.8745098f },
{ 0.9882353f, 0.5372549f, 0.6745098f },
{ 0.8588235f, 0.8431373f, 0.8235294f },
{ 0.8705882f, 0.6666667f, 0.5333334f },
{ 0.4666667f, 0.8666667f, 0.9058824f },
{ 1.0f, 1.0f, 0.4f },
{ 0.572549f, 0.4313726f, 0.682353f },
{ 0.1960784f, 0.2901961f, 0.6980392f },
{ 0.9686275f, 0.3254902f, 0.5803922f },
{ 1.0f, 0.627451f, 0.5372549f },
{ 0.5607843f, 0.3137255f, 0.6156863f },
{ 1.0f, 1.0f, 1.0f },
{ 0.6352941f, 0.6784314f, 0.8156863f },
{ 0.9882353f, 0.4235294f, 0.5215687f },
{ 0.8039216f, 0.6431373f, 0.8705882f },
{ 0.9882353f, 0.9098039f, 0.5137255f },
{ 0.772549f, 0.8901961f, 0.5176471f },
{ 1.0f, 0.682353f, 0.2588235f },
}};
static constexpr NiColor FALLBACK_COLOR{ 1.0f, 1.0f, 1.0f };
inline const NiColor& Get(uint8_t index) {
return (index < TEMPLATE_COLORS.size()) ? TEMPLATE_COLORS[index] : FALLBACK_COLOR;
}
} // namespace SceneColor
#endif // SCENE_COLOR_H