From 530750e5d0084c96ad870d14fb73e7145ad16b60 Mon Sep 17 00:00:00 2001 From: William Fowler Date: Tue, 28 Sep 2021 12:03:50 -0600 Subject: [PATCH] Add support for 007 Nightfire normals lump --- LibBSP/Source/Extensions/VertexExtensions.cs | 16 ++++++++++++++++ LibBSP/Source/Structs/BSP/BSP.cs | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/LibBSP/Source/Extensions/VertexExtensions.cs b/LibBSP/Source/Extensions/VertexExtensions.cs index 8cb7d0a..a93d3bc 100644 --- a/LibBSP/Source/Extensions/VertexExtensions.cs +++ b/LibBSP/Source/Extensions/VertexExtensions.cs @@ -237,6 +237,22 @@ namespace LibBSP { } } + /// + /// Gets the index for the vertex normals lump in the BSP file for a specific map format. + /// + /// The map type. + /// Index for this lump, or -1 if the format doesn't have this lump. + public static int GetIndexForNormalsLump(MapType type) { + switch (type) { + case MapType.Nightfire: { + return 5; + } + default: { + return -1; + } + } + } + /// /// Gets the index for the patch vertices lump in the BSP file for a specific map format. /// diff --git a/LibBSP/Source/Structs/BSP/BSP.cs b/LibBSP/Source/Structs/BSP/BSP.cs index 35a42f7..e870af9 100644 --- a/LibBSP/Source/Structs/BSP/BSP.cs +++ b/LibBSP/Source/Structs/BSP/BSP.cs @@ -111,6 +111,7 @@ namespace LibBSP { // Nightfire private Textures _materials; private NumList _indices; + private Lump _normals; // Source private Lump _originalFaces; private NumList _texTable; @@ -208,6 +209,21 @@ namespace LibBSP { } } + /// + /// A of objects in the BSP file representing the vertex normals of the BSP, if available. + /// + public Lump normals { + get { + if (_normals == null) { + int index = VertexExtensions.GetIndexForNormalsLump(version); + if (index >= 0) { + _normals = VertexExtensions.LumpFactory(reader.ReadLump(this[index]), this, this[index]); + } + } + return _normals; + } + } + /// /// A of objects in the BSP file, if available. ///